From 99e166337bdaadb96140d098d9dde17a9cba9207 Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Sat, 1 Jun 2024 14:51:54 -0500 Subject: [PATCH] Fixed relay things. Fixed compass clicking. --- .../mod/blocks/BlockLaserRelay.java | 8 ++++---- .../mod/event/CommonEvents.java | 17 ++++++++++------- .../mod/network/PacketHandler.java | 4 ++-- .../mod/tile/TileEntityLaserRelayItem.java | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java index e55b291e9..064ab534c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java @@ -104,7 +104,7 @@ public class BlockLaserRelay extends FullyDirectionalBlock.Container implements BlockEntity tile = world.getBlockEntity(pos); if (tile instanceof TileEntityLaserRelay relay) { - if (StackUtil.isValid(stack)) { + if (!stack.isEmpty()) { if (stack.getItem() instanceof ItemLaserWrench) { return InteractionResult.FAIL; } else if (stack.getItem() == CommonConfig.Other.relayConfigureItem) { @@ -120,10 +120,10 @@ public class BlockLaserRelay extends FullyDirectionalBlock.Container implements relay.sendUpdate(); } - return InteractionResult.PASS; + return InteractionResult.SUCCESS; } else if (stack.getItem() instanceof ItemLaserRelayUpgrade) { ItemStack inRelay = relay.inv.getStackInSlot(0); - if (!StackUtil.isValid(inRelay)) { + if (inRelay.isEmpty()) { if (!world.isClientSide) { if (!player.isCreative()) { player.setItemInHand(hand, StackUtil.shrink(stack, 1)); @@ -141,7 +141,7 @@ public class BlockLaserRelay extends FullyDirectionalBlock.Container implements if (player.isShiftKeyDown()) { ItemStack inRelay = relay.inv.getStackInSlot(0).copy(); - if (StackUtil.isValid(inRelay)) { + if (!inRelay.isEmpty()) { if (!world.isClientSide) { relay.inv.setStackInSlot(0, ItemStack.EMPTY); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java index 83cbf4762..466963403 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java @@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.event; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.attachments.ActuallyAttachments; +import de.ellpeck.actuallyadditions.mod.blocks.BlockLaserRelay; import de.ellpeck.actuallyadditions.mod.config.CommonConfig; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.data.PlayerData; @@ -35,6 +36,7 @@ import net.minecraft.world.entity.monster.Spider; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.bus.api.Event; @@ -43,20 +45,21 @@ import net.neoforged.neoforge.event.AnvilUpdateEvent; import net.neoforged.neoforge.event.entity.living.LivingDropsEvent; import net.neoforged.neoforge.event.entity.player.EntityItemPickupEvent; import net.neoforged.neoforge.event.entity.player.PlayerEvent; +import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; import net.neoforged.neoforge.event.level.BlockEvent; import java.util.Locale; public class CommonEvents { - - //TODO spawner shards are yeeted right? @SubscribeEvent - public void onBlockBreakEvent(BlockEvent.BreakEvent event) { - BlockState state = event.getState(); - if (state != null && state.getBlock() == Blocks.SPAWNER) { - // TODO: [port] add back once we've unflattened - // event.getDrops().add(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.SPAWNER_SHARD.ordinal())); + public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event) { //Workaround, cant sneak right click a block with an item normally. + if (event.getLevel().isClientSide) + return; + if( (event.getLevel().getBlockState(event.getHitVec().getBlockPos()).getBlock() instanceof BlockLaserRelay) && (event.getItemStack().is(CommonConfig.Other.relayConfigureItem))) { + event.setUseItem(Event.Result.DENY); + event.setUseBlock(Event.Result.ALLOW); } + } @SubscribeEvent diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java index dc1b7ec7a..db4405301 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java @@ -83,8 +83,8 @@ public final class PacketHandler { // Particle fx = new ParticleLaserItem(mc.level, outX, outY, outZ, stack, 0.025, inX, inY, inZ); //mc.effectRenderer.addEffect(fx); //TODO - mc.level.addParticle(ParticleLaserItem.Factory.createData(stack, outX, outY, outZ), - inX, inY, inZ, 0, 0.025, 0); + mc.level.addParticle(ParticleLaserItem.Factory.createData(stack, inX, inY, inZ), + outX, outY, outZ, 0, 0.025, 0); } }; public static final IDataHandler GUI_BUTTON_TO_TILE_HANDLER = (compound, context) -> { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java index 6c97f8b22..b7e459c38 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java @@ -170,7 +170,7 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay { @Override public void onCompassAction(Player player) { - if (player.isShiftKeyDown()) { + if (player.isCrouching()) { this.priority--; } else { this.priority++;