diff --git a/src/main/java/com/hbm/blocks/machine/MachineChemfac.java b/src/main/java/com/hbm/blocks/machine/MachineChemfac.java index b533df783..4a06df07e 100644 --- a/src/main/java/com/hbm/blocks/machine/MachineChemfac.java +++ b/src/main/java/com/hbm/blocks/machine/MachineChemfac.java @@ -6,7 +6,6 @@ import com.hbm.tileentity.machine.TileEntityMachineChemfac; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; diff --git a/src/main/java/com/hbm/interfaces/IFluidAcceptor.java b/src/main/java/com/hbm/interfaces/IFluidAcceptor.java index dcb749c85..5195ac1b1 100644 --- a/src/main/java/com/hbm/interfaces/IFluidAcceptor.java +++ b/src/main/java/com/hbm/interfaces/IFluidAcceptor.java @@ -17,4 +17,8 @@ public interface IFluidAcceptor extends IFluidContainer { public default int getMaxFluidFillForReceive(FluidType type) { return this.getMaxFluidFill(type); } + + public default void receiveFluid(int amount, FluidType type) { + this.setFluidFill(this.getFluidFill(type) + amount, type); + } } diff --git a/src/main/java/com/hbm/inventory/gui/GUIChemfac.java b/src/main/java/com/hbm/inventory/gui/GUIChemfac.java index 51036d6b3..bed51516f 100644 --- a/src/main/java/com/hbm/inventory/gui/GUIChemfac.java +++ b/src/main/java/com/hbm/inventory/gui/GUIChemfac.java @@ -1,5 +1,6 @@ package com.hbm.inventory.gui; +import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import com.hbm.inventory.container.ContainerChemfac; @@ -27,18 +28,54 @@ public class GUIChemfac extends GuiInfoContainer { @Override public void drawScreen(int mouseX, int mouseY, float f) { super.drawScreen(mouseX, mouseY, f); + + this.drawElectricityInfo(this, mouseX, mouseY, guiLeft + 234, guiTop + 25, 16, 52, chemfac.power, chemfac.getMaxPower()); + + for(int i = 0; i < 8; i ++) { + + int offX = guiLeft + 110 * (i % 2); + int offY = guiTop + 38 * (i / 2); + chemfac.tanks[i * 4 + 0].renderTankInfo(this, mouseX, mouseY, offX + 40, offY + 45 - 32, 5, 34); + chemfac.tanks[i * 4 + 1].renderTankInfo(this, mouseX, mouseY, offX + 45, offY + 45 - 32, 5, 34); + chemfac.tanks[i * 4 + 2].renderTankInfo(this, mouseX, mouseY, offX + 102, offY + 45 - 32, 5, 34); + chemfac.tanks[i * 4 + 3].renderTankInfo(this, mouseX, mouseY, offX + 107, offY + 45 - 32, 5, 34); + } } @Override protected void drawGuiContainerForegroundLayer(int i, int j) { } @Override - protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { + protected void drawGuiContainerBackgroundLayer(float interp, int mX, int mY) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); Minecraft.getMinecraft().getTextureManager().bindTexture(texture); - drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, 211); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, 167); + drawTexturedModalRect(guiLeft + 26, guiTop + 167, 26, 167, 230, 44); drawTexturedModalRect(guiLeft + 26, guiTop + 211, 26, 211, 176, 45); + int p = (int) (chemfac.power * 52 / chemfac.getMaxPower()); + drawTexturedModalRect(guiLeft + 234, guiTop + 77 - p, 0, 219 - p, 16, p); + + if(chemfac.power > 0) + drawTexturedModalRect(guiLeft + 238, guiTop + 11, 0, 219, 9, 12); + + for(int i = 0; i < 8; i ++) { + + int offX = guiLeft + 110 * (i % 2); + int offY = guiTop + 38 * (i / 2); + + int prog = chemfac.progress[i]; + int j = prog * 17 / Math.max(chemfac.maxProgress[i], 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(texture); + drawTexturedModalRect(offX + 51, offY + 16, 202, 247, j, 11); + + chemfac.tanks[i * 4 + 0].renderTank(offX + 41, offY + 46, this.zLevel, 3, 32); + chemfac.tanks[i * 4 + 1].renderTank(offX + 46, offY + 46, this.zLevel, 3, 32); + chemfac.tanks[i * 4 + 2].renderTank(offX + 103, offY + 46, this.zLevel, 3, 32); + chemfac.tanks[i * 4 + 3].renderTank(offX + 108, offY + 46, this.zLevel, 3, 32); + } + + if(Keyboard.isKeyDown(Keyboard.KEY_LMENU)) for(int i = 0; i < this.inventorySlots.inventorySlots.size(); i++) { Slot s = this.inventorySlots.getSlot(i); diff --git a/src/main/java/com/hbm/lib/Library.java b/src/main/java/com/hbm/lib/Library.java index f9a3861bc..ecfb05daa 100644 --- a/src/main/java/com/hbm/lib/Library.java +++ b/src/main/java/com/hbm/lib/Library.java @@ -628,11 +628,13 @@ public class Library { if(consume.getMaxFluidFillForReceive(type) - consume.getFluidFillForReceive(type) >= part) { that.setFluidFill(that.getFluidFill(type) - part, type); - consume.setFluidFillForReceive(consume.getFluidFillForReceive(type) + part, type); + consume.receiveFluid(part, type); + //consume.setFluidFillForReceive(consume.getFluidFillForReceive(type) + part, type); } else { that.setFluidFill(that.getFluidFill(type) - (consume.getMaxFluidFillForReceive(type) - consume.getFluidFillForReceive(type)), type); - consume.setFluidFillForReceive(consume.getMaxFluidFillForReceive(type), type); + consume.receiveFluid(consume.getMaxFluidFillForReceive(type) - consume.getFluidFillForReceive(type), type); + //consume.setFluidFillForReceive(consume.getMaxFluidFillForReceive(type), type); } } } diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemfac.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemfac.java index c386e4b72..19f7d6f45 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemfac.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemfac.java @@ -2,12 +2,17 @@ package com.hbm.tileentity.machine; import java.util.ArrayList; import java.util.List; +import java.util.Random; +import com.hbm.blocks.BlockDummyable; import com.hbm.interfaces.IFluidAcceptor; import com.hbm.inventory.fluid.FluidType; +import com.hbm.main.MainRegistry; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChunkCoordinates; +import net.minecraftforge.common.util.ForgeDirection; public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase { @@ -15,9 +20,56 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase { super(77); } + @Override + public void updateEntity() { + super.updateEntity(); + + if(!worldObj.isRemote) { + + NBTTagCompound data = new NBTTagCompound(); + data.setLong("power", this.power); + data.setIntArray("progress", this.progress); + data.setIntArray("maxProgress", this.maxProgress); + data.setBoolean("isProgressing", isProgressing); + + for(int i = 0; i < tanks.length; i++) { + tanks[i].writeToNBT(data, "t" + i); + } + + this.networkPack(data, 150); + } else { + + if(this.worldObj.getTotalWorldTime() % 5 == 0) { + + ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite(); + ForgeDirection rot = dir.getRotation(ForgeDirection.UP); + Random rand = worldObj.rand; + + double x = xCoord + 0.5 - rot.offsetX * 0.5; + double y = yCoord + 3; + double z = zCoord + 0.5 - rot.offsetZ * 0.5; + + worldObj.spawnParticle("cloud", x + dir.offsetX * 1.5 + rand.nextGaussian() * 0.15, y, z + dir.offsetZ * 1.5 + rand.nextGaussian() * 0.15, 0.0, 0.15, 0.0); + worldObj.spawnParticle("cloud", x - dir.offsetX * 0.5 + rand.nextGaussian() * 0.15, y, z - dir.offsetZ * 0.5 + rand.nextGaussian() * 0.15, 0.0, 0.15, 0.0); + } + } + } + + @Override + public void networkUnpack(NBTTagCompound nbt) { + this.power = nbt.getLong("power"); + this.progress = nbt.getIntArray("progress"); + this.maxProgress = nbt.getIntArray("maxProgress"); + this.isProgressing = nbt.getBoolean("isProgressing"); + + for(int i = 0; i < tanks.length; i++) { + tanks[i].readFromNBT(nbt, "t" + i); + } + } + @Override public long getMaxPower() { - return 0; + return 10_000_000; } @Override diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplantBase.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplantBase.java index 3206ab001..38f54b8a4 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplantBase.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplantBase.java @@ -1,5 +1,8 @@ package com.hbm.tileentity.machine; +import java.util.ArrayList; +import java.util.List; + import com.hbm.interfaces.IFluidAcceptor; import com.hbm.interfaces.IFluidSource; import com.hbm.inventory.FluidTank; @@ -31,7 +34,7 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa public long power; public int[] progress; - public int maxProgress = 100; + public int[] maxProgress; public boolean isProgressing; public FluidTank[] tanks; @@ -43,8 +46,9 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa super(scount); int count = this.getRecipeCount(); - + progress = new int[count]; + maxProgress = new int[count]; tanks = new FluidTank[4 * count]; for(int i = 0; i < 4 * count; i++) { @@ -131,12 +135,12 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa private boolean hasRequiredItems(ChemRecipe recipe, int index) { int[] indices = getSlotIndicesFromIndex(index); - return InventoryUtil.doesArrayHaveIngredients(slots, indices[2], indices[3], recipe.inputs); + return InventoryUtil.doesArrayHaveIngredients(slots, indices[0], indices[1], recipe.inputs); } private boolean hasSpaceForItems(ChemRecipe recipe, int index) { int[] indices = getSlotIndicesFromIndex(index); - return InventoryUtil.doesArrayHaveSpace(slots, indices[0], indices[1], recipe.outputs); + return InventoryUtil.doesArrayHaveSpace(slots, indices[2], indices[3], recipe.outputs); } private void process(int index) { @@ -150,9 +154,9 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa int template = getTemplateIndex(index); ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[template].getItemDamage()); - this.maxProgress = recipe.getDuration() * this.speed / 100; + this.maxProgress[index] = recipe.getDuration() * this.speed / 100; - if(this.progress[index] >= this.maxProgress) { + if(this.progress[index] >= this.maxProgress[index]) { consumeFluids(recipe, index); produceFluids(recipe, index); consumeItems(recipe, index); @@ -178,7 +182,7 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa for(AStack in : recipe.inputs) { if(in != null) - InventoryUtil.tryConsumeAStack(slots, indices[2], indices[3], in); + InventoryUtil.tryConsumeAStack(slots, indices[0], indices[1], in); } } @@ -188,7 +192,7 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa for(ItemStack out : recipe.outputs) { if(out != null) - InventoryUtil.tryAddItemToInventory(slots, indices[0], indices[1], out.copy()); + InventoryUtil.tryAddItemToInventory(slots, indices[2], indices[3], out.copy()); } } private void loadItems(int index) { @@ -357,6 +361,62 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa return maxFill; } + @Override + public int getFluidFillForReceive(FluidType type) { + + int fill = 0; + + for(FluidTank tank : tanks) { + if(tank.index % 4 < 2 && tank.getTankType() == type) { + fill += tank.getFill(); + } + } + + return fill; + } + + @Override + public void receiveFluid(int amount, FluidType type) { + + List rec = new ArrayList(); + + for(FluidTank tank : tanks) { + if(tank.index % 4 < 2 && tank.getTankType() == type) { + rec.add(tank); + } + } + + if(rec.size() == 0) + return; + + int demand = 0; + + for(FluidTank tank : rec) { + demand += tank.getMaxFill() - tank.getFill(); + } + + int part = demand / rec.size(); // dividing ints rounds down anyway + + for(FluidTank tank : rec) { + tank.setFill(tank.getFill() + part); + demand -= part; + } + + //getting rid of annoying rounding errors + if(demand > 0) { + + while(demand > 0) { + + FluidTank tank = rec.get(worldObj.rand.nextInt(rec.size())); + if(tank.getFill() < tank.getMaxFill()) { + //we do single mB steps because the distribution is more even this way and honestly the remainder can't possibly be that big + tank.setFill(tank.getFill() + 1); + demand--; + } + } + } + } + public abstract int getRecipeCount(); public abstract int getTankCapacity(); public abstract int getTemplateIndex(int index); diff --git a/src/main/resources/assets/hbm/textures/gui/processing/gui_chemfac.png b/src/main/resources/assets/hbm/textures/gui/processing/gui_chemfac.png index 9f8823a19..4bbef79d5 100755 Binary files a/src/main/resources/assets/hbm/textures/gui/processing/gui_chemfac.png and b/src/main/resources/assets/hbm/textures/gui/processing/gui_chemfac.png differ diff --git a/src/main/resources/assets/hbm/textures/models/machines/chemfac.png b/src/main/resources/assets/hbm/textures/models/machines/chemfac.png index a8e3f5ba1..5686695b8 100644 Binary files a/src/main/resources/assets/hbm/textures/models/machines/chemfac.png and b/src/main/resources/assets/hbm/textures/models/machines/chemfac.png differ