Skip to content

Commit

Permalink
Add a 'show particles' button to the experience holder and item colle…
Browse files Browse the repository at this point in the history
…ctor - resolves #262
  • Loading branch information
Direwolf20-MC committed Nov 2, 2024
1 parent be2c6f0 commit 8f7ec16
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ExperienceHolderScreen extends BaseMachineScreen<ExperienceHolderCo
private int targetExp;
private boolean ownerOnly;
private boolean collectExp;
public boolean showParticles = true;
private static final ResourceLocation EXPERIENCE_BAR_BACKGROUND_SPRITE = ResourceLocation.withDefaultNamespace("hud/experience_bar_background");
private static final ResourceLocation EXPERIENCE_BAR_PROGRESS_SPRITE = ResourceLocation.withDefaultNamespace("hud/experience_bar_progress");

Expand All @@ -33,6 +34,7 @@ public ExperienceHolderScreen(ExperienceHolderContainer container, Inventory inv
this.targetExp = experienceHolderBE.targetExp;
this.ownerOnly = experienceHolderBE.ownerOnly;
this.collectExp = experienceHolderBE.collectExp;
this.showParticles = experienceHolderBE.showParticles;
}
}

Expand Down Expand Up @@ -69,6 +71,11 @@ else if (Screen.hasShiftDown())
((GrayscaleButton) b).toggleActive();
saveSettings();
}));
addRenderableWidget(ToggleButtonFactory.SHOWPARTICLESBUTTON(topSectionLeft + (topSectionWidth / 2) + 31, topSectionTop + 42, showParticles, b -> {
showParticles = !showParticles;
((GrayscaleButton) b).toggleActive();
saveSettings();
}));
}

@Override
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

public class ItemCollectorScreen extends BaseMachineScreen<ItemCollectorContainer> {
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;
}
}

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}

Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand All @@ -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);
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
public record ExperienceHolderSettingsPayload(
int targetExp,
boolean ownerOnly,
boolean collectExp
boolean collectExp,
boolean showParticles
) implements CustomPacketPayload {
public static final Type<ExperienceHolderSettingsPayload> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(JustDireThings.MODID, "experience_holder_settings"));

Expand All @@ -23,6 +24,7 @@ public Type<ExperienceHolderSettingsPayload> type() {
ByteBufCodecs.INT, ExperienceHolderSettingsPayload::targetExp,
ByteBufCodecs.BOOL, ExperienceHolderSettingsPayload::ownerOnly,
ByteBufCodecs.BOOL, ExperienceHolderSettingsPayload::collectExp,
ByteBufCodecs.BOOL, ExperienceHolderSettingsPayload::showParticles,
ExperienceHolderSettingsPayload::new
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import net.minecraft.resources.ResourceLocation;

public record ItemCollectorSettingsPayload(
boolean respectPickupDelay
boolean respectPickupDelay,
boolean showParticles
) implements CustomPacketPayload {
public static final Type<ItemCollectorSettingsPayload> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(JustDireThings.MODID, "item_collector_settings"));

Expand All @@ -19,6 +20,7 @@ public Type<ItemCollectorSettingsPayload> type() {

public static final StreamCodec<FriendlyByteBuf, ItemCollectorSettingsPayload> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.BOOL, ItemCollectorSettingsPayload::respectPickupDelay,
ByteBufCodecs.BOOL, ItemCollectorSettingsPayload::showParticles,
ItemCollectorSettingsPayload::new
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
});
}
Expand Down

0 comments on commit 8f7ec16

Please sign in to comment.