Skip to content

Commit fd09815

Browse files
committed
25w03a
1 parent c241594 commit fd09815

18 files changed

+100
-39
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
33

44
# Fabric Properties
55
# check https://fabricmc.net/develop/
6-
minecraft_version=25w02a
6+
minecraft_version=25w03a
77
loader_version=0.16.10
88
jsr305_version=3.0.2
99
fabric_version=0.110.5+1.21.4

src/main/java/carpet/commands/PerimeterInfoCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private static int perimeterDiagnose(CommandSourceStack source, BlockPos pos, St
5656
{
5757
nbttagcompound.putString("id", mobId);
5858
Entity baseEntity = EntityType.loadEntityRecursive(nbttagcompound, source.getLevel(), EntitySpawnReason.COMMAND, (entity_1x) -> {
59-
entity_1x.moveTo(new BlockPos(pos.getX(), source.getLevel().getMinY()-10, pos.getZ()), entity_1x.getYRot(), entity_1x. getXRot());
59+
entity_1x.snapTo(new BlockPos(pos.getX(), source.getLevel().getMinY()-10, pos.getZ()), entity_1x.getYRot(), entity_1x. getXRot());
6060
return !source.getLevel().addWithUUID(entity_1x) ? null : entity_1x;
6161
});
6262
if (!(baseEntity instanceof Mob))

src/main/java/carpet/mixins/ExperienceOrb_xpNoCooldownMixin.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ public abstract class ExperienceOrb_xpNoCooldownMixin extends Entity
1919
@Shadow
2020
private int count;
2121

22-
@Shadow
23-
private int value;
24-
2522
public ExperienceOrb_xpNoCooldownMixin(EntityType<?> type, Level world)
2623
{
2724
super(type, world);
@@ -30,13 +27,15 @@ public ExperienceOrb_xpNoCooldownMixin(EntityType<?> type, Level world)
3027
@Shadow
3128
protected abstract int repairPlayerItems(ServerPlayer player, int amount);
3229

30+
@Shadow public abstract int getValue();
31+
3332
@Inject(method = "playerTouch", at = @At("HEAD"))
3433
private void addXP(Player player, CallbackInfo ci) {
3534
if (CarpetSettings.xpNoCooldown && !level().isClientSide) {
3635
player.takeXpDelay = 0;
3736
// reducing the count to 1 and leaving vanilla to deal with it
3837
while (this.count > 1) {
39-
int remainder = this.repairPlayerItems((ServerPlayer) player, this.value);
38+
int remainder = this.repairPlayerItems((ServerPlayer) player, this.getValue());
4039
if (remainder > 0) {
4140
player.giveExperiencePoints(remainder);
4241
}

src/main/java/carpet/mixins/Guardian_renewableSpongesMixin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void thunderHit(ServerLevel serverWorld, LightningBolt lightningEntity)
2525
if (!this.level().isClientSide && !this.isRemoved() && CarpetSettings.renewableSponges && !((Object)this instanceof ElderGuardian))
2626
{
2727
ElderGuardian elderGuardian = new ElderGuardian(EntityType.ELDER_GUARDIAN ,this.level());
28-
elderGuardian.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot());
28+
elderGuardian.snapTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot());
2929
elderGuardian.finalizeSpawn(serverWorld ,this.level().getCurrentDifficultyAt(elderGuardian.blockPosition()), EntitySpawnReason.CONVERSION, null);
3030
elderGuardian.setNoAi(this.isNoAi());
3131

src/main/java/carpet/mixins/LevelChunk_fillUpdatesMixin.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ private void onAdded(BlockState blockState, Level world_1, BlockPos blockPos_1,
2727

2828
@Redirect(method = "setBlockState", at = @At(
2929
value = "INVOKE",
30-
target = "Lnet/minecraft/world/level/block/entity/BlockEntity;preRemoveSideEffects(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Z)V"
30+
target = "Lnet/minecraft/world/level/block/entity/BlockEntity;preRemoveSideEffects(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)V"
3131
))
32-
private void onPreRemoveSideEffects(BlockEntity blockEntity, BlockPos blockPos_1, BlockState blockState_1, boolean boolean_1)
32+
private void onPreRemoveSideEffects(BlockEntity blockEntity, BlockPos blockPos_1, BlockState blockState_1)
3333
{
3434
if (!CarpetSettings.impendingFillSkipUpdates.get())
3535
{
36-
blockEntity.preRemoveSideEffects(blockPos_1, blockState_1, boolean_1);
36+
blockEntity.preRemoveSideEffects(blockPos_1, blockState_1);
3737
}
3838
}
3939

src/main/java/carpet/mixins/LevelChunk_movableBEMixin.java

+17-18
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.minecraft.world.level.Level;
1313
import net.minecraft.world.level.LevelHeightAccessor;
1414
import net.minecraft.world.level.biome.Biome;
15+
import net.minecraft.world.level.block.BaseRailBlock;
1516
import net.minecraft.world.level.block.Block;
1617
import net.minecraft.world.level.block.EntityBlock;
1718
import net.minecraft.world.level.block.entity.BlockEntity;
@@ -81,7 +82,7 @@ private BlockEntity ifGetBlockEntity(LevelChunk worldChunk, BlockPos blockPos_1,
8182
public BlockState setBlockStateWithBlockEntity(BlockPos blockPos_1, BlockState newBlockState, BlockEntity newBlockEntity,
8283
int flags)
8384
{
84-
boolean boolean_1 = (flags & 64) != 0;
85+
8586
int y = blockPos_1.getY();
8687

8788
LevelChunkSection chunkSection = this.getSection(this.getSectionIndex(y));
@@ -122,37 +123,35 @@ public BlockState setBlockStateWithBlockEntity(BlockPos blockPos_1, BlockState n
122123
profiler.pop();
123124
}
124125

125-
boolean hadBlockEntity = oldBlockState.hasBlockEntity();
126126
boolean blockChanged = !oldBlockState.is(newBlock);
127-
127+
boolean boolean_1 = (flags & 64) != 0; // moved by pistons
128128
boolean sideEffects = (flags & Block.UPDATE_SKIP_BLOCK_ENTITY_SIDEEFFECTS) == 0;
129129

130-
if (blockChanged) {
130+
if (blockChanged && oldBlockState.hasBlockEntity()) {
131131
if (level instanceof ServerLevel serverLevel && !(oldBlockState.getBlock() instanceof MovingPistonBlock)) {
132-
if (hadBlockEntity && sideEffects) {
133-
final BlockEntity blockEntity = level.getBlockEntity(blockPos_1);
132+
if (sideEffects) {
133+
BlockEntity blockEntity = level.getBlockEntity(blockPos_1);
134134
if (blockEntity != null) {
135-
blockEntity.preRemoveSideEffects(blockPos_1, oldBlockState, boolean_1);
135+
blockEntity.preRemoveSideEffects(blockPos_1, oldBlockState);
136136
}
137137
}
138+
}
139+
removeBlockEntity(blockPos_1);
140+
}
138141

139-
if (hadBlockEntity) {
140-
removeBlockEntity(blockPos_1);
141-
}
142-
if ((flags & Block.UPDATE_NEIGHBORS) != 0) { // scary change // so many other places that used to call this regardless if the UPDATE_NEIGHBORS flag was set
142+
if (blockChanged || newBlock instanceof BaseRailBlock)
143+
{
144+
if (level instanceof ServerLevel serverLevel && !(oldBlockState.getBlock() instanceof MovingPistonBlock))
145+
{
146+
if ((flags & Block.UPDATE_NEIGHBORS) != 0 || boolean_1)
147+
{
143148
oldBlockState.affectNeighborsAfterRemoval(serverLevel, blockPos_1, boolean_1);
144149
}
145-
} else if (hadBlockEntity) {
146-
removeBlockEntity(blockPos_1);
147150
}
148151
}
149152

150153

151-
152-
153-
154-
155-
if (chunkSection.getBlockState(x, chunkY, z).getBlock() != newBlock)
154+
if (chunkSection.getBlockState(x, chunkY, z).getBlock() != newBlock)
156155
{
157156
return null;
158157
}

src/main/java/carpet/mixins/StructureBlockEntity_limitsMixin.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ private int negativeLimit(int original) {
2929
}
3030

3131
@ModifyArg(
32-
method = "saveStructure(Z)Z",
32+
method = "saveStructure(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/core/BlockPos;Lnet/minecraft/core/Vec3i;ZLjava/lang/String;Z)Z",
3333
at = @At(
3434
value = "INVOKE",
3535
target = "Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate;fillFromWorld(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/core/Vec3i;ZLnet/minecraft/world/level/block/Block;)V"
3636
),
3737
index = 4
3838
)
39-
private Block ignoredBlock(Block original) {
39+
private static Block ignoredBlock(Block original) {
4040
return CarpetSettings.structureBlockIgnoredBlock;
4141
}
4242
}

src/main/java/carpet/mixins/StructureBlockRenderer_mixin.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import carpet.CarpetSettings;
44
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
5-
import net.minecraft.client.renderer.blockentity.StructureBlockRenderer;
5+
import net.minecraft.client.renderer.blockentity.BlockEntityWithBoundingBoxRenderer;
66
import net.minecraft.world.level.block.entity.StructureBlockEntity;
77
import org.spongepowered.asm.mixin.Mixin;
88
import org.spongepowered.asm.mixin.injection.At;
99
import org.spongepowered.asm.mixin.injection.Inject;
1010
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1111

12-
@Mixin(StructureBlockRenderer.class)
12+
@Mixin(BlockEntityWithBoundingBoxRenderer.class)
1313
public abstract class StructureBlockRenderer_mixin implements BlockEntityRenderer<StructureBlockEntity>
1414
{
1515
@Inject(method = "getViewDistance", at = @At("HEAD"), cancellable = true)

src/main/java/carpet/patches/EntityPlayerMPFake.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static boolean createFake(String username, MinecraftServer server, Vec3 p
9393
current = p.get();
9494
}
9595
EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, current, ClientInformation.createDefault(), false);
96-
instance.fixStartingPosition = () -> instance.moveTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
96+
instance.fixStartingPosition = () -> instance.snapTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
9797
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, new CommonListenerCookie(current, 0, instance.clientInformation(), false));
9898
instance.teleportTo(worldIn, pos.x, pos.y, pos.z, Set.of(), (float) yaw, (float) pitch, true);
9999
instance.setHealth(20.0F);

src/main/java/carpet/script/CarpetExpression.java

+37
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,41 @@ public Value scriptRunCommand(ScriptHost host, BlockPos pos)
141141
throw new CarpetExpressionException("Your thoughts are too deep", null);
142142
}
143143
}
144+
145+
public Value explain(ScriptHost host, BlockPos pos)
146+
{
147+
// convert to explain
148+
CarpetScriptServer scriptServer = (CarpetScriptServer) host.scriptServer();
149+
try
150+
{
151+
Context context = new CarpetContext(host, source, origin).
152+
with("x", (c, t) -> new NumericValue(pos.getX() - origin.getX()).bindTo("x")).
153+
with("y", (c, t) -> new NumericValue(pos.getY() - origin.getY()).bindTo("y")).
154+
with("z", (c, t) -> new NumericValue(pos.getZ() - origin.getZ()).bindTo("z"));
155+
Entity e = source.getEntity();
156+
if (e == null)
157+
{
158+
Value nullPlayer = Value.NULL.reboundedTo("p");
159+
context.with("p", (cc, tt) -> nullPlayer);
160+
}
161+
else
162+
{
163+
Value playerValue = new EntityValue(e).bindTo("p");
164+
context.with("p", (cc, tt) -> playerValue);
165+
}
166+
return scriptServer.events.handleEvents.getWhileDisabled(() -> this.expr.explain(context));
167+
}
168+
catch (ExpressionException e)
169+
{
170+
throw new CarpetExpressionException(e.getMessage(), e.stack);
171+
}
172+
catch (ArithmeticException ae)
173+
{
174+
throw new CarpetExpressionException("Math doesn't compute... " + ae.getMessage(), null);
175+
}
176+
catch (StackOverflowError soe)
177+
{
178+
throw new CarpetExpressionException("Your thoughts are too deep", null);
179+
}
180+
}
144181
}

src/main/java/carpet/script/Expression.java

+6
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,12 @@ private LazyValue getAST(Context context)
12511251
return extractOp(optimizeOnlyContext, root, Context.Type.NONE);
12521252
}
12531253

1254+
public Value explain(Context context)
1255+
{
1256+
//todo convert to explain
1257+
return Value.NULL;
1258+
}
1259+
12541260
private int treeSize(ExpressionNode node)
12551261
{
12561262
return node.op instanceof LazyValue.ContextFreeLazyValue ? 1 : node.args.stream().mapToInt(this::treeSize).sum() + 1;

src/main/java/carpet/script/ScriptCommand.java

+20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import carpet.script.utils.AppStoreManager;
66
import carpet.script.exception.CarpetExpressionException;
77
import carpet.script.value.FunctionValue;
8+
import carpet.script.value.NumericValue;
89
import carpet.script.value.Value;
910
import com.mojang.brigadier.CommandDispatcher;
1011
import com.mojang.brigadier.arguments.StringArgumentType;
@@ -358,6 +359,12 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
358359
boolean success = ss(cc).uninstallApp(cc.getSource(), StringArgumentType.getString(cc, "app"));
359360
return success ? 1 : 0;
360361
}));
362+
LiteralArgumentBuilder<CommandSourceStack> x = literal("explain").
363+
requires(Vanilla::ServerPlayer_canScriptACE).
364+
then(argument("expr", StringArgumentType.greedyString()).suggests(ScriptCommand::suggestCode).
365+
executes((cc) -> explain(
366+
cc,
367+
StringArgumentType.getString(cc, "expr"))));
361368

362369
dispatcher.register(literal("script").
363370
requires(Vanilla::ServerPlayer_canScriptGeneral).
@@ -536,6 +543,19 @@ private static int compute(CommandContext<CommandSourceStack> context, String ex
536543
});
537544
}
538545

546+
private static int explain(CommandContext<CommandSourceStack> context, String expr) throws CommandSyntaxException
547+
{
548+
CommandSourceStack source = context.getSource();
549+
CarpetScriptHost host = getHost(context);
550+
return handleCall(source, host, () -> {
551+
CarpetExpression ex = new CarpetExpression(host.main, expr, source, new BlockPos(0, 0, 0));
552+
ex.explain(host, BlockPos.containing(source.getPosition()));
553+
Carpet.Messenger_message(source, "w Expression: ", "wb " + expr);
554+
Carpet.Messenger_message(source, "w Tokens: ", "wb " + ex.getExpr().toString());
555+
return NumericValue.ONE;
556+
});
557+
}
558+
539559
private static int scriptScan(CommandContext<CommandSourceStack> context, BlockPos origin, BlockPos a, BlockPos b, String expr) throws CommandSyntaxException
540560
{
541561
CommandSourceStack source = context.getSource();

src/main/java/carpet/script/api/Auxiliary.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ else if (!interactable && targetBlock == null)
401401
yoffset = -armorstand.getBbHeight() + 0.3;
402402
}
403403
}
404-
armorstand.moveTo(
404+
armorstand.snapTo(
405405
pointLocator.vec.x,
406406
//pointLocator.vec.y - ((!interactable && targetBlock == null)?0.41f:((targetBlock==null)?(armorstand.getHeight()+0.41):(armorstand.getHeight()-0.3))),
407407
pointLocator.vec.y + yoffset,

src/main/java/carpet/script/api/Entities.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static void apply(Expression expression)
143143

144144
ServerLevel serverWorld = cc.level();
145145
Entity entity = EntityType.loadEntityRecursive(tag, serverWorld, EntitySpawnReason.COMMAND, e -> {
146-
e.moveTo(vec3d.x, vec3d.y, vec3d.z, e.getYRot(), e.getXRot());
146+
e.snapTo(vec3d.x, vec3d.y, vec3d.z, e.getYRot(), e.getXRot());
147147
return e;
148148
});
149149
if (entity == null)

src/main/java/carpet/script/value/EntityValue.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ private static void updatePosition(Entity e, double x, double y, double z, float
911911
}
912912
else
913913
{
914-
e.moveTo(x, y, z, yaw, pitch);
914+
e.snapTo(x, y, z, yaw, pitch);
915915
// we were sending to players for not-living entites, that were untracked. Living entities should be tracked.
916916
//((ServerWorld) e.getEntityWorld()).getChunkManager().sendToNearbyPlayers(e, new EntityS2CPacket.(e));
917917
if (e instanceof LivingEntity le)

src/main/java/carpet/utils/BlockInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private static Component wander_chances(BlockPos pos, ServerLevel worldIn)
7676
{
7777
PathfinderMob creature = new ZombifiedPiglin(EntityType.ZOMBIFIED_PIGLIN, worldIn);
7878
creature.finalizeSpawn(worldIn, worldIn.getCurrentDifficultyAt(pos), EntitySpawnReason.NATURAL, null);
79-
creature.moveTo(pos, 0.0F, 0.0F);
79+
creature.snapTo(pos, 0.0F, 0.0F);
8080
RandomStrollGoal wander = new RandomStrollGoal(creature, 0.8D);
8181
int success = 0;
8282
for (int i=0; i<1000; i++)

src/main/java/carpet/utils/PerimeterDiagnostics.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private boolean check_entity_spawn(BlockPos pos)
180180

181181
if (SpawnPlacements.isSpawnPositionOk(sle.type(), worldServer, pos))
182182
{
183-
el.moveTo(pos.getX() + 0.5F, pos.getY(), pos.getZ()+0.5F, 0.0F, 0.0F);
183+
el.snapTo(pos.getX() + 0.5F, pos.getY(), pos.getZ()+0.5F, 0.0F, 0.0F);
184184
return el.checkSpawnObstruction(worldServer) && el.checkSpawnRules(worldServer, EntitySpawnReason.NATURAL) &&
185185
SpawnPlacements.checkSpawnRules(el.getType(),(ServerLevel)el.getCommandSenderWorld(), EntitySpawnReason.NATURAL, el.blockPosition(), el.getCommandSenderWorld().random) &&
186186
worldServer.noCollision(el); // check collision rules once they stop fiddling with them after 1.14.1

src/main/java/carpet/utils/SpawnReporter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ public static List<Component> report(BlockPos pos, ServerLevel worldIn)
439439
{
440440
float f = x + 0.5F;
441441
float f1 = z + 0.5F;
442-
mob.moveTo(f, y, f1, worldIn.random.nextFloat() * 360.0F, 0.0F);
442+
mob.snapTo(f, y, f1, worldIn.random.nextFloat() * 360.0F, 0.0F);
443443
fits = worldIn.noCollision(mob);
444444
EntityType<?> etype = mob.getType();
445445

0 commit comments

Comments
 (0)