Skip to content

Commit

Permalink
Reintroduce test mixins & a command that shows non-categorized features
Browse files Browse the repository at this point in the history
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
Pixaurora committed Dec 6, 2023
1 parent 371dfed commit 9080bc6
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 14 deletions.
44 changes: 44 additions & 0 deletions src/main/java/net/pixaurora/janerator/TestMixinConfig.java
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) {
}
}
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;
}
}
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);
}
}
26 changes: 13 additions & 13 deletions src/main/resources/janerator.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
"package": "net.pixaurora.janerator.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"ChunkAccessMixin",
"ChunkGeneratorMixin",
"ChunkGeneratorsMixin",
"ChunkStatusMixin",
"LevelChunkSectionMixin",
"MinecraftServerMixin",
"NoiseBasedChunkGeneratorAccessor",
"NoiseBasedChunkGeneratorMixin",
"NoiseChunkAccessor",
"PlacedFeatureMixin",
"ProtoChunkMixin"
],
"ChunkAccessMixin",
"ChunkGeneratorMixin",
"ChunkGeneratorsMixin",
"ChunkStatusMixin",
"LevelChunkSectionMixin",
"MinecraftServerMixin",
"NoiseBasedChunkGeneratorAccessor",
"NoiseBasedChunkGeneratorMixin",
"NoiseChunkAccessor",
"PlacedFeatureMixin",
"ProtoChunkMixin"
],
"injectors": {
"defaultRequire": 1
}
}
}
13 changes: 13 additions & 0 deletions src/main/resources/janerator.test.mixins.json
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"
}
3 changes: 2 additions & 1 deletion src/main/resources/quilt.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
]
},
"mixin": [
"janerator.mixins.json"
"janerator.mixins.json",
"janerator.test.mixins.json"
],
"quilt_loom": {
"injected_interfaces": {
Expand Down

0 comments on commit 9080bc6

Please sign in to comment.