Skip to content

Commit

Permalink
Fixed extra unit obtained from pouring liquid unshaped metal into a c…
Browse files Browse the repository at this point in the history
…rucible or into another mold.
  • Loading branch information
Kittychanley committed Jan 1, 2016
1 parent 9162073 commit 9154e5a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 47 deletions.
85 changes: 47 additions & 38 deletions src/Common/com/bioxx/tfc/Containers/ContainerMold.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.*;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

Expand Down Expand Up @@ -92,71 +93,79 @@ public void detectAndSendChanges()
{
PlayerInfo pi = PlayerManagerTFC.getInstance().getPlayerInfoFromPlayer(player);
short oldTransferTimer = pi.moldTransferTimer;
ItemStack sourceStack = containerInv.getStackInSlot(0);
ItemStack inputStack = containerInv.getStackInSlot(1);

if(containerInv.getStackInSlot(0) != null && containerInv.getStackInSlot(1) != null)
if (sourceStack != null && inputStack != null)
{
if(containerInv.getStackInSlot(0).getItem() instanceof ItemMeltedMetal &&
containerInv.getStackInSlot(1).getItem() == TFCItems.ceramicMold &&
containerInv.getStackInSlot(1).getItemDamage() == 1 &&
TFC_ItemHeat.getIsLiquid(containerInv.getStackInSlot(0)))
Item sourceItem = sourceStack.getItem();
Item inputItem = inputStack.getItem();
int inputDamage = inputStack.getItemDamage();

if (sourceItem instanceof ItemMeltedMetal && inputItem == TFCItems.ceramicMold && inputDamage == 1 && TFC_ItemHeat.getIsLiquid(sourceStack))
{
ItemStack is = containerInv.getStackInSlot(0).copy();
ItemStack is = sourceStack.copy();
is.setItemDamage(100);
containerInv.setInventorySlotContents(1,is);
containerInv.setInventorySlotContents(1, is);
pi.moldTransferTimer = 100;
}
else if(containerInv.getStackInSlot(0).getItem() instanceof ItemMeltedMetal &&
containerInv.getStackInSlot(1).getItem() instanceof ItemMeltedMetal &&
containerInv.getStackInSlot(0).getItem() == containerInv.getStackInSlot(1).getItem() &&
containerInv.getStackInSlot(1).getItemDamage() != 0)
else if (sourceItem instanceof ItemMeltedMetal && inputItem instanceof ItemMeltedMetal && sourceItem == inputItem && inputDamage != 0)
{
pi.moldTransferTimer = 100;
}
}

if(containerInv.getStackInSlot(1) != null && pi.moldTransferTimer < 100 &&
if (inputStack != null && pi.moldTransferTimer < 100 &&
CraftingManagerTFC.getInstance().findMatchingRecipe(this.containerInv, world) != null)
{
pi.moldTransferTimer++;
}

if(containerInv.getStackInSlot(0) != null && containerInv.getStackInSlot(1) != null && pi.moldTransferTimer == 1000)
if (sourceStack != null && inputStack != null && pi.moldTransferTimer == 1000)
{
pi.moldTransferTimer = 0;
}

if(containerInv.getStackInSlot(0) == null || containerInv.getStackInSlot(1) == null)
if (sourceStack == null || inputStack == null)
{
pi.moldTransferTimer = 1000;
}

if(containerInv.getStackInSlot(0) != null && containerInv.getStackInSlot(1) != null && pi.moldTransferTimer == 100 &&
containerInv.getStackInSlot(0).getItem() instanceof ItemMeltedMetal &&
containerInv.getStackInSlot(1).getItem() instanceof ItemMeltedMetal)
if (sourceStack != null && inputStack != null && pi.moldTransferTimer == 100)
{
if(containerInv.getStackInSlot(0).getItem() == containerInv.getStackInSlot(1).getItem() && containerInv.getStackInSlot(1).getItemDamage() != 0)
{
int s0 = containerInv.getStackInSlot(0).getItemDamage();
int s1 = containerInv.getStackInSlot(1).getItemDamage();
Item sourceItem = sourceStack.getItem();
Item inputItem = inputStack.getItem();
int newSourceDamage = sourceStack.getItemDamage() + 1;
int inputDamage = inputStack.getItemDamage();
ItemStack recipeOutput = CraftingManagerTFC.getInstance().findMatchingRecipe(this.containerInv, world);

containerInv.getStackInSlot(0).setItemDamage(s0+1);
containerInv.getStackInSlot(1).setItemDamage(s1-1);
if(containerInv.getStackInSlot(0).getItemDamage() == containerInv.getStackInSlot(0).getMaxDamage())
containerInv.setInventorySlotContents(0, new ItemStack(TFCItems.ceramicMold, 1, 1));
if (sourceItem instanceof ItemMeltedMetal && inputItem instanceof ItemMeltedMetal)
{
if (sourceItem == inputItem && inputDamage != 0)
{
sourceStack.setItemDamage(newSourceDamage);
inputStack.setItemDamage(inputDamage - 1);
if (newSourceDamage >= sourceStack.getMaxDamage() - 1) // Subtract one so we never have an unshaped metal with 0/100 units
{
containerInv.setInventorySlotContents(0, new ItemStack(TFCItems.ceramicMold, 1, 1));
}
}
}
else if (recipeOutput != null)
{
recipeOutput.setTagCompound(inputStack.stackTagCompound);
craftResult.setInventorySlotContents(0, recipeOutput);
containerInv.setInventorySlotContents(1, null);
containerInv.setInventorySlotContents(1, new ItemStack(TFCItems.ceramicMold, 1, 1));
containerInv.setInventorySlotContents(0, null);
}
}
else if(containerInv.getStackInSlot(0) != null && containerInv.getStackInSlot(1) != null && pi.moldTransferTimer == 100 &&
CraftingManagerTFC.getInstance().findMatchingRecipe(this.containerInv, world) != null)
{
ItemStack is = CraftingManagerTFC.getInstance().findMatchingRecipe(this.containerInv, world);
is.setTagCompound(containerInv.getStackInSlot(1).stackTagCompound);
craftResult.setInventorySlotContents(0, is);
containerInv.setInventorySlotContents(1, null);
containerInv.setInventorySlotContents(1, new ItemStack(TFCItems.ceramicMold, 1, 1));
containerInv.setInventorySlotContents(0, null);
}

for (int var1 = 0; var1 < this.crafters.size(); ++var1)
for (int i = 0; i < this.crafters.size(); ++i)
{
ICrafting var2 = (ICrafting)this.crafters.get(var1);
ICrafting player = (ICrafting)this.crafters.get(i);
if (pi.moldTransferTimer != oldTransferTimer)
var2.sendProgressBarUpdate(this, 0, pi.moldTransferTimer);
player.sendProgressBarUpdate(this, 0, pi.moldTransferTimer);
}
}
}
Expand Down
31 changes: 22 additions & 9 deletions src/Common/com/bioxx/tfc/TileEntities/TECrucible.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,38 @@ else if (te.fireTemp > temperature)
if(stackToSmelt != null)
{
Item itemToSmelt = stackToSmelt.getItem();
int newDamage = stackToSmelt.getItemDamage() + 1;
int maxDamage = stackToSmelt.getMaxDamage() - 1; // Subtract one so we never have an unshaped metal with 0/100 units

if(itemToSmelt instanceof ItemMeltedMetal && TFC_ItemHeat.getIsLiquid(storage[0]))
{
if(inputTick > 10)
{
if(currentAlloy != null && currentAlloy.outputType != null && itemToSmelt == currentAlloy.outputType.meltedItem)
Metal inputMetal = MetalRegistry.instance.getMetalFromItem(itemToSmelt);

if (currentAlloy != null && currentAlloy.outputType != null && itemToSmelt == currentAlloy.outputType.meltedItem)
{
this.addMetal(MetalRegistry.instance.getMetalFromItem(itemToSmelt), (short) 1);
if(stackToSmelt.getItemDamage()+1 >= storage[0].getMaxDamage())
storage[0] = new ItemStack(TFCItems.ceramicMold,1,1);
this.addMetal(inputMetal, (short) 1);
if (newDamage >= maxDamage)
{
storage[0] = new ItemStack(TFCItems.ceramicMold, 1, 1);
}
else
stackToSmelt.setItemDamage(stackToSmelt.getItemDamage() + 1);
{
stackToSmelt.setItemDamage(newDamage);
}
}
else
{
this.addMetal(MetalRegistry.instance.getMetalFromItem(itemToSmelt), (short) 1);
if(stackToSmelt.getItemDamage()+1 >= stackToSmelt.getMaxDamage())
storage[0] = new ItemStack(TFCItems.ceramicMold,1,1);
this.addMetal(inputMetal, (short) 1);
if (newDamage >= maxDamage)
{
storage[0] = new ItemStack(TFCItems.ceramicMold, 1, 1);
}
else
stackToSmelt.setItemDamage(stackToSmelt.getItemDamage() + 1);
{
stackToSmelt.setItemDamage(newDamage);
}
}
inputTick = 0;
updateGui((byte) 0);
Expand Down

0 comments on commit 9154e5a

Please sign in to comment.