diff options
4 files changed, 205 insertions, 15 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/client/gui/BW_GUIContainer_HeatedWaterPump.java b/src/main/java/com/github/bartimaeusnek/bartworks/client/gui/BW_GUIContainer_HeatedWaterPump.java index b8cd2e9799..c252d5f935 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/client/gui/BW_GUIContainer_HeatedWaterPump.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/client/gui/BW_GUIContainer_HeatedWaterPump.java @@ -45,7 +45,7 @@ public class BW_GUIContainer_HeatedWaterPump extends GuiContainer { int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); - this.drawString(this.fontRendererObj, "Fuel:" + container.fuel + " Water:" + container.water, k, l, 0xffffff); +// this.drawString(this.fontRendererObj, "Fuel:" + container.fuel + " Water:" + container.water, k, l, 0xffffff); if (this.container.fuel > 0) { this.mc.getTextureManager().bindTexture(furnaceGuiTextures); diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/ItemRegistry.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/ItemRegistry.java index 09e4d6be98..5cf42736b6 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/ItemRegistry.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/ItemRegistry.java @@ -146,11 +146,11 @@ public class ItemRegistry { GameRegistry.registerItem(WINDMETER, "BW_SimpleWindMeter"); for (int i = 0; i < GT_Values.VN.length; i++) { - ItemRegistry.diode2A[i] = new GT_MetaTileEntity_Diode(ConfigHandler.IDOffset + GT_Values.VN.length + 1 + i, "Cable Diode 2A " + GT_Values.VN[i], "Cable Diode 2A " + GT_Values.VN[i], i, 2).getStackForm(1L); - ItemRegistry.diode4A[i] = new GT_MetaTileEntity_Diode(ConfigHandler.IDOffset + GT_Values.VN.length * 2 + 1 + i, "Cable Diode 4A " + GT_Values.VN[i], "Cable Diode 4A " + GT_Values.VN[i], i, 4).getStackForm(1L); - ItemRegistry.diode8A[i] = new GT_MetaTileEntity_Diode(ConfigHandler.IDOffset + GT_Values.VN.length * 3 + 1 + i, "Cable Diode 8A " + GT_Values.VN[i], "Cable Diode 8A " + GT_Values.VN[i], i, 8).getStackForm(1L); - ItemRegistry.diode12A[i] = new GT_MetaTileEntity_Diode(ConfigHandler.IDOffset + GT_Values.VN.length * 4 + 1 + i, "Cable Diode 12A " + GT_Values.VN[i], "Cable Diode 12A " + GT_Values.VN[i], i, 12).getStackForm(1L); - ItemRegistry.diode16A[i] = new GT_MetaTileEntity_Diode(ConfigHandler.IDOffset + GT_Values.VN.length * 5 + 1 + i, "Cable Diode 16A " + GT_Values.VN[i], "Cable Diode 16A " + GT_Values.VN[i], i, 16).getStackForm(1L); + ItemRegistry.diode2A[i] = new GT_MetaTileEntity_Diode(ConfigHandler.IDOffset + GT_Values.VN.length + 1 + i, "Cable Diode 2A " + GT_Values.VN[i], "Cable Diode 2A " + GT_Values.VN[i], i).getStackForm(1L); + ItemRegistry.diode4A[i] = new GT_MetaTileEntity_Diode(ConfigHandler.IDOffset + GT_Values.VN.length * 2 + 1 + i, "Cable Diode 4A " + GT_Values.VN[i], "Cable Diode 4A " + GT_Values.VN[i], i).getStackForm(1L); + ItemRegistry.diode8A[i] = new GT_MetaTileEntity_Diode(ConfigHandler.IDOffset + GT_Values.VN.length * 3 + 1 + i, "Cable Diode 8A " + GT_Values.VN[i], "Cable Diode 8A " + GT_Values.VN[i], i).getStackForm(1L); + ItemRegistry.diode12A[i] = new GT_MetaTileEntity_Diode(ConfigHandler.IDOffset + GT_Values.VN.length * 4 + 1 + i, "Cable Diode 12A " + GT_Values.VN[i], "Cable Diode 12A " + GT_Values.VN[i], i).getStackForm(1L); + ItemRegistry.diode16A[i] = new GT_MetaTileEntity_Diode(ConfigHandler.IDOffset + GT_Values.VN.length * 5 + 1 + i, "Cable Diode 16A " + GT_Values.VN[i], "Cable Diode 16A " + GT_Values.VN[i], i).getStackForm(1L); ItemRegistry.energyDistributor[i] = new GT_MetaTileEntity_EnergyDistributor(ConfigHandler.IDOffset + 1 + i, "Energy Distributor " + GT_Values.VN[i], "Energy Distributor " + GT_Values.VN[i], i, "Splits Amperage into several Sides").getStackForm(1L); } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/classic/BW_TileEntity_InfinityTank.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/classic/BW_TileEntity_InfinityTank.java new file mode 100644 index 0000000000..79ac59f5c1 --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/classic/BW_TileEntity_InfinityTank.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2019 bartimaeusnek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.bartimaeusnek.bartworks.common.tileentities.classic; + +import com.github.bartimaeusnek.bartworks.API.ITileWithGUI; +import gregtech.api.util.GT_Utility; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.*; + +import java.util.ArrayList; +import java.util.HashSet; + +public class BW_TileEntity_InfinityTank extends TileEntity implements IFluidTank, IFluidHandler, ITileWithGUI { + + final ArrayList<FluidStack> INTERNALTANKS =new ArrayList<FluidStack>(); + + int selectedTank; + + @Override + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { + return fill(resource, doFill); + } + + @Override + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { + return drain(from,resource != null ? resource.amount : 0,doDrain); + } + + @Override + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { + return drain(maxDrain,doDrain); + } + + @Override + public boolean canFill(ForgeDirection from, Fluid fluid) { + return true; + } + + @Override + public boolean canDrain(ForgeDirection from, Fluid fluid) { + HashSet<Boolean> ret = new HashSet<Boolean>(); + for (FluidStack stack : INTERNALTANKS) { + ret.add(GT_Utility.areFluidsEqual(stack, new FluidStack(fluid, 0))); + if (ret.contains(Boolean.TRUE)) + selectedTank = this.INTERNALTANKS.indexOf(stack); + } + return ret.contains(Boolean.TRUE); + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection from) { + return new FluidTankInfo[0]; + } + + @Override + public FluidStack getFluid() { + if (INTERNALTANKS.get(selectedTank) == null || INTERNALTANKS.get(selectedTank).amount == 0) + if (selectedTank>0) + selectedTank = this.INTERNALTANKS.size()-1; + return INTERNALTANKS.get(selectedTank); + } + + @Override + public int getFluidAmount() { + return INTERNALTANKS.get(selectedTank) != null ? INTERNALTANKS.get(selectedTank).amount : 0; + } + + @Override + public void writeToNBT(NBTTagCompound p_145841_1_) { + super.writeToNBT(p_145841_1_); + + NBTTagList lInternalTank = new NBTTagList(); + + for (int i = 0; i < INTERNALTANKS.size(); i++) { + if (INTERNALTANKS.get(i) != null) { + NBTTagCompound entry = new NBTTagCompound(); + entry.setString("FluidName", INTERNALTANKS.get(i).getFluid().getName()); + entry.setInteger("Ammount", INTERNALTANKS.get(i).amount); + entry.setTag("FluidTag", INTERNALTANKS.get(i).tag); + lInternalTank.appendTag(entry); + } + } + p_145841_1_.setTag("InternalTank",lInternalTank); + } + + + + @Override + public int getCapacity() { + return Integer.MAX_VALUE; + } + + @Override + public FluidTankInfo getInfo() { + return null; + } + + @Override + public int fill(FluidStack resource, boolean doFill) { + if (worldObj.isRemote || resource == null || resource.amount == 0) + return 0; + + if (!doFill) + return resource.amount; + + int id = 0; + + if (canDrain(null,resource.getFluid())) { + for (FluidStack stack : INTERNALTANKS) + if (GT_Utility.areFluidsEqual(stack, resource)) { + this.INTERNALTANKS.get(id = this.INTERNALTANKS.indexOf(stack)).amount += resource.amount; + selectedTank = id; + } + } else { + this.INTERNALTANKS.add(resource); + id = this.INTERNALTANKS.size()-1; + selectedTank = id; + } + return this.INTERNALTANKS.get(id).amount; + } + + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + + FluidStack outputstack = INTERNALTANKS.get(selectedTank); + if (worldObj.isRemote || maxDrain == 0 || this.getFluid() == null || outputstack == null) + return null; + + int actualdrain = maxDrain; + if (actualdrain > outputstack.amount) + actualdrain = outputstack.amount; + FluidStack ret = new FluidStack(outputstack.getFluid(), actualdrain); + if (ret.amount == 0) + ret = null; + if (doDrain) { + outputstack.amount -= actualdrain; + FluidEvent.fireEvent(new FluidEvent.FluidDrainingEvent(outputstack, this.getWorldObj(), this.xCoord, this.yCoord, this.zCoord, this, actualdrain)); + } + return ret; + } + + @Override + public int getGUIID() { + return 4; + } +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/tiered/GT_MetaTileEntity_Diode.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/tiered/GT_MetaTileEntity_Diode.java index 3c4e1c73a7..c0c99dab7a 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/tiered/GT_MetaTileEntity_Diode.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/tiered/GT_MetaTileEntity_Diode.java @@ -22,6 +22,7 @@ package com.github.bartimaeusnek.bartworks.common.tileentities.tiered; +import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; import com.github.bartimaeusnek.bartworks.util.ChatColorHelper; import gregtech.api.enums.GT_Values; import gregtech.api.interfaces.ITexture; @@ -34,19 +35,24 @@ import net.minecraft.nbt.NBTTagCompound; public class GT_MetaTileEntity_Diode extends GT_MetaTileEntity_BasicHull { - private long maxAmps; - private long aAmps; + private long maxAmps = 0L; + private long aAmps = 0L; - public GT_MetaTileEntity_Diode(int aID, String aName, String aNameRegional, int aTier, int maxAmps) { + public GT_MetaTileEntity_Diode(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, "A Simple diode that will allow Energy Flow in only one direction."); - this.maxAmps = maxAmps; - aAmps = maxAmps; } - public GT_MetaTileEntity_Diode(String aName, int aTier, long maxAmps, String[] aDescription, ITexture[][][] aTextures) { + public GT_MetaTileEntity_Diode(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { super(aName, aTier, 0, aDescription, aTextures); - this.maxAmps = maxAmps; - aAmps = maxAmps; + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + if (maxAmps == 0 && !this.getBaseMetaTileEntity().getWorld().isRemote) { + maxAmps = getAmpsfromMeta(this.getBaseMetaTileEntity().getMetaTileID()); + aAmps=maxAmps; + } } @Override @@ -88,7 +94,22 @@ public class GT_MetaTileEntity_Diode extends GT_MetaTileEntity_BasicHull { @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Diode(this.mName, this.mTier, this.maxAmps, this.mDescriptionArray, this.mTextures); + return new GT_MetaTileEntity_Diode(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + private long getAmpsfromMeta(int meta){ + if (meta > ConfigHandler.IDOffset + GT_Values.VN.length && meta <= ConfigHandler.IDOffset + GT_Values.VN.length*2) + return 2L; + else if (meta > ConfigHandler.IDOffset + GT_Values.VN.length*2 && meta <= ConfigHandler.IDOffset + GT_Values.VN.length*3) + return 4L; + else if (meta > ConfigHandler.IDOffset + GT_Values.VN.length*3 && meta <= ConfigHandler.IDOffset + GT_Values.VN.length*4) + return 8L; + else if (meta > ConfigHandler.IDOffset + GT_Values.VN.length*4 && meta <= ConfigHandler.IDOffset + GT_Values.VN.length*5) + return 12L; + else if (meta > ConfigHandler.IDOffset + GT_Values.VN.length*5 && meta <= ConfigHandler.IDOffset + GT_Values.VN.length*6) + return 16L; + else + return 0L; } @SuppressWarnings("deprecation") |