generated from QuiltMC/quilt-template-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reintroduce test mixins & a command that shows non-categorized features
While removed in 029b832 because a lambda was broken, there is now again a use for this since a high coverage of all features across all categories is a nice goal, and this will make it easy to see if anything gets added in future snapshots.
- Loading branch information
Showing
6 changed files
with
152 additions
and
14 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/main/java/net/pixaurora/janerator/TestMixinConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package net.pixaurora.janerator; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.quiltmc.loader.api.QuiltLoader; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo; | ||
|
||
public class TestMixinConfig implements IMixinConfigPlugin { | ||
@Override | ||
public void onLoad(String mixinPackage) { | ||
} | ||
|
||
@Override | ||
public String getRefMapperConfig() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { | ||
return QuiltLoader.isDevelopmentEnvironment(); | ||
} | ||
|
||
@Override | ||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public List<String> getMixins() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { | ||
} | ||
|
||
@Override | ||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/net/pixaurora/janerator/command/HandpickedFeatureCoverageCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.pixaurora.janerator.command; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
|
||
import net.minecraft.commands.CommandBuildContext; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.core.RegistryAccess; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; | ||
import net.pixaurora.janerator.worldgen.feature.HandpickedFeatureCategory; | ||
|
||
import static net.minecraft.commands.Commands.literal; | ||
|
||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
public class HandpickedFeatureCoverageCommand { | ||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext buildContext) { | ||
dispatcher.register( | ||
literal("report-feature-coverage") | ||
.requires(source -> source.hasPermission(2)) | ||
.requires(CommandSourceStack::isPlayer) | ||
.executes(commandContext -> printBlocks(commandContext.getSource())) | ||
); | ||
} | ||
|
||
public static int printBlocks(CommandSourceStack source) { | ||
RegistryAccess registry = source.registryAccess(); | ||
|
||
List<ResourceKey<ConfiguredFeature<?, ?>>> coveredFeatures = Stream.of(HandpickedFeatureCategory.values()) | ||
.flatMap(category -> category.includedFeatures().stream()) | ||
.toList(); | ||
|
||
List<String> missingFeatures = registry.lookupOrThrow(Registries.CONFIGURED_FEATURE).listElementIds() | ||
.filter(feature -> !coveredFeatures.contains(feature)) | ||
.map(ResourceKey::location) | ||
.map(ResourceLocation::getPath) | ||
.toList(); | ||
|
||
int amountMissing = missingFeatures.size(); | ||
|
||
source.sendSuccess(() -> Component.literal(String.format("%d features that were found missing from handpicked categories!", amountMissing)), false); | ||
|
||
if (amountMissing > 0) { | ||
source.sendSuccess(() -> Component.literal(String.join(", ", missingFeatures)), false); | ||
} | ||
|
||
return 1; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/net/pixaurora/janerator/mixin/test/CommandsMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.pixaurora.janerator.mixin.test; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
|
||
import net.minecraft.commands.CommandBuildContext; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.commands.Commands; | ||
import net.pixaurora.janerator.command.HandpickedFeatureCoverageCommand; | ||
|
||
@Mixin(Commands.class) | ||
public class CommandsMixin { | ||
@Shadow | ||
@Final | ||
private CommandDispatcher<CommandSourceStack> dispatcher; | ||
|
||
@Inject(method = "<init>", at = @At("RETURN")) | ||
private void onRegister(Commands.CommandSelection selection, CommandBuildContext buildContext, CallbackInfo ci) { | ||
HandpickedFeatureCoverageCommand.register(this.dispatcher, buildContext); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"required": true, | ||
"minVersion": "0.8", | ||
"package": "net.pixaurora.janerator.mixin.test", | ||
"compatibilityLevel": "JAVA_17", | ||
"mixins": [ | ||
"CommandsMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
}, | ||
"plugin": "net.pixaurora.janerator.TestMixinConfig" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters