Skip to content

Commit

Permalink
24w12a
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed Mar 21, 2024
1 parent 89d06c1 commit 3d229ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=24w09a
minecraft_version=24w12a
loader_version=0.15.7

# Mod Properties
mod_version=1.7.0-beta1
mod_version=1.7.0-beta2
maven_group=io.github.misode
archives_base_name=packtest

# Dependencies
fabric_version=0.96.6+1.20.5
fabric_version=0.96.12+1.20.5
23 changes: 11 additions & 12 deletions src/main/java/io/github/misode/packtest/commands/AssertCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
import net.minecraft.commands.execution.ExecutionControl;
import net.minecraft.commands.execution.Frame;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.ReloadableServerRegistries;
import net.minecraft.server.commands.data.DataCommands;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.state.pattern.BlockInWorld;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootDataManager;
import net.minecraft.world.level.storage.loot.LootDataType;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
Expand Down Expand Up @@ -62,8 +62,8 @@ public class AssertCommand {
Component.literal("Not inside a test")
);
private static final SuggestionProvider<CommandSourceStack> SUGGEST_PREDICATE = (ctx, suggestions) -> {
LootDataManager lootData = ctx.getSource().getServer().getLootData();
return SharedSuggestionProvider.suggestResource(lootData.getKeys(LootDataType.PREDICATE), suggestions);
ReloadableServerRegistries.Holder registries = ctx.getSource().getServer().reloadableRegistries();
return SharedSuggestionProvider.suggestResource(registries.getKeys(Registries.PREDICATE), suggestions);
};

public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext buildContext) {
Expand All @@ -89,7 +89,7 @@ public static void addConditions(LiteralArgumentBuilder<CommandSourceStack> buil
.then(literal("inside")
.executes(expect.apply(AssertCommand::assertEntityInside)))))
.then(literal("predicate")
.then(argument("predicate", ResourceLocationArgument.id())
.then(argument("predicate", ResourceOrIdArgument.lootPredicate(buildContext))
.suggests(SUGGEST_PREDICATE)
.executes(expect.apply(AssertCommand::assertPredicate))))
.then(literal("score")
Expand Down Expand Up @@ -161,18 +161,17 @@ private static AssertResult assertEntityInside(CommandContext<CommandSourceStack
return err(source + " inside test");
}

private static AssertResult assertPredicate(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
ResourceLocation id = ctx.getArgument("predicate", ResourceLocation.class);
LootItemCondition predicate = ResourceLocationArgument.getPredicate(ctx, "predicate");
private static AssertResult assertPredicate(CommandContext<CommandSourceStack> ctx) {
Holder<LootItemCondition> predicate = ResourceOrIdArgument.getLootPredicate(ctx, "predicate");
CommandSourceStack sourceStack = ctx.getSource();
LootParams lootParams = new LootParams.Builder(sourceStack.getLevel())
.withParameter(LootContextParams.ORIGIN, sourceStack.getPosition())
.withOptionalParameter(LootContextParams.THIS_ENTITY, sourceStack.getEntity())
.create(LootContextParamSets.COMMAND);
LootContext lootContext = new LootContext.Builder(lootParams).create(Optional.empty());
lootContext.pushVisitedElement(LootContext.createVisitedEntry(predicate));
String expected = "predicate " + id + " to pass";
if (predicate.test(lootContext)) {
lootContext.pushVisitedElement(LootContext.createVisitedEntry(predicate.value()));
String expected = "predicate " + predicate.getRegisteredName() + " to pass";
if (predicate.value().test(lootContext)) {
return ok(expected);
}
return err(expected);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"accessWidener": "packtest.accesswidener",
"depends": {
"fabricloader": ">=0.15.0",
"minecraft": "~1.20.4",
"minecraft": ">=1.20.5-",
"java": ">=17",
"fabric-api": "*"
}
Expand Down

0 comments on commit 3d229ab

Please sign in to comment.