This commit is contained in:
gnembon committed 2025-01-16 12:43:30 +01:00
1 parent c241594eb6
commit fd098151c4
18 files changed
+100 -39

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check https://fabricmc.net/develop/ # check https://fabricmc.net/develop/
minecraft_version=25w02a minecraft_version=25w03a
loader_version=0.16.10 loader_version=0.16.10
jsr305_version=3.0.2 jsr305_version=3.0.2
fabric_version=0.110.5+1.21.4 fabric_version=0.110.5+1.21.4
@@ -56,7 +56,7 @@ public class PerimeterInfoCommand
{ {
nbttagcompound.putString("id", mobId); nbttagcompound.putString("id", mobId);
Entity baseEntity = EntityType.loadEntityRecursive(nbttagcompound, source.getLevel(), EntitySpawnReason.COMMAND, (entity_1x) -> { Entity baseEntity = EntityType.loadEntityRecursive(nbttagcompound, source.getLevel(), EntitySpawnReason.COMMAND, (entity_1x) -> {
entity_1x.moveTo(new BlockPos(pos.getX(), source.getLevel().getMinY()-10, pos.getZ()), entity_1x.getYRot(), entity_1x. getXRot()); entity_1x.snapTo(new BlockPos(pos.getX(), source.getLevel().getMinY()-10, pos.getZ()), entity_1x.getYRot(), entity_1x. getXRot());
return !source.getLevel().addWithUUID(entity_1x) ? null : entity_1x; return !source.getLevel().addWithUUID(entity_1x) ? null : entity_1x;
}); });
if (!(baseEntity instanceof Mob)) if (!(baseEntity instanceof Mob))
@@ -19,9 +19,6 @@ public abstract class ExperienceOrb_xpNoCooldownMixin extends Entity
@Shadow @Shadow
private int count; private int count;
@Shadow
private int value;
public ExperienceOrb_xpNoCooldownMixin(EntityType<?> type, Level world) public ExperienceOrb_xpNoCooldownMixin(EntityType<?> type, Level world)
{ {
super(type, world); super(type, world);
@@ -30,13 +27,15 @@ public abstract class ExperienceOrb_xpNoCooldownMixin extends Entity
@Shadow @Shadow
protected abstract int repairPlayerItems(ServerPlayer player, int amount); protected abstract int repairPlayerItems(ServerPlayer player, int amount);
@Shadow public abstract int getValue();
@Inject(method = "playerTouch", at = @At("HEAD")) @Inject(method = "playerTouch", at = @At("HEAD"))
private void addXP(Player player, CallbackInfo ci) { private void addXP(Player player, CallbackInfo ci) {
if (CarpetSettings.xpNoCooldown && !level().isClientSide) { if (CarpetSettings.xpNoCooldown && !level().isClientSide) {
player.takeXpDelay = 0; player.takeXpDelay = 0;
// reducing the count to 1 and leaving vanilla to deal with it // reducing the count to 1 and leaving vanilla to deal with it
while (this.count > 1) { while (this.count > 1) {
int remainder = this.repairPlayerItems((ServerPlayer) player, this.value); int remainder = this.repairPlayerItems((ServerPlayer) player, this.getValue());
if (remainder > 0) { if (remainder > 0) {
player.giveExperiencePoints(remainder); player.giveExperiencePoints(remainder);
} }
@@ -25,7 +25,7 @@ public abstract class Guardian_renewableSpongesMixin extends Monster
if (!this.level().isClientSide && !this.isRemoved() && CarpetSettings.renewableSponges && !((Object)this instanceof ElderGuardian)) if (!this.level().isClientSide && !this.isRemoved() && CarpetSettings.renewableSponges && !((Object)this instanceof ElderGuardian))
{ {
ElderGuardian elderGuardian = new ElderGuardian(EntityType.ELDER_GUARDIAN ,this.level()); ElderGuardian elderGuardian = new ElderGuardian(EntityType.ELDER_GUARDIAN ,this.level());
elderGuardian.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot()); elderGuardian.snapTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot());
elderGuardian.finalizeSpawn(serverWorld ,this.level().getCurrentDifficultyAt(elderGuardian.blockPosition()), EntitySpawnReason.CONVERSION, null); elderGuardian.finalizeSpawn(serverWorld ,this.level().getCurrentDifficultyAt(elderGuardian.blockPosition()), EntitySpawnReason.CONVERSION, null);
elderGuardian.setNoAi(this.isNoAi()); elderGuardian.setNoAi(this.isNoAi());
@@ -27,13 +27,13 @@ public class LevelChunk_fillUpdatesMixin
@Redirect(method = "setBlockState", at = @At( @Redirect(method = "setBlockState", at = @At(
value = "INVOKE", value = "INVOKE",
target = "Lnet/minecraft/world/level/block/entity/BlockEntity;preRemoveSideEffects(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Z)V" target = "Lnet/minecraft/world/level/block/entity/BlockEntity;preRemoveSideEffects(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)V"
)) ))
private void onPreRemoveSideEffects(BlockEntity blockEntity, BlockPos blockPos_1, BlockState blockState_1, boolean boolean_1) private void onPreRemoveSideEffects(BlockEntity blockEntity, BlockPos blockPos_1, BlockState blockState_1)
{ {
if (!CarpetSettings.impendingFillSkipUpdates.get()) if (!CarpetSettings.impendingFillSkipUpdates.get())
{ {
blockEntity.preRemoveSideEffects(blockPos_1, blockState_1, boolean_1); blockEntity.preRemoveSideEffects(blockPos_1, blockState_1);
} }
} }
@@ -12,6 +12,7 @@ import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelHeightAccessor; import net.minecraft.world.level.LevelHeightAccessor;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.BaseRailBlock;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
@@ -81,7 +82,7 @@ public abstract class LevelChunk_movableBEMixin extends ChunkAccess implements W
public BlockState setBlockStateWithBlockEntity(BlockPos blockPos_1, BlockState newBlockState, BlockEntity newBlockEntity, public BlockState setBlockStateWithBlockEntity(BlockPos blockPos_1, BlockState newBlockState, BlockEntity newBlockEntity,
int flags) int flags)
{ {
boolean boolean_1 = (flags & 64) != 0;
int y = blockPos_1.getY(); int y = blockPos_1.getY();
LevelChunkSection chunkSection = this.getSection(this.getSectionIndex(y)); LevelChunkSection chunkSection = this.getSection(this.getSectionIndex(y));
@@ -122,37 +123,35 @@ public abstract class LevelChunk_movableBEMixin extends ChunkAccess implements W
profiler.pop(); profiler.pop();
} }
boolean hadBlockEntity = oldBlockState.hasBlockEntity();
boolean blockChanged = !oldBlockState.is(newBlock); boolean blockChanged = !oldBlockState.is(newBlock);
boolean boolean_1 = (flags & 64) != 0; // moved by pistons
boolean sideEffects = (flags & Block.UPDATE_SKIP_BLOCK_ENTITY_SIDEEFFECTS) == 0; boolean sideEffects = (flags & Block.UPDATE_SKIP_BLOCK_ENTITY_SIDEEFFECTS) == 0;
if (blockChanged) { if (blockChanged && oldBlockState.hasBlockEntity()) {
if (level instanceof ServerLevel serverLevel && !(oldBlockState.getBlock() instanceof MovingPistonBlock)) { if (level instanceof ServerLevel serverLevel && !(oldBlockState.getBlock() instanceof MovingPistonBlock)) {
if (hadBlockEntity && sideEffects) { if (sideEffects) {
final BlockEntity blockEntity = level.getBlockEntity(blockPos_1); BlockEntity blockEntity = level.getBlockEntity(blockPos_1);
if (blockEntity != null) { if (blockEntity != null) {
blockEntity.preRemoveSideEffects(blockPos_1, oldBlockState, boolean_1); blockEntity.preRemoveSideEffects(blockPos_1, oldBlockState);
} }
} }
}
removeBlockEntity(blockPos_1);
}
if (hadBlockEntity) { if (blockChanged || newBlock instanceof BaseRailBlock)
removeBlockEntity(blockPos_1); {
} if (level instanceof ServerLevel serverLevel && !(oldBlockState.getBlock() instanceof MovingPistonBlock))
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 {
if ((flags & Block.UPDATE_NEIGHBORS) != 0 || boolean_1)
{
oldBlockState.affectNeighborsAfterRemoval(serverLevel, blockPos_1, boolean_1); oldBlockState.affectNeighborsAfterRemoval(serverLevel, blockPos_1, boolean_1);
} }
} else if (hadBlockEntity) {
removeBlockEntity(blockPos_1);
} }
} }
if (chunkSection.getBlockState(x, chunkY, z).getBlock() != newBlock)
if (chunkSection.getBlockState(x, chunkY, z).getBlock() != newBlock)
{ {
return null; return null;
} }
@@ -29,14 +29,14 @@ public abstract class StructureBlockEntity_limitsMixin
} }
@ModifyArg( @ModifyArg(
method = "saveStructure(Z)Z", method = "saveStructure(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/core/BlockPos;Lnet/minecraft/core/Vec3i;ZLjava/lang/String;Z)Z",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
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" 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"
), ),
index = 4 index = 4
) )
private Block ignoredBlock(Block original) { private static Block ignoredBlock(Block original) {
return CarpetSettings.structureBlockIgnoredBlock; return CarpetSettings.structureBlockIgnoredBlock;
} }
} }
@@ -2,14 +2,14 @@ package carpet.mixins;
import carpet.CarpetSettings; import carpet.CarpetSettings;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.StructureBlockRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityWithBoundingBoxRenderer;
import net.minecraft.world.level.block.entity.StructureBlockEntity; import net.minecraft.world.level.block.entity.StructureBlockEntity;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(StructureBlockRenderer.class) @Mixin(BlockEntityWithBoundingBoxRenderer.class)
public abstract class StructureBlockRenderer_mixin implements BlockEntityRenderer<StructureBlockEntity> public abstract class StructureBlockRenderer_mixin implements BlockEntityRenderer<StructureBlockEntity>
{ {
@Inject(method = "getViewDistance", at = @At("HEAD"), cancellable = true) @Inject(method = "getViewDistance", at = @At("HEAD"), cancellable = true)
@@ -93,7 +93,7 @@ public class EntityPlayerMPFake extends ServerPlayer
current = p.get(); current = p.get();
} }
EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, current, ClientInformation.createDefault(), false); EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, current, ClientInformation.createDefault(), false);
instance.fixStartingPosition = () -> instance.moveTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch); instance.fixStartingPosition = () -> instance.snapTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, new CommonListenerCookie(current, 0, instance.clientInformation(), false)); server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, new CommonListenerCookie(current, 0, instance.clientInformation(), false));
instance.teleportTo(worldIn, pos.x, pos.y, pos.z, Set.of(), (float) yaw, (float) pitch, true); instance.teleportTo(worldIn, pos.x, pos.y, pos.z, Set.of(), (float) yaw, (float) pitch, true);
instance.setHealth(20.0F); instance.setHealth(20.0F);
@@ -141,4 +141,41 @@ public class CarpetExpression
throw new CarpetExpressionException("Your thoughts are too deep", null); throw new CarpetExpressionException("Your thoughts are too deep", null);
} }
} }
public Value explain(ScriptHost host, BlockPos pos)
{
// convert to explain
CarpetScriptServer scriptServer = (CarpetScriptServer) host.scriptServer();
try
{
Context context = new CarpetContext(host, source, origin).
with("x", (c, t) -> new NumericValue(pos.getX() - origin.getX()).bindTo("x")).
with("y", (c, t) -> new NumericValue(pos.getY() - origin.getY()).bindTo("y")).
with("z", (c, t) -> new NumericValue(pos.getZ() - origin.getZ()).bindTo("z"));
Entity e = source.getEntity();
if (e == null)
{
Value nullPlayer = Value.NULL.reboundedTo("p");
context.with("p", (cc, tt) -> nullPlayer);
}
else
{
Value playerValue = new EntityValue(e).bindTo("p");
context.with("p", (cc, tt) -> playerValue);
}
return scriptServer.events.handleEvents.getWhileDisabled(() -> this.expr.explain(context));
}
catch (ExpressionException e)
{
throw new CarpetExpressionException(e.getMessage(), e.stack);
}
catch (ArithmeticException ae)
{
throw new CarpetExpressionException("Math doesn't compute... " + ae.getMessage(), null);
}
catch (StackOverflowError soe)
{
throw new CarpetExpressionException("Your thoughts are too deep", null);
}
}
} }
@@ -1251,6 +1251,12 @@ public class Expression
return extractOp(optimizeOnlyContext, root, Context.Type.NONE); return extractOp(optimizeOnlyContext, root, Context.Type.NONE);
} }
public Value explain(Context context)
{
//todo convert to explain
return Value.NULL;
}
private int treeSize(ExpressionNode node) private int treeSize(ExpressionNode node)
{ {
return node.op instanceof LazyValue.ContextFreeLazyValue ? 1 : node.args.stream().mapToInt(this::treeSize).sum() + 1; return node.op instanceof LazyValue.ContextFreeLazyValue ? 1 : node.args.stream().mapToInt(this::treeSize).sum() + 1;
@@ -5,6 +5,7 @@ import carpet.script.external.Vanilla;
import carpet.script.utils.AppStoreManager; import carpet.script.utils.AppStoreManager;
import carpet.script.exception.CarpetExpressionException; import carpet.script.exception.CarpetExpressionException;
import carpet.script.value.FunctionValue; import carpet.script.value.FunctionValue;
import carpet.script.value.NumericValue;
import carpet.script.value.Value; import carpet.script.value.Value;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
@@ -358,6 +359,12 @@ public class ScriptCommand
boolean success = ss(cc).uninstallApp(cc.getSource(), StringArgumentType.getString(cc, "app")); boolean success = ss(cc).uninstallApp(cc.getSource(), StringArgumentType.getString(cc, "app"));
return success ? 1 : 0; return success ? 1 : 0;
})); }));
LiteralArgumentBuilder<CommandSourceStack> x = literal("explain").
requires(Vanilla::ServerPlayer_canScriptACE).
then(argument("expr", StringArgumentType.greedyString()).suggests(ScriptCommand::suggestCode).
executes((cc) -> explain(
cc,
StringArgumentType.getString(cc, "expr"))));
dispatcher.register(literal("script"). dispatcher.register(literal("script").
requires(Vanilla::ServerPlayer_canScriptGeneral). requires(Vanilla::ServerPlayer_canScriptGeneral).
@@ -536,6 +543,19 @@ public class ScriptCommand
}); });
} }
private static int explain(CommandContext<CommandSourceStack> context, String expr) throws CommandSyntaxException
{
CommandSourceStack source = context.getSource();
CarpetScriptHost host = getHost(context);
return handleCall(source, host, () -> {
CarpetExpression ex = new CarpetExpression(host.main, expr, source, new BlockPos(0, 0, 0));
ex.explain(host, BlockPos.containing(source.getPosition()));
Carpet.Messenger_message(source, "w Expression: ", "wb " + expr);
Carpet.Messenger_message(source, "w Tokens: ", "wb " + ex.getExpr().toString());
return NumericValue.ONE;
});
}
private static int scriptScan(CommandContext<CommandSourceStack> context, BlockPos origin, BlockPos a, BlockPos b, String expr) throws CommandSyntaxException private static int scriptScan(CommandContext<CommandSourceStack> context, BlockPos origin, BlockPos a, BlockPos b, String expr) throws CommandSyntaxException
{ {
CommandSourceStack source = context.getSource(); CommandSourceStack source = context.getSource();
@@ -401,7 +401,7 @@ public class Auxiliary
yoffset = -armorstand.getBbHeight() + 0.3; yoffset = -armorstand.getBbHeight() + 0.3;
} }
} }
armorstand.moveTo( armorstand.snapTo(
pointLocator.vec.x, pointLocator.vec.x,
//pointLocator.vec.y - ((!interactable && targetBlock == null)?0.41f:((targetBlock==null)?(armorstand.getHeight()+0.41):(armorstand.getHeight()-0.3))), //pointLocator.vec.y - ((!interactable && targetBlock == null)?0.41f:((targetBlock==null)?(armorstand.getHeight()+0.41):(armorstand.getHeight()-0.3))),
pointLocator.vec.y + yoffset, pointLocator.vec.y + yoffset,
@@ -143,7 +143,7 @@ public class Entities
ServerLevel serverWorld = cc.level(); ServerLevel serverWorld = cc.level();
Entity entity = EntityType.loadEntityRecursive(tag, serverWorld, EntitySpawnReason.COMMAND, e -> { Entity entity = EntityType.loadEntityRecursive(tag, serverWorld, EntitySpawnReason.COMMAND, e -> {
e.moveTo(vec3d.x, vec3d.y, vec3d.z, e.getYRot(), e.getXRot()); e.snapTo(vec3d.x, vec3d.y, vec3d.z, e.getYRot(), e.getXRot());
return e; return e;
}); });
if (entity == null) if (entity == null)
@@ -911,7 +911,7 @@ public class EntityValue extends Value
} }
else else
{ {
e.moveTo(x, y, z, yaw, pitch); e.snapTo(x, y, z, yaw, pitch);
// we were sending to players for not-living entites, that were untracked. Living entities should be tracked. // we were sending to players for not-living entites, that were untracked. Living entities should be tracked.
//((ServerWorld) e.getEntityWorld()).getChunkManager().sendToNearbyPlayers(e, new EntityS2CPacket.(e)); //((ServerWorld) e.getEntityWorld()).getChunkManager().sendToNearbyPlayers(e, new EntityS2CPacket.(e));
if (e instanceof LivingEntity le) if (e instanceof LivingEntity le)
+1 -1
View File
@@ -76,7 +76,7 @@ public class BlockInfo
{ {
PathfinderMob creature = new ZombifiedPiglin(EntityType.ZOMBIFIED_PIGLIN, worldIn); PathfinderMob creature = new ZombifiedPiglin(EntityType.ZOMBIFIED_PIGLIN, worldIn);
creature.finalizeSpawn(worldIn, worldIn.getCurrentDifficultyAt(pos), EntitySpawnReason.NATURAL, null); creature.finalizeSpawn(worldIn, worldIn.getCurrentDifficultyAt(pos), EntitySpawnReason.NATURAL, null);
creature.moveTo(pos, 0.0F, 0.0F); creature.snapTo(pos, 0.0F, 0.0F);
RandomStrollGoal wander = new RandomStrollGoal(creature, 0.8D); RandomStrollGoal wander = new RandomStrollGoal(creature, 0.8D);
int success = 0; int success = 0;
for (int i=0; i<1000; i++) for (int i=0; i<1000; i++)
@@ -180,7 +180,7 @@ public class PerimeterDiagnostics
if (SpawnPlacements.isSpawnPositionOk(sle.type(), worldServer, pos)) if (SpawnPlacements.isSpawnPositionOk(sle.type(), worldServer, pos))
{ {
el.moveTo(pos.getX() + 0.5F, pos.getY(), pos.getZ()+0.5F, 0.0F, 0.0F); el.snapTo(pos.getX() + 0.5F, pos.getY(), pos.getZ()+0.5F, 0.0F, 0.0F);
return el.checkSpawnObstruction(worldServer) && el.checkSpawnRules(worldServer, EntitySpawnReason.NATURAL) && return el.checkSpawnObstruction(worldServer) && el.checkSpawnRules(worldServer, EntitySpawnReason.NATURAL) &&
SpawnPlacements.checkSpawnRules(el.getType(),(ServerLevel)el.getCommandSenderWorld(), EntitySpawnReason.NATURAL, el.blockPosition(), el.getCommandSenderWorld().random) && SpawnPlacements.checkSpawnRules(el.getType(),(ServerLevel)el.getCommandSenderWorld(), EntitySpawnReason.NATURAL, el.blockPosition(), el.getCommandSenderWorld().random) &&
worldServer.noCollision(el); // check collision rules once they stop fiddling with them after 1.14.1 worldServer.noCollision(el); // check collision rules once they stop fiddling with them after 1.14.1
@@ -439,7 +439,7 @@ public class SpawnReporter
{ {
float f = x + 0.5F; float f = x + 0.5F;
float f1 = z + 0.5F; float f1 = z + 0.5F;
mob.moveTo(f, y, f1, worldIn.random.nextFloat() * 360.0F, 0.0F); mob.snapTo(f, y, f1, worldIn.random.nextFloat() * 360.0F, 0.0F);
fits = worldIn.noCollision(mob); fits = worldIn.noCollision(mob);
EntityType<?> etype = mob.getType(); EntityType<?> etype = mob.getType();