diff options
Diffstat (limited to 'src/Java/miscutil')
22 files changed, 2028 insertions, 9 deletions
diff --git a/src/Java/miscutil/MiscUtils.java b/src/Java/miscutil/MiscUtils.java index 93e1800bc7..a70c8676df 100644 --- a/src/Java/miscutil/MiscUtils.java +++ b/src/Java/miscutil/MiscUtils.java @@ -6,7 +6,6 @@ import java.awt.event.ActionListener; import miscutil.core.commands.CommandMath; import miscutil.core.common.CommonProxy; import miscutil.core.creativetabs.AddToCreativeTab; -import miscutil.core.handler.CraftingManager; import miscutil.core.lib.LoadedMods; import miscutil.core.lib.Strings; import miscutil.core.util.Utils; @@ -40,7 +39,7 @@ implements ActionListener LoadedMods.checkLoaded(); Utils.LOG_INFO("Doing some house cleaning."); AddToCreativeTab.initialiseTabs(); - CraftingManager.mainRegistry(); + //CraftingManager.mainRegistry(); proxy.registerTileEntities(); proxy.registerRenderThings(); proxy.preInit(event); diff --git a/src/Java/miscutil/core/item/ModItems.java b/src/Java/miscutil/core/item/ModItems.java index 88671b5152..06fba3d35a 100644 --- a/src/Java/miscutil/core/item/ModItems.java +++ b/src/Java/miscutil/core/item/ModItems.java @@ -288,6 +288,12 @@ public final class ModItems { GameRegistry.registerItem(itemPlateBloodSteel, "itemPlateBloodSteel"); + //Try some New Tools from GT + //ItemStack x = null; + //GregTech_API.constructHardHammerItem("unlocalalizedName", "Full name", 500 /**Max Damage**/,500 /**Entity Damage**/); + //GregTech_API.registerHardHammer(x); + + } } diff --git a/src/Java/miscutil/core/lib/Strings.java b/src/Java/miscutil/core/lib/Strings.java index 032d169c46..0142101c76 100644 --- a/src/Java/miscutil/core/lib/Strings.java +++ b/src/Java/miscutil/core/lib/Strings.java @@ -8,7 +8,6 @@ public class Strings { public static final String MODID = "miscutils"; public static final String VERSION = "0.7.8gtu"; public static final boolean DEBUG = true; - public static boolean GREGTECH; public static final boolean LOAD_ALL_CONTENT = false; public static final int GREG_FIRST_ID = 760; @@ -21,4 +20,6 @@ public class Strings { ENERGYBUFFER, TOOLBUILDER, NULL, NULL1, NULL2 } + //public static final Materials2[] MiscGeneratedMaterials = new Materials2[1000]; + } diff --git a/src/Java/miscutil/enderio/conduit/MetaConduitBase.java b/src/Java/miscutil/enderio/conduit/MetaConduitBase.java new file mode 100644 index 0000000000..ea7c431ecb --- /dev/null +++ b/src/Java/miscutil/enderio/conduit/MetaConduitBase.java @@ -0,0 +1,245 @@ +package miscutil.enderio.conduit; + +import static gregtech.api.enums.GT_Values.V; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.items.GT_MetaBase_Item; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import ic2.api.item.IElectricItem; +import miscutil.core.handler.GuiHandler; +import miscutil.core.util.Utils; +import miscutil.gregtech.metatileentity.implementations.GregtechMetaTileEntity; +import miscutil.gregtech.util.IMessage; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +/** + * NEVER INCLUDE THIS FILE IN YOUR MOD!!! + * + * This is the main construct for my Basic Machines such as the Automatic Extractor + * Extend this class to make a simple Machine + */ +public class MetaConduitBase extends GregtechMetaTileEntity { + + /* + * public GregtechMetaEnergyBuffer() { super.this + * setCreativeTab(GregTech_API.TAB_GREGTECH); } + */ + + public int mAmpage = 1; + public boolean mCharge = false, mDecharge = false; + public int mBatteryCount = 1, mChargeableCount = 1; + + public MetaConduitBase(int aID, String aName, String aNameRegional, int aTier, String aDescription, int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public MetaConduitBase(String aName, int aTier, String aDescription, ITexture[][][] aTextures, int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] {mDescription, mInventory.length + " Slots"}; + } + + /* + * MACHINE_STEEL_SIDE + */ + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[2][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = new ITexture[] { new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_HEATPROOFCASING) }; + rTextures[1][i + 1] = new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_HEATPROOFCASING), + mInventory.length > 4 ? Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier] + : Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier] }; + } + return rTextures; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + return mTextures[aSide == aFacing ? 1 : 0][aColorIndex+1]; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new MetaConduitBase(mName, mTier, mDescription, mTextures, mInventory.length); + } + + @Override public boolean isSimpleMachine() {return false;} + @Override public boolean isElectric() {return true;} + @Override public boolean isValidSlot(int aIndex) {return true;} + @Override public boolean isFacingValid(byte aFacing) {return true;} + @Override public boolean isEnetInput() {return true;} + @Override public boolean isEnetOutput() {return true;} + @Override public boolean isInputFacing(byte aSide) {return aSide!=getBaseMetaTileEntity().getFrontFacing();} + @Override public boolean isOutputFacing(byte aSide) {return aSide==getBaseMetaTileEntity().getFrontFacing();} + @Override public boolean isTeleporterCompatible() {return false;} + @Override public long getMinimumStoredEU() {return V[mTier]*4*mInventory.length;} + @Override public long maxEUStore() {return V[mTier]*250;} + + @Override + public long maxEUInput() { + return V[mTier]; + } + + @Override + public long maxEUOutput() { + return V[mTier]; + } + + @Override + public long maxAmperesIn() { + return mChargeableCount * mAmpage; + } + + @Override + public long maxAmperesOut() { + return mChargeableCount * mAmpage; + } + @Override public int rechargerSlotStartIndex() {return 0;} + @Override public int dechargerSlotStartIndex() {return 0;} + @Override public int rechargerSlotCount() {return mCharge?mInventory.length:0;} + @Override public int dechargerSlotCount() {return mDecharge?mInventory.length:0;} + @Override public int getProgresstime() {return (int)getBaseMetaTileEntity().getUniversalEnergyStored();} + @Override public int maxProgresstime() {return (int)getBaseMetaTileEntity().getUniversalEnergyCapacity();} + @Override public boolean isAccessAllowed(EntityPlayer aPlayer) {return true;} + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + // + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + // + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + Utils.LOG_WARNING("Right Click on MTE by Player"); + if (aBaseMetaTileEntity.isClientSide()) return true; + //aBaseMetaTileEntity.openGUI(aPlayer); + + Utils.LOG_WARNING("MTE is Client-side"); + showEnergy(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + private void showEnergy(World worldIn, EntityPlayer playerIn){ + Utils.LOG_WARNING("Begin Show Energy"); + final double c = ((double) getProgresstime() / maxProgresstime()) * 100; + Utils.LOG_WARNING(""+c); + final double roundOff = Math.round(c * 100.0) / 100.0; + IMessage.messageThePlayer("Energy: " + getProgresstime() + " EU at "+V[mTier]+"v ("+roundOff+"%)"); + Utils.LOG_WARNING("Making new instance of Guihandler"); + GuiHandler block = new GuiHandler(); + Utils.LOG_WARNING("Guihandler.toString(): "+block.toString()); + block.getClientGuiElement(1, playerIn, worldIn, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ); + + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + mCharge = aBaseMetaTileEntity.getStoredEU() / 2 > aBaseMetaTileEntity + .getEUCapacity() / 3; + mDecharge = aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity() / 3; + mBatteryCount = 1; + mChargeableCount = 1; + for (ItemStack tStack : mInventory) if (GT_ModHandler.isElectricItem(tStack, mTier)) { + if (GT_ModHandler.isChargerItem(tStack)) mBatteryCount++; + mChargeableCount++; + } + } + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + if(GT_ModHandler.isElectricItem(aStack)&&aStack.getUnlocalizedName().startsWith("gt.metaitem.01.")){ + String name = aStack.getUnlocalizedName(); + if(name.equals("gt.metaitem.01.32510")|| + name.equals("gt.metaitem.01.32511")|| + name.equals("gt.metaitem.01.32520")|| + name.equals("gt.metaitem.01.32521")|| + name.equals("gt.metaitem.01.32530")|| + name.equals("gt.metaitem.01.32531")){ + return true; + } + } + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + if(!GT_Utility.isStackValid(aStack)){ + return false; + } + if(GT_ModHandler.isElectricItem(aStack, this.mTier)){ + return true; + } + return false; + } + + public long[] getStoredEnergy(){ + long tScale = getBaseMetaTileEntity().getEUCapacity(); + long tStored = getBaseMetaTileEntity().getStoredEU(); + if (mInventory != null) { + for (ItemStack aStack : mInventory) { + if (GT_ModHandler.isElectricItem(aStack)) { + + if (aStack.getItem() instanceof GT_MetaBase_Item) { + Long[] stats = ((GT_MetaBase_Item) aStack.getItem()) + .getElectricStats(aStack); + if (stats != null) { + tScale = tScale + stats[0]; + tStored = tStored + + ((GT_MetaBase_Item) aStack.getItem()) + .getRealCharge(aStack); + } + } else if (aStack.getItem() instanceof IElectricItem) { + tStored = tStored + + (long) ic2.api.item.ElectricItem.manager + .getCharge(aStack); + tScale = tScale + + (long) ((IElectricItem) aStack.getItem()) + .getMaxCharge(aStack); + } + } + } + + } + return new long[] { tStored, tScale }; + } + + private long count=0; + private long mStored=0; + private long mMax=0; + + @Override + public String[] getInfoData() { + count++; + if(mMax==0||count%20==0){ + long[] tmp = getStoredEnergy(); + mStored=tmp[0]; + mMax=tmp[1]; + } + + return new String[] { + getLocalName(), + "Internal Storage:", + GT_Utility.formatNumbers(mStored)+" EU /", + GT_Utility.formatNumbers(mMax)+" EU"}; + } +}
\ No newline at end of file diff --git a/src/Java/miscutil/enderio/conduit/ModConduits.java b/src/Java/miscutil/enderio/conduit/ModConduits.java new file mode 100644 index 0000000000..04cb120ec7 --- /dev/null +++ b/src/Java/miscutil/enderio/conduit/ModConduits.java @@ -0,0 +1,6 @@ +package miscutil.enderio.conduit; + + +public class ModConduits { + +} diff --git a/src/Java/miscutil/enderio/conduit/gas/AbstractGasConduit.java b/src/Java/miscutil/enderio/conduit/gas/AbstractGasConduit.java new file mode 100644 index 0000000000..ee7ba3d954 --- /dev/null +++ b/src/Java/miscutil/enderio/conduit/gas/AbstractGasConduit.java @@ -0,0 +1,208 @@ +package crazypants.enderio.conduit.gas; + +import com.enderio.core.common.util.BlockCoord; +import com.enderio.core.common.util.DyeColor; +import cpw.mods.fml.common.Optional.Method; +import crazypants.enderio.conduit.AbstractConduit; +import crazypants.enderio.conduit.ConduitUtil; +import crazypants.enderio.conduit.ConnectionMode; +import crazypants.enderio.conduit.IConduit; +import crazypants.enderio.conduit.IConduitBundle; +import crazypants.enderio.machine.RedstoneControlMode; +import crazypants.enderio.machine.reservoir.TileReservoir; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import mekanism.api.gas.IGasHandler; +import net.minecraft.block.Block; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public abstract class AbstractGasConduit + extends AbstractConduit + implements IGasConduit +{ + protected final EnumMap<ForgeDirection, RedstoneControlMode> extractionModes = new EnumMap(ForgeDirection.class); + protected final EnumMap<ForgeDirection, DyeColor> extractionColors = new EnumMap(ForgeDirection.class); + protected final Map<ForgeDirection, Integer> externalRedstoneSignals = new HashMap(); + protected boolean redstoneStateDirty = true; + + @Optional.Method(modid="MekanismAPI|gas") + public IGasHandler getExternalHandler(ForgeDirection direction) + { + IGasHandler con = GasUtil.getExternalGasHandler(getBundle().getWorld(), getLocation().getLocation(direction)); + return (con != null) && (!(con instanceof IConduitBundle)) ? con : null; + } + + @Optional.Method(modid="MekanismAPI|gas") + public IGasHandler getTankContainer(BlockCoord bc) + { + return GasUtil.getGasHandler(getBundle().getWorld(), bc); + } + + public boolean canConnectToExternal(ForgeDirection direction, boolean ignoreDisabled) + { + IGasHandler h = getExternalHandler(direction); + if (h == null) { + return false; + } + return true; + } + + public Class<? extends IConduit> getBaseConduitType() + { + return IGasConduit.class; + } + + public boolean onNeighborBlockChange(Block blockId) + { + this.redstoneStateDirty = true; + return super.onNeighborBlockChange(blockId); + } + + public void setExtractionRedstoneMode(RedstoneControlMode mode, ForgeDirection dir) + { + this.extractionModes.put(dir, mode); + this.redstoneStateDirty = true; + } + + public RedstoneControlMode getExtractionRedstoneMode(ForgeDirection dir) + { + RedstoneControlMode res = (RedstoneControlMode)this.extractionModes.get(dir); + if (res == null) { + res = RedstoneControlMode.ON; + } + return res; + } + + public void setExtractionSignalColor(ForgeDirection dir, DyeColor col) + { + this.extractionColors.put(dir, col); + } + + public DyeColor getExtractionSignalColor(ForgeDirection dir) + { + DyeColor result = (DyeColor)this.extractionColors.get(dir); + if (result == null) { + return DyeColor.RED; + } + return result; + } + + public boolean canOutputToDir(ForgeDirection dir) + { + if ((isExtractingFromDir(dir)) || (getConnectionMode(dir) == ConnectionMode.DISABLED)) { + return false; + } + if (this.conduitConnections.contains(dir)) { + return true; + } + if (!this.externalConnections.contains(dir)) { + return false; + } + IGasHandler ext = getExternalHandler(dir); + if ((ext instanceof TileReservoir)) + { + TileReservoir tr = (TileReservoir)ext; + return (!tr.isMultiblock()) || (!tr.isAutoEject()); + } + return true; + } + + protected boolean autoExtractForDir(ForgeDirection dir) + { + if (!isExtractingFromDir(dir)) { + return false; + } + RedstoneControlMode mode = getExtractionRedstoneMode(dir); + if (mode == RedstoneControlMode.IGNORE) { + return true; + } + if (mode == RedstoneControlMode.NEVER) { + return false; + } + if (this.redstoneStateDirty) + { + this.externalRedstoneSignals.clear(); + this.redstoneStateDirty = false; + } + DyeColor col = getExtractionSignalColor(dir); + int signal = ConduitUtil.getInternalSignalForColor(getBundle(), col); + if ((RedstoneControlMode.isConditionMet(mode, signal)) && (mode != RedstoneControlMode.OFF)) { + return true; + } + return isConditionMetByExternalSignal(dir, mode, col); + } + + private boolean isConditionMetByExternalSignal(ForgeDirection dir, RedstoneControlMode mode, DyeColor col) + { + int externalSignal = 0; + if (col == DyeColor.RED) + { + Integer val = (Integer)this.externalRedstoneSignals.get(dir); + if (val == null) + { + TileEntity te = getBundle().getEntity(); + externalSignal = te.getWorldObj().getStrongestIndirectPower(te.xCoord, te.yCoord, te.zCoord); + this.externalRedstoneSignals.put(dir, Integer.valueOf(externalSignal)); + } + else + { + externalSignal = val.intValue(); + } + } + return RedstoneControlMode.isConditionMet(mode, externalSignal); + } + + public boolean isExtractingFromDir(ForgeDirection dir) + { + return getConnectionMode(dir) == ConnectionMode.INPUT; + } + + public void writeToNBT(NBTTagCompound nbtRoot) + { + super.writeToNBT(nbtRoot); + for (Map.Entry<ForgeDirection, RedstoneControlMode> entry : this.extractionModes.entrySet()) { + if (entry.getValue() != null) + { + short ord = (short)((RedstoneControlMode)entry.getValue()).ordinal(); + nbtRoot.setShort("extRM." + ((ForgeDirection)entry.getKey()).name(), ord); + } + } + for (Map.Entry<ForgeDirection, DyeColor> entry : this.extractionColors.entrySet()) { + if (entry.getValue() != null) + { + short ord = (short)((DyeColor)entry.getValue()).ordinal(); + nbtRoot.setShort("extSC." + ((ForgeDirection)entry.getKey()).name(), ord); + } + } + } + + public void readFromNBT(NBTTagCompound nbtRoot, short nbtVersion) + { + super.readFromNBT(nbtRoot, nbtVersion); + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) + { + String key = "extRM." + dir.name(); + if (nbtRoot.hasKey(key)) + { + short ord = nbtRoot.getShort(key); + if ((ord >= 0) && (ord < RedstoneControlMode.values().length)) { + this.extractionModes.put(dir, RedstoneControlMode.values()[ord]); + } + } + key = "extSC." + dir.name(); + if (nbtRoot.hasKey(key)) + { + short ord = nbtRoot.getShort(key); + if ((ord >= 0) && (ord < DyeColor.values().length)) { + this.extractionColors.put(dir, DyeColor.values()[ord]); + } + } + } + } +} diff --git a/src/Java/miscutil/enderio/conduit/gas/AbstractGasTankConduit.java b/src/Java/miscutil/enderio/conduit/gas/AbstractGasTankConduit.java new file mode 100644 index 0000000000..7226ad8328 --- /dev/null +++ b/src/Java/miscutil/enderio/conduit/gas/AbstractGasTankConduit.java @@ -0,0 +1,176 @@ +package crazypants.enderio.conduit.gas; + +import com.enderio.core.common.util.BlockCoord; +import cpw.mods.fml.common.Optional.Method; +import crazypants.enderio.conduit.AbstractConduitNetwork; +import crazypants.enderio.conduit.ConduitUtil; +import crazypants.enderio.conduit.ConnectionMode; +import crazypants.enderio.conduit.IConduitBundle; +import crazypants.enderio.conduit.RaytraceResult; +import crazypants.enderio.conduit.geom.CollidableComponent; +import crazypants.enderio.tool.ToolUtil; +import java.util.List; +import mekanism.api.gas.GasStack; +import mekanism.api.gas.IGasHandler; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public abstract class AbstractGasTankConduit + extends AbstractGasConduit +{ + protected ConduitGasTank tank = new ConduitGasTank(0); + protected boolean stateDirty = false; + protected long lastEmptyTick = 0L; + protected int numEmptyEvents = 0; + + public boolean onBlockActivated(EntityPlayer player, RaytraceResult res, List<RaytraceResult> all) + { + if (player.getCurrentEquippedItem() == null) { + return false; + } + if (ToolUtil.isToolEquipped(player)) + { + if (!getBundle().getEntity().getWorldObj().isRemote) { + if ((res != null) && (res.component != null)) + { + ForgeDirection connDir = res.component.dir; + ForgeDirection faceHit = ForgeDirection.getOrientation(res.movingObjectPosition.sideHit); + if ((connDir == ForgeDirection.UNKNOWN) || (connDir == faceHit)) + { + if (getConnectionMode(faceHit) == ConnectionMode.DISABLED) + { + setConnectionMode(faceHit, getNextConnectionMode(faceHit)); + return true; + } + BlockCoord loc = getLocation().getLocation(faceHit); + IGasConduit n = (IGasConduit)ConduitUtil.getConduit(getBundle().getEntity().getWorldObj(), loc.x, loc.y, loc.z, IGasConduit.class); + if (n == null) { + return false; + } + if (!canJoinNeighbour(n)) { + return false; + } + if (!(n instanceof AbstractGasTankConduit)) { + return false; + } + AbstractGasTankConduit neighbour = (AbstractGasTankConduit)n; + if ((neighbour.getGasType() == null) || (getGasType() == null)) + { + GasStack type = getGasType(); + type = type != null ? type : neighbour.getGasType(); + neighbour.setGasTypeOnNetwork(neighbour, type); + setGasTypeOnNetwork(this, type); + } + return ConduitUtil.joinConduits(this, faceHit); + } + if (containsExternalConnection(connDir)) + { + setConnectionMode(connDir, getNextConnectionMode(connDir)); + } + else if (containsConduitConnection(connDir)) + { + GasStack curGasType = null; + if (getTankNetwork() != null) { + curGasType = getTankNetwork().getGasType(); + } + ConduitUtil.disconectConduits(this, connDir); + setGasType(curGasType); + } + } + } + return true; + } + return false; + } + + private void setGasTypeOnNetwork(AbstractGasTankConduit con, GasStack type) + { + AbstractConduitNetwork<?, ?> n = con.getNetwork(); + if (n != null) + { + AbstractGasTankConduitNetwork<?> network = (AbstractGasTankConduitNetwork)n; + network.setGasType(type); + } + } + + protected abstract boolean canJoinNeighbour(IGasConduit paramIGasConduit); + + public abstract AbstractGasTankConduitNetwork<? extends AbstractGasTankConduit> getTankNetwork(); + + @Optional.Method(modid="MekanismAPI|gas") + public void setGasType(GasStack gasType) + { + if ((this.tank.getGas() != null) && (this.tank.getGas().isGasEqual(gasType))) { + return; + } + if (gasType != null) { + gasType = gasType.copy(); + } else if (this.tank.getGas() == null) { + return; + } + this.tank.setGas(gasType); + this.stateDirty = true; + } + + public ConduitGasTank getTank() + { + return this.tank; + } + + @Optional.Method(modid="MekanismAPI|gas") + public GasStack getGasType() + { + GasStack result = null; + if (getTankNetwork() != null) { + result = getTankNetwork().getGasType(); + } + if (result == null) { + result = this.tank.getGas(); + } + return result; + } + + public boolean canOutputToDir(ForgeDirection dir) + { + if (super.canOutputToDir(dir)) + { + IGasHandler ext = getExternalHandler(dir); + return (ext != null) && (ext.canReceiveGas(dir.getOpposite(), this.tank.getGasType())); + } + return false; + } + + protected abstract void updateTank(); + + public void readFromNBT(NBTTagCompound nbtRoot, short nbtVersion) + { + super.readFromNBT(nbtRoot, nbtVersion); + updateTank(); + if (nbtRoot.hasKey("tank")) + { + GasStack gas = GasStack.readFromNBT(nbtRoot.getCompoundTag("tank")); + this.tank.setGas(gas); + } + else + { + this.tank.setGas(null); + } + } + + public void writeToNBT(NBTTagCompound nbtRoot) + { + super.writeToNBT(nbtRoot); + GasStack gt = getGasType(); + if (GasUtil.isGasValid(gt)) + { + updateTank(); + gt = gt.copy(); + gt.amount = this.tank.getStored(); + nbtRoot.setTag("tank", gt.write(new NBTTagCompound())); + } + } +} diff --git a/src/Java/miscutil/enderio/conduit/gas/AbstractGasTankConduitNetwork.java b/src/Java/miscutil/enderio/conduit/gas/AbstractGasTankConduitNetwork.java new file mode 100644 index 0000000000..75a4a3c1ad --- /dev/null +++ b/src/Java/miscutil/enderio/conduit/gas/AbstractGasTankConduitNetwork.java @@ -0,0 +1,68 @@ +package crazypants.enderio.conduit.gas; + +import crazypants.enderio.conduit.AbstractConduitNetwork; +import mekanism.api.gas.GasStack; + +public class AbstractGasTankConduitNetwork<T extends AbstractGasTankConduit> + extends AbstractConduitNetwork<IGasConduit, T> +{ + protected GasStack gasType; + + protected AbstractGasTankConduitNetwork(Class<T> cl) + { + super(cl, IGasConduit.class); + } + + public GasStack getGasType() + { + return this.gasType; + } + + public void addConduit(T con) + { + super.addConduit(con); + con.setGasType(this.gasType); + } + + public boolean setGasType(GasStack newType) + { + if ((this.gasType != null) && (this.gasType.isGasEqual(newType))) { + return false; + } + if (newType != null) + { + this.gasType = newType.copy(); + this.gasType.amount = 0; + } + else + { + this.gasType = null; + } + for (AbstractGasTankConduit conduit : this.conduits) { + conduit.setGasType(this.gasType); + } + return true; + } + + public boolean canAcceptGas(GasStack acceptable) + { + return areGassCompatable(this.gasType, acceptable); + } + + public static boolean areGassCompatable(GasStack a, GasStack b) + { + if ((a == null) || (b == null)) { + return true; + } + return a.isGasEqual(b); + } + + public int getTotalVolume() + { + int totalVolume = 0; + for (T con : this.conduits) { + totalVolume += con.getTank().getStored(); + } + return totalVolume; + } +} diff --git a/src/Java/miscutil/enderio/conduit/gas/ConduitGasTank.java b/src/Java/miscutil/enderio/conduit/gas/ConduitGasTank.java new file mode 100644 index 0000000000..08aef66656 --- /dev/null +++ b/src/Java/miscutil/enderio/conduit/gas/ConduitGasTank.java @@ -0,0 +1,164 @@ +package crazypants.enderio.conduit.gas; + +import cpw.mods.fml.common.Optional.Method; +import mekanism.api.gas.Gas; +import mekanism.api.gas.GasStack; +import mekanism.api.gas.GasTank; +import net.minecraft.nbt.NBTTagCompound; + +public class ConduitGasTank + extends GasTank +{ + private int capacity; + + ConduitGasTank(int capacity) + { + super(capacity); + this.capacity = capacity; + } + + public float getFilledRatio() + { + if (getStored() <= 0) { + return 0.0F; + } + if (getMaxGas() <= 0) { + return -1.0F; + } + float res = getStored() / getMaxGas(); + return res; + } + + public boolean isFull() + { + return getStored() >= getMaxGas(); + } + + public void setAmount(int amount) + { + if (this.stored != null) { + this.stored.amount = amount; + } + } + + public int getAvailableSpace() + { + return getMaxGas() - getStored(); + } + + public void addAmount(int amount) + { + setAmount(getStored() + amount); + } + + public int getMaxGas() + { + return this.capacity; + } + + public void setCapacity(int capacity) + { + this.capacity = capacity; + if (getStored() > capacity) { + setAmount(capacity); + } + } + + @Optional.Method(modid="MekanismAPI|gas") + public int receive(GasStack resource, boolean doReceive) + { + if ((resource == null) || (resource.getGas().getID() < 0)) { + return 0; + } + if ((this.stored == null) || (this.stored.getGas().getID() < 0)) + { + if (resource.amount <= this.capacity) + { + if (doReceive) { + setGas(resource.copy()); + } + return resource.amount; + } + if (doReceive) + { + this.stored = resource.copy(); + this.stored.amount = this.capacity; + } + return this.capacity; + } + if (!this.stored.isGasEqual(resource)) { + return 0; + } + int space = this.capacity - this.stored.amount; + if (resource.amount <= space) + { + if (doReceive) { + addAmount(resource.amount); + } + return resource.amount; + } + if |
