From cb6214dec9bd1341e6844ecd1aa0f2757f166bd8 Mon Sep 17 00:00:00 2001 From: gnembon Date: Fri, 13 Sep 2019 09:31:26 -0300 Subject: [PATCH 1/9] 0 return state doesn't mean a failed command --- src/main/java/carpet/helpers/TickSpeed.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/java/carpet/helpers/TickSpeed.java b/src/main/java/carpet/helpers/TickSpeed.java index d5be837c..08165846 100644 --- a/src/main/java/carpet/helpers/TickSpeed.java +++ b/src/main/java/carpet/helpers/TickSpeed.java @@ -89,15 +89,7 @@ public class TickSpeed CommandManager icommandmanager = tick_warp_sender.getMinecraftServer().getCommandManager(); try { - int j = icommandmanager.execute(tick_warp_sender, tick_warp_callback); - - if (j < 1) - { - if (time_advancerer != null) - { - Messenger.m(time_advancerer, "r Command Callback failed: ", "rb /"+tick_warp_callback,"/"+tick_warp_callback); - } - } + icommandmanager.execute(tick_warp_sender, tick_warp_callback); } catch (Throwable var23) { From 296d327d640a56dff0b9bbf0172b1b8cb85da2df Mon Sep 17 00:00:00 2001 From: gnembon Date: Fri, 13 Sep 2019 09:32:38 -0300 Subject: [PATCH 2/9] custom rule values are displayed on the rule menus. --- src/main/java/carpet/settings/SettingsManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/carpet/settings/SettingsManager.java b/src/main/java/carpet/settings/SettingsManager.java index c430bf23..eb14dc04 100644 --- a/src/main/java/carpet/settings/SettingsManager.java +++ b/src/main/java/carpet/settings/SettingsManager.java @@ -434,6 +434,11 @@ public class SettingsManager args.add(makeSetRuleButton(rule, option, true)); args.add("w "); } + if (!rule.options.contains(rule.getAsString())) + { + args.add(makeSetRuleButton(rule, rule.getAsString(), true)); + args.add("w "); + } args.remove(args.size()-1); return Messenger.c(args.toArray(new Object[0])); } From aeceacc73332e6cb4b42cdef52f1e2a0f65fe53f Mon Sep 17 00:00:00 2001 From: gnembon Date: Fri, 13 Sep 2019 09:39:53 -0300 Subject: [PATCH 3/9] tick warp will display better messages in case its busy. --- src/main/java/carpet/helpers/TickSpeed.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet/helpers/TickSpeed.java b/src/main/java/carpet/helpers/TickSpeed.java index 08165846..8cf8982d 100644 --- a/src/main/java/carpet/helpers/TickSpeed.java +++ b/src/main/java/carpet/helpers/TickSpeed.java @@ -59,7 +59,9 @@ public class TickSpeed } if (time_bias > 0) { - return Messenger.c("l Another player is already advancing time at the moment. Try later or talk to them"); + String who = "Another player"; + if (time_advancerer != null) who = time_advancerer.getEntityName(); + return Messenger.c("l "+who+" is already advancing time at the moment. Try later or ask them"); } time_advancerer = player; time_warp_start_time = System.nanoTime(); From 8ece019f71d6a4ece81b556901685fffe1db2746 Mon Sep 17 00:00:00 2001 From: gnembon Date: Fri, 13 Sep 2019 12:06:38 -0300 Subject: [PATCH 4/9] fixed harlem shake and directionality in superhot --- .../MinecraftClient_pausedShakeMixin.java | 24 +++++++++++++++++++ .../ServerPlayNetworkHandler_tickMixin.java | 4 +++- src/main/resources/carpet.mixins.json | 3 ++- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/main/java/carpet/mixins/MinecraftClient_pausedShakeMixin.java diff --git a/src/main/java/carpet/mixins/MinecraftClient_pausedShakeMixin.java b/src/main/java/carpet/mixins/MinecraftClient_pausedShakeMixin.java new file mode 100644 index 00000000..9865af5b --- /dev/null +++ b/src/main/java/carpet/mixins/MinecraftClient_pausedShakeMixin.java @@ -0,0 +1,24 @@ +package carpet.mixins; + +import carpet.helpers.TickSpeed; +import net.minecraft.client.MinecraftClient; +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.Redirect; + +@Mixin(MinecraftClient.class) +public class MinecraftClient_pausedShakeMixin +{ + @Shadow private boolean paused; + + @Redirect(method = "render", at = @At( + value = "FIELD", + target = "Lnet/minecraft/client/MinecraftClient;paused:Z", + ordinal = 0 + )) + private boolean isPausedForRendering(MinecraftClient client) + { + return paused || !TickSpeed.process_entities; + } +} diff --git a/src/main/java/carpet/mixins/ServerPlayNetworkHandler_tickMixin.java b/src/main/java/carpet/mixins/ServerPlayNetworkHandler_tickMixin.java index afe068cb..480f53fa 100644 --- a/src/main/java/carpet/mixins/ServerPlayNetworkHandler_tickMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayNetworkHandler_tickMixin.java @@ -36,7 +36,9 @@ public class ServerPlayNetworkHandler_tickMixin )) private void checkMove(PlayerMoveC2SPacket p, CallbackInfo ci) { - if (p.getX(player.x) - lastTickX > 0.0001D || p.getY(player.y) - lastTickY > 0.0001D || p.getY(player.y) - lastTickY > 0.0001D) + if (Math.abs(p.getX(player.x) - lastTickX) > 0.0001D + || Math.abs(p.getY(player.y) - lastTickY) > 0.0001D + || Math.abs(p.getY(player.y) - lastTickY) > 0.0001D) { TickSpeed.reset_player_active_timeout(); } diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 174a43f0..4cd22f74 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -138,7 +138,8 @@ "ClientPlayerInteractionManager_ghostBlocksMixin", "BlockEntityRenderDispatcher_movableTEMixin", - "PistonBlockEntityRenderer_movableTEMixin" + "PistonBlockEntityRenderer_movableTEMixin", + "MinecraftClient_pausedShakeMixin" ], "server": [ "MinecraftDedicatedServerMixin" From 256d54fab72228c9c13756f17ee317de3ebbc1a7 Mon Sep 17 00:00:00 2001 From: gnembon Date: Fri, 13 Sep 2019 17:00:14 -0300 Subject: [PATCH 5/9] removed all mentions of a tile per official Micro$oft corporate mappings --- README.md | 4 ++-- .../PistonBlockEntityRenderer_movableTEMixin.java | 2 +- .../mixins/PistonBlockEntity_movableTEMixin.java | 10 +++++----- .../java/carpet/mixins/PistonBlock_movableTEMixin.java | 10 +++++----- .../carpet/mixins/PistonHandler_movableTEMixin.java | 4 ++-- .../java/carpet/mixins/WorldChunk_movableTEMixin.java | 2 +- src/main/java/carpet/mixins/World_tickMixin.java | 2 +- src/main/java/carpet/settings/CarpetSettings.java | 4 ++-- src/main/java/carpet/utils/CarpetProfiler.java | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 79a0c148..3b0bd2e7 100644 --- a/README.md +++ b/README.md @@ -276,8 +276,8 @@ Pistons, Glass and Sponge can be broken faster with their appropriate tools * Required options: `true`, `false` * Categories: `SURVIVAL` -## movableTileEntities -Pistons can push tile entities, like hoppers, chests etc. +## movableBlockEntities +Pistons can push block entities, like hoppers, chests etc. * Type: `boolean` * Default value: `false` * Required options: `true`, `false` diff --git a/src/main/java/carpet/mixins/PistonBlockEntityRenderer_movableTEMixin.java b/src/main/java/carpet/mixins/PistonBlockEntityRenderer_movableTEMixin.java index 9be523af..f841ae43 100644 --- a/src/main/java/carpet/mixins/PistonBlockEntityRenderer_movableTEMixin.java +++ b/src/main/java/carpet/mixins/PistonBlockEntityRenderer_movableTEMixin.java @@ -22,7 +22,7 @@ public abstract class PistonBlockEntityRenderer_movableTEMixin extends BlockEnti double double_3, float float_1, int int_1, CallbackInfo ci) { if (!((PistonBlockEntityInterface) pistonBlockEntity_1).isRenderModeSet()) - ((PistonBlockEntityInterface) pistonBlockEntity_1).setRenderCarriedBlockEntity(CarpetSettings.movableTileEntities && ((PistonBlockEntityInterface) pistonBlockEntity_1).getCarriedBlockEntity() != null); + ((PistonBlockEntityInterface) pistonBlockEntity_1).setRenderCarriedBlockEntity(CarpetSettings.movableBlockEntities && ((PistonBlockEntityInterface) pistonBlockEntity_1).getCarriedBlockEntity() != null); } @Inject(method = "method_3576", at = @At("RETURN")) diff --git a/src/main/java/carpet/mixins/PistonBlockEntity_movableTEMixin.java b/src/main/java/carpet/mixins/PistonBlockEntity_movableTEMixin.java index 0de7a544..667950af 100644 --- a/src/main/java/carpet/mixins/PistonBlockEntity_movableTEMixin.java +++ b/src/main/java/carpet/mixins/PistonBlockEntity_movableTEMixin.java @@ -77,7 +77,7 @@ public abstract class PistonBlockEntity_movableTEMixin extends BlockEntity imple target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) private boolean movableTEsetBlockState0(World world, BlockPos blockPos_1, BlockState blockAState_2, int int_1) { - if (!CarpetSettings.movableTileEntities) + if (!CarpetSettings.movableBlockEntities) return world.setBlockState(blockPos_1, blockAState_2, int_1); else return ((WorldInterface) (world)).setBlockStateWithBlockEntity(blockPos_1, blockAState_2, this.carriedBlockEntity, int_1); @@ -87,7 +87,7 @@ public abstract class PistonBlockEntity_movableTEMixin extends BlockEntity imple target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) private boolean movableTEsetBlockState1(World world, BlockPos blockPos_1, BlockState blockState_2, int int_1) { - if (!CarpetSettings.movableTileEntities) + if (!CarpetSettings.movableBlockEntities) return world.setBlockState(blockPos_1, blockState_2, int_1); else { @@ -103,7 +103,7 @@ public abstract class PistonBlockEntity_movableTEMixin extends BlockEntity imple //Handle TNT Explosions or other ways the moving Block is broken //Also /setblock will cause this to be called, and drop e.g. a moving chest's contents. // This is MC-40380 (BlockEntities that aren't Inventories drop stuff when setblock is called ) - if (CarpetSettings.movableTileEntities && this.carriedBlockEntity != null && !this.world.isClient && this.world.getBlockState(this.pos).getBlock() == Blocks.AIR) + if (CarpetSettings.movableBlockEntities && this.carriedBlockEntity != null && !this.world.isClient && this.world.getBlockState(this.pos).getBlock() == Blocks.AIR) { BlockState blockState_2; if (this.source) @@ -118,7 +118,7 @@ public abstract class PistonBlockEntity_movableTEMixin extends BlockEntity imple @Inject(method = "fromTag", at = @At(value = "TAIL")) private void onFromTag(CompoundTag compoundTag_1, CallbackInfo ci) { - if (CarpetSettings.movableTileEntities && compoundTag_1.containsKey("carriedTileEntityCM", 10)) + if (CarpetSettings.movableBlockEntities && compoundTag_1.containsKey("carriedTileEntityCM", 10)) { if (this.pushedBlock.getBlock() instanceof BlockEntityProvider) this.carriedBlockEntity = ((BlockEntityProvider) (this.pushedBlock.getBlock())).createBlockEntity(this.world); @@ -130,7 +130,7 @@ public abstract class PistonBlockEntity_movableTEMixin extends BlockEntity imple @Inject(method = "toTag", at = @At(value = "RETURN", shift = At.Shift.BEFORE)) private void onToTag(CompoundTag compoundTag_1, CallbackInfoReturnable cir) { - if (CarpetSettings.movableTileEntities && this.carriedBlockEntity != null) + if (CarpetSettings.movableBlockEntities && this.carriedBlockEntity != null) { //Leave name "carriedTileEntityCM" instead of "carriedBlockEntityCM" for upgrade compatibility with 1.13.2 movable TE compoundTag_1.put("carriedTileEntityCM", this.carriedBlockEntity.toTag(new CompoundTag())); diff --git a/src/main/java/carpet/mixins/PistonBlock_movableTEMixin.java b/src/main/java/carpet/mixins/PistonBlock_movableTEMixin.java index 7dda8b94..d06b10bb 100644 --- a/src/main/java/carpet/mixins/PistonBlock_movableTEMixin.java +++ b/src/main/java/carpet/mixins/PistonBlock_movableTEMixin.java @@ -35,13 +35,13 @@ public abstract class PistonBlock_movableTEMixin extends FacingBlock { Block block_1 = blockState_1.getBlock(); //Make CommandBlocks movable, either use instanceof CommandBlock or the 3 cmd block objects, - if (CarpetSettings.movableTileEntities && block_1 instanceof CommandBlock) + if (CarpetSettings.movableBlockEntities && block_1 instanceof CommandBlock) { cir.setReturnValue(true); } } - private static boolean isPushableTileEntityBlock(Block block) + private static boolean isPushableBlockEntity(Block block) { //Making PISTON_EXTENSION (BlockPistonMoving) pushable would not work as its createNewTileEntity()-method returns null return block != Blocks.ENDER_CHEST && block != Blocks.ENCHANTING_TABLE && @@ -58,7 +58,7 @@ public abstract class PistonBlock_movableTEMixin extends FacingBlock } else { - return !(CarpetSettings.movableTileEntities && isPushableTileEntityBlock(block)); + return !(CarpetSettings.movableBlockEntities && isPushableBlockEntity(block)); } } @Inject(method = "move", at = @At(value = "INVOKE", shift = At.Shift.BEFORE, @@ -69,7 +69,7 @@ public abstract class PistonBlock_movableTEMixin extends FacingBlock Direction direction_2, Set set_1) { //Get the blockEntities and remove them from the world before any magic starts to happen - if (CarpetSettings.movableTileEntities) + if (CarpetSettings.movableBlockEntities) { list1_BlockEntities.set(Lists.newArrayList()); for (int i = 0; i < list_1.size(); ++i) @@ -99,7 +99,7 @@ public abstract class PistonBlock_movableTEMixin extends FacingBlock { BlockEntity blockEntityPiston = PistonExtensionBlock.createBlockEntityPiston((BlockState) list_2.get(int_3), direction_1, boolean_1, false); - if (CarpetSettings.movableTileEntities) + if (CarpetSettings.movableBlockEntities) ((PistonBlockEntityInterface) blockEntityPiston).setCarriedBlockEntity(list1_BlockEntities.get().get(int_3)); world_1.setBlockEntity(blockPos_4, blockEntityPiston); } diff --git a/src/main/java/carpet/mixins/PistonHandler_movableTEMixin.java b/src/main/java/carpet/mixins/PistonHandler_movableTEMixin.java index c21e21f3..17c2e9e4 100644 --- a/src/main/java/carpet/mixins/PistonHandler_movableTEMixin.java +++ b/src/main/java/carpet/mixins/PistonHandler_movableTEMixin.java @@ -66,7 +66,7 @@ public abstract class PistonHandler_movableTEMixin * @author 2No2Name */ private boolean stickToStickySide(BlockPos blockPos_1){ - if(!CarpetSettings.movableTileEntities) + if(!CarpetSettings.movableBlockEntities) return true; BlockState blockState_1 = this.world.getBlockState(blockPos_1); @@ -107,7 +107,7 @@ public abstract class PistonHandler_movableTEMixin * @author 2No2Nameb */ private Block redirectSlimeBlock() { - if (CarpetSettings.movableTileEntities && isStickyOnSide(blockState_1, this.direction.getOpposite())) + if (CarpetSettings.movableBlockEntities && isStickyOnSide(blockState_1, this.direction.getOpposite())) return blockState_1.getBlock(); //this makes the comparison in the while condition "while(blockState_1.getBlock() == redirectSlimeBlock())" evaluate to true, so the block is treated as sticky else return Blocks.SLIME_BLOCK; //vanilla behavior diff --git a/src/main/java/carpet/mixins/WorldChunk_movableTEMixin.java b/src/main/java/carpet/mixins/WorldChunk_movableTEMixin.java index 161f72e8..ac1d56d9 100644 --- a/src/main/java/carpet/mixins/WorldChunk_movableTEMixin.java +++ b/src/main/java/carpet/mixins/WorldChunk_movableTEMixin.java @@ -48,7 +48,7 @@ public abstract class WorldChunk_movableTEMixin implements WorldChunkInterface private BlockEntity ifGetBlockEntity(WorldChunk worldChunk, BlockPos blockPos_1, WorldChunk.CreationType worldChunk$CreationType_1) { - if (!CarpetSettings.movableTileEntities) + if (!CarpetSettings.movableBlockEntities) { return this.getBlockEntity(blockPos_1, WorldChunk.CreationType.CHECK); } diff --git a/src/main/java/carpet/mixins/World_tickMixin.java b/src/main/java/carpet/mixins/World_tickMixin.java index 0d18805d..2abb4257 100644 --- a/src/main/java/carpet/mixins/World_tickMixin.java +++ b/src/main/java/carpet/mixins/World_tickMixin.java @@ -36,7 +36,7 @@ public abstract class World_tickMixin implements WorldInterface @Inject(method = "tickBlockEntities", at = @At("HEAD")) private void startBlockEntities(CallbackInfo ci) { - currentSection = CarpetProfiler.start_section((World) (Object) this, "Tile Entities", CarpetProfiler.TYPE.GENERAL); + currentSection = CarpetProfiler.start_section((World) (Object) this, "Block Entities", CarpetProfiler.TYPE.GENERAL); } @Inject(method = "tickBlockEntities", at = @At("TAIL")) diff --git a/src/main/java/carpet/settings/CarpetSettings.java b/src/main/java/carpet/settings/CarpetSettings.java index 85ef7e9a..3400c596 100644 --- a/src/main/java/carpet/settings/CarpetSettings.java +++ b/src/main/java/carpet/settings/CarpetSettings.java @@ -147,8 +147,8 @@ public class CarpetSettings @Rule( desc = "Guardians turn into Elder Guardian when struck by lightning", category = FEATURE ) public static boolean renewableSponges = false; - @Rule( desc = "Pistons can push tile entities, like hoppers, chests etc.", category = {EXPERIMENTAL, FEATURE} ) - public static boolean movableTileEntities = false; + @Rule( desc = "Pistons can push block entities, like hoppers, chests etc.", category = {EXPERIMENTAL, FEATURE} ) + public static boolean movableBlockEntities = false; @Rule( desc = "Saplings turn into dead shrubs in hot climates and no water access", category = FEATURE ) public static boolean desertShrubs = false; diff --git a/src/main/java/carpet/utils/CarpetProfiler.java b/src/main/java/carpet/utils/CarpetProfiler.java index 70bf4a63..f9facb78 100644 --- a/src/main/java/carpet/utils/CarpetProfiler.java +++ b/src/main/java/carpet/utils/CarpetProfiler.java @@ -25,8 +25,8 @@ public class CarpetProfiler private static String[] DIMENSIONS = {"overworld", "the_end", "the_nether"}; private static String[] SECTIONS = { "Spawning and Random Ticks", "Ticket Manager","Unloading", - "Blocks", "Entities", "Tile Entities", - "Entities (Client)", "Tile Entities (Client)", + "Blocks", "Entities", "Block Entities", + "Entities (Client)", "Block Entities (Client)", "Village", "Environment"}; public enum TYPE From 7e2a001be5da040dc9f7aaaf5dc80c11f5410107 Mon Sep 17 00:00:00 2001 From: gnembon Date: Sat, 14 Sep 2019 20:08:49 -0300 Subject: [PATCH 6/9] sending command trees are deferred to the end of the tick. --- src/main/java/carpet/settings/SettingsManager.java | 10 +++++++--- src/main/java/carpet/utils/SpawnReporter.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/carpet/settings/SettingsManager.java b/src/main/java/carpet/settings/SettingsManager.java index eb14dc04..7e8c838b 100644 --- a/src/main/java/carpet/settings/SettingsManager.java +++ b/src/main/java/carpet/settings/SettingsManager.java @@ -11,6 +11,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.ServerTask; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.BaseText; @@ -168,10 +169,13 @@ public class SettingsManager { return; } - for (ServerPlayerEntity entityplayermp : server.getPlayerManager().getPlayerList()) + server.method_18858(new ServerTask(this.server.getTicks(), () -> { - server.getCommandManager().sendCommandTree(entityplayermp); - } + for (ServerPlayerEntity entityplayermp : server.getPlayerManager().getPlayerList()) + { + server.getCommandManager().sendCommandTree(entityplayermp); + } + })); } private void loadConfigurationFromConf() diff --git a/src/main/java/carpet/utils/SpawnReporter.java b/src/main/java/carpet/utils/SpawnReporter.java index 97b8419e..1a64628b 100644 --- a/src/main/java/carpet/utils/SpawnReporter.java +++ b/src/main/java/carpet/utils/SpawnReporter.java @@ -109,7 +109,7 @@ public class SpawnReporter int rounds = spawn_tries.get(enumcreaturetype); lst.add(Messenger.c(String.format("w %s: ", enumcreaturetype.getName()), (cur < 0) ? "g -" : (color + " " + cur), "g / ", mobColor + " " + max, - (rounds == 1) ? "w " : String.format("fi (%d rounds/tick)", spawn_tries.get(enumcreaturetype)) + (rounds == 1) ? "w " : String.format("gi (%d rounds/tick)", spawn_tries.get(enumcreaturetype)) )); } else From 8b7e9143da937e57cc5ecae4b375a534d55c2871 Mon Sep 17 00:00:00 2001 From: gnembon Date: Sat, 14 Sep 2019 23:05:20 -0300 Subject: [PATCH 7/9] added in_dimension to the API --- .../java/carpet/script/CarpetEventServer.java | 16 +++--- .../java/carpet/script/CarpetExpression.java | 53 +++++++++++++++++-- .../java/carpet/script/value/BlockValue.java | 9 ++-- .../java/carpet/script/value/EntityValue.java | 6 +-- 4 files changed, 66 insertions(+), 18 deletions(-) diff --git a/src/main/java/carpet/script/CarpetEventServer.java b/src/main/java/carpet/script/CarpetEventServer.java index 461dde8f..fb352c64 100644 --- a/src/main/java/carpet/script/CarpetEventServer.java +++ b/src/main/java/carpet/script/CarpetEventServer.java @@ -302,7 +302,7 @@ public class CarpetEventServer { eventHandlers.get("player_clicks_block").call( () -> Arrays.asList( ((c, t) -> new EntityValue(player)), - ((c, t) -> new BlockValue(null, player.world, blockpos)), + ((c, t) -> new BlockValue(null, player.getServerWorld(), blockpos)), ((c, t) -> new StringValue(facing.getName())) ), player::getCommandSource); } @@ -319,7 +319,7 @@ public class CarpetEventServer ((c, t) -> new EntityValue(player)), ((c, t) -> ListValue.fromItemStack(itemstack)), ((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")), - ((c, t) -> new BlockValue(null, player.world, blockpos)), + ((c, t) -> new BlockValue(null, player.getServerWorld(), blockpos)), ((c, t) -> new StringValue(enumfacing.getName())), ((c, t) -> ListValue.of( new NumericValue(vec3d.x), @@ -330,11 +330,11 @@ public class CarpetEventServer }, player::getCommandSource); } - public void onBlockBroken(PlayerEntity player, BlockPos pos, BlockState previousBS) + public void onBlockBroken(ServerPlayerEntity player, BlockPos pos, BlockState previousBS) { eventHandlers.get("player_breaks_block").call( () -> Arrays.asList( ((c, t) -> new EntityValue(player)), - ((c, t) -> new BlockValue(previousBS, player.getEntityWorld(), pos)) + ((c, t) -> new BlockValue(previousBS, player.getServerWorld(), pos)) ), player::getCommandSource); } @@ -355,22 +355,22 @@ public class CarpetEventServer ), player::getCommandSource); } - public void onStartSneaking(PlayerEntity player) + public void onStartSneaking(ServerPlayerEntity player) { eventHandlers.get("player_starts_sneaking").call( () -> Arrays.asList(((c, t) -> new EntityValue(player))), player::getCommandSource); } - public void onStopSneaking(PlayerEntity player) + public void onStopSneaking(ServerPlayerEntity player) { eventHandlers.get("player_stops_sneaking").call( () -> Arrays.asList(((c, t) -> new EntityValue(player))), player::getCommandSource); } - public void onStartSprinting(PlayerEntity player) + public void onStartSprinting(ServerPlayerEntity player) { eventHandlers.get("player_starts_sprinting").call( () -> Arrays.asList(((c, t) -> new EntityValue(player))), player::getCommandSource); } - public void onStopSprinting(PlayerEntity player) + public void onStopSprinting(ServerPlayerEntity player) { eventHandlers.get("player_stops_sprinting").call( () -> Arrays.asList(((c, t) -> new EntityValue(player))), player::getCommandSource); } diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index 70558a8c..a9434a36 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -60,7 +60,6 @@ import net.minecraft.sound.SoundCategory; import net.minecraft.state.StateFactory; import net.minecraft.state.property.Property; import net.minecraft.text.LiteralText; -import net.minecraft.text.TranslatableText; import net.minecraft.util.Clearable; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -74,6 +73,7 @@ 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.dimension.DimensionType; import net.minecraft.world.loot.context.LootContext; import net.minecraft.world.loot.context.LootContextParameters; import org.apache.commons.lang3.tuple.Pair; @@ -797,7 +797,7 @@ public class CarpetExpression this.expr.addLazyFunction("set", -1, (c, t, lv) -> { CarpetContext cc = (CarpetContext)c; - World world = cc.s.getWorld(); + ServerWorld world = cc.s.getWorld(); if (lv.size() < 2 || lv.size() % 2 == 1) throw new InternalExpressionException("set block should have at least 2 params and odd attributes"); BlockValue.LocatorResult targetLocator = BlockValue.fromParams(cc, lv, 0); @@ -1981,7 +1981,7 @@ public class CarpetExpression { BlockPos center = BlockValue.fromParams((CarpetContext) c, lv,0).block.getPos(); - World world = ((CarpetContext) c).s.getWorld(); + ServerWorld world = ((CarpetContext) c).s.getWorld(); List neighbours = new ArrayList<>(); neighbours.add(new BlockValue(null, world, center.up())); @@ -2679,6 +2679,53 @@ public class CarpetExpression return (cc, tt) -> retval; }); + this.expr.addLazyFunction("in_dimension", 2, (c, t, lv) -> { + ServerCommandSource outerSource = ((CarpetContext)c).s; + Value dimensionValue = lv.get(0).evalValue(c); + ServerCommandSource innerSource = outerSource; + if (dimensionValue instanceof EntityValue) + { + innerSource = outerSource.withWorld((ServerWorld) ((EntityValue)dimensionValue).getEntity().getEntityWorld()); + } + else if (dimensionValue instanceof BlockValue) + { + BlockValue bv = (BlockValue)dimensionValue; + if (bv.getWorld() != null) + { + innerSource = outerSource.withWorld(bv.getWorld()); + } + else + { + throw new InternalExpressionException("in_dimension accepts only world-localized block arguments"); + } + } + else + { + String dimString = dimensionValue.getString().toLowerCase(Locale.ROOT); + switch (dimString) + { + case "nether": + case "the_nether": + innerSource = outerSource.withWorld(outerSource.getMinecraftServer().getWorld(DimensionType.THE_NETHER)); + break; + case "end": + case "the_end": + innerSource = outerSource.withWorld(outerSource.getMinecraftServer().getWorld(DimensionType.THE_END)); + break; + case "overworld": + case "over_world": + innerSource = outerSource.withWorld(outerSource.getMinecraftServer().getWorld(DimensionType.OVERWORLD)); + break; + default: + throw new InternalExpressionException("Incorrect dimension string: "+dimString); + } + } + ((CarpetContext) c).s = innerSource; + Value retval = lv.get(1).evalValue(c); + ((CarpetContext) c).s = outerSource; + return (cc, tt) -> retval; + }); + this.expr.addLazyFunction("plop", 4, (c, t, lv) ->{ BlockValue.LocatorResult locator = BlockValue.fromParams((CarpetContext)c, lv, 0); if (lv.size() <= locator.offset) diff --git a/src/main/java/carpet/script/value/BlockValue.java b/src/main/java/carpet/script/value/BlockValue.java index 7e7de4c5..9818e8ee 100644 --- a/src/main/java/carpet/script/value/BlockValue.java +++ b/src/main/java/carpet/script/value/BlockValue.java @@ -12,6 +12,7 @@ import net.minecraft.block.Blocks; import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; @@ -32,7 +33,7 @@ public class BlockValue extends Value public static final BlockValue NULL = new BlockValue(null, null, null); private BlockState blockState; private BlockPos pos; - private World world; + private ServerWorld world; private CompoundTag data; public static BlockValue fromCoords(CarpetContext c, int x, int y, int z) @@ -212,7 +213,7 @@ public class BlockValue extends Value } - public BlockValue(BlockState state, World world, BlockPos position) + public BlockValue(BlockState state, ServerWorld world, BlockPos position) { this.world = world; blockState = state; @@ -220,7 +221,7 @@ public class BlockValue extends Value data = null; } - public BlockValue(BlockState state, World world, BlockPos position, CompoundTag nbt) + public BlockValue(BlockState state, ServerWorld world, BlockPos position, CompoundTag nbt) { this.world = world; blockState = state; @@ -258,6 +259,8 @@ public class BlockValue extends Value return pos; } + public ServerWorld getWorld() { return world;} + public static class LocatorResult { diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index dc7ffb71..e357fa10 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -7,12 +7,10 @@ import carpet.helpers.Tracer; import carpet.script.CarpetContext; import carpet.script.Fluff; import carpet.script.exception.InternalExpressionException; -import carpet.settings.CarpetSettings; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.client.network.packet.EntityPassengersSetS2CPacket; import net.minecraft.client.network.packet.EntityPositionS2CPacket; -import net.minecraft.client.network.packet.EntityVelocityUpdateS2CPacket; import net.minecraft.command.EntitySelector; import net.minecraft.command.EntitySelectorReader; import net.minecraft.command.arguments.NbtPathArgumentType; @@ -234,7 +232,7 @@ public class EntityValue extends Value put("home", (e, a) -> { if (e instanceof MobEntity) { - return (((MobEntity) e).getWalkTargetRange () > 0)?new BlockValue(null, e.getEntityWorld(), ((MobEntityWithAi) e).getWalkTarget()):Value.FALSE; + return (((MobEntity) e).getWalkTargetRange () > 0)?new BlockValue(null, (ServerWorld) e.getEntityWorld(), ((MobEntityWithAi) e).getWalkTarget()):Value.FALSE; } return Value.NULL; }); @@ -379,7 +377,7 @@ public class EntityValue extends Value switch (hitres.getType()) { case MISS: return Value.NULL; - case BLOCK: return new BlockValue(null, e.getEntityWorld(), ((BlockHitResult)hitres).getBlockPos() ); + case BLOCK: return new BlockValue(null, (ServerWorld) e.getEntityWorld(), ((BlockHitResult)hitres).getBlockPos() ); case ENTITY: return new EntityValue(((EntityHitResult)hitres).getEntity()); } return Value.NULL; From 741434dbaba3a062daa986aa87145d8a239511bb Mon Sep 17 00:00:00 2001 From: gnembon Date: Sat, 14 Sep 2019 23:05:41 -0300 Subject: [PATCH 8/9] pretties mob names --- src/main/java/carpet/utils/SpawnReporter.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/carpet/utils/SpawnReporter.java b/src/main/java/carpet/utils/SpawnReporter.java index 1a64628b..64c7f5b1 100644 --- a/src/main/java/carpet/utils/SpawnReporter.java +++ b/src/main/java/carpet/utils/SpawnReporter.java @@ -18,7 +18,6 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.util.DyeColor; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.registry.Registry; import net.minecraft.world.Heightmap; import net.minecraft.world.SpawnHelper; import net.minecraft.world.World; @@ -152,7 +151,7 @@ public class SpawnReporter lst.add( Messenger.c( "w - ", Messenger.tp("wb",pair.getRight()), - String.format("w : %s", EntityType.getId(pair.getLeft()).toString().replaceFirst("minecraft.","")) + String.format("w : %s", pair.getLeft().getName().getString()) )); } @@ -266,7 +265,7 @@ public class SpawnReporter lst.add( Messenger.c( "w - ", Messenger.tp("wb",pos), - String.format("w : %s", EntityType.getId(type).toString().replaceFirst("minecraft.","")) + String.format("w : %s", type.getName().getString()) )); } } @@ -359,7 +358,7 @@ public class SpawnReporter for (EntityType type: spawn_stats.get(code).keySet()) { report.add(Messenger.s(String.format(" - %s: %d spawns, %d per hour", - Registry.ENTITY_TYPE.getId(type).toString().replaceFirst("minecraft:",""), + type.getName().getString(), spawn_stats.get(code).getLong(type), (72000 * spawn_stats.get(code).getLong(type)/duration )))); } @@ -476,7 +475,7 @@ public class SpawnReporter } } - String creature_name = Registry.ENTITY_TYPE.getId(mob.getType()).toString().replaceFirst("minecraft:",""); + String creature_name = mob.getType().getName().getString(); String pack_size = String.format("%d", mob.getLimitPerChunk());//String.format("%d-%d", animal.minGroupCount, animal.maxGroupCount); int weight = ((WeightedPickerEntryMixin) spawnEntry).getWeight(); if (canspawn) From 27656294ec6d71eb09abafbc2ac778fdf324accb Mon Sep 17 00:00:00 2001 From: gnembon Date: Sat, 14 Sep 2019 23:12:11 -0300 Subject: [PATCH 9/9] added API docs for in_dimension --- src/main/java/carpet/script/CarpetExpression.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index a9434a36..0ab51a92 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -2306,6 +2306,10 @@ public class CarpetExpression * *

current_dimension()

*

Returns current dimension that scripts run in.

+ *

in_dimension(smth, expr)

+ *

Evaluates the expression expr with different dimension execution context. smth can + * be an entity, world-localized block, so not block('stone'), or a string representing a dimension like: + * 'nether', 'end' or 'overworld'.

*

schedule(delay, function, args...)

*

Schedules a user defined function to run with a specified delay ticks of delay. * Scheduled functions run at the end of the tick, and they will run in order they were scheduled.