From 4e814b3df36e1bedc743a85c593ff46d4ffd5c6e Mon Sep 17 00:00:00 2001 From: lothrazar Date: Thu, 3 Oct 2024 18:19:33 -0700 Subject: [PATCH] avoid client-server issues with facade event. update guidebook text to mention facades --- .../lothrazar/cyclic/event/ItemEvents.java | 27 +++++++++++++------ .../resources/assets/cyclic/lang/en_us.json | 6 ++--- update.json | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/lothrazar/cyclic/event/ItemEvents.java b/src/main/java/com/lothrazar/cyclic/event/ItemEvents.java index d5590ff6c..29d4a4a48 100644 --- a/src/main/java/com/lothrazar/cyclic/event/ItemEvents.java +++ b/src/main/java/com/lothrazar/cyclic/event/ItemEvents.java @@ -67,6 +67,8 @@ import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.HitResult.Type; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.ForgeMod; import net.minecraftforge.event.entity.ProjectileImpactEvent; import net.minecraftforge.event.entity.living.LivingDamageEvent; @@ -481,7 +483,8 @@ public void onHit(PlayerInteractEvent.LeftClickBlock event) { ItemStack held = player.getItemInHand(event.getHand()); Level world = player.getCommandSenderWorld(); BlockState target = world.getBlockState(event.getPos()); - if (target.getBlock() instanceof IBlockFacade && player.isCrouching()) { + if (player.isCrouching() + && target.getBlock() instanceof IBlockFacade) { // onHitFacadeHandler(event, player, held, target); // @@ -524,8 +527,9 @@ public void onHit(PlayerInteractEvent.LeftClickBlock event) { } } + // private void onHitFacadeHandler(PlayerInteractEvent.LeftClickBlock event, Player player, ItemStack held, BlockState target) { - if (held.isEmpty()) { + if (held.isEmpty() && event.getLevel().isClientSide()) { PacketRegistry.INSTANCE.sendToServer(new BlockFacadeMessage(event.getPos(), true)); } else { @@ -543,17 +547,24 @@ private void onHitFacadeHandler(PlayerInteractEvent.LeftClickBlock event, Player ModCyclic.LOGGER.info("not allowed to use this item as a facade from config: " + held.getItem()); return; } - BlockHitResult bhr = (BlockHitResult) player.pick(5, 1, false); - BlockPlaceContext context = new BlockPlaceContext(player, event.getHand(), held, bhr); - BlockState facadeState = null; - facadeState = block.getStateForPlacement(context); - CompoundTag tags = NbtUtils.writeBlockState(facadeState); - PacketRegistry.INSTANCE.sendToServer(new BlockFacadeMessage(event.getPos(), tags)); + if (event.getLevel().isClientSide()) { + onHitFacadeClient(event, player, held, block); + } } //cancel the event so creative players will not break it event.setCanceled(true); } + @OnlyIn(Dist.CLIENT) + private void onHitFacadeClient(PlayerInteractEvent.LeftClickBlock event, Player player, ItemStack held, Block block) { + BlockHitResult bhr = (BlockHitResult) player.pick(5, 1, false); + BlockPlaceContext context = new BlockPlaceContext(player, event.getHand(), held, bhr); + BlockState facadeState = null; + facadeState = block.getStateForPlacement(context); + CompoundTag tags = NbtUtils.writeBlockState(facadeState); + PacketRegistry.INSTANCE.sendToServer(new BlockFacadeMessage(event.getPos(), tags)); + } + @SubscribeEvent public void onPlayerPickup(EntityItemPickupEvent event) { if (event.getEntity() instanceof Player) { diff --git a/src/main/resources/assets/cyclic/lang/en_us.json b/src/main/resources/assets/cyclic/lang/en_us.json index d8a573f07..f9746cde6 100644 --- a/src/main/resources/assets/cyclic/lang/en_us.json +++ b/src/main/resources/assets/cyclic/lang/en_us.json @@ -1504,15 +1504,15 @@ "block.cyclic.fluid_pipe": "Fluid Cable", "block.cyclic.fluid_pipe.tooltip": "Pipe liquid between blocks; use a Cable Wrench to customize", "block.cyclic.fluid_pipe.tooltip0": "Also collects fluid source blocks from the world", - "block.cyclic.fluid_pipe.guide": "Pipe liquid between blocks. Has extraction mode with a filter GUI, and a yellow blocked state to disable the flow. Also collects fluid from the world. Maximum of 16 buckets per tick. ", + "block.cyclic.fluid_pipe.guide": "Pipe liquid between blocks. Has extraction mode with a filter GUI, and a yellow blocked state to disable the flow. Also collects fluid from the world. Shift-left-click to set and remove blocks to cover the pipe as a Facade ", "block.cyclic.bundled_pipe": "Bundled Cable", "block.cyclic.bundled_pipe.tooltip": "Transfer items, fluids, and energy", "block.cyclic.energy_pipe": "Energy Cable", "block.cyclic.energy_pipe.tooltip": "Pipe energy between blocks; use a Cable Wrench to customize", - "block.cyclic.energy_pipe.guide": "Pipe energy between blocks. Has extraction mode with a filter GUI, and a yellow blocked state to disable the flow. Maximum of 32000 RF per tick. ", + "block.cyclic.energy_pipe.guide": "Pipe energy between blocks. Has extraction mode with a filter GUI, and a yellow blocked state to disable the flow. Shift-left-click to set and remove blocks to cover the pipe as a Facade ", "block.cyclic.item_pipe": "Item Cable", "block.cyclic.item_pipe.tooltip": "Pipe items between blocks; use a Cable Wrench to customize", - "block.cyclic.item_pipe.guide": "Pipe items between blocks. Has extraction mode with a filter GUI, and a yellow blocked state to disable the flow. Max speed is one stack (64 items) per tick in each direction. ", + "block.cyclic.item_pipe.guide": "Pipe items between blocks. Has extraction mode with a filter GUI, and a yellow blocked state to disable the flow. Shift-left-click to set and remove blocks to cover the pipe as a Facade ", "block.cyclic.item_pipe_sort": "Item Sorter", "block.cyclic.item_pipe_sort.tooltip": "Sorting machine for use with cables and hoppers", "block.cyclic.item_pipe_sort.filter": "Output here only if it matches this filter", diff --git a/update.json b/update.json index 10874c00b..39cf1713c 100644 --- a/update.json +++ b/update.json @@ -186,6 +186,6 @@ ,"1.20.11":"Fix create new world crash from previous version 'Feature order cycle found minecraft:frozen_peaks': Merge pull request #2426 from Apollounknowndev/trunk/1.20.1 " ,"1.12.12":"Added config controls to the settings in the item.laser_cannon laser beam; along with a new option to render the laser even when you miss. Battery and Claystone Battery now have their storage capacity defined in the config file. Some default config values have been changed, and upper limits have been raised. Increase capacity of the (creative) Infinite Battery. Rebalanced recipes for Breaker and Placer. Fix a bug where if the Item User is configured to consume energy, it still had the capability (connected to cables and showed RF in Jade); fixed to match behavior of other configured blocks " ,"1.12.13":"Fix Mattock not saving contents of Shulker Boxes when mined #2411. Block Reach enchantment now has max level 5 to give players more control of how far the reach boost is increased; so levels I through V are now available. Since players normally have 5 blocks of reach distance: level I reaches 8, II reaches 10, III reaches 12, IV reaches 14, and V reaches 16 blocks (+4 for anything beyond with something like apotheosis)" - ,"1.12.14":"Renamed 'Concentrated Glowstone' to 'Glowstone Facade' and 'Concentrated Soundproofing' to 'Soundproofing Facade'. Fixed issues with both blocks to correctly render facades (use sneak-left-click), and they no longer have an inventory" + ,"1.13.0":"Renamed 'Concentrated Glowstone' to 'Glowstone Facade' and 'Concentrated Soundproofing' to 'Soundproofing Facade'. Fixed issues with both blocks to correctly render facades (use sneak-left-click while not in creative), and they no longer have an inventory" } }