Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes BSU and HSU dupe #85

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -42,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;
Expand Down Expand Up @@ -127,14 +131,34 @@ 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());
updateSignItemLines();
}

@Nullable
private ItemStack getStoredItemDisplay() {
if (this.stored != null) {
ItemStack displayItemStack = stored.clone();
ItemMeta meta = displayItemStack.getItemMeta();
List<String> newLore = new ArrayList<>();
if (meta != null) {
List<String> currentLore = meta.getLore();
if (currentLore != null) {newLore.addAll(currentLore);}
}
newLore.add(ChatColor.GRAY + "Stored Item");
meta.setLore(newLore);
displayItemStack.setItemMeta(meta);
return displayItemStack;
}
return null;
}

private void updateSignQuantityLine() {
if (isLocked()) {
signLabel[1] = ChatColor.DARK_RED + Integer.toString(getTotalAmount());
Expand Down Expand Up @@ -322,7 +346,7 @@ public void onServerTick() {

Debugger.getInstance().debug(2, this + " amount changed! " + oldTotalAmount + " -> " + getTotalAmount());
getProgressMeter().setMaxProgress(maxCapacity);
setProcessing(stored);
setProcessing(storedDisplay);
setProgress(maxCapacity - (double) getStorageAmount());
update(false);
updateAttachedLabelSigns();
Expand Down Expand Up @@ -359,7 +383,7 @@ public void onBlockUnregistered(Location location) {
@Override
public void onBlockRegistered(Location location, boolean isPlacing) {
getProgressMeter().setMaxProgress(maxCapacity);
setProcessing(stored);
setProcessing(storedDisplay);
setProgress(maxCapacity - (double) storageAmount);
ItemStack output = getOutputItem();
outputAmount = output == null ? 0 : output.getAmount();
Expand Down