use of mods.railcraft.common.fluids.TankManager in project Railcraft by Railcraft.
the class TileTankIronValve method update.
@Override
public void update() {
super.update();
if (Game.isClient(worldObj))
return;
decrementFilling();
if (isMaster) {
TileEntity tileBelow = tileCache.getTileOnSide(EnumFacing.DOWN);
TileTankIronValve valveBelow = null;
if (tileBelow instanceof TileTankIronValve) {
valveBelow = (TileTankIronValve) tileBelow;
if (valveBelow.isStructureValid() && valveBelow.getPatternMarker() == 'T') {
//noinspection ConstantConditions
StandardTank tankBelow = valveBelow.getTankManager().get(0);
assert tankBelow != null;
FluidStack liquid = tankBelow.getFluid();
if (liquid != null && liquid.amount >= tankBelow.getCapacity() - FluidTools.BUCKET_VOLUME) {
valveBelow = null;
FluidStack fillStack = liquid.copy();
fillStack.amount = FluidTools.BUCKET_VOLUME - (tankBelow.getCapacity() - liquid.amount);
if (fillStack.amount > 0) {
int used = tank.fill(fillStack, false);
if (used > 0) {
fillStack = tankBelow.drain(used, true);
tank.fill(fillStack, true);
}
}
}
} else
valveBelow = null;
}
if (valveBelow != null) {
FluidStack available = tankManager.drain(0, FluidTools.BUCKET_VOLUME, false);
if (available != null && available.amount > 0) {
int used = valveBelow.fill(available, true);
tankManager.drain(0, used, true);
}
}
}
if (getPatternPosition().getY() - getPattern().getMasterOffset().getY() == 0) {
TankManager tMan = getTankManager();
if (tMan != null)
tMan.push(tileCache, Predicates.notInstanceOf(TileTankBase.class), FLUID_OUTPUTS, 0, FLOW_RATE);
}
TileMultiBlock masterBlock = getMasterBlock();
if (masterBlock instanceof TileTankBase) {
TileTankBase masterTileTankBase = (TileTankBase) masterBlock;
int compValue = masterTileTankBase.getComparatorValue();
if (previousComparatorValue != compValue) {
previousComparatorValue = compValue;
getWorld().notifyNeighborsOfStateChange(getPos(), null);
}
}
if (previousStructureValidity != isStructureValid())
getWorld().notifyNeighborsOfStateChange(getPos(), null);
previousStructureValidity = isStructureValid();
}
use of mods.railcraft.common.fluids.TankManager in project Railcraft by Railcraft.
the class TESRHollowTank method renderTileEntityAt.
@Override
public void renderTileEntityAt(TileTankBase tile, double x, double y, double z, float partialTicks, int destroyStage) {
if (!tile.isStructureValid())
return;
if (tile instanceof TileTankIronValve) {
TileTankIronValve valve = (TileTankIronValve) tile;
StandardTank fillTank = valve.getFillTank();
FluidStack fillStack = fillTank.getFluid();
if (fillStack != null && fillStack.amount > 0) {
OpenGL.glPushMatrix();
if (valve.getPattern().getPatternMarkerChecked(valve.getPatternPosition()) == 'A') {
prepFillTexture(fillStack);
int height = getTankHeight(valve);
float yOffset = height / 2f;
float vScale = height - 2f;
OpenGL.glTranslatef((float) x + 0.5F, (float) y + yOffset - height + 1, (float) z + 0.5F);
OpenGL.glScalef(1f, vScale, 1f);
draw(fillStack);
} else if (valve.getPattern().getPatternMarkerChecked(valve.getPatternPosition().add(-1, 0, 0)) == 'A') {
prepFillTexture(fillStack);
float vScale = getVerticalScaleSide(valve);
float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
OpenGL.glTranslatef((float) x - 0.5F + RenderTools.PIXEL * 5, (float) y + yOffset, (float) z + 0.5F);
OpenGL.glScalef(1f, vScale, 1f);
draw(fillStack);
} else if (valve.getPattern().getPatternMarkerChecked(valve.getPatternPosition().add(1, 0, 0)) == 'A') {
prepFillTexture(fillStack);
float vScale = getVerticalScaleSide(valve);
float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
OpenGL.glTranslatef((float) x + 1.5F - RenderTools.PIXEL * 5, (float) y + yOffset, (float) z + 0.5F);
OpenGL.glScalef(1f, vScale, 1f);
draw(fillStack);
} else if (valve.getPattern().getPatternMarkerChecked(valve.getPatternPosition().add(0, 0, -1)) == 'A') {
prepFillTexture(fillStack);
float vScale = getVerticalScaleSide(valve);
float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
OpenGL.glTranslatef((float) x + 0.5F, (float) y + yOffset, (float) z - 0.5F + RenderTools.PIXEL * 5);
OpenGL.glScalef(1f, vScale, 1f);
draw(fillStack);
} else if (valve.getPattern().getPatternMarkerChecked(valve.getPatternPosition().add(0, 0, 1)) == 'A') {
prepFillTexture(fillStack);
float vScale = getVerticalScaleSide(valve);
float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
OpenGL.glTranslatef((float) x + 0.5F, (float) y + yOffset, (float) z + 1.5F - RenderTools.PIXEL * 5);
OpenGL.glScalef(1f, vScale, 1f);
draw(fillStack);
}
OpenGL.glPopMatrix();
}
}
if (!tile.isMaster() || tile.isInvalid())
return;
int height = getTankHeight(tile);
float yOffset = height / 2f;
float vScale = height - 2;
float hScale = tile.getPattern().getPatternWidthX() - 2;
TankManager tankManager = tile.getTankManager();
if (tankManager == null)
return;
StandardTank tank = tankManager.get(0);
if (tank == null)
return;
FluidStack fluidStack = tank.getFluid();
if (fluidStack != null && fluidStack.amount > 0) {
preGL();
OpenGL.glTranslatef((float) x + 0.5F, (float) y + yOffset + 0.01f, (float) z + 0.5F);
OpenGL.glScalef(hScale, vScale, hScale);
// OpenGL.glScalef(0.999f, 1, 0.999f);
int[] displayLists = FluidRenderer.getLiquidDisplayLists(fluidStack);
OpenGL.glPushMatrix();
float cap = tank.getCapacity();
float level = Math.min(fluidStack.amount, cap) / cap;
bindTexture(FluidRenderer.getFluidSheet(fluidStack));
FluidRenderer.setColorForFluid(fluidStack);
OpenGL.glCallList(displayLists[(int) (level * (float) (FluidRenderer.DISPLAY_STAGES - 1))]);
OpenGL.glPopMatrix();
postGL();
}
}
use of mods.railcraft.common.fluids.TankManager in project Railcraft by Railcraft.
the class TileSteamTurbine method update.
// @Override
// public ChargeHandler getChargeHandler() {
// return chargeHandler;
// }
@Override
public void update() {
super.update();
if (Game.isHost(worldObj)) {
if (isStructureValid()) {
if (isMaster())
addToNet();
// chargeHandler.tick();
} else
dropFromNet();
// double chargeNeeded = chargeHandler.getCapacity() - chargeHandler.getCharge();
double chargeNeeded = 0;
if (chargeNeeded > 0) {
double draw = (chargeNeeded / IC2_OUTPUT) * BC_OUTPUT;
double e = getEnergy();
if (e < draw)
draw = e;
removeEnergy(draw);
// chargeHandler.addCharge((draw / BC_OUTPUT) * IC2_OUTPUT);
}
if (isMaster()) {
boolean addedEnergy = false;
if (energy < BC_OUTPUT * 2) {
FluidStack steam = tankSteam.drainInternal(STEAM_USAGE, false);
// if(steam != null) System.out.println("steam=" + steam.amount);
if (steam != null && steam.amount >= STEAM_USAGE) {
ItemStack rotor = inv.getStackInSlot(0);
if (InvTools.isItemEqual(rotor, getSampleRotor())) /*&& rotor.getItemDamage() < rotor.getMaxDamage() - 5*/
{
addedEnergy = true;
energy += BC_OUTPUT;
tankSteam.drainInternal(STEAM_USAGE, true);
tankWater.fillInternal(waterFilter, true);
inv.setInventorySlotContents(0, ((ItemTurbineRotor) rotor.getItem()).useRotor(rotor));
}
}
}
output = (float) ((output * 49D + (addedEnergy ? 100D : 0D)) / 50D);
// System.out.println("addedEnergy=" + addedEnergy);
if (clock % 4 == 0) {
gaugeState = (byte) getOutput();
WorldPlugin.addBlockEvent(worldObj, getPos(), getBlockType(), 1, gaugeState);
}
}
}
TankManager tMan = getTankManager();
if (tMan != null)
tMan.push(tileCache, Predicates.instanceOf(TileBoilerFirebox.class), EnumFacing.HORIZONTALS, TANK_WATER, WATER_OUTPUT);
}
use of mods.railcraft.common.fluids.TankManager in project Railcraft by Railcraft.
the class TileTankWater method update.
@Override
public void update() {
super.update();
if (Game.isHost(getWorld())) {
if (isMaster()) {
if (worldObj.provider.getDimension() != -1 && clock % REFILL_INTERVAL == 0) {
float rate = REFILL_RATE;
Biome biome = worldObj.getBiome(getPos());
float humidity = biome.getRainfall();
rate *= humidity;
// String debug = "Biome=" + biome.biomeName + ", Humidity=" + humidity;
boolean outside = false;
for (int x = getX() - 1; x <= getX() + 1; x++) {
for (int z = getZ() - 1; z <= getZ() + 1; z++) {
outside = worldObj.canBlockSeeSky(new BlockPos(x, getY() + 3, z));
// System.out.println(x + ", " + (yCoord + 3) + ", " + z);
if (outside)
break;
}
}
// debug += ", Outside=" + outside;
if (!outside)
rate *= REFILL_PENALTY_INSIDE;
else if (worldObj.isRaining())
if (biome.getEnableSnow())
// debug += ", Snow=true";
rate *= REFILL_PENALTY_SNOW;
else
// debug += ", Rain=true";
rate *= REFILL_BOOST_RAIN;
int rateFinal = MathHelper.floor_float(rate);
if (rateFinal < REFILL_RATE_MIN)
rateFinal = REFILL_RATE_MIN;
// debug += ", Refill=" + rateFinal;
// System.out.println(debug);
FluidStack fillStack = Fluids.WATER.get(rateFinal);
tank.fillInternal(fillStack, true);
}
//FIXME
// if (clock % FluidTools.BUCKET_FILL_TIME == 0)
// FluidTools.processContainers(tankManager.get(0), this, SLOT_INPUT, SLOT_OUTPUT);
}
TankManager tMan = getTankManager();
if (tMan != null)
tMan.push(tileCache, Predicates.notInstanceOf(getClass()), LIQUID_OUTPUTS, 0, OUTPUT_RATE);
}
}
Aggregations