diff options
| author | kekzdealer <kekzdealer@gmail.com> | 2019-11-21 18:38:33 +0100 |
|---|---|---|
| committer | kekzdealer <kekzdealer@gmail.com> | 2019-11-21 18:38:33 +0100 |
| commit | f9eac626254ed31477925618a45af5005e4628ac (patch) | |
| tree | 60e9b73067f9cb5e7a656a1d73b2a232887e0da8 /src/main/java/kekztech | |
| parent | 5fe214204875ac23e078e514dcd4fc8a001e3d37 (diff) | |
| download | GT5-Unofficial-f9eac626254ed31477925618a45af5005e4628ac.tar.gz GT5-Unofficial-f9eac626254ed31477925618a45af5005e4628ac.tar.bz2 GT5-Unofficial-f9eac626254ed31477925618a45af5005e4628ac.zip | |
first try at MultiItemHandler
Diffstat (limited to 'src/main/java/kekztech')
| -rw-r--r-- | src/main/java/kekztech/KekzCore.java | 7 | ||||
| -rw-r--r-- | src/main/java/kekztech/MultiItemHandler.java | 86 |
2 files changed, 84 insertions, 9 deletions
diff --git a/src/main/java/kekztech/KekzCore.java b/src/main/java/kekztech/KekzCore.java index 41f02ae036..9d0ae23283 100644 --- a/src/main/java/kekztech/KekzCore.java +++ b/src/main/java/kekztech/KekzCore.java @@ -119,7 +119,6 @@ public class KekzCore { System.out.println("Registering KekzTech recipes...");
final MetaItem_CraftingComponent craftingItem = MetaItem_CraftingComponent.getInstance();
- final MetaItem_ReactorComponent reactorItem = MetaItem_ReactorComponent.getInstance();
// Multiblock Controllers
final Object[] mk1_recipe = {
@@ -393,9 +392,9 @@ public class KekzCore { Materials.CarbonDioxide.getGas(16000),
craftingItem.getStackOfAmountFromDamage(Items.IsotopicallyPureDiamondCrystal.getMetaID(), 1), 10000, 2400, 7680);
GT_Values.RA.addAutoclaveRecipe(
- craftingItem.getStackOfAmountFromDamage(Items.IsotopicallyPureDiamondDust.getMetaID(), 4),
- Materials.CarbonDioxide.getGas(16000),
- craftingItem.getStackOfAmountFromDamage(Items.IsotopicallyPureDiamondCrystal.getMetaID(), 1), 10000, 2400, 1920);
+ craftingItem.getStackOfAmountFromDamage(Items.BoronArsenideDust.getMetaID(), 4),
+ Materials.Nitrogen.getGas(4000),
+ craftingItem.getStackOfAmountFromDamage(Items.BoronArsenideCrystal.getMetaID(), 1), 10000, 2400, 1920);
// Heat Pipes
GT_Values.RA.addLatheRecipe(
diff --git a/src/main/java/kekztech/MultiItemHandler.java b/src/main/java/kekztech/MultiItemHandler.java index aac3dc59c4..766abbbb93 100644 --- a/src/main/java/kekztech/MultiItemHandler.java +++ b/src/main/java/kekztech/MultiItemHandler.java @@ -1,18 +1,41 @@ package kekztech; +import java.util.ArrayList; + +import net.minecraft.item.ItemStack; + public class MultiItemHandler { - private int itemTypeCapacity = 128; - private int perTypeCapacity = 1024; + private int perTypeCapacity = 0; private boolean locked = true; + private final ArrayList<ItemStack> items = new ArrayList<>(); + public MultiItemHandler() { } - public void setItemTypeCapacity(int itemTypeCapacity) { - this.itemTypeCapacity = itemTypeCapacity; + /** + * Tries to adapt the internal storage to match structure changes. + * Structure should turn off and give a warning if this returns false. + * Otherwise items might unavailable. + * + * @param itemTypeCapacity + * New item array length to adapt to. + * @return Success status of the operation. + */ + public boolean setItemTypeCapacity(int itemTypeCapacity) { + if(items.size() > itemTypeCapacity) { + System.out.println("WARNING: ITEM SERVER STRUCTURE WAS DOWNSIZED TOO FAR! LOCKING FOR SAFETY."); + setLock(true); + return false; + } else { + items.ensureCapacity(itemTypeCapacity); + // If the lock was engaged, it should only be disengaged by turning + // the structure back on after fixing the above warning. + return true; + } } public void setPerTypeCapacity(int perTypeCapacity) { @@ -21,6 +44,7 @@ public class MultiItemHandler { /** * Lock internal storage in case Item Server is not running. + * May also be engaged in case of item safety issues. * * @param state * Lock state. @@ -30,12 +54,64 @@ public class MultiItemHandler { } public int getItemTypeCapacity() { - return itemTypeCapacity; + return items.size(); } public int getPerTypeCapacity() { return perTypeCapacity; } + public ItemStack getStackInSlot(int slot) { + System.out.println("Stack in slot " + slot + " requested"); + if(locked || slot >= items.size()) { + return null; + } else { + return items.get(slot); + } + } + + public void insertStackInSlot(int slot, ItemStack itemStack) { + System.out.println("Inserting " + itemStack.getDisplayName() + " into " + slot); + if(itemStack == null + || items.get(slot) != null + || locked + || slot >= items.size()) { + return; + } else { + items.set(slot, itemStack); + } + } + + public int increaseStackInSlot(int slot, int amount) { + System.out.println("Increasing item in slot " + slot + " by " + amount); + if(slot >= items.size() + || locked + || amount <= 0) { + return 0; + } else { + final int space = perTypeCapacity - items.get(slot).stackSize; + final int fit = Math.min(space, amount); + items.get(slot).stackSize += fit; + return fit; + } + } + + public int reduceStackInSlot(int slot, int amount) { + System.out.println("Reducing item in slot " + slot + " by " + amount); + if(slot >= items.size() + || locked + || amount <= 0) { + return 0; + } else { + final int available = items.get(slot).stackSize; + final int take = Math.min(available, amount); + items.get(slot).stackSize -= take; + if(take == available) { + items.set(slot, null); + } + return take; + } + } + } |
