From c0ec7e56a422b19b5dbfa7349d657e7bcf7e8ff7 Mon Sep 17 00:00:00 2001 From: Sefiraat Date: Sun, 4 Jul 2021 22:02:12 +0100 Subject: [PATCH 1/3] Fixes BSU and HSU dupe --- .../blocks/machines/BigStorageUnit.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/blocks/machines/BigStorageUnit.java b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/blocks/machines/BigStorageUnit.java index 7fbeb5c8..abc33138 100644 --- a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/blocks/machines/BigStorageUnit.java +++ b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/blocks/machines/BigStorageUnit.java @@ -1,6 +1,8 @@ package io.github.thebusybiscuit.sensibletoolbox.blocks.machines; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import javax.annotation.Nonnull; @@ -24,6 +26,7 @@ import org.bukkit.inventory.Recipe; import org.bukkit.inventory.RecipeChoice.MaterialChoice; import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.metadata.FixedMetadataValue; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; @@ -135,6 +138,20 @@ public void setStoredItemType(ItemStack stored) { updateSignItemLines(); } + @Nullable + private ItemStack getStoredItemDisplay() { + if (this.stored != null) { + ItemStack displayItemStack = stored.clone(); + ItemMeta meta = displayItemStack.getItemMeta(); + List lore = meta != null && meta.getLore() != null ? meta.getLore() : new ArrayList<>(); + lore.add(ChatColor.GRAY + "Stored Item"); + meta.setLore(lore); + displayItemStack.setItemMeta(meta); + return displayItemStack; + } + return null; + } + private void updateSignQuantityLine() { if (isLocked()) { signLabel[1] = ChatColor.DARK_RED + Integer.toString(getTotalAmount()); @@ -322,7 +339,7 @@ public void onServerTick() { Debugger.getInstance().debug(2, this + " amount changed! " + oldTotalAmount + " -> " + getTotalAmount()); getProgressMeter().setMaxProgress(maxCapacity); - setProcessing(stored); + setProcessing(getStoredItemDisplay()); setProgress(maxCapacity - (double) getStorageAmount()); update(false); updateAttachedLabelSigns(); @@ -359,7 +376,7 @@ public void onBlockUnregistered(Location location) { @Override public void onBlockRegistered(Location location, boolean isPlacing) { getProgressMeter().setMaxProgress(maxCapacity); - setProcessing(stored); + setProcessing(getStoredItemDisplay()); setProgress(maxCapacity - (double) storageAmount); ItemStack output = getOutputItem(); outputAmount = output == null ? 0 : output.getAmount(); From 8d9386227a13a012e4fcc235b690464f4c5a9b99 Mon Sep 17 00:00:00 2001 From: Sefiraat Date: Mon, 5 Jul 2021 07:49:23 +0100 Subject: [PATCH 2/3] Setup display item with stored item --- .../sensibletoolbox/blocks/machines/BigStorageUnit.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/blocks/machines/BigStorageUnit.java b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/blocks/machines/BigStorageUnit.java index abc33138..b271eed1 100644 --- a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/blocks/machines/BigStorageUnit.java +++ b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/blocks/machines/BigStorageUnit.java @@ -45,6 +45,7 @@ public class BigStorageUnit extends AbstractProcessingMachine { private static final String STB_LAST_BSU_INSERT = "STB_Last_BSU_Insert"; private static final long DOUBLE_CLICK_TIME = 250L; private ItemStack stored; + private ItemStack storedDisplay; private int storageAmount; private int outputAmount; private int maxCapacity; @@ -130,8 +131,10 @@ public void setStoredItemType(ItemStack stored) { if (stored != null) { this.stored = stored.clone(); this.stored.setAmount(1); + this.storedDisplay = getStoredItemDisplay(); } else if (!isLocked()) { this.stored = null; + this.storedDisplay = null; } maxCapacity = getStackCapacity() * (this.stored == null ? 64 : this.stored.getMaxStackSize()); @@ -339,7 +342,7 @@ public void onServerTick() { Debugger.getInstance().debug(2, this + " amount changed! " + oldTotalAmount + " -> " + getTotalAmount()); getProgressMeter().setMaxProgress(maxCapacity); - setProcessing(getStoredItemDisplay()); + setProcessing(storedDisplay); setProgress(maxCapacity - (double) getStorageAmount()); update(false); updateAttachedLabelSigns(); @@ -376,7 +379,7 @@ public void onBlockUnregistered(Location location) { @Override public void onBlockRegistered(Location location, boolean isPlacing) { getProgressMeter().setMaxProgress(maxCapacity); - setProcessing(getStoredItemDisplay()); + setProcessing(storedDisplay); setProgress(maxCapacity - (double) storageAmount); ItemStack output = getOutputItem(); outputAmount = output == null ? 0 : output.getAmount(); From 2f1ccb37142a1063c05f789bb2003a3b5b987419 Mon Sep 17 00:00:00 2001 From: Sefiraat Date: Wed, 14 Jul 2021 22:02:27 +0100 Subject: [PATCH 3/3] cache lore --- .../blocks/machines/BigStorageUnit.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/blocks/machines/BigStorageUnit.java b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/blocks/machines/BigStorageUnit.java index b271eed1..e9c5e682 100644 --- a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/blocks/machines/BigStorageUnit.java +++ b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/blocks/machines/BigStorageUnit.java @@ -146,9 +146,13 @@ private ItemStack getStoredItemDisplay() { if (this.stored != null) { ItemStack displayItemStack = stored.clone(); ItemMeta meta = displayItemStack.getItemMeta(); - List lore = meta != null && meta.getLore() != null ? meta.getLore() : new ArrayList<>(); - lore.add(ChatColor.GRAY + "Stored Item"); - meta.setLore(lore); + List newLore = new ArrayList<>(); + if (meta != null) { + List currentLore = meta.getLore(); + if (currentLore != null) {newLore.addAll(currentLore);} + } + newLore.add(ChatColor.GRAY + "Stored Item"); + meta.setLore(newLore); displayItemStack.setItemMeta(meta); return displayItemStack; }