aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kekztech
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/kekztech')
-rw-r--r--src/main/java/kekztech/Items.java189
-rw-r--r--src/main/java/kekztech/KekzCore.java173
-rw-r--r--src/main/java/kekztech/MultiFluidHandler.java293
-rw-r--r--src/main/java/kekztech/MultiItemHandler.java185
-rw-r--r--src/main/java/kekztech/ServerProxy.java7
5 files changed, 392 insertions, 455 deletions
diff --git a/src/main/java/kekztech/Items.java b/src/main/java/kekztech/Items.java
index cb79d01947..50e56ced00 100644
--- a/src/main/java/kekztech/Items.java
+++ b/src/main/java/kekztech/Items.java
@@ -1,94 +1,95 @@
-package kekztech;
-
-import items.MetaItem_CraftingComponent;
-import items.MetaItem_ReactorComponent;
-import net.minecraft.item.ItemStack;
-import net.minecraftforge.oredict.OreDictionary;
-import util.Util;
-
-import java.util.Arrays;
-
-public enum Items {
- // Heat Vents
- T1HeatVent(0,0), T2HeatVent(1,0), T3HeatVent(2,0), T4HeatVent(3,0),
- T1ComponentHeatVent(4,0), T2ComponentHeatVent(5,0), T3ComponentHeatVent(6,0), T4ComponentHeatVent(7,0),
- T1OverclockedHeatVent(8,0), T2OverclockedHeatVent(9,0), T3OverclockedHeatVent(10,0), T4OverclockedHeatVent(11,0),
- // Heat Exchanger
- T1HeatExchanger(12,0), T2HeatExchanger(13,0), T3HeatExchanger(14,0), T4HeatExchanger(15,0),
- // Fuel Rods
- UraniumFuelRod(16,0), UraniumDualFuelRod(17,0), UraniumQuadFuelRod(18,0),
- ThoriumFuelRod(19,0), ThoriumDualFuelRod(20,0), ThoriumQuadFuelRod(21,0),
- MOXFuelRod(22,0), MOXDualFuelRod(23,0), MOXQuadFuelRod(24,0),
- NaquadahFuelRod(25,0), NaquadahDualFuelRod(26,0), NaquadahQuadFuelRod(27,0),
- Th_MOXFuelRod(28,0), Th_MOXDualFuelRod(29,0), Th_MOXQuadFuelRod(30,0),
- // Depleted Fuel Rods
- DepletedUraniumFuelRod(31,0), DepletedUraniumDualFuelRod(32,0), DepletedUraniumQuadFuelRod(33,0),
- DepletedThoriumFuelRod(34,0), DepletedThoriumDualFuelRod(35,0), DepletedThoriumQuadFuelRod(36,0),
- DepletedMOXFuelRod(37,0), DepletedMOXDualFuelRod(38,0), DepletedMOXQuadFuelRod(39,0),
- DepletedNaquadahFuelRod(40,0), DepletedNaquadahDualFuelRod(41,0), DepletedNaquadahQuadFuelRod(42,0),
- Th_DepletedMOXFuelRod(43,0), Th_DepletedMOXDualFuelRod(44,0), Th_DepletedMOXQuadFuelRod(45,0),
- // Neutron Reflectors
- T1NeutronReflector(46,0), T2NeutronReflector(47,0),
- // Coolant Cells
- HeliumCoolantCell360k(48,0), NaKCoolantCell360k(49,0),
-
- // Heat Pipes
- CopperHeatPipe(0,1), SilverHeatPipe(1,1), BoronArsenideHeatPipe(2,1), DiamondHeatPipe(3,1),
- BoronArsenideDust(4,1), IsotopicallyPureDiamondDust(5,1), AmineCarbamiteDust(6,1),
- BoronArsenideCrystal(7,1), IsotopicallyPureDiamondCrystal(8,1),
- // Ceramics
- YSZCeramicDust(9,1), GDCCeramicDust(10,1),
- YttriaDust(11,1), ZirconiaDust(12,1), CeriaDust(13,1),
- YSZCeramicPlate(14,1), GDCCeramicPlate(15,1),
- ItemServerBlade(16,1),
- // Error Item
- Error(0,1),
- // Configurator
- Configurator(0, 1);
-
- static {
- YttriaDust.setOreDictName("dustYttriumOxide");
- ZirconiaDust.setOreDictName("dustCubicZirconia");
- }
-
- private final int metaID;
- private final int identifier;
-
- private Items(int metaID, int identifier) {
- this.metaID = metaID;
- this.identifier = identifier;
- }
-
- public int getMetaID() {
- return metaID;
- }
-
- String OreDictName;
-
- private void registerOreDict(){
- OreDictionary.registerOre(getOreDictName(),getNonOreDictedItemStack(1));
- }
-
- public static void registerOreDictNames(){
- Arrays.stream(Items.values()).filter(e -> e.getOreDictName() != null).forEach(Items::registerOreDict);
- }
-
- public ItemStack getNonOreDictedItemStack(int amount){
- return identifier == 0 ? new ItemStack(MetaItem_ReactorComponent.getInstance(),amount,this.getMetaID()) :
- new ItemStack(MetaItem_CraftingComponent.getInstance(),amount,this.getMetaID());
- }
-
- public ItemStack getOreDictedItemStack(int amount){
- return this.getOreDictName() != null ? Util.getStackofAmountFromOreDict(this.getOreDictName(),amount) :
- identifier == 0 ? new ItemStack(MetaItem_ReactorComponent.getInstance(),amount,this.getMetaID()) :
- new ItemStack(MetaItem_CraftingComponent.getInstance(),amount,this.getMetaID());
- }
-
- public String getOreDictName() {
- return OreDictName;
- }
-
- public void setOreDictName(String oreDictName) {
- OreDictName = oreDictName;
- }
-}
+package kekztech;
+
+import common.items.MetaItem_CraftingComponent;
+import common.items.MetaItem_ReactorComponent;
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.oredict.OreDictionary;
+import util.Util;
+
+import java.util.Arrays;
+
+public enum Items {
+ /*
+ // Heat Vents
+ T1HeatVent(0,0), T2HeatVent(1,0), T3HeatVent(2,0), T4HeatVent(3,0),
+ T1ComponentHeatVent(4,0), T2ComponentHeatVent(5,0), T3ComponentHeatVent(6,0), T4ComponentHeatVent(7,0),
+ T1OverclockedHeatVent(8,0), T2OverclockedHeatVent(9,0), T3OverclockedHeatVent(10,0), T4OverclockedHeatVent(11,0),
+ // Heat Exchanger
+ T1HeatExchanger(12,0), T2HeatExchanger(13,0), T3HeatExchanger(14,0), T4HeatExchanger(15,0),
+ // Fuel Rods
+ UraniumFuelRod(16,0), UraniumDualFuelRod(17,0), UraniumQuadFuelRod(18,0),
+ ThoriumFuelRod(19,0), ThoriumDualFuelRod(20,0), ThoriumQuadFuelRod(21,0),
+ MOXFuelRod(22,0), MOXDualFuelRod(23,0), MOXQuadFuelRod(24,0),
+ NaquadahFuelRod(25,0), NaquadahDualFuelRod(26,0), NaquadahQuadFuelRod(27,0),
+ Th_MOXFuelRod(28,0), Th_MOXDualFuelRod(29,0), Th_MOXQuadFuelRod(30,0),
+ // Depleted Fuel Rods
+ DepletedUraniumFuelRod(31,0), DepletedUraniumDualFuelRod(32,0), DepletedUraniumQuadFuelRod(33,0),
+ DepletedThoriumFuelRod(34,0), DepletedThoriumDualFuelRod(35,0), DepletedThoriumQuadFuelRod(36,0),
+ DepletedMOXFuelRod(37,0), DepletedMOXDualFuelRod(38,0), DepletedMOXQuadFuelRod(39,0),
+ DepletedNaquadahFuelRod(40,0), DepletedNaquadahDualFuelRod(41,0), DepletedNaquadahQuadFuelRod(42,0),
+ Th_DepletedMOXFuelRod(43,0), Th_DepletedMOXDualFuelRod(44,0), Th_DepletedMOXQuadFuelRod(45,0),
+ // Neutron Reflectors
+ T1NeutronReflector(46,0), T2NeutronReflector(47,0),
+ // Coolant Cells
+ HeliumCoolantCell360k(48,0), NaKCoolantCell360k(49,0),
+
+ // Heat Pipes
+ CopperHeatPipe(0,1), SilverHeatPipe(1,1), BoronArsenideHeatPipe(2,1), DiamondHeatPipe(3,1),
+ BoronArsenideDust(4,1), IsotopicallyPureDiamondDust(5,1), AmineCarbamiteDust(6,1),
+ BoronArsenideCrystal(7,1), IsotopicallyPureDiamondCrystal(8,1),
+ */
+ // Ceramics
+ YSZCeramicDust(9,1), GDCCeramicDust(10,1),
+ YttriaDust(11,1), ZirconiaDust(12,1), CeriaDust(13,1),
+ YSZCeramicPlate(14,1), GDCCeramicPlate(15,1),
+ // Error Item
+ Error(0,1),
+ // Configurator
+ Configurator(0, 1);
+
+ static {
+ YttriaDust.setOreDictName("dustYttriumOxide");
+ ZirconiaDust.setOreDictName("dustCubicZirconia");
+ }
+
+ private final int metaID;
+ private final int identifier;
+
+ Items(int metaID, int identifier) {
+ this.metaID = metaID;
+ this.identifier = identifier;
+ }
+
+ public int getMetaID() {
+ return metaID;
+ }
+
+ String OreDictName;
+
+ private void registerOreDict(){
+ OreDictionary.registerOre(getOreDictName(),getNonOreDictedItemStack(1));
+ }
+
+ public static void registerOreDictNames(){
+ Arrays.stream(Items.values()).filter(e -> e.getOreDictName() != null).forEach(Items::registerOreDict);
+ }
+
+ public ItemStack getNonOreDictedItemStack(int amount){
+ return identifier == 0 ? new ItemStack(MetaItem_ReactorComponent.getInstance(),amount,this.getMetaID()) :
+ new ItemStack(MetaItem_CraftingComponent.getInstance(),amount,this.getMetaID());
+ }
+
+ public ItemStack getOreDictedItemStack(int amount){
+ return this.getOreDictName() != null ? Util.getStackofAmountFromOreDict(this.getOreDictName(),amount) :
+ identifier == 0 ? new ItemStack(MetaItem_ReactorComponent.getInstance(),amount,this.getMetaID()) :
+ new ItemStack(MetaItem_CraftingComponent.getInstance(),amount,this.getMetaID());
+ }
+
+ public String getOreDictName() {
+ return OreDictName;
+ }
+
+ public void setOreDictName(String oreDictName) {
+ OreDictName = oreDictName;
+ }
+}
diff --git a/src/main/java/kekztech/KekzCore.java b/src/main/java/kekztech/KekzCore.java
index 7574c1f399..1aed8315ce 100644
--- a/src/main/java/kekztech/KekzCore.java
+++ b/src/main/java/kekztech/KekzCore.java
@@ -1,105 +1,68 @@
-package kekztech;
-
-import client.renderer.TESR_SECapacitor;
-import client.renderer.TESR_SETether;
-import common.Blocks;
-import common.Recipes;
-import common.Researches;
-import common.tileentities.*;
-import cpw.mods.fml.client.registry.ClientRegistry;
-import cpw.mods.fml.common.Mod;
-import cpw.mods.fml.common.event.FMLInitializationEvent;
-import cpw.mods.fml.common.event.FMLPostInitializationEvent;
-import cpw.mods.fml.common.event.FMLPreInitializationEvent;
-import cpw.mods.fml.common.network.NetworkRegistry;
-import cpw.mods.fml.common.registry.GameRegistry;
-import items.ErrorItem;
-import items.MetaItem_CraftingComponent;
-import items.MetaItem_ReactorComponent;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-/**
- * My GT-Meta-IDs are: 13101 - 13500
- *
- * @author kekzdealer
- *
- */
-@Mod(modid = KekzCore.MODID, name = KekzCore.NAME, version = KekzCore.VERSION,
- dependencies =
- "required-after:IC2;"
- + "required-after:gregtech;"
- + "required-after:tectech;"
- + "required-after:Thaumcraft;"
- + "required-after:ThaumicTinkerer;"
- + "after:bartworks;"
- + "after:dreamcraft"
- )
-public class KekzCore {
-
- public static final String NAME = "KekzTech";
- public static final String MODID = "kekztech";
- public static final String VERSION = "0.4.5";
-
- public static final Logger LOGGER = LogManager.getLogger(NAME);
-
- @Mod.Instance("kekztech")
- public static KekzCore instance;
-
- public static GTMTE_SOFuelCellMK1 sofc1;
- public static GTMTE_SOFuelCellMK2 sofc2;
- public static GTMTE_ModularNuclearReactor mdr;
- public static GTMTE_FluidMultiStorage fms;
- public static GTMTE_ItemServer is;
- public static GTMTE_LapotronicSuperCapacitor lsc;
- public static GTMTE_SpaceElevator se;
-
- @Mod.EventHandler
- public void preInit(FMLPreInitializationEvent event) {
- // Items
- ErrorItem.getInstance().registerItem();
- MetaItem_ReactorComponent.getInstance().registerItem();
- MetaItem_CraftingComponent.getInstance().registerItem();
- Items.registerOreDictNames();
-
- Blocks.preInit();
-
- // Register TileEntities
- GameRegistry.registerTileEntity(TE_TFFTMultiHatch.class, "kekztech_tfftmultihatch_tile");
- //GameRegistry.registerTileEntity(TE_ItemServerIOPort.class, "kekztech_itemserverioport_tile");
- GameRegistry.registerTileEntity(TE_ItemProxyCable.class, "kekztech_itemproxycable_tile");
- GameRegistry.registerTileEntity(TE_ItemProxySource.class, "kekztech_itemproxysource_tile");
- GameRegistry.registerTileEntity(TE_ItemProxyEndpoint.class, "kekztech_itemproxyendpoint_tile");
- GameRegistry.registerTileEntity(TE_ThaumiumReinforcedJar.class, "kekztech_thaumiumreinforcedjar");
- GameRegistry.registerTileEntity(TE_IchorJar.class, "kekztech_ichorjar");
-
- // Register guis
- NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
-
- // Register TESR
- ClientRegistry.bindTileEntitySpecialRenderer(TE_SpaceElevatorTether.class, new TESR_SETether());
- ClientRegistry.bindTileEntitySpecialRenderer(TE_SpaceElevatorCapacitor.class, new TESR_SECapacitor());
-
- Researches.preInit();
- }
-
- @Mod.EventHandler
- public void init(FMLInitializationEvent event) {
- // Multiblock controllers
- sofc1 = new GTMTE_SOFuelCellMK1(13101, "multimachine.fuelcellmk1", "Solid-Oxide Fuel Cell Mk I");
- sofc2 = new GTMTE_SOFuelCellMK2(13102, "multimachine.fuelcellmk2", "Solid-Oxide Fuel Cell Mk II");
- mdr = new GTMTE_ModularNuclearReactor(13103, "multimachine.nuclearreactor", "Nuclear Reactor");
- fms = new GTMTE_FluidMultiStorage(13104, "multimachine.tf_fluidtank", "T.F.F.T");
- //is = new GTMTE_ItemServer(13105, "multimachine.itemserver", "Item Server");
- lsc = new GTMTE_LapotronicSuperCapacitor(13106, "multimachine.supercapacitor", "Lapotronic Supercapacitor");
- se = new GTMTE_SpaceElevator(13107, "multimachine.spaceelevator", "Space Elevator");
- // Register renderer
- //RenderingRegistry.registerBlockHandler(ConduitRenderer.getInstance());
- }
-
- @Mod.EventHandler
- public void postInit(FMLPostInitializationEvent event) {
- Recipes.postInit();
- Researches.postInit();
- }
-}
+package kekztech;
+
+import client.renderer.TESR_SECapacitor;
+import client.renderer.TESR_SETether;
+import common.Blocks;
+import common.CommonProxy;
+import common.Recipes;
+import common.Researches;
+import common.tileentities.*;
+import cpw.mods.fml.client.registry.ClientRegistry;
+import cpw.mods.fml.common.Mod;
+import cpw.mods.fml.common.SidedProxy;
+import cpw.mods.fml.common.event.FMLInitializationEvent;
+import cpw.mods.fml.common.event.FMLPostInitializationEvent;
+import cpw.mods.fml.common.event.FMLPreInitializationEvent;
+import cpw.mods.fml.common.network.NetworkRegistry;
+import cpw.mods.fml.common.registry.GameRegistry;
+import common.items.ErrorItem;
+import common.items.MetaItem_CraftingComponent;
+import common.items.MetaItem_ReactorComponent;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ * My GT-Meta-IDs are: 13101 - 13500
+ *
+ * @author kekzdealer
+ *
+ */
+@Mod(modid = KekzCore.MODID, name = KekzCore.NAME, version = KekzCore.VERSION,
+ dependencies =
+ "required-after:IC2;"
+ + "required-after:gregtech;"
+ + "required-after:tectech;"
+ + "required-after:Thaumcraft;"
+ + "required-after:ThaumicTinkerer;"
+ + "after:bartworks;"
+ + "after:dreamcraft"
+ )
+public class KekzCore {
+
+ public static final String NAME = "KekzTech";
+ public static final String MODID = "kekztech";
+ public static final String VERSION = "0.5";
+
+ public static final Logger LOGGER = LogManager.getLogger(NAME);
+
+ @Mod.Instance("kekztech")
+ public static KekzCore instance;
+
+ @SidedProxy(clientSide = "client.ClientProxy", serverSide = "kekztech.ServerProxy")
+ public static CommonProxy proxy;
+
+ @Mod.EventHandler
+ public void preInit(FMLPreInitializationEvent event) {
+ proxy.preInit(event);
+ }
+
+ @Mod.EventHandler
+ public void init(FMLInitializationEvent event) {
+ proxy.init(event);
+ }
+
+ @Mod.EventHandler
+ public void postInit(FMLPostInitializationEvent event) {
+ proxy.postInit(event);
+ }
+}
diff --git a/src/main/java/kekztech/MultiFluidHandler.java b/src/main/java/kekztech/MultiFluidHandler.java
index f1a527b2c0..399f9faa8b 100644
--- a/src/main/java/kekztech/MultiFluidHandler.java
+++ b/src/main/java/kekztech/MultiFluidHandler.java
@@ -1,34 +1,61 @@
package kekztech;
-import java.util.ArrayList;
-import java.util.List;
-
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.fluids.FluidStack;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
public class MultiFluidHandler {
-
- public static final int MAX_DISTINCT_FLUIDS = 25;
-
- private final List<FluidStack> fluids = new ArrayList<>(MAX_DISTINCT_FLUIDS);
- private int capacityPerFluid;
+
+ private final FluidStack[] fluids;
+ private final int maxDistinctFluids;
+ private final int capacityPerFluid;
private boolean locked = true;
private boolean doVoidExcess = false;
private byte fluidSelector = -1;
- public MultiFluidHandler() {
-
- }
-
- public MultiFluidHandler(int capacityPerFluid) {
+ public MultiFluidHandler(int maxDistinctFluids, int capacityPerFluid, FluidStack[] fluidsToAdd) {
+ this.maxDistinctFluids = maxDistinctFluids;
+ this.fluids = new FluidStack[maxDistinctFluids];
+ if(fluidsToAdd != null) {
+ int tFluidLengt = (maxDistinctFluids <fluidsToAdd.length) ? maxDistinctFluids:fluidsToAdd.length;
+ for (int i = 0; i < tFluidLengt; i++) {
+ this.fluids[i] = fluidsToAdd[i];
+ }
+ }
this.capacityPerFluid = capacityPerFluid;
}
-
- public MultiFluidHandler(int capacityPerFluid, List<FluidStack> fluids) {
- this.capacityPerFluid = capacityPerFluid;
- this.fluids.addAll(fluids);
+
+ /**
+ * Initialize a new MultiFluidHandler object with the given parameters
+ * @param maxDistinctFluids
+ * How many different fluids can be stored
+ * @param capacityPerFluid
+ * How much capacity each fluid should have
+ * @param fluidsToAdd
+ * Fluids to add immediately
+ * @return
+ * A new instance
+ */
+ public static MultiFluidHandler newInstance(int maxDistinctFluids, int capacityPerFluid, FluidStack...fluidsToAdd) {
+ return new MultiFluidHandler(maxDistinctFluids, capacityPerFluid, fluidsToAdd);
+ }
+
+ /**
+ * Deep copy a MultiFluidHandler instance with a new capacity
+ * @param toCopy
+ * The MultiFluidHandler that should be copied
+ * @param capacityPerFluid
+ * How much capacity each fluid should have
+ * @return
+ * A new instance
+ */
+ public static MultiFluidHandler newAdjustedInstance(MultiFluidHandler toCopy, int capacityPerFluid) {
+ return new MultiFluidHandler(toCopy.maxDistinctFluids, capacityPerFluid, toCopy.fluids);
}
/**
@@ -46,12 +73,14 @@ public class MultiFluidHandler {
/**
* Used to tell the MFH if a fluid is selected by
* an Integrated Circuit in the controller.
+ * If the Integrate Circuit configuration exceeds
+ * the number of stored fluid, the configuration will be ignored.
*
* @param fluidSelector
* Selected fluid or -1 if no fluid is selected
*/
public void setFluidSelector(byte fluidSelector) {
- this.fluidSelector = fluidSelector;
+ this.fluidSelector = fluidSelector < fluids.length ? fluidSelector : -1;
}
/**
@@ -62,59 +91,152 @@ public class MultiFluidHandler {
public byte getSelectedFluid() {
return fluidSelector;
}
-
- public boolean contains(FluidStack fluid) {
- return !locked && fluids.contains(fluid);
+
+ public FluidStack[] getAllFluids() {
+ return fluids;
}
+
+ public int getFluidPosistion(FluidStack aFluid) {
+
+ for (int i = 0; i < fluids.length; i++)
+ {
+ FluidStack tFluid = fluids[i];
+ if (tFluid != null && tFluid.isFluidEqual(aFluid))
+ return i;
+ }
+ return -1;
+ }
+
+ public boolean contains(FluidStack aFluid) {
+ if (locked)
+ return false;
+ return getFluidPosistion(aFluid)>=0;
+ }
+
+ public int countFluids()
+ {
+ int tCount = 0;
+ for (int i = 0; i < fluids.length; i++) {
+ if (fluids[i] != null)
+ tCount++;
+ }
+ return tCount;
+ }
+
public int getCapacity() {
return capacityPerFluid;
}
-
- public List<FluidStack> getFluids(){
- return (!locked) ? fluids : new ArrayList<>();
+ public int getMaxDistinctFluids() {
+ return maxDistinctFluids;
}
-
- public FluidStack getFluid(int slot) {
- return (!locked && fluids.size() > 0 && slot >= 0 && slot < MAX_DISTINCT_FLUIDS)
- ? fluids.get(slot) : null;
+
+ /**
+ * Returns a deep copy of the the FluidStack in the requested slot
+ * @param slot
+ * requested slot
+ * @return
+ * deep copy of the requested FluidStack
+ */
+ public FluidStack getFluidCopy(int slot) {
+ if (slot >= fluids.length)
+ return null;
+ if (!locked
+ && fluids.length > 0
+ && slot >= 0
+ && slot < maxDistinctFluids)
+ {
+ FluidStack tFluid = fluids[slot];
+ if (tFluid != null)
+ return tFluid.copy();
+ }
+ return null;
}
-
+
+ /**
+ * Returns the amount of different fluids currently stored.
+ * @return
+ * amount of different fluids currently stored (0-25)
+ */
+ public int getDistinctFluids() {
+ int distinctFluids = 0;
+ for (FluidStack f : fluids) {
+ if (f != null)
+ distinctFluids++;
+ }
+ return distinctFluids;
+ }
+
+ /**
+ * Helper method to save a MultiFluidHandler to NBT data
+ * @param nbt
+ * The NBT Tag to write to
+ * @return
+ * Updated NBT Tag
+ */
public NBTTagCompound saveNBTData(NBTTagCompound nbt) {
nbt = (nbt == null) ? new NBTTagCompound() : nbt;
nbt.setInteger("capacityPerFluid", getCapacity());
+ nbt.setInteger("maxDistinctFluids",this.maxDistinctFluids);
int c = 0;
for(FluidStack f : fluids) {
- nbt.setTag("" + c, f.writeToNBT(new NBTTagCompound()));
+ if (f == null)
+ {
+ c++;
+ continue;
+ }
+ nbt.setTag( String.valueOf(c), f.writeToNBT(new NBTTagCompound()));
c++;
}
return nbt;
}
-
- public void loadNBTData(NBTTagCompound nbt) {
+
+ /**
+ * Helper method to initialize a MultiFluidHandler from NBT data
+ * @param nbt
+ * The NBT Tag to read from
+ * @return
+ * A new Instance
+ */
+ static public MultiFluidHandler loadNBTData(NBTTagCompound nbt) {
nbt = (nbt == null) ? new NBTTagCompound() : nbt;
- capacityPerFluid = nbt.getInteger("capacityPerFluid");
-
- fluids.clear();
+ final int capacityPerFluid = nbt.getInteger("capacityPerFluid");
final NBTTagCompound fluidsTag = (NBTTagCompound) nbt.getTag("fluids");
- for(int i = 0; i < MultiFluidHandler.MAX_DISTINCT_FLUIDS; i++) {
- final NBTTagCompound fnbt = (NBTTagCompound) fluidsTag.getTag("" + i);
- if(fnbt == null) {
- break;
+ int distinctFluids = nbt.getInteger("maxDistinctFluids");
+ if (!nbt.hasKey("maxDistinctFluids"))
+ distinctFluids = 25;// adding it so it doesent break on upgrading
+ final FluidStack[] loadedFluids = new FluidStack[distinctFluids];
+
+ if (fluidsTag != null)
+ {
+ for (int i = 0; i < distinctFluids; i++) {
+ final NBTTagCompound fluidNBT = (NBTTagCompound) fluidsTag.getTag("" + i);
+ if(fluidNBT == null) {
+ loadedFluids[i] = null;
+ } else {
+ loadedFluids[i] = FluidStack.loadFluidStackFromNBT(fluidNBT);
+ }
}
- fluids.add(FluidStack.loadFluidStackFromNBT(fnbt));
}
+ return new MultiFluidHandler(distinctFluids, capacityPerFluid, loadedFluids);
}
public ArrayList<String> getInfoData() {
- final ArrayList<String> lines = new ArrayList<>(fluids.size());
+ final ArrayList<String> lines = new ArrayList<>(fluids.length);
lines.add(EnumChatFormatting.YELLOW + "Stored Fluids:" + EnumChatFormatting.RESET);
- for(int i = 0; i < fluids.size(); i++) {
- lines.add(i + " - " + fluids.get(i).getLocalizedName() + ": "
- + fluids.get(i).amount + "L ("
- + (Math.round(100.0f * fluids.get(i).amount / getCapacity())) + "%)");
+ for(int i = 0; i < fluids.length; i++) {
+ FluidStack tFluid = fluids[i];
+ if (tFluid == null) {
+ lines.add(i + " - " + "null" + ": "
+ + "0" + "L ("
+ + "0" + "%)");
+ } else {
+ lines.add(i + " - " + tFluid.getLocalizedName() + ": "
+ + tFluid.amount + "L ("
+ + (Math.round(100.0f * tFluid.amount / getCapacity())) + "%)");
+ }
}
return lines;
@@ -133,20 +255,28 @@ public class MultiFluidHandler {
if(locked) {
return 0;
}
- if(fluids.size() == MAX_DISTINCT_FLUIDS && !contains(push)) {
+ int empty = getNullSlot();
+ int fluidCount = countFluids();
+ if(fluidCount >= maxDistinctFluids && !contains(push)) {
// Already contains 25 fluids and this isn't one of them
return 0;
- } else if (fluids.size() < MAX_DISTINCT_FLUIDS && !contains(push)) {
+ } else if (empty < maxDistinctFluids && !contains(push)) {
// Add new fluid
final int fit = Math.min(getCapacity(), push.amount);
if(doPush) {
- fluids.add(new FluidStack(push.getFluid(), fit));
+ if (empty == -1)
+ return 0;
+ else
+ fluids[empty] = new FluidStack(push.getFluid(), fit);
}
// If doVoidExcess, pretend all of it fit
return doVoidExcess ? push.amount : fit;
} else {
- // Add to existing fluid
- final FluidStack existing = fluids.get(fluids.indexOf(push));
+ // Add to existing fluids
+ int index = getFluidPosistion(push);
+ if (index < 0)
+ return 0;
+ final FluidStack existing = fluids[index];
final int fit = Math.min(getCapacity() - existing.amount, push.amount);
if(doPush) {
existing.amount += fit;
@@ -155,6 +285,16 @@ public class MultiFluidHandler {
return doVoidExcess ? push.amount : fit;
}
}
+
+
+ public int getNullSlot()
+ {
+ for (int i = 0; i < fluids.length; i++) {
+ if (fluids[i] == null)
+ return i;
+ }
+ return -1;
+ }
/**
* Fill fluid into the specified tank.
@@ -171,19 +311,25 @@ public class MultiFluidHandler {
if(locked) {
return 0;
}
- if(slot < 0 || slot >= MAX_DISTINCT_FLUIDS) {
+ FluidStack tFluid = fluids[slot];
+ if(slot < 0 || slot >= maxDistinctFluids) {
// Invalid slot
return 0;
}
- if((fluids.get(slot) != null) && !fluids.get(slot).equals(push)) {
+ if((tFluid != null) && !tFluid.equals(push)) {
// Selected slot is taken by a non-matching fluid
return 0;
} else {
+ int fit = 0;
// Add to existing fluid
- final FluidStack existing = fluids.get(slot);
- final int fit = Math.min(getCapacity() - existing.amount, push.amount);
- if(doPush) {
- existing.amount += fit;
+ if (tFluid == null) {
+ fit = Math.min(getCapacity(),push.amount);
+ fluids[slot] = new FluidStack(push.getFluid(), fit);
+ } else {
+ fit = Math.min(getCapacity() - tFluid.amount, push.amount);
+ if(doPush) {
+ tFluid.amount += fit;
+ }
}
// If doVoidExcess, pretend all of it fit
return doVoidExcess ? push.amount : fit;
@@ -200,16 +346,19 @@ public class MultiFluidHandler {
* @return Amount of fluid that was (or would have been, if simulated) pulled.
*/
public int pullFluid(FluidStack pull, boolean doPull) {
- if (locked || !contains(pull)) {
+ if (locked) {
return 0;
} else {
- final FluidStack src = fluids.get(fluids.indexOf(pull));
+ int tIndex = getFluidPosistion(pull);
+ if (tIndex < 0)
+ return 0;
+ FluidStack src = fluids[tIndex];
final int rec = Math.min(pull.amount, src.amount);
if (doPull) {
src.amount -= rec;
}
if (src.amount == 0) {
- fluids.remove(src);
+ fluids[tIndex]= null;
}
return rec;
}
@@ -227,22 +376,22 @@ public class MultiFluidHandler {
* @return Amount of fluid that was (or would have been, if simulated) pulled.
*/
public int pullFluid(FluidStack pull, int slot, boolean doPull) {
- if(locked) {
+ if(locked || slot >= fluids.length) {
return 0;
}
- if(slot < 0 || slot >= MAX_DISTINCT_FLUIDS) {
+ if(slot < 0 || slot >= maxDistinctFluids) {
return 0;
}
- if(!fluids.get(slot).equals(pull)) {
+ FluidStack tFluid = fluids[slot];
+ if(tFluid == null || !tFluid.equals(pull)) {
return 0;
} else {
- final FluidStack src = fluids.get(slot);
- final int rec = Math.min(pull.amount, src.amount);
+ final int rec = Math.min(pull.amount, tFluid.amount);
if(doPull) {
- src.amount -= rec;
+ tFluid.amount -= rec;
}
- if(src.amount == 0) {
- fluids.remove(src);
+ if(tFluid.amount == 0) {
+ fluids[slot] = null;
}
return rec;
}
@@ -258,13 +407,15 @@ public class MultiFluidHandler {
if(locked) {
return false;
}
- if(fluids.size() == MAX_DISTINCT_FLUIDS && !contains(push)) {
+ int tFluidIndex = getFluidPosistion(push);
+ int fluidCount = countFluids();
+ if(fluidCount >= maxDistinctFluids && !contains(push)) {
return false;
- } else if (fluids.size() < MAX_DISTINCT_FLUIDS && !contains(push)) {
+ } else if (fluidCount < maxDistinctFluids && !contains(push)) {
return Math.min(getCapacity(), push.amount) > 0;
} else {
- final int remcap = getCapacity() - fluids.get(fluids.indexOf(push)).amount;
- return doVoidExcess ? true : (Math.min(remcap, push.amount) > 0);
+ final int remcap = getCapacity() - fluids[tFluidIndex].amount;
+ return doVoidExcess || (Math.min(remcap, push.amount) > 0);
}
}
}
diff --git a/src/main/java/kekztech/MultiItemHandler.java b/src/main/java/kekztech/MultiItemHandler.java
deleted file mode 100644
index 27d936efec..0000000000
--- a/src/main/java/kekztech/MultiItemHandler.java
+++ /dev/null
@@ -1,185 +0,0 @@
-package kekztech;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import net.minecraft.item.ItemStack;
-
-public class MultiItemHandler {
-
- private int perTypeCapacity = 0;
-
- private boolean locked = true;
-
- private ItemStack[] items;
-
- public MultiItemHandler() {
-
- }
-
- public List<String> debugPrint() {
- if(items == null) {
- return new ArrayList<String>();
- }
- final ArrayList<String> slots = new ArrayList<>();
-
- for(int i = 0; i < items.length; i++) {
- slots.add("Slot " + i + " contains " + items[i].stackSize + " " + items[i].getDisplayName());
- }
-
- return slots;
- }
-
- /**
- * 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
- */
- public void setItemTypeCapacity(int itemTypeCapacity) {
- System.out.println("Configuring type capacity");
- 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 {
- // 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;
- }
- }
-
- public void setPerTypeCapacity(int perTypeCapacity) {
- this.perTypeCapacity = perTypeCapacity;
- }
-
- /**
- * Lock internal storage in case Item Server is not running.
- *
- * @param state
- * Lock state.
- */
- public void setLock(boolean state) {
- locked = state;
- }
-
- public int getItemTypeCapacity() {
- return items != null ? items.length : 0;
- }
-
- 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.length) {
- return null;
- } else {
- 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.
- * @return
- * Operation success state.
- */
- public boolean insertStackInSlot(int slot, ItemStack itemStack) {
- System.out.println("Inserting " + itemStack.getDisplayName() + " into " + slot);
- if(itemStack == null
- || items[slot] != null
- || locked
- || slot >= items.length) {
- return false;
- } else {
- items[slot] = itemStack;
- return true;
- }
- }
-
- /**
- * 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.length
- || locked
- || amount <= 0) {
- return 0;
- } else {
- final int space = perTypeCapacity - items[slot].stackSize;
- final int fit = Math.min(space, amount);
- 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.length
- || locked
- || amount <= 0) {
- return 0;
- } else {
- final int available = items[slot].stackSize;
- final int take = Math.min(available, amount);
- items[slot].stackSize -= take;
- if(take == available) {
- items[slot] = null;
- }
- return take;
- }
- }
-
-
-}
diff --git a/src/main/java/kekztech/ServerProxy.java b/src/main/java/kekztech/ServerProxy.java
new file mode 100644
index 0000000000..0291cf687f
--- /dev/null
+++ b/src/main/java/kekztech/ServerProxy.java
@@ -0,0 +1,7 @@
+package kekztech;
+
+import common.CommonProxy;
+
+public class ServerProxy extends CommonProxy {
+
+}