From 8f7ec1659795aa70f5ad703cfada094f4f09f5e1 Mon Sep 17 00:00:00 2001 From: direwolf20 <39863894+Direwolf20-MC@users.noreply.github.com> Date: Sat, 2 Nov 2024 13:05:31 -0400 Subject: [PATCH] Add a 'show particles' button to the experience holder and item collector - resolves #262 --- .../client/screens/ExperienceHolderScreen.java | 9 ++++++++- .../client/screens/ItemCollectorScreen.java | 9 ++++++++- .../common/blockentities/ExperienceHolderBE.java | 7 ++++++- .../common/blockentities/ItemCollectorBE.java | 8 +++++++- .../network/data/ExperienceHolderSettingsPayload.java | 4 +++- .../network/data/ItemCollectorSettingsPayload.java | 4 +++- .../network/handler/ExperienceHolderSettingsPacket.java | 2 +- .../network/handler/ItemCollectorSettingsPacket.java | 2 +- 8 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/direwolf20/justdirethings/client/screens/ExperienceHolderScreen.java b/src/main/java/com/direwolf20/justdirethings/client/screens/ExperienceHolderScreen.java index 20fd4150..844e974b 100644 --- a/src/main/java/com/direwolf20/justdirethings/client/screens/ExperienceHolderScreen.java +++ b/src/main/java/com/direwolf20/justdirethings/client/screens/ExperienceHolderScreen.java @@ -22,6 +22,7 @@ public class ExperienceHolderScreen extends BaseMachineScreen { + showParticles = !showParticles; + ((GrayscaleButton) b).toggleActive(); + saveSettings(); + })); } @Override @@ -100,6 +107,6 @@ public void renderXPBar(GuiGraphics guiGraphics, float partialTicks, int mouseX, @Override public void saveSettings() { super.saveSettings(); - PacketDistributor.sendToServer(new ExperienceHolderSettingsPayload(targetExp, ownerOnly, collectExp)); + PacketDistributor.sendToServer(new ExperienceHolderSettingsPayload(targetExp, ownerOnly, collectExp, showParticles)); } } diff --git a/src/main/java/com/direwolf20/justdirethings/client/screens/ItemCollectorScreen.java b/src/main/java/com/direwolf20/justdirethings/client/screens/ItemCollectorScreen.java index bbf8755b..06483ad4 100644 --- a/src/main/java/com/direwolf20/justdirethings/client/screens/ItemCollectorScreen.java +++ b/src/main/java/com/direwolf20/justdirethings/client/screens/ItemCollectorScreen.java @@ -12,10 +12,12 @@ public class ItemCollectorScreen extends BaseMachineScreen { public boolean respectPickupDelay = false; + public boolean showParticles = true; public ItemCollectorScreen(ItemCollectorContainer container, Inventory inv, Component name) { super(container, inv, name); if (container.baseMachineBE instanceof ItemCollectorBE itemCollectorBE) { respectPickupDelay = itemCollectorBE.respectPickupDelay; + showParticles = itemCollectorBE.showParticles; } } @@ -27,11 +29,16 @@ public void init() { ((GrayscaleButton) b).toggleActive(); saveSettings(); })); + addRenderableWidget(ToggleButtonFactory.SHOWPARTICLESBUTTON(getGuiLeft() + 98, topSectionTop + 62, showParticles, b -> { + showParticles = !showParticles; + ((GrayscaleButton) b).toggleActive(); + saveSettings(); + })); } @Override public void saveSettings() { super.saveSettings(); - PacketDistributor.sendToServer(new ItemCollectorSettingsPayload(respectPickupDelay)); + PacketDistributor.sendToServer(new ItemCollectorSettingsPayload(respectPickupDelay, showParticles)); } } diff --git a/src/main/java/com/direwolf20/justdirethings/common/blockentities/ExperienceHolderBE.java b/src/main/java/com/direwolf20/justdirethings/common/blockentities/ExperienceHolderBE.java index a6608894..f0fde6a0 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/blockentities/ExperienceHolderBE.java +++ b/src/main/java/com/direwolf20/justdirethings/common/blockentities/ExperienceHolderBE.java @@ -40,6 +40,7 @@ public class ExperienceHolderBE extends BaseMachineBE implements AreaAffectingBE private Player currentPlayer; public boolean collectExp; public boolean ownerOnly; + public boolean showParticles = true; public ExperienceHolderBE(BlockPos pPos, BlockState pBlockState) { super(Registration.ExperienceHolderBE.get(), pPos, pBlockState); @@ -60,11 +61,12 @@ public AreaAffectingData getAreaAffectingData() { return areaAffectingData; } - public void changeSettings(Player player, int targetExp, boolean ownerOnly, boolean collectExp) { + public void changeSettings(Player player, int targetExp, boolean ownerOnly, boolean collectExp, boolean showParticles) { if (this.ownerOnly && !player.getUUID().equals(placedByUUID)) return; this.targetExp = targetExp; this.ownerOnly = ownerOnly; this.collectExp = collectExp; + this.showParticles = showParticles; markDirtyClient(); } @@ -173,6 +175,7 @@ public void tickServer() { } public void doParticles(ItemStack itemStack, Vec3 sourcePos, boolean toBlock) { + if (!showParticles) return; Direction direction = getBlockState().getValue(BlockStateProperties.FACING); BlockPos blockPos = getBlockPos(); Vec3 baubleSpot = new Vec3(blockPos.getX() + 0.5f - (0.3 * direction.getStepX()), blockPos.getY() + 0.5f - (0.3 * direction.getStepY()), blockPos.getZ() + 0.5f - (0.3 * direction.getStepZ())); @@ -271,6 +274,7 @@ public void saveAdditional(CompoundTag tag, HolderLookup.Provider provider) { tag.putInt("targetExp", targetExp); tag.putBoolean("collectExp", collectExp); tag.putBoolean("ownerOnly", ownerOnly); + tag.putBoolean("showParticles", showParticles); } @Override @@ -280,6 +284,7 @@ public void loadAdditional(CompoundTag tag, HolderLookup.Provider provider) { targetExp = tag.getInt("targetExp"); collectExp = tag.getBoolean("collectExp"); ownerOnly = tag.getBoolean("ownerOnly"); + showParticles = tag.getBoolean("showParticles"); } @Override diff --git a/src/main/java/com/direwolf20/justdirethings/common/blockentities/ItemCollectorBE.java b/src/main/java/com/direwolf20/justdirethings/common/blockentities/ItemCollectorBE.java index 0de5a0dc..1c6624d5 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/blockentities/ItemCollectorBE.java +++ b/src/main/java/com/direwolf20/justdirethings/common/blockentities/ItemCollectorBE.java @@ -37,6 +37,7 @@ public class ItemCollectorBE extends BaseMachineBE implements FilterableBE, Area public AreaAffectingData areaAffectingData = new AreaAffectingData(getBlockState().getValue(BlockStateProperties.FACING).getOpposite()); public RedstoneControlData redstoneControlData = new RedstoneControlData(); public boolean respectPickupDelay = false; + public boolean showParticles = true; public ItemCollectorBE(BlockPos pPos, BlockState pBlockState) { super(Registration.ItemCollectorBE.get(), pPos, pBlockState); @@ -70,8 +71,9 @@ public void tickServer() { findItemsAndStore(); } - public void setSettings(boolean respectPickupDelay) { + public void setSettings(boolean respectPickupDelay, boolean showParticles) { this.respectPickupDelay = respectPickupDelay; + this.showParticles = showParticles; markDirtyClient(); } @@ -81,6 +83,8 @@ public FilterBasicHandler getFilterHandler() { } public void doParticles(ItemStack itemStack, Vec3 sourcePos) { + if (!showParticles) + return; Direction direction = getBlockState().getValue(BlockStateProperties.FACING); BlockPos blockPos = getBlockPos(); ItemFlowParticleData data = new ItemFlowParticleData(itemStack, blockPos.getX() + 0.5f - (0.3 * direction.getStepX()), blockPos.getY() + 0.5f - (0.3 * direction.getStepY()), blockPos.getZ() + 0.5f - (0.3 * direction.getStepZ()), 5); @@ -146,11 +150,13 @@ public AreaAffectingData getDefaultAreaData(AreaAffectingBE areaAffectingBE) { public void saveAdditional(CompoundTag tag, HolderLookup.Provider provider) { super.saveAdditional(tag, provider); tag.putBoolean("respectPickupDelay", respectPickupDelay); + tag.putBoolean("showParticles", showParticles); } @Override public void loadAdditional(CompoundTag tag, HolderLookup.Provider provider) { super.loadAdditional(tag, provider); respectPickupDelay = tag.getBoolean("respectPickupDelay"); + showParticles = tag.getBoolean("showParticles"); } } diff --git a/src/main/java/com/direwolf20/justdirethings/common/network/data/ExperienceHolderSettingsPayload.java b/src/main/java/com/direwolf20/justdirethings/common/network/data/ExperienceHolderSettingsPayload.java index 00a93211..9f90d5a8 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/network/data/ExperienceHolderSettingsPayload.java +++ b/src/main/java/com/direwolf20/justdirethings/common/network/data/ExperienceHolderSettingsPayload.java @@ -10,7 +10,8 @@ public record ExperienceHolderSettingsPayload( int targetExp, boolean ownerOnly, - boolean collectExp + boolean collectExp, + boolean showParticles ) implements CustomPacketPayload { public static final Type TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(JustDireThings.MODID, "experience_holder_settings")); @@ -23,6 +24,7 @@ public Type type() { ByteBufCodecs.INT, ExperienceHolderSettingsPayload::targetExp, ByteBufCodecs.BOOL, ExperienceHolderSettingsPayload::ownerOnly, ByteBufCodecs.BOOL, ExperienceHolderSettingsPayload::collectExp, + ByteBufCodecs.BOOL, ExperienceHolderSettingsPayload::showParticles, ExperienceHolderSettingsPayload::new ); } diff --git a/src/main/java/com/direwolf20/justdirethings/common/network/data/ItemCollectorSettingsPayload.java b/src/main/java/com/direwolf20/justdirethings/common/network/data/ItemCollectorSettingsPayload.java index 9dfdf44d..133f97cb 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/network/data/ItemCollectorSettingsPayload.java +++ b/src/main/java/com/direwolf20/justdirethings/common/network/data/ItemCollectorSettingsPayload.java @@ -8,7 +8,8 @@ import net.minecraft.resources.ResourceLocation; public record ItemCollectorSettingsPayload( - boolean respectPickupDelay + boolean respectPickupDelay, + boolean showParticles ) implements CustomPacketPayload { public static final Type TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(JustDireThings.MODID, "item_collector_settings")); @@ -19,6 +20,7 @@ public Type type() { public static final StreamCodec STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.BOOL, ItemCollectorSettingsPayload::respectPickupDelay, + ByteBufCodecs.BOOL, ItemCollectorSettingsPayload::showParticles, ItemCollectorSettingsPayload::new ); } diff --git a/src/main/java/com/direwolf20/justdirethings/common/network/handler/ExperienceHolderSettingsPacket.java b/src/main/java/com/direwolf20/justdirethings/common/network/handler/ExperienceHolderSettingsPacket.java index 986e2360..93802913 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/network/handler/ExperienceHolderSettingsPacket.java +++ b/src/main/java/com/direwolf20/justdirethings/common/network/handler/ExperienceHolderSettingsPacket.java @@ -20,7 +20,7 @@ public void handle(final ExperienceHolderSettingsPayload payload, final IPayload AbstractContainerMenu container = sender.containerMenu; if (container instanceof ExperienceHolderContainer experienceHolderContainer && experienceHolderContainer.baseMachineBE instanceof ExperienceHolderBE experienceHolderBE) { - experienceHolderBE.changeSettings(sender, payload.targetExp(), payload.ownerOnly(), payload.collectExp()); + experienceHolderBE.changeSettings(sender, payload.targetExp(), payload.ownerOnly(), payload.collectExp(), payload.showParticles()); } }); } diff --git a/src/main/java/com/direwolf20/justdirethings/common/network/handler/ItemCollectorSettingsPacket.java b/src/main/java/com/direwolf20/justdirethings/common/network/handler/ItemCollectorSettingsPacket.java index 62348b40..2269ed8d 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/network/handler/ItemCollectorSettingsPacket.java +++ b/src/main/java/com/direwolf20/justdirethings/common/network/handler/ItemCollectorSettingsPacket.java @@ -20,7 +20,7 @@ public void handle(final ItemCollectorSettingsPayload payload, final IPayloadCon AbstractContainerMenu container = sender.containerMenu; if (container instanceof ItemCollectorContainer itemCollectorContainer && itemCollectorContainer.baseMachineBE instanceof ItemCollectorBE itemCollectorBE) { - itemCollectorBE.setSettings(payload.respectPickupDelay()); + itemCollectorBE.setSettings(payload.respectPickupDelay(), payload.showParticles()); } }); }