Skip to content

Instantly share code, notes, and snippets.

@marchermans
Last active August 29, 2015 14:19
Show Gist options
  • Save marchermans/6edaea2cb7829f7bae4f to your computer and use it in GitHub Desktop.
Save marchermans/6edaea2cb7829f7bae4f to your computer and use it in GitHub Desktop.
FirePit update routine
public void updateEntity()
{
if (worldObj.isRemote)
{
return;
}
iIsBurning = false;
if (heatFurnace() > 0F)
{
iIsBurning = true;
}
heatIngots();
markDirty();
}
public float heatFurnace() {
float tTotalAddedHeat;
iLastAddedHeat = 0F;
for (int tFuelStackIndex = 0; tFuelStackIndex < FUELSTACK_AMOUNT; tFuelStackIndex++) {
if (iFuelStackBurningTime[tFuelStackIndex] == null)
{
iFuelStackBurningTime[tFuelStackIndex] = -1;
}
if (iFuelStackBurningTime[tFuelStackIndex] == -1)
{
if (iFuelStacks[tFuelStackIndex] == null)
{
continue;
}
ItemStack tTargetedFuelStack = iFuelStacks[tFuelStackIndex];
//Check if the stack is a valid Fuel in the Furnace
if ((tTargetedFuelStack != null) && (TileEntityFurnace.isItemFuel(tTargetedFuelStack))) {
//Update the Fuelstack if a new piece of fuel is needed.
if (iFuelStackBurningTime[tFuelStackIndex] == -1) {
--tTargetedFuelStack.stackSize;
iFuelStackBurningTime[tFuelStackIndex] = 0;
iFuelStackFuelAmount[tFuelStackIndex] = TileEntityFurnace.getItemBurnTime(tTargetedFuelStack);
if (tTargetedFuelStack.stackSize == 0) {
iFuelStacks[tFuelStackIndex] = tTargetedFuelStack.getItem().getContainerItem(tTargetedFuelStack);
}
}
}
}
if (iFuelStackBurningTime[tFuelStackIndex] > -1)
{
++iFuelStackBurningTime[tFuelStackIndex];
if (tFuelStackIndex == 3)
{
System.out.println(iFuelStackBurningTime[tFuelStackIndex]);
}
//Process depleted fuelstack
if (iFuelStackBurningTime[tFuelStackIndex].intValue() == iFuelStackFuelAmount[tFuelStackIndex].intValue()) {
iFuelStackBurningTime[tFuelStackIndex] = -1;
}
iLastAddedHeat += iPositiveHeatCoefficient;
}
}
tTotalAddedHeat = iLastAddedHeat;
return tTotalAddedHeat;
}
public float heatIngots()
{
if (iLastAddedHeat <= 0F) {return 0F;}
float tAddableHeatPerItem = iLastAddedHeat / (getHeatableIngotAmount() + 1);
iCurrentTemperature += (tAddableHeatPerItem + iNegativeHeatCoefficient);
for (int tIngotStackCount = 0; tIngotStackCount < INGOTSTACKS_AMOUNT; tIngotStackCount ++)
{
if (iIngotStacks[tIngotStackCount] == null )
{
continue;
}
ItemHeatedIngot.setItemTemperature(iIngotStacks[tIngotStackCount], tAddableHeatPerItem + iNegativeHeatCoefficient);
}
iLastAddedHeat = iLastAddedHeat + (getHeatableIngotAmount() + 1) * iNegativeHeatCoefficient;
return tAddableHeatPerItem + iNegativeHeatCoefficient;
}
@Override
public void markDirty()
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
super.markDirty();
worldObj.func_147451_t(xCoord, yCoord, zCoord);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment