Skip to content

Commit

Permalink
Unmerged 1.6.4 commit: Casting Channels behave properly with faucets #…
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Aug 28, 2014
1 parent 0ae49b6 commit b8bdc7d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
@@ -1,14 +1,17 @@
package tconstruct.smeltery.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tconstruct.library.TConstructRegistry;
import tconstruct.smeltery.TinkerSmeltery;
import tconstruct.smeltery.logic.CastingChannelLogic;
import tconstruct.smeltery.model.BlockRenderCastingChannel;

Expand All @@ -34,9 +37,13 @@ public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer
ItemStack stack = player.getCurrentEquippedItem();
CastingChannelLogic tile = (CastingChannelLogic) world.getTileEntity(x, y, z);

if (stack == null)
if (stack != null && stack.getItem() == Item.getItemFromBlock(TinkerSmeltery.castingChannel))
return false;
else
{
tile.changeOutputs(player, side, hitX, hitY, hitZ);
return true;
return true;
}
}

@Override
Expand Down
54 changes: 29 additions & 25 deletions src/main/java/tconstruct/smeltery/logic/CastingChannelLogic.java
Expand Up @@ -26,7 +26,7 @@

public class CastingChannelLogic extends TileEntity implements IFluidHandler
{
public final static int fillMax = TConstruct.ingotLiquidValue;
public final static int fillMax = TConstruct.ingotLiquidValue * 3;
public final static int outputMax = TConstruct.ingotLiquidValue;
FluidTank internalTank = new FluidTank(fillMax);
HashMap<ForgeDirection, FluidTank> subTanks = new HashMap();
Expand All @@ -48,10 +48,10 @@ public CastingChannelLogic()
validOutputs.add(ForgeDirection.EAST);
validOutputs.add(ForgeDirection.WEST);

subTanks.put(ForgeDirection.NORTH, new FluidTank(TConstruct.ingotLiquidValue / 4));
subTanks.put(ForgeDirection.SOUTH, new FluidTank(TConstruct.ingotLiquidValue / 4));
subTanks.put(ForgeDirection.WEST, new FluidTank(TConstruct.ingotLiquidValue / 4));
subTanks.put(ForgeDirection.EAST, new FluidTank(TConstruct.ingotLiquidValue / 4));
subTanks.put(ForgeDirection.NORTH, new FluidTank(fillMax / 4));
subTanks.put(ForgeDirection.SOUTH, new FluidTank(fillMax / 4));
subTanks.put(ForgeDirection.WEST, new FluidTank(fillMax / 4));
subTanks.put(ForgeDirection.EAST, new FluidTank(fillMax / 4));
}

@Override
Expand All @@ -65,9 +65,9 @@ public void updateEntity ()
if (possibleFaucet != null && possibleFaucet instanceof FaucetLogic)
flagActiveFaucet = ((FaucetLogic) possibleFaucet).active;

if (ticks == 6 && !flagActiveFaucet)
if (ticks == 6)// && !flagActiveFaucet)
this.distributeFluids();
if (ticks >= 12 && !flagActiveFaucet)
if (ticks >= 12)// && !flagActiveFaucet)
{
if (recentlyFilledDelay != 0)
recentlyFilledDelay--;
Expand All @@ -85,14 +85,14 @@ public void changeOutputs (EntityPlayer player, int side, float hitX, float hitY
if(player.isSneaking())
{
if(mode == null || mode == CastingChannelMode.SINGLEDRAIN)
mode = CastingChannelMode.CONTINUEDRAIN;
else
mode = CastingChannelMode.SINGLEDRAIN;
if(mode == null || mode == CastingChannelMode.SINGLEDRAIN)
mode = CastingChannelMode.CONTINUEDRAIN;
else
mode = CastingChannelMode.SINGLEDRAIN;
String s = "Casting Channel Mode "+(worldObj.isRemote?"client side: ":"server side: ");
player.addChatMessage(s+mode.toString());
return;
String s = "Casting Channel Mode "+(worldObj.isRemote?"client side: ":"server side: ");
player.addChatMessage(s+mode.toString());
return;
}
*/

Expand Down Expand Up @@ -168,7 +168,7 @@ public void changeOutputs (EntityPlayer player, int side, float hitX, float hitY
}

}
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
markDirtyForRendering();
}

private void distributeFluids ()
Expand All @@ -185,7 +185,7 @@ private void distributeFluids ()
if (connected.contains(lastProvider))
connected.remove(lastProvider);

