Skip to content

Commit

Permalink
Fix Tanks doing their stuff clientside #1535
Browse files Browse the repository at this point in the history
As a side effect this change also fixes the tank-filling-animation and synchronizes it
  • Loading branch information
bonii-xx committed Apr 12, 2015
1 parent 7e0b9fa commit d37db87
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
55 changes: 29 additions & 26 deletions src/main/java/tconstruct/smeltery/blocks/LavaTankBlock.java
Expand Up @@ -163,49 +163,52 @@ public boolean onBlockActivated (World world, int i, int j, int k, EntityPlayer
{
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
LavaTankLogic logic = (LavaTankLogic) world.getTileEntity(i, j, k);
if (liquid != null)
// putting liquid into the tank
if (liquid != null && !world.isRemote)
{
int amount = logic.fill(ForgeDirection.UNKNOWN, liquid, false);
if (amount == liquid.amount)
{
logic.fill(ForgeDirection.UNKNOWN, liquid, true);
if (!entityplayer.capabilities.isCreativeMode)
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, consumeItem(current));
return true;

// update
entityplayer.inventoryContainer.detectAndSendChanges();
world.markBlockForUpdate(i,j,k);
}
else
return true;

return true;
}
// taking liquit out of the tank

This comment has been minimized.

Copy link
@TherminatorX

TherminatorX Apr 13, 2015

Contributor

liquit?

else if (FluidContainerRegistry.isBucket(current))
{
FluidTankInfo[] tanks = logic.getTankInfo(ForgeDirection.UNKNOWN);
FluidStack fillFluid = tanks[0].fluid;// getFluid();
ItemStack fillStack = FluidContainerRegistry.fillFluidContainer(fillFluid, current);
if (fillStack != null)
{
logic.drain(ForgeDirection.UNKNOWN, FluidContainerRegistry.getFluidForFilledItem(fillStack).amount, true);
if (!entityplayer.capabilities.isCreativeMode)
{
if (current.stackSize == 1)
{
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, fillStack);
}
else
{
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, consumeItem(current));

if (!entityplayer.inventory.addItemStackToInventory(fillStack))
{
entityplayer.dropPlayerItemWithRandomChoice(fillStack, false);
if(!world.isRemote) {
ItemStack fillStack = FluidContainerRegistry.fillFluidContainer(fillFluid, current);
if (fillStack != null) {
logic.drain(ForgeDirection.UNKNOWN, FluidContainerRegistry.getFluidForFilledItem(fillStack).amount, true);
if (!entityplayer.capabilities.isCreativeMode && !world.isRemote) {
if (current.stackSize == 1) {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, fillStack);
} else {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, consumeItem(current));

if (!entityplayer.inventory.addItemStackToInventory(fillStack)) {
entityplayer.dropPlayerItemWithRandomChoice(fillStack, false);
}
}

// update inventory
entityplayer.inventoryContainer.detectAndSendChanges();
// and block
}
world.markBlockForUpdate(i, j, k);
}
return true;
}
else
{
return true;
}

return true;
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/main/java/tconstruct/smeltery/logic/LavaTankLogic.java
Expand Up @@ -23,7 +23,7 @@ public int fill (ForgeDirection from, FluidStack resource, boolean doFill)
int amount = tank.fill(resource, doFill);
if (amount > 0 && doFill)
{
renderOffset = resource.amount;
renderOffset += resource.amount;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, this.getBlockType());
}
Expand Down Expand Up @@ -135,6 +135,9 @@ public void readCustomNBT (NBTTagCompound tags)
}
else
tank.setFluid(null);

if(tags.hasKey("renderOffset"))
renderOffset = tags.getInteger("renderOffset");
}

@Override
Expand All @@ -147,6 +150,7 @@ public void writeCustomNBT (NBTTagCompound tags)
tags.setString("fluidName", liquid.getFluid().getName());
tags.setInteger("amount", liquid.amount);
}
tags.setInteger("renderOffset", renderOffset);
}

/* Packets */
Expand Down Expand Up @@ -175,9 +179,12 @@ public boolean canUpdate ()
@Override
public void updateEntity ()
{
if (renderOffset > 0)
if (renderOffset != 0)
{
renderOffset -= 6;
renderOffset -= renderOffset/12 + 1; // has to be at least 1

if(renderOffset < 0)
renderOffset = 0;
worldObj.func_147479_m(xCoord, yCoord, zCoord);
}
}
Expand Down

0 comments on commit d37db87

Please sign in to comment.