From 1835f6ff91c006eb07c5bfa3971dd9517438fbd7 Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Fri, 3 Jan 2014 14:26:41 -0500 Subject: [PATCH] Update TE, add module config syncing --- build.properties | 4 +- common/cofh/api/energy/EnergyStorage.java | 7 +++ common/cofh/api/energy/IEnergyHandler.java | 8 +-- common/cofh/api/transport/IItemConduit.java | 19 ++++-- .../api/transport/IItemConduitConnection.java | 15 ----- common/mekanism/common/CommonProxy.java | 2 +- common/mekanism/common/IModule.java | 17 ++++++ .../common/network/PacketConfigSync.java | 13 ++++ .../TileEntityLogisticalTransporter.java | 35 +++++++---- .../generators/common/MekanismGenerators.java | 60 ++++++++++++++----- .../mekanism/tools/common/MekanismTools.java | 9 +++ 11 files changed, 138 insertions(+), 51 deletions(-) delete mode 100644 common/cofh/api/transport/IItemConduitConnection.java diff --git a/build.properties b/build.properties index 89c55a18b..6078a8503 100644 --- a/build.properties +++ b/build.properties @@ -1,6 +1,6 @@ dir.development=./ dir.mcp=${dir.development}forge/mcp version.minecraft=1.6.4 -version.mod.major=5 -version.mod.minor=6 +version.mod.major=6 +version.mod.minor=0 version.mod.revis=0 diff --git a/common/cofh/api/energy/EnergyStorage.java b/common/cofh/api/energy/EnergyStorage.java index 3ba04c2e1..b3383aebe 100644 --- a/common/cofh/api/energy/EnergyStorage.java +++ b/common/cofh/api/energy/EnergyStorage.java @@ -35,11 +35,18 @@ public class EnergyStorage implements IEnergyStorage { public EnergyStorage readFromNBT(NBTTagCompound nbt) { this.energy = nbt.getInteger("Energy"); + + if (energy > capacity) { + energy = capacity; + } return this; } public NBTTagCompound writeToNBT(NBTTagCompound nbt) { + if (energy < 0) { + energy = 0; + } nbt.setInteger("Energy", energy); return nbt; } diff --git a/common/cofh/api/energy/IEnergyHandler.java b/common/cofh/api/energy/IEnergyHandler.java index 671716090..ec28941d3 100644 --- a/common/cofh/api/energy/IEnergyHandler.java +++ b/common/cofh/api/energy/IEnergyHandler.java @@ -18,7 +18,7 @@ public interface IEnergyHandler { * @param from * Orientation the energy is received from. * @param maxReceive - * Maximum amount of energy to received. + * Maximum amount of energy to receive. * @param simulate * If TRUE, the charge will only be simulated. * @return Amount of energy that was (or would have been, if simulated) received. @@ -29,17 +29,17 @@ public interface IEnergyHandler { * Remove energy from an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler. * * @param from - * Orientation the energy is extracted to. + * Orientation the energy is extracted from. * @param maxExtract * Maximum amount of energy to extract. * @param simulate - * If TRUE, the discharge will only be simulated. + * If TRUE, the extraction will only be simulated. * @return Amount of energy that was (or would have been, if simulated) extracted. */ int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate); /** - * Returns true if the Handler functions on a given side - if a Tile Entity can receive and/or send energy from a given side, this should return true. + * Returns true if the Handler functions on a given side - if a Tile Entity can receive or send energy on a given side, this should return true. */ boolean canInterface(ForgeDirection from); diff --git a/common/cofh/api/transport/IItemConduit.java b/common/cofh/api/transport/IItemConduit.java index 56714cc91..fc5ce9549 100644 --- a/common/cofh/api/transport/IItemConduit.java +++ b/common/cofh/api/transport/IItemConduit.java @@ -6,16 +6,27 @@ import net.minecraftforge.common.ForgeDirection; /** * This interface is implemented on Item Conduits. Use it to attempt to eject items into an entry point. * - * @author Zeldo Kavira + * @author Zeldo Kavira, King Lemming * */ public interface IItemConduit { /** - * Insert items into the conduit. Returns the ItemStack left (null if fully routed). Will only accept items if they have an valid destination. + * Insert an ItemStack into the IItemConduit. Will only accept items if there is a valid destination. This returns what is remaining of the original stack - + * a null return means that the entire stack was accepted/routed! * - * Pass the conduit the side *opposite* the one you are ejecting from! + * @param from + * Orientation the item is inserted from. + * @param item + * ItemStack to be inserted. The size of this stack corresponds to the maximum amount to insert. + * @return An ItemStack representing how much is remaining after the item was inserted (or would have been, if simulated) into the Conduit. */ - public ItemStack sendItems(ItemStack item, ForgeDirection from); + public ItemStack insertItem(ForgeDirection from, ItemStack item); + /* THE FOLLOWING WILL BE REMOVED IN 3.0.1.X */ + @Deprecated + public ItemStack insertItem(ForgeDirection from, ItemStack item, boolean simulate); + + @Deprecated + public ItemStack sendItems(ItemStack item, ForgeDirection from); } diff --git a/common/cofh/api/transport/IItemConduitConnection.java b/common/cofh/api/transport/IItemConduitConnection.java deleted file mode 100644 index e8cad7f58..000000000 --- a/common/cofh/api/transport/IItemConduitConnection.java +++ /dev/null @@ -1,15 +0,0 @@ -package cofh.api.transport; - -import net.minecraftforge.common.ForgeDirection; - -/** - * Implement this interface to explicitly control sided Item Conduit connections for a Tile Entity. - * - * @author Zeldo Kavira - * - */ -public interface IItemConduitConnection { - - public boolean canConduitConnect(ForgeDirection from); - -} diff --git a/common/mekanism/common/CommonProxy.java b/common/mekanism/common/CommonProxy.java index e10c23359..c4e8450d8 100644 --- a/common/mekanism/common/CommonProxy.java +++ b/common/mekanism/common/CommonProxy.java @@ -139,7 +139,7 @@ public class CommonProxy Mekanism.ENERGY_PER_REDSTONE = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "EnergyPerRedstone", 10000D).getDouble(10000D); Mekanism.VOICE_PORT = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "VoicePort", 36123).getInt(); //If this is less than 1, upgrades make machines worse. If less than 0, I don't even know. - Mekanism.maxUpgradeMultiplier = Math.max(1, Mekanism.configuration.get(Configuration.CATEGORY_GENERAL,"UpgradeModifier", 10).getInt()); + Mekanism.maxUpgradeMultiplier = Math.max(1, Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "UpgradeModifier", 10).getInt()); Mekanism.TO_TE = Mekanism.TO_BC*10; Mekanism.FROM_TE = Mekanism.FROM_BC/10; diff --git a/common/mekanism/common/IModule.java b/common/mekanism/common/IModule.java index 08919bd74..896d4f47f 100644 --- a/common/mekanism/common/IModule.java +++ b/common/mekanism/common/IModule.java @@ -1,5 +1,10 @@ package mekanism.common; +import java.io.DataOutputStream; +import java.io.IOException; + +import com.google.common.io.ByteArrayDataInput; + /** * Implement in your main class if your mod happens to be completely reliant on Mekanism, or in other words, is a Mekanism module. * @author aidancbrady @@ -19,4 +24,16 @@ public interface IModule * @return unique name of the module */ public String getName(); + + /** + * Writes this module's configuration to a ConfigSync packet. + * @param dataStream - the DataOutputStream of the sync packet + */ + public void writeConfig(DataOutputStream dataStream) throws IOException; + + /** + * Reads this module's configuration from the original ConfigSync packet. + * @param dataStream - the incoming ByteArrayDataInput of the sync packet + */ + public void readConfig(ByteArrayDataInput dataStream) throws IOException; } diff --git a/common/mekanism/common/network/PacketConfigSync.java b/common/mekanism/common/network/PacketConfigSync.java index 7286f9cb8..c86092b76 100644 --- a/common/mekanism/common/network/PacketConfigSync.java +++ b/common/mekanism/common/network/PacketConfigSync.java @@ -2,6 +2,7 @@ package mekanism.common.network; import java.io.DataOutputStream; +import mekanism.common.IModule; import mekanism.common.Mekanism; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; @@ -66,6 +67,12 @@ public class PacketConfigSync implements IMekanismPacket Mekanism.oxidationChamberUsage = dataStream.readDouble(); Mekanism.chemicalInfuserUsage = dataStream.readDouble(); Mekanism.chemicalInjectionChamberUsage = dataStream.readDouble(); + Mekanism.electrolyticSeparatorUsage = dataStream.readDouble(); + + for(IModule module : Mekanism.modulesLoaded) + { + module.readConfig(dataStream); + } Mekanism.proxy.onConfigSync(); } @@ -111,5 +118,11 @@ public class PacketConfigSync implements IMekanismPacket dataStream.writeDouble(Mekanism.oxidationChamberUsage); dataStream.writeDouble(Mekanism.chemicalInfuserUsage); dataStream.writeDouble(Mekanism.chemicalInjectionChamberUsage); + dataStream.writeDouble(Mekanism.electrolyticSeparatorUsage); + + for(IModule module : Mekanism.modulesLoaded) + { + module.writeConfig(dataStream); + } } } diff --git a/common/mekanism/common/tileentity/TileEntityLogisticalTransporter.java b/common/mekanism/common/tileentity/TileEntityLogisticalTransporter.java index 62e8754cc..d9a2619c2 100644 --- a/common/mekanism/common/tileentity/TileEntityLogisticalTransporter.java +++ b/common/mekanism/common/tileentity/TileEntityLogisticalTransporter.java @@ -4,8 +4,8 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.Set; -import mekanism.api.EnumColor; import mekanism.api.Coord4D; +import mekanism.api.EnumColor; import mekanism.common.HashList; import mekanism.common.IConfigurable; import mekanism.common.ILogisticalTransporter; @@ -34,13 +34,14 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipeTile; +import cofh.api.transport.IItemConduit; import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class TileEntityLogisticalTransporter extends TileEntity implements ITileNetwork, ILogisticalTransporter, IPipeTile, IConfigurable +public class TileEntityLogisticalTransporter extends TileEntity implements ITileNetwork, ILogisticalTransporter, IPipeTile, IConfigurable, IItemConduit { public static final int SPEED = 5; @@ -518,15 +519,9 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile @Override public int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - if(doAdd) - { - TileEntity tile = Coord4D.get(this).getFromSide(from).getTileEntity(worldObj); - - ItemStack rejects = TransporterUtils.insert(tile, this, stack, null, true, 0); - return TransporterManager.getToUse(stack, rejects).stackSize; - } - - return 0; + TileEntity tile = Coord4D.get(this).getFromSide(from).getTileEntity(worldObj); + ItemStack rejects = TransporterUtils.insert(tile, this, stack, null, doAdd, 0); + return TransporterManager.getToUse(stack, rejects).stackSize; } @Override @@ -608,4 +603,22 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile { return 1; } + + @Override + public ItemStack insertItem(ForgeDirection from, ItemStack item) + { + return TransporterUtils.insert(Coord4D.get(this).getFromSide(from).getTileEntity(worldObj), this, item, null, true, 0); + } + + @Override + public ItemStack insertItem(ForgeDirection from, ItemStack item, boolean simulate) + { + return insertItem(from, item); + } + + @Override + public ItemStack sendItems(ItemStack item, ForgeDirection from) + { + return sendItems(item, from); + } } diff --git a/common/mekanism/generators/common/MekanismGenerators.java b/common/mekanism/generators/common/MekanismGenerators.java index 47f15d878..f8faabe19 100644 --- a/common/mekanism/generators/common/MekanismGenerators.java +++ b/common/mekanism/generators/common/MekanismGenerators.java @@ -1,5 +1,29 @@ package mekanism.generators.common; +import java.io.DataOutputStream; +import java.io.IOException; + +import mekanism.api.infuse.InfuseObject; +import mekanism.api.infuse.InfuseRegistry; +import mekanism.api.infuse.InfuseType; +import mekanism.common.IModule; +import mekanism.common.Mekanism; +import mekanism.common.MekanismRecipe; +import mekanism.common.RecipeHandler; +import mekanism.common.Version; +import mekanism.common.item.ItemMekanism; +import mekanism.common.util.MekanismUtils; +import mekanism.common.util.MekanismUtils.ResourceType; +import mekanism.generators.common.block.BlockGenerator; +import mekanism.generators.common.item.ItemBlockGenerator; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraftforge.oredict.OreDictionary; + +import com.google.common.io.ByteArrayDataInput; + import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; @@ -10,20 +34,6 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; -import mekanism.api.infuse.InfuseObject; -import mekanism.api.infuse.InfuseRegistry; -import mekanism.api.infuse.InfuseType; -import mekanism.common.*; -import mekanism.common.item.ItemMekanism; -import mekanism.common.util.MekanismUtils; -import mekanism.common.util.MekanismUtils.ResourceType; -import mekanism.generators.common.block.BlockGenerator; -import mekanism.generators.common.item.ItemBlockGenerator; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; -import net.minecraftforge.oredict.OreDictionary; @Mod(modid = "MekanismGenerators", name = "MekanismGenerators", version = "6.0.0", dependencies = "required-after:Mekanism") @NetworkMod(clientSideRequired = true, serverSideRequired = false) @@ -174,4 +184,26 @@ public class MekanismGenerators implements IModule { return "Generators"; } + + @Override + public void writeConfig(DataOutputStream dataStream) throws IOException + { + dataStream.writeDouble(advancedSolarGeneration); + dataStream.writeDouble(bioGeneration); + dataStream.writeDouble(heatGeneration); + dataStream.writeDouble(hydrogenGeneration); + dataStream.writeDouble(solarGeneration); + dataStream.writeDouble(windGeneration); + } + + @Override + public void readConfig(ByteArrayDataInput dataStream) throws IOException + { + advancedSolarGeneration = dataStream.readDouble(); + bioGeneration = dataStream.readDouble(); + heatGeneration = dataStream.readDouble(); + hydrogenGeneration = dataStream.readDouble(); + solarGeneration = dataStream.readDouble(); + windGeneration = dataStream.readDouble(); + } } diff --git a/common/mekanism/tools/common/MekanismTools.java b/common/mekanism/tools/common/MekanismTools.java index ed29a6a5d..608a1fd4e 100644 --- a/common/mekanism/tools/common/MekanismTools.java +++ b/common/mekanism/tools/common/MekanismTools.java @@ -1,7 +1,10 @@ package mekanism.tools.common; +import java.io.DataOutputStream; import java.util.Random; +import com.google.common.io.ByteArrayDataInput; + import mekanism.common.IModule; import mekanism.common.Mekanism; import mekanism.common.MekanismRecipe; @@ -648,4 +651,10 @@ public class MekanismTools implements IModule { return "Tools"; } + + @Override + public void writeConfig(DataOutputStream dataStream) {} + + @Override + public void readConfig(ByteArrayDataInput dataStream) {} }