From 65012d8427e621d52c27fc04a0b708a43be1e34d Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Sun, 3 Nov 2013 00:14:54 -0400 Subject: [PATCH] Fix up inventory insert calculation --- .../client/render/MekanismRenderer.java | 15 +++++++ .../render/tileentity/RenderEnergyCube.java | 14 ++----- common/mekanism/common/EnergyNetwork.java | 2 +- common/mekanism/common/util/CableUtils.java | 3 +- .../common/util/TransporterUtils.java | 42 ++++++++++--------- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/common/mekanism/client/render/MekanismRenderer.java b/common/mekanism/client/render/MekanismRenderer.java index 0aa291ae8..84ab1b381 100644 --- a/common/mekanism/client/render/MekanismRenderer.java +++ b/common/mekanism/client/render/MekanismRenderer.java @@ -200,6 +200,21 @@ public class MekanismRenderer GL11.glPopAttrib(); } + public static void blendOn() + { + GL11.glShadeModel(GL11.GL_SMOOTH); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + } + + public static void blendOff() + { + GL11.glShadeModel(GL11.GL_FLAT); + GL11.glDisable(GL11.GL_LINE_SMOOTH); + GL11.glDisable(GL11.GL_POLYGON_SMOOTH); + GL11.glDisable(GL11.GL_BLEND); + } + /** * Cleaned-up snip of ItemRenderer.renderItem() -- meant to render 2D items as equipped. * @param item - ItemStack to render diff --git a/common/mekanism/client/render/tileentity/RenderEnergyCube.java b/common/mekanism/client/render/tileentity/RenderEnergyCube.java index 67980646f..22b8e816e 100644 --- a/common/mekanism/client/render/tileentity/RenderEnergyCube.java +++ b/common/mekanism/client/render/tileentity/RenderEnergyCube.java @@ -26,7 +26,7 @@ public class RenderEnergyCube extends TileEntitySpecialRenderer @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick) { - renderAModelAt((TileEntityEnergyCube)tileEntity, x, y, z, 1F); + renderAModelAt((TileEntityEnergyCube)tileEntity, x, y, z, partialTick); } private void renderAModelAt(TileEntityEnergyCube tileEntity, double x, double y, double z, float partialTick) @@ -40,15 +40,11 @@ public class RenderEnergyCube extends TileEntitySpecialRenderer model.render(0.0625F); GL11.glPopMatrix(); - //Energy Core Render GL11.glPushMatrix(); GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5); bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "EnergyCore.png")); - GL11.glShadeModel(GL11.GL_SMOOTH); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - + MekanismRenderer.blendOn(); MekanismRenderer.glowOn(); EnumColor c = tileEntity.tier.color; @@ -63,11 +59,7 @@ public class RenderEnergyCube extends TileEntitySpecialRenderer GL11.glPopMatrix(); MekanismRenderer.glowOff(); - - GL11.glShadeModel(GL11.GL_FLAT); - GL11.glDisable(GL11.GL_LINE_SMOOTH); - GL11.glDisable(GL11.GL_POLYGON_SMOOTH); - GL11.glDisable(GL11.GL_BLEND); + MekanismRenderer.blendOff(); GL11.glPopMatrix(); } diff --git a/common/mekanism/common/EnergyNetwork.java b/common/mekanism/common/EnergyNetwork.java index 866b78efe..3213faf9c 100644 --- a/common/mekanism/common/EnergyNetwork.java +++ b/common/mekanism/common/EnergyNetwork.java @@ -345,6 +345,6 @@ public class EnergyNetwork extends DynamicNetwork @Override public String getFlow() { - return ElectricityDisplay.getDisplay((float)(getPower()*Mekanism.TO_UE), ElectricityDisplay.ElectricUnit.WATT); + return ElectricityDisplay.getDisplay((float)(getPower()*Mekanism.TO_UE), ElectricityDisplay.ElectricUnit.JOULES); } } diff --git a/common/mekanism/common/util/CableUtils.java b/common/mekanism/common/util/CableUtils.java index 874b6e4a4..025341dfb 100644 --- a/common/mekanism/common/util/CableUtils.java +++ b/common/mekanism/common/util/CableUtils.java @@ -271,7 +271,8 @@ public final class CableUtils { if(TransmissionType.checkTransmissionType(tileEntity, TransmissionType.ENERGY)) { - emitter.setEnergy(emitter.getEnergy() - (Math.min(emitter.getEnergy(), emitter.getMaxOutput()) - CableUtils.emitEnergyToNetwork(Math.min(emitter.getEnergy(), emitter.getMaxOutput()), emitter, emitter.getOutputtingSide()))); + double energyToSend = Math.min(emitter.getEnergy(), emitter.getMaxOutput()); + emitter.setEnergy(emitter.getEnergy() - (energyToSend - emitEnergyToNetwork(energyToSend, emitter, emitter.getOutputtingSide()))); return; } else if(tileEntity instanceof IStrictEnergyAcceptor) diff --git a/common/mekanism/common/util/TransporterUtils.java b/common/mekanism/common/util/TransporterUtils.java index 4c281aa25..10c7000da 100644 --- a/common/mekanism/common/util/TransporterUtils.java +++ b/common/mekanism/common/util/TransporterUtils.java @@ -229,40 +229,43 @@ public final class TransporterUtils public static ItemStack putStackInInventory(IInventory inventory, ItemStack itemStack, int side) { + ItemStack toInsert = itemStack.copy(); + if(!(inventory instanceof ISidedInventory)) { for(int i = 0; i <= inventory.getSizeInventory() - 1; i++) { - if(inventory.isItemValidForSlot(i, itemStack)) + if(inventory.isItemValidForSlot(i, toInsert)) { ItemStack inSlot = inventory.getStackInSlot(i); if(inSlot == null) { - inventory.setInventorySlotContents(i, itemStack); + inventory.setInventorySlotContents(i, toInsert); return null; } - else if(inSlot.isItemEqual(itemStack) && inSlot.stackSize < inSlot.getMaxStackSize()) + else if(inSlot.isItemEqual(toInsert) && inSlot.stackSize < inSlot.getMaxStackSize()) { - if(inSlot.stackSize + itemStack.stackSize <= inSlot.getMaxStackSize()) + if(inSlot.stackSize + toInsert.stackSize <= inSlot.getMaxStackSize()) { - ItemStack toSet = itemStack.copy(); + ItemStack toSet = toInsert.copy(); toSet.stackSize += inSlot.stackSize; inventory.setInventorySlotContents(i, toSet); return null; } else { - int rejects = (inSlot.stackSize + itemStack.stackSize) - inSlot.getMaxStackSize(); + int rejects = (inSlot.stackSize + toInsert.stackSize) - inSlot.getMaxStackSize(); - ItemStack toSet = itemStack.copy(); + ItemStack toSet = toInsert.copy(); toSet.stackSize = inSlot.getMaxStackSize(); - ItemStack remains = itemStack.copy(); + ItemStack remains = toInsert.copy(); remains.stackSize = rejects; inventory.setInventorySlotContents(i, toSet); - return remains; + + toInsert = remains; } } } @@ -278,36 +281,37 @@ public final class TransporterUtils { int slotID = slots[get]; - if(sidedInventory.isItemValidForSlot(slotID, itemStack) && sidedInventory.canInsertItem(slotID, itemStack, ForgeDirection.getOrientation(side).getOpposite().ordinal())) + if(sidedInventory.isItemValidForSlot(slotID, toInsert) && sidedInventory.canInsertItem(slotID, toInsert, ForgeDirection.getOrientation(side).getOpposite().ordinal())) { ItemStack inSlot = inventory.getStackInSlot(slotID); if(inSlot == null) { - inventory.setInventorySlotContents(slotID, itemStack); + inventory.setInventorySlotContents(slotID, toInsert); return null; } - else if(inSlot.isItemEqual(itemStack) && inSlot.stackSize < inSlot.getMaxStackSize()) + else if(inSlot.isItemEqual(toInsert) && inSlot.stackSize < inSlot.getMaxStackSize()) { - if(inSlot.stackSize + itemStack.stackSize <= inSlot.getMaxStackSize()) + if(inSlot.stackSize + toInsert.stackSize <= inSlot.getMaxStackSize()) { - ItemStack toSet = itemStack.copy(); + ItemStack toSet = toInsert.copy(); toSet.stackSize += inSlot.stackSize; inventory.setInventorySlotContents(slotID, toSet); return null; } else { - int rejects = (inSlot.stackSize + itemStack.stackSize) - inSlot.getMaxStackSize(); + int rejects = (inSlot.stackSize + toInsert.stackSize) - inSlot.getMaxStackSize(); - ItemStack toSet = itemStack.copy(); + ItemStack toSet = toInsert.copy(); toSet.stackSize = inSlot.getMaxStackSize(); - ItemStack remains = itemStack.copy(); + ItemStack remains = toInsert.copy(); remains.stackSize = rejects; inventory.setInventorySlotContents(slotID, toSet); - return remains; + + toInsert = remains; } } } @@ -315,7 +319,7 @@ public final class TransporterUtils } } - return itemStack; + return toInsert; } public static SlotInfo takeItem(IInventory inventory, int side)