From 21bfdd34248af3e226014dbef025f1eb3a643f2e Mon Sep 17 00:00:00 2001 From: gnembon Date: Mon, 8 Jul 2019 16:13:33 -0300 Subject: [PATCH 01/13] early tracer --- src/main/java/carpet/helpers/Tracer.java | 16 ++++++++++++++ .../java/carpet/script/CarpetExpression.java | 22 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/carpet/helpers/Tracer.java diff --git a/src/main/java/carpet/helpers/Tracer.java b/src/main/java/carpet/helpers/Tracer.java new file mode 100644 index 00000000..c49cfc19 --- /dev/null +++ b/src/main/java/carpet/helpers/Tracer.java @@ -0,0 +1,16 @@ +package carpet.helpers; + +import net.minecraft.entity.Entity; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.RayTraceContext; + +public class Tracer +{ + public static HitResult traceEntityLook(Entity entity, double reach) { + Vec3d vec3d_1 = entity.getCameraPosVec(1.0F); + Vec3d vec3d_2 = entity.getRotationVec(1.0F); + Vec3d vec3d_3 = vec3d_1.add(vec3d_2.x * reach, vec3d_2.y * reach, vec3d_2.z * reach); + return entity.world.rayTrace(new RayTraceContext(vec3d_1, vec3d_3, RayTraceContext.ShapeType.OUTLINE, RayTraceContext.FluidHandling.ANY, entity)); + } +} diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index 29b5ad6f..19389f1c 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -3,6 +3,7 @@ package carpet.script; import carpet.CarpetServer; import carpet.fakes.MinecraftServerInterface; import carpet.helpers.FeatureGenerator; +import carpet.helpers.Tracer; import carpet.script.Fluff.TriFunction; import carpet.script.exception.CarpetExpressionException; import carpet.script.exception.ExpressionException; @@ -53,6 +54,9 @@ import net.minecraft.state.StateFactory; import net.minecraft.state.property.Property; import net.minecraft.text.LiteralText; import net.minecraft.util.Identifier; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.EntityHitResult; +import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.EulerAngle; @@ -1241,6 +1245,24 @@ public class CarpetExpression Value res = new NumericValue(item.getStack().getCount()); return (_c, _t) -> res; }); + + this.expr.addLazyFunction("trace_block", -1, (c, t, lv) -> { + Value entityValue = lv.get(0).evalValue(c); + if (!(entityValue instanceof EntityValue)) + throw new InternalExpressionException("First argument of trace_block should be an entity"); + Entity e = ((EntityValue) entityValue).getEntity(); + HitResult hitres = Tracer.traceEntityLook(e, 20); + switch (hitres.getType()) + { + case MISS: + return (_c, _t) -> Value.NULL; + case BLOCK: + return (_c, _t) -> new BlockValue(null, e.getEntityWorld(), ((BlockHitResult)hitres).getBlockPos() ); + case ENTITY: + return (_c, _t) -> new EntityValue(((EntityHitResult)hitres).getEntity()); + } + return LazyValue.NULL; + }); } From da063aacb4ab07c77d80adc47a0c36d29ea024d9 Mon Sep 17 00:00:00 2001 From: gnembon Date: Tue, 9 Jul 2019 09:28:54 -0300 Subject: [PATCH 02/13] smooth low tps --- .../RenderTickCounter_tickSpeedMixin.java | 23 +++++++++++++++++++ .../java/carpet/settings/CarpetSettings.java | 3 +++ src/main/resources/carpet.mixins.json | 1 + 3 files changed, 27 insertions(+) create mode 100644 src/main/java/carpet/mixins/RenderTickCounter_tickSpeedMixin.java diff --git a/src/main/java/carpet/mixins/RenderTickCounter_tickSpeedMixin.java b/src/main/java/carpet/mixins/RenderTickCounter_tickSpeedMixin.java new file mode 100644 index 00000000..9e4927e0 --- /dev/null +++ b/src/main/java/carpet/mixins/RenderTickCounter_tickSpeedMixin.java @@ -0,0 +1,23 @@ +package carpet.mixins; + +import carpet.helpers.TickSpeed; +import carpet.settings.CarpetSettings; +import net.minecraft.client.render.RenderTickCounter; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(RenderTickCounter.class) +public class RenderTickCounter_tickSpeedMixin { + @Redirect(method = "beginRenderTick", at = @At( + value = "FIELD", + target = "Lnet/minecraft/client/render/RenderTickCounter;timeScale:F" + )) + private float adjustTickSpeed(RenderTickCounter counter) { + if (CarpetSettings.smoothClientAnimations) + { + return Math.max(50.0f, TickSpeed.mspt); + } + return 50f; + } +} \ No newline at end of file diff --git a/src/main/java/carpet/settings/CarpetSettings.java b/src/main/java/carpet/settings/CarpetSettings.java index 02942790..1d46be6e 100644 --- a/src/main/java/carpet/settings/CarpetSettings.java +++ b/src/main/java/carpet/settings/CarpetSettings.java @@ -223,6 +223,9 @@ public class CarpetSettings @Rule(desc = "fill/clone/setblock and structure blocks cause block updates", category = CREATIVE) public static boolean fillUpdates = true; + @Rule(desc = "smooth client animations with low tps settings", extra = "works only in SP, and will slow down players", category = CREATIVE) + public static boolean smoothClientAnimations; + private static class PushLimitLimits extends Validator { @Override public Integer validate(ServerCommandSource source, ParsedRule currentRule, Integer newValue, String string) { return (newValue>0 && newValue <= 1024) ? newValue : null; diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index a715a07c..3c35b4a8 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -113,6 +113,7 @@ "WorldChunk_movableTEMixin" ], "client": [ + "RenderTickCounter_tickSpeedMixin", "MinecraftClientMixin", "IntegratedServerMixin", "InGameHudMixin", From 4c031ba2ef1a2499efdbe07cd51a606471b130a8 Mon Sep 17 00:00:00 2001 From: gnembon Date: Tue, 9 Jul 2019 16:51:18 -0300 Subject: [PATCH 03/13] mark chunks for resend --- src/main/java/carpet/CarpetServer.java | 2 +- .../java/carpet/script/CarpetExpression.java | 54 ++++++++++++------- .../carpet/script/CarpetScriptServer.java | 33 +++++++++--- 3 files changed, 64 insertions(+), 25 deletions(-) diff --git a/src/main/java/carpet/CarpetServer.java b/src/main/java/carpet/CarpetServer.java index 5c411f08..a0da2265 100644 --- a/src/main/java/carpet/CarpetServer.java +++ b/src/main/java/carpet/CarpetServer.java @@ -64,7 +64,7 @@ public class CarpetServer // static for now - easier to handle all around the co { TickSpeed.tick(server); HUDController.update_hud(server); - scriptServer.events.tick(); + scriptServer.tick(); //in case something happens CarpetSettings.impendingFillSkipUpdates = false; diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index 19389f1c..5a04b640 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -65,6 +65,8 @@ import net.minecraft.util.registry.Registry; import net.minecraft.world.Heightmap; import net.minecraft.world.LightType; import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.chunk.Chunk; import net.minecraft.world.loot.context.LootContext; import net.minecraft.world.loot.context.LootContextParameters; import org.apache.commons.lang3.tuple.Pair; @@ -926,6 +928,40 @@ public class CarpetExpression return (_c, _t) -> retval; }); + this.expr.addLazyFunction("trace_block", -1, (c, t, lv) -> { + Value entityValue = lv.get(0).evalValue(c); + if (!(entityValue instanceof EntityValue)) + throw new InternalExpressionException("First argument of trace_block should be an entity"); + Entity e = ((EntityValue) entityValue).getEntity(); + HitResult hitres = Tracer.traceEntityLook(e, 20); + switch (hitres.getType()) + { + case MISS: + return (_c, _t) -> Value.NULL; + case BLOCK: + return (_c, _t) -> new BlockValue(null, e.getEntityWorld(), ((BlockHitResult)hitres).getBlockPos() ); + case ENTITY: + return (_c, _t) -> new EntityValue(((EntityHitResult)hitres).getEntity()); + } + return LazyValue.NULL; + }); + + this.expr.addLazyFunction("set_biome", -1, (c, t, lv) -> { + CarpetContext cc = (CarpetContext)c; + BlockValue.LocatorResult locator = BlockValue.fromParams(cc, lv, 0); + String biomeName = lv.get(locator.offset+0).evalValue(c).getString(); + Biome biome = Registry.BIOME.get(new Identifier(biomeName)); + byte biomeId = (byte) (Registry.BIOME.getRawId(biome) & 255); + ServerWorld world = cc.s.getWorld(); + BlockPos pos = locator.block.getPos(); + Chunk chunk = world.getChunk(pos); + chunk.getBiomeArray()[(pos.getX() & 15) | (pos.getZ() & 15) << 4] = biome; + chunk.setShouldSave(true); + //world.method_14178().markForUpdate(pos); + CarpetServer.scriptServer.markChunkForUpdate(world, pos); + return LazyValue.NULL; + + }); } @@ -1245,24 +1281,6 @@ public class CarpetExpression Value res = new NumericValue(item.getStack().getCount()); return (_c, _t) -> res; }); - - this.expr.addLazyFunction("trace_block", -1, (c, t, lv) -> { - Value entityValue = lv.get(0).evalValue(c); - if (!(entityValue instanceof EntityValue)) - throw new InternalExpressionException("First argument of trace_block should be an entity"); - Entity e = ((EntityValue) entityValue).getEntity(); - HitResult hitres = Tracer.traceEntityLook(e, 20); - switch (hitres.getType()) - { - case MISS: - return (_c, _t) -> Value.NULL; - case BLOCK: - return (_c, _t) -> new BlockValue(null, e.getEntityWorld(), ((BlockHitResult)hitres).getBlockPos() ); - case ENTITY: - return (_c, _t) -> new EntityValue(((EntityHitResult)hitres).getEntity()); - } - return LazyValue.NULL; - }); } diff --git a/src/main/java/carpet/script/CarpetScriptServer.java b/src/main/java/carpet/script/CarpetScriptServer.java index 0b686ad3..8c96ea7d 100644 --- a/src/main/java/carpet/script/CarpetScriptServer.java +++ b/src/main/java/carpet/script/CarpetScriptServer.java @@ -14,16 +14,16 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.tree.CommandNode; +import net.minecraft.client.network.packet.ChunkDataS2CPacket; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.chunk.Chunk; +import org.apache.commons.lang3.tuple.Pair; import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static net.minecraft.server.command.CommandManager.argument; @@ -38,6 +38,7 @@ public class CarpetScriptServer public boolean stopAll; Set holyMoly; public CarpetEventServer events; + private Set> modifiedChunks = new HashSet<>(); public static List bundledModuleData = new ArrayList(){{ add(new CameraPathModule()); @@ -330,4 +331,24 @@ public class CarpetScriptServer } return true; } + + void markChunkForUpdate(ServerWorld world, BlockPos pos) + { + modifiedChunks.add(Pair.of(world, new ChunkPos(pos))); + } + + public void tick() + { + for (Pair tuple : modifiedChunks) + { + //ChunkDataS2CPacket + ServerWorld world = tuple.getLeft(); + ChunkPos chpos = tuple.getRight(); + Chunk chunk = world.getChunk(chpos.x, chpos.z); + //..... + + } + modifiedChunks.clear(); + events.tick(); + } } From 6871ac027c7e01b1b768d9a2510ea4c8468036da Mon Sep 17 00:00:00 2001 From: gnembon Date: Wed, 10 Jul 2019 13:07:54 -0300 Subject: [PATCH 04/13] proper block updating --- .../java/carpet/script/CarpetExpression.java | 14 ++++++++++++-- .../java/carpet/script/CarpetScriptServer.java | 16 ---------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index 5a04b640..105a7d1d 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -949,16 +949,26 @@ public class CarpetExpression this.expr.addLazyFunction("set_biome", -1, (c, t, lv) -> { CarpetContext cc = (CarpetContext)c; BlockValue.LocatorResult locator = BlockValue.fromParams(cc, lv, 0); + if (lv.size() == locator.offset) + throw new InternalExpressionException("set_biome needs a biome name as an argument"); String biomeName = lv.get(locator.offset+0).evalValue(c).getString(); Biome biome = Registry.BIOME.get(new Identifier(biomeName)); + if (biome == null) + throw new InternalExpressionException("Unknown biome: "+biomeName); byte biomeId = (byte) (Registry.BIOME.getRawId(biome) & 255); ServerWorld world = cc.s.getWorld(); BlockPos pos = locator.block.getPos(); Chunk chunk = world.getChunk(pos); chunk.getBiomeArray()[(pos.getX() & 15) | (pos.getZ() & 15) << 4] = biome; chunk.setShouldSave(true); - //world.method_14178().markForUpdate(pos); - CarpetServer.scriptServer.markChunkForUpdate(world, pos); + for (int i = 0; i<16; i++) + { + BlockPos section = new BlockPos((pos.getX()>>4 <<4)+8, 16*i, (pos.getZ()>>4 <<4)+8); + world.method_14178().markForUpdate(section); + world.method_14178().markForUpdate(section.east()); + world.method_14178().markForUpdate(section.west()); + world.method_14178().markForUpdate(section.north()); + } return LazyValue.NULL; }); diff --git a/src/main/java/carpet/script/CarpetScriptServer.java b/src/main/java/carpet/script/CarpetScriptServer.java index 8c96ea7d..81767381 100644 --- a/src/main/java/carpet/script/CarpetScriptServer.java +++ b/src/main/java/carpet/script/CarpetScriptServer.java @@ -38,7 +38,6 @@ public class CarpetScriptServer public boolean stopAll; Set holyMoly; public CarpetEventServer events; - private Set> modifiedChunks = new HashSet<>(); public static List bundledModuleData = new ArrayList(){{ add(new CameraPathModule()); @@ -332,23 +331,8 @@ public class CarpetScriptServer return true; } - void markChunkForUpdate(ServerWorld world, BlockPos pos) - { - modifiedChunks.add(Pair.of(world, new ChunkPos(pos))); - } - public void tick() { - for (Pair tuple : modifiedChunks) - { - //ChunkDataS2CPacket - ServerWorld world = tuple.getLeft(); - ChunkPos chpos = tuple.getRight(); - Chunk chunk = world.getChunk(chpos.x, chpos.z); - //..... - - } - modifiedChunks.clear(); events.tick(); } } From 3aa6c1d9250ff50516b2e96f499b20516323ba06 Mon Sep 17 00:00:00 2001 From: gnembon Date: Wed, 10 Jul 2019 17:20:36 -0300 Subject: [PATCH 05/13] chunk efresh --- .../java/carpet/script/CarpetExpression.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index 105a7d1d..49fa3af3 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -281,6 +281,20 @@ public class CarpetExpression return pcount; } + private void forceChunkUpdate(BlockPos pos, ServerWorld world) + { + Chunk chunk = world.getChunk(pos); + chunk.setShouldSave(true); + for (int i = 0; i<16; i++) + { + BlockPos section = new BlockPos((pos.getX()>>4 <<4)+8, 16*i, (pos.getZ()>>4 <<4)+8); + world.method_14178().markForUpdate(section); + world.method_14178().markForUpdate(section.east()); + world.method_14178().markForUpdate(section.west()); + world.method_14178().markForUpdate(section.north()); + } + } + /** *

Blocks / World API

*
@@ -656,7 +670,7 @@ public class CarpetExpression this.expr.addLazyFunction("blast_resistance", -1, (c, t, lv) -> genericStateTest(c, "blast_resistance", lv, (s, p, w) -> new NumericValue(s.getBlock().getBlastResistance()))); - + // Deprecated this.expr.addLazyFunction("top", -1, (c, t, lv) -> { String type = lv.get(0).evalValue(c).getString().toLowerCase(Locale.ROOT); @@ -960,15 +974,7 @@ public class CarpetExpression BlockPos pos = locator.block.getPos(); Chunk chunk = world.getChunk(pos); chunk.getBiomeArray()[(pos.getX() & 15) | (pos.getZ() & 15) << 4] = biome; - chunk.setShouldSave(true); - for (int i = 0; i<16; i++) - { - BlockPos section = new BlockPos((pos.getX()>>4 <<4)+8, 16*i, (pos.getZ()>>4 <<4)+8); - world.method_14178().markForUpdate(section); - world.method_14178().markForUpdate(section.east()); - world.method_14178().markForUpdate(section.west()); - world.method_14178().markForUpdate(section.north()); - } + this.forceChunkUpdate(pos, world); return LazyValue.NULL; }); @@ -2504,9 +2510,14 @@ public class CarpetExpression this.expr.addLazyFunction("plop", 4, (c, t, lv) ->{ BlockValue.LocatorResult locator = BlockValue.fromParams((CarpetContext)c, lv, 0); - Boolean res = FeatureGenerator.spawn(lv.get(locator.offset).evalValue(c).getString(), ((CarpetContext)c).s.getWorld(), locator.block.getPos()); + if (lv.size() <= locator.offset) + throw new InternalExpressionException("plop needs extra argument indicating what to plop"); + String what = lv.get(locator.offset).evalValue(c).getString(); + Boolean res = FeatureGenerator.spawn(what, ((CarpetContext)c).s.getWorld(), locator.block.getPos()); if (res == null) return (c_, t_) -> Value.NULL; + if (what.equalsIgnoreCase("boulder")) // there might be more of those + this.forceChunkUpdate(locator.block.getPos(), ((CarpetContext)c).s.getWorld()); return (c_, t_) -> new NumericValue(res); }); From 6e2ee7605fc3f4b3882a1b00099d79d4b5f8c234 Mon Sep 17 00:00:00 2001 From: gnembon Date: Thu, 11 Jul 2019 14:43:49 -0300 Subject: [PATCH 06/13] better handling of unknown exceptions --- src/main/java/carpet/script/Expression.java | 42 ++++++++++++++++++++- src/main/java/carpet/script/Fluff.java | 28 ++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/Expression.java b/src/main/java/carpet/script/Expression.java index 70a7c762..88ac9cac 100644 --- a/src/main/java/carpet/script/Expression.java +++ b/src/main/java/carpet/script/Expression.java @@ -506,6 +506,14 @@ public class Expression implements Cloneable { throw new ExpressionException(e, token, "Your math is wrong, "+exc.getMessage()); } + catch (ExitStatement exit) + { + throw exit; + } + catch (Exception exc) + { + throw new ExpressionException(e, token, "Error while evaluating expression: "+exc.getMessage()); + } } }); } @@ -532,6 +540,14 @@ public class Expression implements Cloneable { throw new ExpressionException(e, t, "Your math is wrong, "+exc.getMessage()); } + catch (ExitStatement exit) + { + throw exit; + } + catch (Exception exc) + { + throw new ExpressionException(e, t, "Error while evaluating expression: "+exc.getMessage()); + } } }); } @@ -557,6 +573,14 @@ public class Expression implements Cloneable { throw new ExpressionException(e, token, "Your math is wrong, "+exc.getMessage()); } + catch (ExitStatement exit) + { + throw exit; + } + catch (Exception exc) + { + throw new ExpressionException(e, token, "Error while evaluating expression: "+exc.getMessage()); + } } }); } @@ -663,6 +687,14 @@ public class Expression implements Cloneable { throw new ExpressionException(e, t, "Your math is wrong, "+exc.getMessage()); } + catch (ExitStatement exit) + { + throw exit; + } + catch (Exception exc) + { + throw new ExpressionException(e, t, "Error while evaluating expression: "+exc.getMessage()); + } } }); } @@ -725,7 +757,7 @@ public class Expression implements Cloneable { retVal = returnStatement.retval; } - catch (ThrowStatement throwStatement) + catch (ThrowStatement throwStatement) // might not be really necessary { retVal = throwStatement.retval; rethrow = true; @@ -738,6 +770,14 @@ public class Expression implements Cloneable { throw new ExpressionException(function_context, t, "Your math is wrong, "+exc.getMessage()); } + catch (ExitStatement exit) + { + throw exit; + } + catch (Exception exc) + { + throw new ExpressionException(e, t, "Error while evaluating expression: "+exc.getMessage()); + } for (String global: globals) { LazyValue lv = newFrame.getVariable(global); diff --git a/src/main/java/carpet/script/Fluff.java b/src/main/java/carpet/script/Fluff.java index c8d55378..082ecfdd 100644 --- a/src/main/java/carpet/script/Fluff.java +++ b/src/main/java/carpet/script/Fluff.java @@ -108,6 +108,18 @@ public abstract class Fluff { throw new ExpressionException(e, t, exc.getMessage()); } + catch (ArithmeticException exc) + { + throw new ExpressionException(e, t, "Your math is wrong, "+exc.getMessage()); + } + catch (Expression.ExitStatement exit) + { + throw exit; + } + catch (Exception exc) + { + throw new ExpressionException(e, t, "Error while evaluating expression: "+exc.getMessage()); + } } } @@ -154,6 +166,14 @@ public abstract class Fluff { throw new ExpressionException(e, t, "Your math is wrong, "+exc.getMessage()); } + catch (Expression.ExitStatement exit) + { + throw exit; + } + catch (Exception exc) + { + throw new ExpressionException(e, t, "Error while evaluating expression: "+exc.getMessage()); + } } } @@ -182,6 +202,14 @@ public abstract class Fluff { throw new ExpressionException(e, t, "Your math is wrong, "+exc.getMessage()); } + catch (Expression.ExitStatement exit) + { + throw exit; + } + catch (Exception exc) + { + throw new ExpressionException(e, t, "Error while evaluating expression: "+exc.getMessage()); + } } @Override From 99835f34741312ff2804a50480b24688648a9feb Mon Sep 17 00:00:00 2001 From: gnembon Date: Thu, 11 Jul 2019 17:09:55 -0300 Subject: [PATCH 07/13] better handling of unknown exceptions --- .../carpet/mixins/Entity_horseFixMixin.java | 35 +++++++++++++++++++ .../java/carpet/settings/CarpetSettings.java | 7 ++++ src/main/resources/carpet.mixins.json | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 src/main/java/carpet/mixins/Entity_horseFixMixin.java diff --git a/src/main/java/carpet/mixins/Entity_horseFixMixin.java b/src/main/java/carpet/mixins/Entity_horseFixMixin.java new file mode 100644 index 00000000..685c21a4 --- /dev/null +++ b/src/main/java/carpet/mixins/Entity_horseFixMixin.java @@ -0,0 +1,35 @@ +package carpet.mixins; + +import carpet.settings.CarpetSettings; +import net.minecraft.client.network.packet.EntityPositionS2CPacket; +import net.minecraft.entity.Entity; +import net.minecraft.entity.mob.MobEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.World; +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; + +@Mixin(Entity.class) +public abstract class Entity_horseFixMixin +{ + @Shadow private Entity vehicle; + + @Shadow public abstract World getEntityWorld(); + + @Inject(method = "stopRiding", at = @At("HEAD")) + private void resetNavigation(CallbackInfo ci) + { + if (vehicle != null && vehicle instanceof MobEntity && CarpetSettings.horseWanderingFix) + { + ((MobEntity) vehicle).getNavigation().stop(); + if (!getEntityWorld().isClient) + { + ((ServerWorld) getEntityWorld()).method_14178().sendToNearbyPlayers((Entity)(Object)this, new EntityPositionS2CPacket(vehicle)); + } + } + } + +} diff --git a/src/main/java/carpet/settings/CarpetSettings.java b/src/main/java/carpet/settings/CarpetSettings.java index 1d46be6e..89416edf 100644 --- a/src/main/java/carpet/settings/CarpetSettings.java +++ b/src/main/java/carpet/settings/CarpetSettings.java @@ -401,4 +401,11 @@ public class CarpetSettings @Rule(desc = "Spawning requires much less CPU and Memory", category = OPTIMIZATION) public static boolean lagFreeSpawning = false; + + @Rule( + desc = "Prevents horses and other mobs to wander into the distance after dismounting", + extra = "Fixes issues with various Joergens wandering off and disappearing client-side", + category = BUGFIX + ) + public static boolean horseWanderingFix = false; } diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 3c35b4a8..3fb50f52 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -81,6 +81,8 @@ "Entity_portalSuffocationMixin", "PortalForcer_portalSuffocationMixin", + "Entity_horseFixMixin", + "HopperBlockEntityMixin", "ContainerMixin", "ClientConnectionMixin", From 99229280c25516ad8622fc0f39995eaa6717ee84 Mon Sep 17 00:00:00 2001 From: gnembon Date: Mon, 15 Jul 2019 08:50:27 -0300 Subject: [PATCH 08/13] player modules --- src/main/java/carpet/commands/ScriptCommand.java | 2 +- src/main/java/carpet/script/CarpetScriptServer.java | 12 ++++++++---- src/main/java/carpet/script/ScriptHost.java | 13 ++++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/carpet/commands/ScriptCommand.java b/src/main/java/carpet/commands/ScriptCommand.java index dbd31102..dd9034bf 100644 --- a/src/main/java/carpet/commands/ScriptCommand.java +++ b/src/main/java/carpet/commands/ScriptCommand.java @@ -206,7 +206,7 @@ public class ScriptCommand suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.listAvailableModules(),bb)). executes((cc) -> { - boolean success = CarpetServer.scriptServer.addScriptHost(cc.getSource(), StringArgumentType.getString(cc, "package")); + boolean success = CarpetServer.scriptServer.addScriptHost(cc.getSource(), StringArgumentType.getString(cc, "package"), false); return success?1:0; }) ); diff --git a/src/main/java/carpet/script/CarpetScriptServer.java b/src/main/java/carpet/script/CarpetScriptServer.java index 81767381..531bc48f 100644 --- a/src/main/java/carpet/script/CarpetScriptServer.java +++ b/src/main/java/carpet/script/CarpetScriptServer.java @@ -15,6 +15,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.tree.CommandNode; import net.minecraft.client.network.packet.ChunkDataS2CPacket; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; @@ -34,6 +35,7 @@ public class CarpetScriptServer //make static for now, but will change that later: public ScriptHost globalHost; public Map modules; + public Map, ScriptHost> playerModules; long tickStart; public boolean stopAll; Set holyMoly; @@ -45,7 +47,7 @@ public class CarpetScriptServer public CarpetScriptServer() { - globalHost = createMinecraftScriptHost(null); + globalHost = createMinecraftScriptHost(null, null); events = new CarpetEventServer(); modules = new HashMap<>(); tickStart = 0L; @@ -113,7 +115,7 @@ public class CarpetScriptServer } - private static ScriptHost createMinecraftScriptHost(String name) + private static ScriptHost createMinecraftScriptHost(String name, ModuleInterface code) { ScriptHost host = new ScriptHost(name); host.globalVariables.put("_x", (c, t) -> Value.ZERO); @@ -122,11 +124,13 @@ public class CarpetScriptServer return host; } - public boolean addScriptHost(ServerCommandSource source, String name) + public boolean addScriptHost(ServerCommandSource source, String name, boolean perPlayer) { name = name.toLowerCase(Locale.ROOT); - ScriptHost newHost = createMinecraftScriptHost(name); ModuleInterface module = getModule(name); + ScriptHost newHost = createMinecraftScriptHost(name, module); + // move to host constructor..... + ..... if (module == null) { Messenger.m(source, "r Unable to locate the package, but created empty host "+name+" instead"); diff --git a/src/main/java/carpet/script/ScriptHost.java b/src/main/java/carpet/script/ScriptHost.java index 18852b7a..3341c848 100644 --- a/src/main/java/carpet/script/ScriptHost.java +++ b/src/main/java/carpet/script/ScriptHost.java @@ -1,6 +1,7 @@ package carpet.script; import carpet.CarpetServer; +import carpet.script.bundled.ModuleInterface; import carpet.settings.CarpetSettings; import carpet.script.exception.ExpressionException; import carpet.script.exception.InvalidCallbackException; @@ -30,9 +31,14 @@ public class ScriptHost private String name; public String getName() {return name;} - ScriptHost(String name) + private ModuleInterface myCode; + + ScriptHost(String name) { this(name, null);} + + ScriptHost(String name, ModuleInterface code) { this.name = name; + this.myCode = code; globalVariables.put("euler", (c, t) -> Expression.euler); globalVariables.put("pi", (c, t) -> Expression.PI); globalVariables.put("null", (c, t) -> Value.NULL); @@ -44,6 +50,11 @@ public class ScriptHost globalVariables.put("_i", (c, t) -> Value.ZERO); globalVariables.put("_a", (c, t) -> Value.ZERO); } + + public boolean replicable() { return myCode != null; } + + public ScriptHost replicate() { return new ScriptHost(name, myCode); } + public Expression getExpressionForFunction(String name) { return globalFunctions.get(name).getExpression(); From 16e4649a2323d267409019ee6bd7c84109e4a370 Mon Sep 17 00:00:00 2001 From: gnembon Date: Mon, 15 Jul 2019 11:16:12 -0300 Subject: [PATCH 09/13] not needed here --- src/main/java/carpet/script/CarpetScriptServer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/carpet/script/CarpetScriptServer.java b/src/main/java/carpet/script/CarpetScriptServer.java index 531bc48f..1229b85e 100644 --- a/src/main/java/carpet/script/CarpetScriptServer.java +++ b/src/main/java/carpet/script/CarpetScriptServer.java @@ -35,7 +35,6 @@ public class CarpetScriptServer //make static for now, but will change that later: public ScriptHost globalHost; public Map modules; - public Map, ScriptHost> playerModules; long tickStart; public boolean stopAll; Set holyMoly; From 45b13f31e472c1db1152aeea1f98ee71c9c33463 Mon Sep 17 00:00:00 2001 From: gnembon Date: Mon, 15 Jul 2019 12:31:36 -0300 Subject: [PATCH 10/13] set_biome --- src/main/java/carpet/script/CarpetExpression.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index 49fa3af3..042c0ebc 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -352,6 +352,8 @@ public class CarpetExpression * place_item('piston,x,y,z,'down') // places a piston facing down * place_item('carrot',x,y,z) // attempts to plant a carrot plant. Returns true if could place carrots at that position. * + *

set_biome(pos, biome_name)

+ *

changes biome at that block position.

*

update(pos)

*

Causes a block update at position.

*

block_tick(pos)

@@ -942,7 +944,7 @@ public class CarpetExpression return (_c, _t) -> retval; }); - this.expr.addLazyFunction("trace_block", -1, (c, t, lv) -> { + /*this.expr.addLazyFunction("trace_block", -1, (c, t, lv) -> { Value entityValue = lv.get(0).evalValue(c); if (!(entityValue instanceof EntityValue)) throw new InternalExpressionException("First argument of trace_block should be an entity"); @@ -958,7 +960,7 @@ public class CarpetExpression return (_c, _t) -> new EntityValue(((EntityHitResult)hitres).getEntity()); } return LazyValue.NULL; - }); + });*/ this.expr.addLazyFunction("set_biome", -1, (c, t, lv) -> { CarpetContext cc = (CarpetContext)c; @@ -969,15 +971,14 @@ public class CarpetExpression Biome biome = Registry.BIOME.get(new Identifier(biomeName)); if (biome == null) throw new InternalExpressionException("Unknown biome: "+biomeName); - byte biomeId = (byte) (Registry.BIOME.getRawId(biome) & 255); ServerWorld world = cc.s.getWorld(); BlockPos pos = locator.block.getPos(); Chunk chunk = world.getChunk(pos); chunk.getBiomeArray()[(pos.getX() & 15) | (pos.getZ() & 15) << 4] = biome; this.forceChunkUpdate(pos, world); return LazyValue.NULL; - }); + // need get_biome } From dd611d74db92d2ee3f54a0110e0da5231c396d4f Mon Sep 17 00:00:00 2001 From: gnembon Date: Mon, 15 Jul 2019 12:34:13 -0300 Subject: [PATCH 11/13] added todo --- src/main/java/carpet/script/CarpetScriptServer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/carpet/script/CarpetScriptServer.java b/src/main/java/carpet/script/CarpetScriptServer.java index 1229b85e..dacc0e7c 100644 --- a/src/main/java/carpet/script/CarpetScriptServer.java +++ b/src/main/java/carpet/script/CarpetScriptServer.java @@ -125,11 +125,10 @@ public class CarpetScriptServer public boolean addScriptHost(ServerCommandSource source, String name, boolean perPlayer) { + //TODO add per player modules to support player actions better on a server name = name.toLowerCase(Locale.ROOT); ModuleInterface module = getModule(name); ScriptHost newHost = createMinecraftScriptHost(name, module); - // move to host constructor..... - ..... if (module == null) { Messenger.m(source, "r Unable to locate the package, but created empty host "+name+" instead"); From b967e74ac67448c94980fb21ec5a254ba9bc771c Mon Sep 17 00:00:00 2001 From: gnembon Date: Mon, 15 Jul 2019 12:47:08 -0300 Subject: [PATCH 12/13] fix imports --- .../java/carpet/script/CarpetScriptServer.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/carpet/script/CarpetScriptServer.java b/src/main/java/carpet/script/CarpetScriptServer.java index dacc0e7c..b736b15a 100644 --- a/src/main/java/carpet/script/CarpetScriptServer.java +++ b/src/main/java/carpet/script/CarpetScriptServer.java @@ -1,7 +1,6 @@ package carpet.script; import carpet.CarpetServer; -import carpet.settings.CarpetSettings; import carpet.script.bundled.CameraPathModule; import carpet.script.bundled.FileModule; import carpet.script.bundled.ModuleInterface; @@ -14,17 +13,16 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.tree.CommandNode; -import net.minecraft.client.network.packet.ChunkDataS2CPacket; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.chunk.Chunk; -import org.apache.commons.lang3.tuple.Pair; import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import static net.minecraft.server.command.CommandManager.argument; From 1dcf35bbf067630da2b89e492ee8f04762f74e98 Mon Sep 17 00:00:00 2001 From: gnembon Date: Mon, 15 Jul 2019 12:50:44 -0300 Subject: [PATCH 13/13] not needed --- src/main/java/carpet/script/ScriptHost.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/carpet/script/ScriptHost.java b/src/main/java/carpet/script/ScriptHost.java index 3341c848..58651f55 100644 --- a/src/main/java/carpet/script/ScriptHost.java +++ b/src/main/java/carpet/script/ScriptHost.java @@ -51,10 +51,6 @@ public class ScriptHost globalVariables.put("_a", (c, t) -> Value.ZERO); } - public boolean replicable() { return myCode != null; } - - public ScriptHost replicate() { return new ScriptHost(name, myCode); } - public Expression getExpressionForFunction(String name) { return globalFunctions.get(name).getExpression();