int output = Math.min(internalTank.getFluidAmount(), 12);
int output = Math.min(internalTank.getFluidAmount(), outputMax);
int connectedAmount = connected.size();
if (connectedAmount < 1)
connectedAmount = 1;
Expand Down Expand Up @@ -218,7 +218,7 @@ private void distributeFluids ()
debugLog.add("Internal Tank now contains: "+internalTank.getFluidAmount()+"mb");
debugLog.add("SubTank now contains: "+subTanks.get(dirOut).getFluidAmount()+"mb");
*/
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
markDirtyForRendering();
}
/* DEBUG
if(printDebugLog)
Expand All @@ -237,7 +237,7 @@ private void distributeFluids ()
/* DEBUG
debugLog.add("Importing from "+lastProvider+"ern SubTank");
*/
FluidStack tempFS = new FluidStack(inputTank.getFluid().getFluid(), Math.min(inputTank.getFluidAmount(), 12));
FluidStack tempFS = new FluidStack(inputTank.getFluid().getFluid(), Math.min(inputTank.getFluidAmount(), outputMax));
int fit = internalTank.fill(tempFS, false);
/* DEBUG
debugLog.add("Internal Tank will accept "+fit+"mb");
Expand All @@ -256,8 +256,7 @@ private void distributeFluids ()
debugLog.add("Internal Tank now contains: "+internalTank.getFluidAmount()+"mb");
debugLog.add("SubTank now contains: "+inputTank.getFluidAmount()+"mb");
*/

this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
markDirtyForRendering();
}
/* DEBUG
if(printDebugLog)
Expand All @@ -281,7 +280,7 @@ private void outputFluids ()
connected.remove(lastProvider);
if (connected.containsKey(ForgeDirection.DOWN) && this.internalTank.getFluid() != null) // Prioritizes FluidHandlers below
{
int output = Math.min(internalTank.getFluid().amount, 12);
int output = Math.min(internalTank.getFluid().amount, outputMax);
FluidStack tempFS = new FluidStack(internalTank.getFluid().getFluid(), output);
int fittingBelow = ((IFluidHandler) connected.get(ForgeDirection.DOWN)).fill(ForgeDirection.UP, tempFS, false);
if (fittingBelow > 0)
Expand All @@ -300,7 +299,7 @@ private void outputFluids ()
/* DEBUG
debugLog.add("Exporting from "+dir+"ern SubTank");
*/
FluidStack tempFS = new FluidStack(subTanks.get(dir).getFluid().getFluid(), Math.min(subTanks.get(dir).getFluidAmount(), 12));
FluidStack tempFS = new FluidStack(subTanks.get(dir).getFluid().getFluid(), Math.min(subTanks.get(dir).getFluidAmount(), outputMax));
int fit = ((IFluidHandler) connected.get(dir)).fill(dir.getOpposite(), tempFS, false);
/* DEBUG
debugLog.add("New Channel will accept "+fit+"mb");
Expand Down Expand Up @@ -347,6 +346,11 @@ public float tankBelow ()
return 0.5f;
}

private void markDirtyForRendering()
{
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}

public HashMap<ForgeDirection, TileEntity> getOutputs ()
{
HashMap<ForgeDirection, TileEntity> map = new HashMap();
Expand All @@ -368,10 +372,10 @@ public int fill (ForgeDirection from, FluidStack resource, boolean doFill)
{
if (doFill)
{
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
markDirtyForRendering();
this.lastProvider = from;
if (this.internalTank.getFluid() == null)
this.recentlyFilledDelay = 2;
//if (this.internalTank.getFluid() == null)
//this.recentlyFilledDelay = 2;
}

if (from == ForgeDirection.UP)
Expand Down
Expand Up @@ -148,7 +148,7 @@ public boolean renderWorldBlock (IBlockAccess world, int x, int y, int z, Block
{
float liquidAmount = (float) tankMain.fluid.amount / (float) tankMain.capacity * 0.125f;
double startY = tile.tankBelow();
renderer.setRenderBounds(0.375D, startY, 0.375D, 0.625D, 0.5 + liquidAmount, 0.625D); //Center
renderer.setRenderBounds(0.375D, startY, 0.375D, 0.625D, 0.51 + liquidAmount, 0.625D); //Center
renderLiquidPart(world, x, y, z, block, renderer, tankMain.fluid, false);
}
for (ForgeDirection dir : outputs)
Expand All @@ -160,8 +160,8 @@ public boolean renderWorldBlock (IBlockAccess world, int x, int y, int z, Block
if (tankSub == null || tankSub.fluid == null)
break;
float liquidAmount = (float) tankSub.fluid.amount / (float) tankSub.capacity * 0.125f / 2;
renderer.setRenderBounds(bounds[0], 0.5, bounds[1], bounds[2], 0.5 + liquidAmount, bounds[3]);
renderLiquidPart(world, x, y, z, block, renderer, tankSub.fluid, true);
renderer.setRenderBounds(bounds[0], 0.51, bounds[1], bounds[2], 0.5 + liquidAmount, bounds[3]);
renderLiquidPart(world, x, y, z, block, renderer, tankSub.fluid, false);
}
}
return true;
Expand Down

0 comments on commit b8bdc7d

Please sign in to comment.