aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorkekzdealer <kekzdealer@gmail.com>2020-02-18 16:01:52 +0100
committerkekzdealer <kekzdealer@gmail.com>2020-02-18 16:01:52 +0100
commitba8d49bd6c77d69630135c887272e9d0c8c7311d (patch)
tree1863d73a809f4da25c103c980b7b77f9314b9736 /src/main
parentb4ad6bbaf80fc10d4b4256badac13f69e286288b (diff)
downloadGT5-Unofficial-ba8d49bd6c77d69630135c887272e9d0c8c7311d.tar.gz
GT5-Unofficial-ba8d49bd6c77d69630135c887272e9d0c8c7311d.tar.bz2
GT5-Unofficial-ba8d49bd6c77d69630135c887272e9d0c8c7311d.zip
Fixed Item Server structure check. Wrote better doc for the MIH
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/kekztech/KekzCore.java1
-rw-r--r--src/main/java/kekztech/MultiItemHandler.java112
-rw-r--r--src/main/java/tileentities/GTMTE_ItemServer.java121
3 files changed, 142 insertions, 92 deletions
diff --git a/src/main/java/kekztech/KekzCore.java b/src/main/java/kekztech/KekzCore.java
index 114446ad38..64e1298d3c 100644
--- a/src/main/java/kekztech/KekzCore.java
+++ b/src/main/java/kekztech/KekzCore.java
@@ -18,7 +18,6 @@ import blocks.Block_TFFTStorageFieldBlockT3;
import blocks.Block_TFFTStorageFieldBlockT4;
import blocks.Block_TFFTStorageFieldBlockT5;
import blocks.Block_YSZUnit;
-import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
diff --git a/src/main/java/kekztech/MultiItemHandler.java b/src/main/java/kekztech/MultiItemHandler.java
index 766abbbb93..9416dbebcf 100644
--- a/src/main/java/kekztech/MultiItemHandler.java
+++ b/src/main/java/kekztech/MultiItemHandler.java
@@ -1,7 +1,5 @@
package kekztech;
-import java.util.ArrayList;
-
import net.minecraft.item.ItemStack;
public class MultiItemHandler {
@@ -10,31 +8,44 @@ public class MultiItemHandler {
private boolean locked = true;
- private final ArrayList<ItemStack> items = new ArrayList<>();
+ private ItemStack[] items;
public MultiItemHandler() {
}
- /**
- * 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.
+ /**
+ * Adapts the internal storage to structure changes.
+ * In the event of structure down-sizing, all excess items
+ * will be dropped on the ground.
*
* @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;
+ public void setItemTypeCapacity(int itemTypeCapacity) {
+ if(items.length > itemTypeCapacity) {
+ // Generate new smaller backing array
+ final ItemStack[] newItems = new ItemStack[itemTypeCapacity];
+ for(int i = 0; i < newItems.length; i++) {
+ newItems[i] = items[i];
+ }
+ // Sort out item overflow
+ final ItemStack[] toDrop = new ItemStack[items.length - itemTypeCapacity];
+ for(int i = 0; i < toDrop.length; i++) {
+ toDrop[i] = items[i + newItems.length - 1];
+ }
+ // TODO drop overflow items to the ground
+
+ // Swap array
+ items = newItems;
} 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;
+ // Generate new larger backing array
+ final ItemStack[] newItems = new ItemStack[itemTypeCapacity];
+ for(int i = 0; i < items.length; i++) {
+ newItems[i] = items[i];
+ }
+
+ // Swap array
+ items = newItems;
}
}
@@ -44,7 +55,6 @@ 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.
@@ -54,60 +64,98 @@ public class MultiItemHandler {
}
public int getItemTypeCapacity() {
- return items.size();
+ return items.length;
}
public int getPerTypeCapacity() {
return perTypeCapacity;
}
+ /**
+ * Returns the ItemStack from the specified slot.
+ *
+ * @param slot
+ * Storage slot number. Zero indexed.
+ * @return
+ * ItemStack from storage or null if
+ * storage is locked or invalid slot parameter.
+ */
public ItemStack getStackInSlot(int slot) {
System.out.println("Stack in slot " + slot + " requested");
- if(locked || slot >= items.size()) {
+ if(locked || slot >= items.length) {
return null;
} else {
- return items.get(slot);
+ return items[slot];
}
}
+ /**
+ * Inserts a new ItemStack into storage,
+ * but only if the slot is still unassigned.
+ *
+ * @param slot
+ * Storage slot number. Zero indexed.
+ * @param itemStack
+ * ItemStack to insert.
+ */
public void insertStackInSlot(int slot, ItemStack itemStack) {
System.out.println("Inserting " + itemStack.getDisplayName() + " into " + slot);
if(itemStack == null
- || items.get(slot) != null
+ || items[slot] != null
|| locked
- || slot >= items.size()) {
+ || slot >= items.length) {
return;
} else {
- items.set(slot, itemStack);
+ items[slot] = itemStack;
}
}
+ /**
+ * Tries to increase the item amount in a specified slot.
+ *
+ * @param slot
+ * Storage slot number. Zero indexed.
+ * @param amount
+ * Amount to increase by.
+ * @return
+ * Actual amount the item amount was increased by.
+ */
public int increaseStackInSlot(int slot, int amount) {
System.out.println("Increasing item in slot " + slot + " by " + amount);
- if(slot >= items.size()
+ if(slot >= items.length
|| locked
|| amount <= 0) {
return 0;
} else {
- final int space = perTypeCapacity - items.get(slot).stackSize;
+ final int space = perTypeCapacity - items[slot].stackSize;
final int fit = Math.min(space, amount);
- items.get(slot).stackSize += fit;
+ items[slot].stackSize += fit;
return fit;
}
}
+ /**
+ * Tries to reduce the item amount in a specified slot.
+ *
+ * @param slot
+ * Storage slot number. Zero indexed.
+ * @param amount
+ * Amount to decrease by.
+ * @return
+ * Actual amount the item amount was decreased by.
+ */
public int reduceStackInSlot(int slot, int amount) {
System.out.println("Reducing item in slot " + slot + " by " + amount);
- if(slot >= items.size()
+ if(slot >= items.length
|| locked
|| amount <= 0) {
return 0;
} else {
- final int available = items.get(slot).stackSize;
+ final int available = items[slot].stackSize;
final int take = Math.min(available, amount);
- items.get(slot).stackSize -= take;
+ items[slot].stackSize -= take;
if(take == available) {
- items.set(slot, null);
+ items[slot] = null;
}
return take;
}
diff --git a/src/main/java/tileentities/GTMTE_ItemServer.java b/src/main/java/tileentities/GTMTE_ItemServer.java
index 9b4d50c5d4..3753b8e17a 100644
--- a/src/main/java/tileentities/GTMTE_ItemServer.java
+++ b/src/main/java/tileentities/GTMTE_ItemServer.java
@@ -34,7 +34,8 @@ public class GTMTE_ItemServer extends GT_MetaTileEntity_MultiBlockBase {
private final Block_ItemServerDrive DRIVE = Block_ItemServerDrive.getInstance();
private final Block_ItemServerRackCasing CASING = Block_ItemServerRackCasing.getInstance();
private final Block_ItemServerIOPort IO_PORT = Block_ItemServerIOPort.getInstance();
- private final String ALU_FRAME_BOX_NAME = "gt.blockmachines.gt_frame_aluminium";
+ private final String ALU_FRAME_BOX_NAME = "gt.blockmachines";
+ private final int ALU_FRAME_BOX_META = 6;//4115;
private final int CASING_TEXTURE_ID = 176;
private MultiItemHandler mih;
@@ -111,8 +112,8 @@ public class GTMTE_ItemServer extends GT_MetaTileEntity_MultiBlockBase {
this.mEfficiency = 10000 - (this.getIdealStatus() - this.getRepairStatus()) * 1000;
this.mEfficiencyIncrease = 10000;
- this.mEUt = (int) (BASE_SLICE_ENERGY_COST * sliceCount * Math.pow(2, config));
- super.mMaxProgresstime = 10;
+ this.mEUt = (int) -(BASE_SLICE_ENERGY_COST * sliceCount * Math.pow(2, config));
+ super.mMaxProgresstime = 20;
mih.setPerTypeCapacity((int) (BASE_PER_ITEM_CAPACITY * Math.pow(4, config)));
@@ -184,9 +185,8 @@ public class GTMTE_ItemServer extends GT_MetaTileEntity_MultiBlockBase {
&& !super.addEnergyInputToMachineList(currentTE, CASING_TEXTURE_ID)) {
// If it's not a hatch, is it the right casing for this machine?
- // TODO: Also check IO port
if(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) {
- // yay
+ // is casing
} else if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == IO_PORT) {
final TE_ItemServerIOPort port =
(TE_ItemServerIOPort) thisController.getWorld().getTileEntity(
@@ -201,23 +201,31 @@ public class GTMTE_ItemServer extends GT_MetaTileEntity_MultiBlockBase {
}
}
+ if(formationChecklist) {
+ System.out.println("Item Server front slice approved");
+ }
+
// Check slices
int slicesFound = 0;
- int zOffset = 1;
- for(int s = 0; s < slicesFound; s++) {
- final Vector3ic probe = rotateOffsetVector(forgeDirection, 1, 0, zOffset);
- // Probe if another slice might exist
- if(thisController.getBlockOffset(probe.x(), probe.y(), probe.z()) == DRIVE) {
- formationChecklist = checkSlice(thisController, zOffset);
- if(!formationChecklist) {
- break;
- } else {
- slicesFound++;
- zOffset += 2;
- }
+ int zOffset = -1;
+
+ while(slicesFound < 5) {
+ if(checkSlice(thisController, forgeDirection, zOffset)) {
+ slicesFound++;
+ zOffset -= 3;
+
+ System.out.println("Item Server slice approved: " + slicesFound);
+ } else {
+ System.out.println("Item Server slice rejected: " + slicesFound + 1);
+ break;
}
}
+ if(slicesFound < 1) {
+ System.out.println("At least one slice required for storage");
+ formationChecklist = false;
+ }
+
if(this.mEnergyHatches.size() < 1) {
System.out.println("At least one energy hatch is required!");
formationChecklist = false;
@@ -229,12 +237,13 @@ public class GTMTE_ItemServer extends GT_MetaTileEntity_MultiBlockBase {
}
if(formationChecklist) {
- slicesFound = sliceCount;
+ sliceCount = slicesFound;
if(mih == null) {
mih = new MultiItemHandler();
mih.setItemTypeCapacity(slicesFound * BASE_ITEM_TYPES_PER_SLICE);
}
+ System.out.println("Configuring " + ioPorts.size() + " ports");
for(TE_ItemServerIOPort port : ioPorts) {
port.setMultiItemHandler(mih);
}
@@ -243,19 +252,16 @@ public class GTMTE_ItemServer extends GT_MetaTileEntity_MultiBlockBase {
return formationChecklist;
}
- public boolean checkSlice(IGregTechTileEntity thisController, int zOffset) {
- // Figure out the vector for the direction the back face of the controller is facing
- final Vector3ic forgeDirection = new Vector3i(
- ForgeDirection.getOrientation(thisController.getBackFacing()).offsetX,
- ForgeDirection.getOrientation(thisController.getBackFacing()).offsetY,
- ForgeDirection.getOrientation(thisController.getBackFacing()).offsetZ
- );
+ public boolean checkSlice(IGregTechTileEntity thisController, Vector3ic forgeDirection, int zOffset) {
boolean formationChecklist = true;
- for(int Z = 0; Z <= 2; Z++) {
- if(Z != 2) {
+ for(int Z = 0; Z >= -2; Z--) {
+ // Is not back slice
+ if(Z != -2) {
+ // Left to right
for(int X = -1; X <= 1; X++) {
- for(int Y = 0; Y < 5; Y++) {
+ // Bottom to top
+ for(int Y = 0; Y <= 4; Y++) {
final Vector3ic offset = rotateOffsetVector(forgeDirection, X, Y, zOffset + Z);
// Server rack roof is casings
@@ -270,9 +276,8 @@ public class GTMTE_ItemServer extends GT_MetaTileEntity_MultiBlockBase {
&& !super.addEnergyInputToMachineList(currentTE, CASING_TEXTURE_ID)) {
// If it's not a hatch, is it the right casing for this machine?
- // TODO: Also check IO port
if(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) {
- // yay
+ // is casing
} else if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == IO_PORT) {
final TE_ItemServerIOPort port =
(TE_ItemServerIOPort) thisController.getWorld().getTileEntity(
@@ -287,14 +292,19 @@ public class GTMTE_ItemServer extends GT_MetaTileEntity_MultiBlockBase {
}
// Middle wall is aluminium frame boxes
- else if(Y < 4 && X == 0) {
- if(!(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()).getUnlocalizedName().equals(ALU_FRAME_BOX_NAME))) {
+ else if(Y <= 3 && X == 0) {
+ if(!(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()).getUnlocalizedName().equals(ALU_FRAME_BOX_NAME))
+ || !(thisController.getMetaIDOffset(offset.x(), offset.y(), offset.z()) == ALU_FRAME_BOX_META)) {
+ System.out.println("Rejected Frame box: "
+ + thisController.getBlockOffset(offset.x(), offset.y(), offset.z()).getUnlocalizedName()
+ + ":"
+ + thisController.getMetaIDOffset(offset.x(), offset.y(), offset.z()));
formationChecklist = false;
}
}
// Side walls are item server drives
- else if(Y < 4 && X != 0) {
+ else if(Y <= 3 && X != 0) {
if(!(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == DRIVE)) {
formationChecklist = false;
}
@@ -304,38 +314,30 @@ public class GTMTE_ItemServer extends GT_MetaTileEntity_MultiBlockBase {
} else {
// Back slice
for(int X = -1; X <= 1; X++) {
- for(int Y = 0; Y < 5; Y++) {
+ for(int Y = 0; Y <= 4; Y++) {
// Get next TE
final Vector3ic offset = rotateOffsetVector(forgeDirection, X, Y, zOffset + Z);
IGregTechTileEntity currentTE =
thisController.getIGregTechTileEntityOffset(offset.x(), offset.y(), offset.z());
- // Disallow nonsensical hatches in the middle of the structure
- if(Y < 4 && Y > 0 && X == 0) {
- if(!(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING)) {
+ if(!super.addMaintenanceToMachineList(currentTE, CASING_TEXTURE_ID)
+ && !super.addInputToMachineList(currentTE, CASING_TEXTURE_ID)
+ && !super.addEnergyInputToMachineList(currentTE, CASING_TEXTURE_ID)) {
+
+ // If it's not a hatch, is it the right casing for this machine?
+ if(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) {
+ // is casing
+ } else if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == IO_PORT) {
+ final TE_ItemServerIOPort port =
+ (TE_ItemServerIOPort) thisController.getWorld().getTileEntity(
+ thisController.getXCoord() + offset.x(),
+ thisController.getYCoord() + offset.y(),
+ thisController.getZCoord() + offset.z());
+ ioPorts.add(port);
+ } else {
formationChecklist = false;
}
- } else {
- if(!super.addMaintenanceToMachineList(currentTE, CASING_TEXTURE_ID)
- && !super.addInputToMachineList(currentTE, CASING_TEXTURE_ID)
- && !super.addEnergyInputToMachineList(currentTE, CASING_TEXTURE_ID)) {
-
- // If it's not a hatch, is it the right casing for this machine?
- // TODO: Also check IO port
- if(thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == CASING) {
- // yay
- } else if (thisController.getBlockOffset(offset.x(), offset.y(), offset.z()) == IO_PORT) {
- final TE_ItemServerIOPort port =
- (TE_ItemServerIOPort) thisController.getWorld().getTileEntity(
- thisController.getXCoord() + offset.x(),
- thisController.getYCoord() + offset.y(),
- thisController.getZCoord() + offset.z());
- ioPorts.add(port);
- } else {
- formationChecklist = false;
- }
- }
}
}
}
@@ -351,8 +353,9 @@ public class GTMTE_ItemServer extends GT_MetaTileEntity_MultiBlockBase {
final ArrayList<String> ll = new ArrayList<>();//mfh.getInfoData();
ll.add(EnumChatFormatting.YELLOW + "Operational Data:" + EnumChatFormatting.RESET);
- ll.add("Per-Fluid Capacity: " + BASE_PER_ITEM_CAPACITY);
- ll.add("Running Cost: " + (-super.mEUt) + "EU/t");
+ ll.add("Per-Item Capacity: " + mih.getPerTypeCapacity());
+ ll.add("Item-Type Capacity: " + BASE_ITEM_TYPES_PER_SLICE * sliceCount);
+ ll.add("Running Cost: " + -(super.mEUt) + "EU/t");
ll.add("Maintenance Status: " + ((super.getRepairStatus() == super.getIdealStatus())
? EnumChatFormatting.GREEN + "Working perfectly" + EnumChatFormatting.RESET
: EnumChatFormatting.RED + "Has Problems" + EnumChatFormatting.RESET));