Skip to content

Commit

Permalink
avoid client-server issues with facade event. update guidebook text t…
Browse files Browse the repository at this point in the history
…o mention facades
  • Loading branch information
Lothrazar committed Oct 4, 2024
1 parent 15dadd0 commit 4e814b3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
27 changes: 19 additions & 8 deletions src/main/java/com/lothrazar/cyclic/event/ItemEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
//
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/assets/cyclic/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion update.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 4e814b3

Please sign in to comment.