mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-18 03:15:26 +00:00
reimplement fluid flowing down without using updateEntity
This makes flowing logic instant (and called only once when placing a tank) instead of calling updateEntity every tick, thus making the tank way more performant Also got rid of onComparatorUpdate because comparator logic doesn't work anyway
This commit is contained in:
1 parent
a54ee0f6fb
commit
c8aa902d23
2 files changed
+37
-36
No files matched your search
@@ -138,19 +138,14 @@ public class ItemCertusQuartzTank extends BaseItemBlockContainer implements IFlu
|
||||
@Override
|
||||
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side,
|
||||
float hitX, float hitY, float hitZ, int metadata) {
|
||||
if (!world.setBlock(x, y, z, this.field_150939_a, metadata, 3)) {
|
||||
if (!super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (world.getBlock(x, y, z) == this.field_150939_a) {
|
||||
this.field_150939_a.onBlockPlacedBy(world, x, y, z, player, stack);
|
||||
this.field_150939_a.onPostBlockPlaced(world, x, y, z, metadata);
|
||||
if (stack != null) {
|
||||
((TileCertusQuartzTank) world.getTileEntity(x, y, z)).readFromItemNBT(stack.getTagCompound());
|
||||
}
|
||||
|
||||
if (stack != null && stack.hasTagCompound()) {
|
||||
((TileCertusQuartzTank) world.getTileEntity(x, y, z))
|
||||
.readFromNBTWithoutCoords(stack.getTagCompound().getCompoundTag("tileEntity"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.glodblock.github.common.tile;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -19,7 +17,6 @@ import com.glodblock.github.util.BlockPos;
|
||||
public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
|
||||
|
||||
public FluidTank tank = new FluidTank(32000);
|
||||
private boolean hasUpdate;
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
@@ -155,31 +152,6 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
|
||||
return (float) this.tank.getFluidAmount() / this.tank.getCapacity();
|
||||
}
|
||||
|
||||
private void onComparatorUpdate(World world, int x, int y, int z, Block block) {
|
||||
world.func_147453_f(x, y, z, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (this.tank.getFluid() != null) {
|
||||
TileCertusQuartzTank below = getTankBelow();
|
||||
if (below != null) {
|
||||
FluidStack filled = this.tank.getFluid().copy();
|
||||
filled.amount = below.fill(this.tank.getFluid(), true, true);
|
||||
if (filled.amount >= 0) {
|
||||
this.drain(filled, true, true);
|
||||
this.hasUpdate = true;
|
||||
below.hasUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.hasUpdate) {
|
||||
onComparatorUpdate(this.worldObj, this.xCoord, this.yCoord, this.zCoord, this.getBlockType());
|
||||
this.hasUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
private TileCertusQuartzTank getTankAbove() {
|
||||
TileEntity tile = new BlockPos(this).getOffSet(0, 1, 0).getTileEntity();
|
||||
if (tile instanceof TileCertusQuartzTank tankTile) {
|
||||
@@ -242,6 +214,31 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
|
||||
return this.getTankInfo(true);
|
||||
}
|
||||
|
||||
private void flowFluidDown(boolean checkTankAbove) {
|
||||
if (this.getFluid() != null) {
|
||||
TileCertusQuartzTank below = getTankBelow();
|
||||
if (below != null) {
|
||||
FluidStack fluid = this.tank.getFluid().copy();
|
||||
int amount = below.tank.fill(fluid, true);
|
||||
if (amount > 0) {
|
||||
this.tank.drain(amount, true);
|
||||
this.update();
|
||||
below.update();
|
||||
below.flowFluidDown(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (checkTankAbove) {
|
||||
TileCertusQuartzTank above = getTankAbove();
|
||||
if (above != null && above.getFluid() != null) {
|
||||
if (this.getFluid() == null || this.getFluid() == above.getFluid()) {
|
||||
above.flowFluidDown(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (!this.worldObj.isRemote) {
|
||||
markDirty();
|
||||
@@ -278,6 +275,15 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
|
||||
this.tank.readFromNBT(tag);
|
||||
}
|
||||
|
||||
// Specifically used when player is placing a tank in world,
|
||||
// so we can apply the item's NBT and flow down its fluid in lower tanks
|
||||
public void readFromItemNBT(NBTTagCompound tag) {
|
||||
if (tag != null) {
|
||||
this.readFromNBTWithoutCoords(tag.getCompoundTag("tileEntity"));
|
||||
}
|
||||
this.flowFluidDown(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
Reference in new issue
Block a user