|
39 | 39 | import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; |
40 | 40 | import net.minecraft.world.level.storage.loot.parameters.LootContextParams; |
41 | 41 | import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; |
| 42 | +import net.minecraft.world.phys.AABB; |
42 | 43 | import net.minecraft.world.scores.Objective; |
43 | 44 | import net.minecraft.world.scores.ReadOnlyScoreInfo; |
44 | 45 | import net.minecraft.world.scores.ScoreHolder; |
@@ -84,7 +85,9 @@ public static void addConditions(LiteralArgumentBuilder<CommandSourceStack> buil |
84 | 85 | .then(literal("data")) |
85 | 86 | .then(literal("entity") |
86 | 87 | .then(argument("entities", EntityArgument.entities()) |
87 | | - .executes(expect.apply(AssertCommand::assertEntity)))) |
| 88 | + .executes(expect.apply(AssertCommand::assertEntity)) |
| 89 | + .then(literal("inside") |
| 90 | + .executes(expect.apply(AssertCommand::assertEntityInside))))) |
88 | 91 | .then(literal("predicate") |
89 | 92 | .then(argument("predicate", ResourceLocationArgument.id()) |
90 | 93 | .suggests(SUGGEST_PREDICATE) |
@@ -130,15 +133,34 @@ private static AssertResult assertBlock(CommandContext<CommandSourceStack> ctx) |
130 | 133 | private static AssertResult assertEntity(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException { |
131 | 134 | EntitySelector selector = ctx.getArgument("entities", EntitySelector.class); |
132 | 135 | String source = ((PackTestArgumentSource)selector).packtest$getSource(); |
133 | | - Collection<? extends Entity> entities = selector.findEntities(ctx.getSource()); |
| 136 | + List<? extends Entity> entities = selector.findEntities(ctx.getSource()); |
134 | 137 | if (!entities.isEmpty()) { |
135 | 138 | Entity firstEntity = entities.stream().findFirst().orElseThrow(); |
136 | 139 | String firstName = Objects.requireNonNull(firstEntity.getDisplayName()).getString(); |
137 | | - return ok(source, firstName + (entities.size() <= 1 ? "" : " and " + (entities.size() - 1) + " more")); |
| 140 | + return ok(source, firstName + (entities.size() == 1 ? "" : " and " + (entities.size() - 1) + " more")); |
138 | 141 | } |
139 | 142 | return err(source); |
140 | 143 | } |
141 | 144 |
|
| 145 | + private static AssertResult assertEntityInside(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException { |
| 146 | + EntitySelector selector = ctx.getArgument("entities", EntitySelector.class); |
| 147 | + String source = ((PackTestArgumentSource)selector).packtest$getSource(); |
| 148 | + GameTestHelper helper = ((PackTestSourceStack)ctx.getSource()).packtest$getHelper(); |
| 149 | + if (helper == null) { |
| 150 | + throw ERROR_NO_HELPER.create(); |
| 151 | + } |
| 152 | + AABB bounds = helper.getBounds().inflate(1); |
| 153 | + List<? extends Entity> entities = selector.findEntities(ctx.getSource()).stream() |
| 154 | + .filter(entity -> bounds.contains(entity.position())) |
| 155 | + .toList(); |
| 156 | + if (!entities.isEmpty()) { |
| 157 | + Entity firstEntity = entities.stream().findFirst().orElseThrow(); |
| 158 | + String firstName = Objects.requireNonNull(firstEntity.getDisplayName()).getString(); |
| 159 | + return ok(source + " inside test", firstName + (entities.size() == 1 ? "" : " and " + (entities.size() - 1) + " more")); |
| 160 | + } |
| 161 | + return err(source + " inside test"); |
| 162 | + } |
| 163 | + |
142 | 164 | private static AssertResult assertPredicate(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException { |
143 | 165 | ResourceLocation id = ctx.getArgument("predicate", ResourceLocation.class); |
144 | 166 | LootItemCondition predicate = ResourceLocationArgument.getPredicate(ctx, "predicate"); |
|
0 commit comments