Skip to content

Commit

Permalink
Merge pull request #11 from LinoxGH/master
Browse files Browse the repository at this point in the history
Fixing issue #6 and code cleanup.
  • Loading branch information
TheBusyBiscuit committed Aug 31, 2019
2 parents 6cf3a52 + 8419a7c commit 0d14dd9
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 53 deletions.
35 changes: 15 additions & 20 deletions src/me/john000708/barrels/Barrel.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Barrel extends SlimefunItem {
private int capacity;
private boolean allowDisplayItem;

public Barrel(Category category, ItemStack item, String name, RecipeType recipeType, final ItemStack[] recipe, int capacity) {
protected Barrel(Category category, ItemStack item, String name, RecipeType recipeType, final ItemStack[] recipe, int capacity) {
super(category, item, name, recipeType, recipe);

this.capacity = capacity;
Expand Down Expand Up @@ -131,7 +131,8 @@ public boolean onBreak(Player player, Block b, SlimefunItem slimefunItem, Unregi
b.getWorld().dropItem(b.getLocation(), SlimefunItem.getByID("BIO_PROTECTION").getItem());

if (BlockStorage.getLocationInfo(b.getLocation(), "storedItems") == null) return true;
int storedAmount = Integer.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "storedItems"));
//There's no need to box the integer.
int storedAmount = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "storedItems"));

ItemStack item = inv.getItemInSlot(22);
ItemMeta meta = item.getItemMeta();
Expand Down Expand Up @@ -184,7 +185,6 @@ public boolean isSynchronized() {
public void tick(Block block, SlimefunItem slimefunItem, Config config) {
updateBarrel(block);


if (Barrels.displayItem) {
allowDisplayItem = block.getRelative(BlockFace.UP).getType() == Material.AIR;
DisplayItem.updateDisplayItem(block, getCapacity(block), allowDisplayItem);
Expand All @@ -208,7 +208,8 @@ public int getCapacity(Block b) {
BlockStorage.addBlockInfo(b, "capacity", String.valueOf(this.capacity));
}

return Integer.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "capacity"));
//There's no need to box the integer.
return Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "capacity"));
}

public int[] getInputSlots() {
Expand All @@ -222,7 +223,8 @@ public int[] getOutputSlots() {
private ItemStack getCapacityItem(Block b) {
StringBuilder bar = new StringBuilder();

int storedItems = Integer.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "storedItems"));
//There's no need to box the integer.
int storedItems = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "storedItems"));
float percentage = Math.round((float) storedItems / (float) getCapacity(b) * 100.0F);

bar.append("&8[");
Expand Down Expand Up @@ -271,7 +273,8 @@ private void updateBarrel(Block b) {
if (BlockStorage.getLocationInfo(b.getLocation(), "storedItems") == null) {
BlockStorage.addBlockInfo(b, "storedItems", "1");
}
int storedAmount = Integer.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "storedItems"));
//There's no need to box the integer.
int storedAmount = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "storedItems"));

if (storedAmount < getCapacity(b)) {
if (storedAmount + input.getAmount() > getCapacity(b)) {
Expand Down Expand Up @@ -303,7 +306,8 @@ else if (inventory.getItemInSlot(22).getType() == Material.BARRIER) {

if (BlockStorage.getLocationInfo(b.getLocation(), "storedItems") == null) return;

int stored = Integer.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "storedItems"));
//There's no need to box the integer.
int stored = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "storedItems"));
ItemStack output = inventory.getItemInSlot(22).clone();

if (inventory.getItemInSlot(getOutputSlots()[0]) != null) {
Expand All @@ -313,20 +317,10 @@ else if (inventory.getItemInSlot(22).getType() == Material.BARRIER) {

int requested = output.getMaxStackSize() - inventory.getItemInSlot(getOutputSlots()[0]).getAmount();

if (stored >= requested) {
output.setAmount(requested);
}
else {
output.setAmount(stored);
}
output.setAmount(Math.min(stored, requested));
}
else {
if (stored > output.getMaxStackSize()) {
output.setAmount(output.getMaxStackSize());
}
else {
output.setAmount(stored);
}
output.setAmount(Math.min(stored, output.getMaxStackSize()));
}

ItemMeta meta = output.getItemMeta();
Expand All @@ -348,7 +342,8 @@ else if (inventory.getItemInSlot(22).getType() == Material.BARRIER) {

BlockStorage.addBlockInfo(b, "storedItems", String.valueOf(stored - output.getAmount()));

pushItems(b, new ItemStack[]{output});
// There's no need to create an array in here.
pushItems(b, output);

if ((stored - output.getAmount()) <= 0) {
BlockStorage.addBlockInfo(b, "storedItems", null);
Expand Down
Loading

0 comments on commit 0d14dd9

Please sign in to comment.