add #2627, FluidSpilledEvent; BC 7.0.2
This commit is contained in:
parent
e2033f5cea
commit
5cdedf9deb
27 changed files with 61 additions and 664 deletions
|
@ -10,9 +10,12 @@ Additions:
|
|||
|
||||
Improvements:
|
||||
|
||||
* [#2627] Kinesis Pipes no longer connect to Chutes (asie)
|
||||
* Rewritten fluid pipes! (asie)
|
||||
* A lot less TPS lag!
|
||||
* Up to 3x less bandwidth usage!
|
||||
* Fluid Pipes and Tanks now emit FluidSpilledEvent (asie)
|
||||
* Rewritten Builder robot (hea3ven)
|
||||
* Improved Zone Planner UI - now has a fullscreen button (asie)
|
||||
|
||||
Bugfixes:
|
||||
|
|
|
@ -20,7 +20,6 @@ import net.minecraftforge.common.util.Constants;
|
|||
import buildcraft.api.blueprints.BuildingPermission;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.MappingNotFoundException;
|
||||
import buildcraft.api.blueprints.MappingRegistry;
|
||||
import buildcraft.api.blueprints.SchematicBlock;
|
||||
import buildcraft.api.blueprints.SchematicEntity;
|
||||
import buildcraft.api.blueprints.Translation;
|
||||
|
|
|
@ -5,8 +5,10 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import gnu.trove.map.TIntObjectMap;
|
||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||
|
||||
import buildcraft.api.tablet.TabletBitmap;
|
||||
|
||||
public final class TabletFont {
|
||||
|
|
|
@ -42,6 +42,12 @@ public class BlockTank extends BlockBuildCraft {
|
|||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int par6) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile != null && tile instanceof TileTank) {
|
||||
TileTank tank = (TileTank) tile;
|
||||
tank.onBlockBreak();
|
||||
}
|
||||
|
||||
TileEntity tileAbove = world.getTileEntity(x, y + 1, z);
|
||||
TileEntity tileBelow = world.getTileEntity(x, y - 1, z);
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ package buildcraft.factory;
|
|||
|
||||
import java.lang.ref.WeakReference;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.InventoryCraftResult;
|
||||
|
|
|
@ -17,6 +17,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
import cofh.api.energy.IEnergyHandler;
|
||||
import buildcraft.api.power.IRedstoneEngineReceiver;
|
||||
import buildcraft.api.transport.IInjectable;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.core.lib.RFBattery;
|
||||
import buildcraft.core.lib.block.TileBuildCraft;
|
||||
import buildcraft.core.lib.inventory.ITransactor;
|
||||
|
@ -200,6 +201,6 @@ public class TileHopper extends TileBuildCraft implements IInventory, IEnergyHan
|
|||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection side) {
|
||||
// blocks up and down
|
||||
return side.ordinal() >= 2;
|
||||
return side.ordinal() >= 2 && !(getTile(side) instanceof IPipeTile);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.minecraft.world.EnumSkyBlock;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidEvent;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
@ -50,6 +51,15 @@ public class TileTank extends TileBuildCraft implements IFluidHandler {
|
|||
}
|
||||
}
|
||||
|
||||
protected void onBlockBreak() {
|
||||
if (!tank.isEmpty()) {
|
||||
FluidEvent.fireEvent(new FluidEvent.FluidSpilledEvent(
|
||||
tank.getFluid(),
|
||||
worldObj, xCoord, yCoord, zCoord
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package buildcraft.robotics.map;
|
||||
|
||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import buildcraft.api.core.INBTStoreable;
|
||||
|
||||
|
|
|
@ -12,7 +12,9 @@ import java.util.Iterator;
|
|||
import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
import gnu.trove.map.hash.TLongObjectHashMap;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import buildcraft.core.lib.utils.NBTUtils;
|
||||
|
|
|
@ -16,11 +16,9 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import buildcraft.BuildCraftSilicon;
|
||||
import buildcraft.api.events.BlockInteractionEvent;
|
||||
import buildcraft.api.power.ILaserTargetBlock;
|
||||
import buildcraft.core.BCCreativeTab;
|
||||
import buildcraft.core.lib.block.BlockBuildCraft;
|
||||
|
|
|
@ -29,7 +29,7 @@ public class BlockPackager extends BlockBuildCraft {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
return new TilePackager();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package buildcraft.silicon;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntityThrowable;
|
||||
|
@ -12,7 +9,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import buildcraft.BuildCraftSilicon;
|
||||
|
||||
public class EntityPackage extends EntityThrowable {
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package buildcraft.silicon;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntitySnowball;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
|
|
@ -11,10 +11,7 @@ package buildcraft.silicon;
|
|||
import net.minecraft.client.renderer.entity.RenderSnowball;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
import buildcraft.BuildCraftSilicon;
|
||||
import buildcraft.builders.EntityMechanicalArm;
|
||||
import buildcraft.core.lib.render.RenderVoid;
|
||||
import buildcraft.silicon.render.RenderLaserBlock;
|
||||
import buildcraft.silicon.render.RenderLaserTable;
|
||||
import buildcraft.silicon.render.RenderLaserTile;
|
||||
|
|
|
@ -240,7 +240,7 @@ public class TilePackager extends TileBuildCraft implements ISidedInventory {
|
|||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
if (slot == 9) {
|
||||
return (stack == null || stack.getItem() == Items.paper || stack.getItem() instanceof ItemPackage);
|
||||
return stack == null || stack.getItem() == Items.paper || stack.getItem() instanceof ItemPackage;
|
||||
}
|
||||
return visibleInventory.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ public class TileStampingTable extends TileLaserTableBase implements IHasWork, I
|
|||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return SLOTS;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import net.minecraft.inventory.ICrafting;
|
|||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import buildcraft.core.lib.gui.BuildCraftContainer;
|
||||
import buildcraft.core.lib.gui.slots.IPhantomSlot;
|
||||
import buildcraft.core.lib.gui.slots.SlotOutput;
|
||||
import buildcraft.core.lib.gui.slots.SlotValidated;
|
||||
import buildcraft.silicon.TilePackager;
|
||||
|
|
|
@ -14,7 +14,6 @@ import net.minecraft.inventory.ICrafting;
|
|||
import net.minecraft.inventory.Slot;
|
||||
import buildcraft.core.lib.gui.BuildCraftContainer;
|
||||
import buildcraft.core.lib.gui.slots.SlotOutput;
|
||||
import buildcraft.core.lib.gui.slots.SlotUntouchable;
|
||||
import buildcraft.core.lib.gui.slots.SlotValidated;
|
||||
import buildcraft.silicon.TileStampingTable;
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ package buildcraft.silicon.gui;
|
|||
import org.lwjgl.opengl.GL11;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import buildcraft.core.lib.gui.GuiBuildCraft;
|
||||
import buildcraft.core.lib.utils.StringUtils;
|
||||
import buildcraft.silicon.TilePackager;
|
||||
|
|
|
@ -11,7 +11,6 @@ package buildcraft.silicon.gui;
|
|||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import buildcraft.core.lib.gui.slots.SlotPhantom;
|
||||
import buildcraft.silicon.TilePackager;
|
||||
|
||||
public class SlotPackager extends SlotPhantom {
|
||||
public SlotPackager(IInventory iinventory, int slotIndex, int posX, int posY) {
|
||||
|
|
|
@ -1,618 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.transport;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftTransport;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.lib.utils.MathUtils;
|
||||
import buildcraft.transport.network.PacketFluidUpdate;
|
||||
import buildcraft.transport.pipes.PipeFluidsCobblestone;
|
||||
import buildcraft.transport.pipes.PipeFluidsDiamond;
|
||||
import buildcraft.transport.pipes.PipeFluidsEmerald;
|
||||
import buildcraft.transport.pipes.PipeFluidsGold;
|
||||
import buildcraft.transport.pipes.PipeFluidsIron;
|
||||
import buildcraft.transport.pipes.PipeFluidsQuartz;
|
||||
import buildcraft.transport.pipes.PipeFluidsSandstone;
|
||||
import buildcraft.transport.pipes.PipeFluidsStone;
|
||||
import buildcraft.transport.pipes.PipeFluidsVoid;
|
||||
import buildcraft.transport.pipes.PipeFluidsWood;
|
||||
import buildcraft.transport.pipes.events.PipeEventFluid;
|
||||
import buildcraft.transport.utils.FluidPipeTank;
|
||||
import buildcraft.transport.utils.FluidRenderData;
|
||||
|
||||
public class PipeTransportFluidsOld extends PipeTransport implements IFluidHandler {
|
||||
public static final Map<Class<? extends Pipe<?>>, Integer> fluidCapacities = new HashMap<Class<? extends Pipe<?>>, Integer>();
|
||||
|
||||
public class PipeSection extends FluidTank {
|
||||
private short currentTime = 0;
|
||||
// Tracks how much of the liquid is inbound in timeslots
|
||||
private short[] incomming;
|
||||
|
||||
// Tracks how much is currently available (has spent it's inbound delaytime)
|
||||
public PipeSection(int capacity) {
|
||||
super(null, capacity);
|
||||
incomming = new short[travelDelay];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill) {
|
||||
if (resource == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int maxToFill = Math.min(resource.amount, flowRate - incomming[currentTime]);
|
||||
if (maxToFill <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FluidStack stackToFill = resource.copy();
|
||||
stackToFill.amount = maxToFill;
|
||||
int filled = super.fill(stackToFill, doFill);
|
||||
|
||||
if (doFill) {
|
||||
incomming[currentTime] += filled;
|
||||
}
|
||||
|
||||
return filled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(int maxDrain, boolean doDrain) {
|
||||
int maxToDrain = getAvailable();
|
||||
if (maxToDrain > maxDrain) {
|
||||
maxToDrain = maxDrain;
|
||||
}
|
||||
if (maxToDrain > flowRate) {
|
||||
maxToDrain = flowRate;
|
||||
}
|
||||
if (maxToDrain <= 0) {
|
||||
return null;
|
||||
}
|
||||
return super.drain(maxToDrain, doDrain);
|
||||
}
|
||||
|
||||
public void moveFluids() {
|
||||
// Processes the inbound liquid
|
||||
incomming[currentTime] = 0;
|
||||
}
|
||||
|
||||
public void setTime(short newTime) {
|
||||
currentTime = newTime;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.setFluid(null);
|
||||
incomming = new short[travelDelay];
|
||||
}
|
||||
|
||||
public int getAvailable() {
|
||||
int all = getFluidAmount();
|
||||
for (short slot : incomming) {
|
||||
all -= slot;
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTank readFromNBT(NBTTagCompound compoundTag) {
|
||||
this.setCapacity(compoundTag.getInteger("capacity"));
|
||||
|
||||
for (int i = 0; i < travelDelay; ++i) {
|
||||
incomming[i] = compoundTag.getShort("in[" + i + "]");
|
||||
}
|
||||
setFluid(FluidStack.loadFluidStackFromNBT(compoundTag));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound subTag) {
|
||||
subTag.setInteger("capacity", this.getCapacity());
|
||||
|
||||
for (int i = 0; i < travelDelay; ++i) {
|
||||
incomming[i] = subTag.getShort("in[" + i + "]");
|
||||
}
|
||||
|
||||
if (this.getFluid() != null) {
|
||||
this.getFluid().writeToNBT(subTag);
|
||||
}
|
||||
|
||||
return subTag;
|
||||
}
|
||||
}
|
||||
|
||||
public enum TransferState {
|
||||
None, Input, Output
|
||||
}
|
||||
/**
|
||||
* The amount of liquid contained by a pipe section. For simplicity, all
|
||||
* pipe sections are assumed to be of the same volume.
|
||||
*/
|
||||
public static int LIQUID_IN_PIPE = FluidContainerRegistry.BUCKET_VOLUME / 4;
|
||||
public static short INPUT_TTL = 60; // 100
|
||||
public static short OUTPUT_TTL = 80; // 80
|
||||
public static short OUTPUT_COOLDOWN = 30; // 30
|
||||
|
||||
private static final ForgeDirection[] directions = ForgeDirection.VALID_DIRECTIONS;
|
||||
private static final ForgeDirection[] orientations = ForgeDirection.values();
|
||||
public byte initClient = 0;
|
||||
public int travelDelay = 12;
|
||||
public int flowRate;
|
||||
public FluidRenderData[] renderCache = new FluidRenderData[orientations.length];
|
||||
public FluidPipeTank pipeTank;
|
||||
|
||||
private final TransferState[] transferState = new TransferState[directions.length];
|
||||
private final int[] inputPerTick = new int[directions.length];
|
||||
private final short[] inputTTL = new short[]{0, 0, 0, 0, 0, 0};
|
||||
private final short[] outputTTL = new short[]{OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL};
|
||||
private final short[] outputCooldown = new short[]{0, 0, 0, 0, 0, 0};
|
||||
private final SafeTimeTracker tracker = new SafeTimeTracker(BuildCraftCore.updateFactor);
|
||||
private int clientSyncCounter = 0;
|
||||
|
||||
public PipeTransportFluidsOld() {
|
||||
for (ForgeDirection direction : orientations) {
|
||||
transferState[direction.ordinal()] = TransferState.None;
|
||||
}
|
||||
}
|
||||
|
||||
public void initFromPipe(Class<? extends Pipe> pipeClass) {
|
||||
flowRate = fluidCapacities.get(pipeClass);
|
||||
travelDelay = MathUtils.clamp(Math.round(16 / (flowRate / 10)), 1, 12);
|
||||
pipeTank = new FluidPipeTank(LIQUID_IN_PIPE, travelDelay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPipeTile.PipeType getPipeType() {
|
||||
return IPipeTile.PipeType.FLUID;
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return LIQUID_IN_PIPE;
|
||||
}
|
||||
|
||||
private boolean canReceiveFluid(ForgeDirection o) {
|
||||
TileEntity tile = container.getTile(o);
|
||||
|
||||
if (!container.isPipeConnected(o)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tile instanceof IPipeTile) {
|
||||
Pipe<?> pipe = (Pipe<?>) ((IPipeTile) tile).getPipe();
|
||||
|
||||
if (pipe == null || !inputOpen(o.getOpposite())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (tile instanceof IFluidHandler) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (container.getWorldObj().isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
moveFluids();
|
||||
|
||||
if (tracker.markTimeIfDelay(container.getWorldObj())) {
|
||||
boolean init = false;
|
||||
if (++clientSyncCounter > BuildCraftCore.longUpdateFactor) {
|
||||
clientSyncCounter = 0;
|
||||
init = true;
|
||||
}
|
||||
PacketFluidUpdate packet = computeFluidUpdate(init, true);
|
||||
|
||||
if (packet != null) {
|
||||
BuildCraftTransport.instance.sendToPlayers(packet, container.getWorldObj(), container.xCoord, container.yCoord, container.zCoord, DefaultProps.PIPE_CONTENTS_RENDER_DIST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the PacketFluidUpdate packet for transmission to a client
|
||||
*
|
||||
* @param initPacket everything is sent, no delta stuff ( first packet )
|
||||
* @param persistChange The render cache change is persisted
|
||||
* @return PacketFluidUpdate liquid update packet
|
||||
*/
|
||||
private PacketFluidUpdate computeFluidUpdate(boolean initPacket, boolean persistChange) {
|
||||
boolean changed = false;
|
||||
BitSet delta = new BitSet(PacketFluidUpdate.FLUID_DATA_NUM * ForgeDirection.VALID_DIRECTIONS.length);
|
||||
|
||||
if (initClient > 0) {
|
||||
initClient--;
|
||||
if (initClient == 1) {
|
||||
changed = true;
|
||||
delta.set(0, PacketFluidUpdate.FLUID_DATA_NUM * ForgeDirection.VALID_DIRECTIONS.length);
|
||||
}
|
||||
}
|
||||
|
||||
FluidRenderData[] renderCacheCopy = this.renderCache.clone();
|
||||
|
||||
for (ForgeDirection dir : orientations) {
|
||||
FluidStack current = pipeTank.getStack(dir);
|
||||
FluidStack prev = renderCacheCopy[dir.ordinal()] != null ? renderCacheCopy[dir.ordinal()].getFluidStack() : null;
|
||||
|
||||
if (current != null && current.getFluid() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prev == null && current == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prev == null ^ current == null) {
|
||||
changed = true;
|
||||
if (current != null) {
|
||||
renderCacheCopy[dir.ordinal()] = new FluidRenderData(current);
|
||||
} else {
|
||||
renderCacheCopy[dir.ordinal()] = null;
|
||||
}
|
||||
delta.set(dir.ordinal() * PacketFluidUpdate.FLUID_DATA_NUM + PacketFluidUpdate.FLUID_ID_BIT);
|
||||
delta.set(dir.ordinal() * PacketFluidUpdate.FLUID_DATA_NUM + PacketFluidUpdate.FLUID_AMOUNT_BIT);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prev == null || current == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!prev.equals(current) || initPacket) {
|
||||
changed = true;
|
||||
renderCacheCopy[dir.ordinal()] = new FluidRenderData(current);
|
||||
delta.set(dir.ordinal() * PacketFluidUpdate.FLUID_DATA_NUM + PacketFluidUpdate.FLUID_ID_BIT);
|
||||
}
|
||||
|
||||
int displayQty = (prev.amount * 4 + current.amount) / 5;
|
||||
if (displayQty == 0 && current.amount > 0 || initPacket) {
|
||||
displayQty = current.amount;
|
||||
}
|
||||
displayQty = Math.min(getCapacity(), displayQty);
|
||||
|
||||
if (prev.amount != displayQty || initPacket) {
|
||||
changed = true;
|
||||
renderCacheCopy[dir.ordinal()].amount = displayQty;
|
||||
delta.set(dir.ordinal() * PacketFluidUpdate.FLUID_DATA_NUM + PacketFluidUpdate.FLUID_AMOUNT_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
if (persistChange) {
|
||||
this.renderCache = renderCacheCopy;
|
||||
}
|
||||
|
||||
if (changed || initPacket) {
|
||||
PacketFluidUpdate packet = new PacketFluidUpdate(container.xCoord, container.yCoord, container.zCoord, initPacket);
|
||||
packet.renderCache = renderCacheCopy;
|
||||
packet.delta = delta;
|
||||
return packet;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes client
|
||||
*/
|
||||
@Override
|
||||
public void sendDescriptionPacket() {
|
||||
super.sendDescriptionPacket();
|
||||
|
||||
initClient = 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
pipeTank.readFromNBT(nbttagcompound);
|
||||
|
||||
for (ForgeDirection direction : orientations) {
|
||||
if (direction != ForgeDirection.UNKNOWN) {
|
||||
transferState[direction.ordinal()] = TransferState.values()[nbttagcompound.getShort("transferState[" + direction.ordinal() + "]")];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
pipeTank.writeToNBT(nbttagcompound);
|
||||
|
||||
for (ForgeDirection direction : orientations) {
|
||||
if (direction != ForgeDirection.UNKNOWN) {
|
||||
nbttagcompound.setShort("transferState[" + direction.ordinal() + "]", (short) transferState[direction.ordinal()].ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void moveFluids() {
|
||||
short newTimeSlot = (short) (container.getWorldObj().getTotalWorldTime() % travelDelay);
|
||||
|
||||
short outputCount = computeCurrentConnectionStatesAndTickFlows(newTimeSlot > 0 && newTimeSlot < travelDelay ? newTimeSlot : 0);
|
||||
moveFromPipe(outputCount);
|
||||
moveFromCenter(outputCount);
|
||||
moveToCenter();
|
||||
}
|
||||
|
||||
private void moveFromPipe(short outputCount) {
|
||||
// Move liquid from the non-center to the connected output blocks
|
||||
if (outputCount > 0) {
|
||||
for (ForgeDirection o : directions) {
|
||||
if (transferState[o.ordinal()] == TransferState.Output) {
|
||||
TileEntity target = this.container.getTile(o);
|
||||
if (!(target instanceof IFluidHandler)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FluidStack liquidToPush = internalTanks[o.ordinal()].drain(flowRate, false);
|
||||
if (liquidToPush != null && liquidToPush.amount > 0) {
|
||||
int filled = ((IFluidHandler) target).fill(o.getOpposite(), liquidToPush, true);
|
||||
internalTanks[o.ordinal()].drain(filled, true);
|
||||
if (filled <= 0) {
|
||||
outputTTL[o.ordinal()]--;
|
||||
}
|
||||
// else FluidEvent.fireEvent(new FluidMotionEvent(liquidToPush, container.getWorldObj(), container.xCoord, container.yCoord, container.zCoord));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void moveFromCenter(short outputCount) {
|
||||
// Split liquids moving to output equally based on flowrate, how much each side can accept and available liquid
|
||||
FluidStack pushStack = internalTanks[ForgeDirection.UNKNOWN.ordinal()].getFluid();
|
||||
int totalAvailable = internalTanks[ForgeDirection.UNKNOWN.ordinal()].getAvailable();
|
||||
if (totalAvailable < 1) {
|
||||
return;
|
||||
}
|
||||
if (pushStack != null) {
|
||||
FluidStack testStack = pushStack.copy();
|
||||
testStack.amount = flowRate;
|
||||
// Move liquid from the center to the output sides
|
||||
Multiset<ForgeDirection> realDirections = HashMultiset.create(6);
|
||||
for (ForgeDirection direction : directions) {
|
||||
if (transferState[direction.ordinal()] == TransferState.Output) {
|
||||
realDirections.add(direction);
|
||||
}
|
||||
}
|
||||
container.pipe.eventBus.handleEvent(PipeEventFluid.FindDest.class, new PipeEventFluid.FindDest(container.pipe, pushStack, realDirections));
|
||||
for (ForgeDirection direction : realDirections.elementSet()) {
|
||||
int available = internalTanks[direction.ordinal()].fill(testStack, false);
|
||||
int ammountToPush = (int) (available / (double) flowRate / realDirections.size() * Math.min(flowRate, totalAvailable) * realDirections.count(direction));
|
||||
if (ammountToPush < 1) {
|
||||
ammountToPush++;
|
||||
}
|
||||
|
||||
FluidStack liquidToPush = internalTanks[ForgeDirection.UNKNOWN.ordinal()].drain(ammountToPush, false);
|
||||
if (liquidToPush != null) {
|
||||
int filled = internalTanks[direction.ordinal()].fill(liquidToPush, true);
|
||||
internalTanks[ForgeDirection.UNKNOWN.ordinal()].drain(filled, true);
|
||||
// if (filled > 0)
|
||||
// FluidEvent.fireEvent(new FluidMotionEvent(liquidToPush, container.getWorldObj(), container.xCoord, container.yCoord, container.zCoord));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void moveToCenter() {
|
||||
int transferInCount = 0;
|
||||
FluidStack stackInCenter = internalTanks[ForgeDirection.UNKNOWN.ordinal()].drain(flowRate, false);
|
||||
int spaceAvailable = internalTanks[ForgeDirection.UNKNOWN.ordinal()].getCapacity();
|
||||
if (stackInCenter != null) {
|
||||
spaceAvailable -= stackInCenter.amount;
|
||||
}
|
||||
|
||||
for (ForgeDirection dir : directions) {
|
||||
inputPerTick[dir.ordinal()] = 0;
|
||||
if (transferState[dir.ordinal()] == TransferState.Output) {
|
||||
continue;
|
||||
}
|
||||
FluidStack testStack = internalTanks[dir.ordinal()].drain(flowRate, false);
|
||||
if (testStack == null) {
|
||||
continue;
|
||||
}
|
||||
if (stackInCenter != null && !stackInCenter.isFluidEqual(testStack)) {
|
||||
continue;
|
||||
}
|
||||
inputPerTick[dir.ordinal()] = testStack.amount;
|
||||
transferInCount++;
|
||||
}
|
||||
|
||||
for (ForgeDirection dir : directions) {
|
||||
// Move liquid from input sides to the center
|
||||
if (transferState[dir.ordinal()] != TransferState.Output && inputPerTick[dir.ordinal()] > 0) {
|
||||
|
||||
int ammountToDrain = (int) ((double) inputPerTick[dir.ordinal()] / (double) flowRate / transferInCount * Math.min(flowRate, spaceAvailable));
|
||||
if (ammountToDrain < 1) {
|
||||
ammountToDrain++;
|
||||
}
|
||||
|
||||
FluidStack liquidToPush = internalTanks[dir.ordinal()].drain(ammountToDrain, false);
|
||||
if (liquidToPush != null) {
|
||||
int filled = internalTanks[ForgeDirection.UNKNOWN.ordinal()].fill(liquidToPush, true);
|
||||
internalTanks[dir.ordinal()].drain(filled, true);
|
||||
// if (filled > 0)
|
||||
// FluidEvent.fireEvent(new FluidMotionEvent(liquidToPush, container.getWorldObj(), container.xCoord, container.yCoord, container.zCoord));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private short computeCurrentConnectionStatesAndTickFlows(short newTimeSlot) {
|
||||
short outputCount = 0;
|
||||
|
||||
// Processes all internal tanks
|
||||
for (ForgeDirection direction : orientations) {
|
||||
internalTanks[direction.ordinal()].setTime(newTimeSlot);
|
||||
internalTanks[direction.ordinal()].moveFluids();
|
||||
// Input processing
|
||||
if (direction == ForgeDirection.UNKNOWN) {
|
||||
continue;
|
||||
}
|
||||
if (transferState[direction.ordinal()] == TransferState.Input) {
|
||||
inputTTL[direction.ordinal()]--;
|
||||
if (inputTTL[direction.ordinal()] <= 0) {
|
||||
transferState[direction.ordinal()] = TransferState.None;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!container.pipe.outputOpen(direction)) {
|
||||
transferState[direction.ordinal()] = TransferState.None;
|
||||
continue;
|
||||
}
|
||||
if (outputCooldown[direction.ordinal()] > 0) {
|
||||
outputCooldown[direction.ordinal()]--;
|
||||
continue;
|
||||
}
|
||||
if (outputTTL[direction.ordinal()] <= 0) {
|
||||
transferState[direction.ordinal()] = TransferState.None;
|
||||
outputCooldown[direction.ordinal()] = OUTPUT_COOLDOWN;
|
||||
outputTTL[direction.ordinal()] = OUTPUT_TTL;
|
||||
continue;
|
||||
}
|
||||
if (canReceiveFluid(direction) && outputOpen(direction)) {
|
||||
transferState[direction.ordinal()] = TransferState.Output;
|
||||
outputCount++;
|
||||
}
|
||||
}
|
||||
return outputCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(int blockId) {
|
||||
super.onNeighborBlockChange(blockId);
|
||||
|
||||
for (ForgeDirection direction : directions) {
|
||||
if (!container.isPipeConnected(direction)) {
|
||||
internalTanks[direction.ordinal()].reset();
|
||||
transferState[direction.ordinal()] = TransferState.None;
|
||||
renderCache[direction.ordinal()] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPipeConnect(TileEntity tile, ForgeDirection side) {
|
||||
if (tile instanceof IPipeTile) {
|
||||
Pipe<?> pipe2 = (Pipe<?>) ((IPipeTile) tile).getPipe();
|
||||
if (BlockGenericPipe.isValid(pipe2) && !(pipe2.transport instanceof PipeTransportFluids)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (tile instanceof IFluidHandler) {
|
||||
IFluidHandler liq = (IFluidHandler) tile;
|
||||
|
||||
/*FluidTankInfo[] tankInfo = liq.getTankInfo(side.getOpposite());
|
||||
if (tankInfo != null && tankInfo.length > 0) {
|
||||
return true;
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
|
||||
return tile instanceof IPipeTile;
|
||||
}
|
||||
|
||||
/**
|
||||
* ITankContainer implementation *
|
||||
*/
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return fill(from.ordinal(), resource, doFill);
|
||||
}
|
||||
|
||||
private int fill(int tankIndex, FluidStack resource, boolean doFill) {
|
||||
ForgeDirection d = ForgeDirection.getOrientation(tankIndex);
|
||||
if (d != ForgeDirection.UNKNOWN && !inputOpen(d)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: Workaround - look into further in 7.0 (or just rewrite it to be 1 tank with 7 amounts - MatthiasM2)?
|
||||
for (int i = 0; i <= 6; i++) {
|
||||
if (internalTanks[i].getFluid() != null && !internalTanks[i].getFluid().isFluidEqual(resource)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int filled;
|
||||
|
||||
if (this.container.pipe instanceof IPipeTransportFluidsHook) {
|
||||
filled = ((IPipeTransportFluidsHook) this.container.pipe).fill(orientations[tankIndex], resource, doFill);
|
||||
} else {
|
||||
filled = internalTanks[tankIndex].fill(resource, doFill);
|
||||
}
|
||||
|
||||
if (filled > 0 && doFill && tankIndex != ForgeDirection.UNKNOWN.ordinal()) {
|
||||
transferState[tankIndex] = TransferState.Input;
|
||||
inputTTL[tankIndex] = INPUT_TTL;
|
||||
}
|
||||
|
||||
return filled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return inputOpen(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return new FluidTankInfo[]{new FluidTankInfo(null)};
|
||||
}
|
||||
|
||||
static {
|
||||
fluidCapacities.put(PipeFluidsCobblestone.class, 1 * BuildCraftTransport.pipeFluidsBaseFlowRate);
|
||||
fluidCapacities.put(PipeFluidsDiamond.class, 8 * BuildCraftTransport.pipeFluidsBaseFlowRate);
|
||||
fluidCapacities.put(PipeFluidsEmerald.class, 4 * BuildCraftTransport.pipeFluidsBaseFlowRate);
|
||||
fluidCapacities.put(PipeFluidsGold.class, 8 * BuildCraftTransport.pipeFluidsBaseFlowRate);
|
||||
fluidCapacities.put(PipeFluidsIron.class, 4 * BuildCraftTransport.pipeFluidsBaseFlowRate);
|
||||
fluidCapacities.put(PipeFluidsQuartz.class, 4 * BuildCraftTransport.pipeFluidsBaseFlowRate);
|
||||
fluidCapacities.put(PipeFluidsSandstone.class, 2 * BuildCraftTransport.pipeFluidsBaseFlowRate);
|
||||
fluidCapacities.put(PipeFluidsStone.class, 2 * BuildCraftTransport.pipeFluidsBaseFlowRate);
|
||||
fluidCapacities.put(PipeFluidsVoid.class, 1 * BuildCraftTransport.pipeFluidsBaseFlowRate);
|
||||
fluidCapacities.put(PipeFluidsWood.class, 1 * BuildCraftTransport.pipeFluidsBaseFlowRate);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidEvent;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
@ -34,6 +35,21 @@ import buildcraft.transport.pipes.events.PipeEventFluid;
|
|||
import buildcraft.transport.utils.FluidRenderData;
|
||||
|
||||
public class PipeTransportFluids extends PipeTransport implements IFluidHandler {
|
||||
public static final Map<Class<? extends Pipe<?>>, Integer> fluidCapacities = new HashMap<Class<? extends Pipe<?>>, Integer>();
|
||||
|
||||
/**
|
||||
* The amount of liquid contained by a pipe section. For simplicity, all
|
||||
* pipe sections are assumed to be of the same volume.
|
||||
*/
|
||||
public static int LIQUID_IN_PIPE = FluidContainerRegistry.BUCKET_VOLUME / 4;
|
||||
public static int MAX_TRAVEL_DELAY = 12;
|
||||
public static short INPUT_TTL = 60; // 100
|
||||
public static short OUTPUT_TTL = 80; // 80
|
||||
public static short OUTPUT_COOLDOWN = 30; // 30
|
||||
|
||||
private static final ForgeDirection[] directions = ForgeDirection.VALID_DIRECTIONS;
|
||||
private static final ForgeDirection[] orientations = ForgeDirection.values();
|
||||
|
||||
public class PipeSection {
|
||||
public int amount;
|
||||
|
||||
|
@ -118,25 +134,11 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
|||
}
|
||||
}
|
||||
|
||||
public static final Map<Class<? extends Pipe<?>>, Integer> fluidCapacities = new HashMap<Class<? extends Pipe<?>>, Integer>();
|
||||
|
||||
/**
|
||||
* The amount of liquid contained by a pipe section. For simplicity, all
|
||||
* pipe sections are assumed to be of the same volume.
|
||||
*/
|
||||
public static int LIQUID_IN_PIPE = FluidContainerRegistry.BUCKET_VOLUME / 4;
|
||||
public static int MAX_TRAVEL_DELAY = 12;
|
||||
public static short INPUT_TTL = 60; // 100
|
||||
public static short OUTPUT_TTL = 80; // 80
|
||||
public static short OUTPUT_COOLDOWN = 30; // 30
|
||||
|
||||
public PipeSection[] sections = new PipeSection[7];
|
||||
public FluidStack fluidType;
|
||||
|
||||
public FluidRenderData renderCache = new FluidRenderData();
|
||||
|
||||
private static final ForgeDirection[] directions = ForgeDirection.VALID_DIRECTIONS;
|
||||
private static final ForgeDirection[] orientations = ForgeDirection.values();
|
||||
private final SafeTimeTracker networkSyncTracker = new SafeTimeTracker(BuildCraftCore.updateFactor);
|
||||
private final TransferState[] transferState = new TransferState[directions.length];
|
||||
private final int[] inputPerTick = new int[directions.length];
|
||||
|
@ -467,6 +469,22 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropContents() {
|
||||
if (fluidType != null) {
|
||||
int totalAmount = 0;
|
||||
for (int i = 0; i < 7; i++) {
|
||||
totalAmount += sections[i].amount;
|
||||
}
|
||||
if (totalAmount > 0) {
|
||||
FluidEvent.fireEvent(new FluidEvent.FluidSpilledEvent(
|
||||
new FluidStack(fluidType, totalAmount),
|
||||
getWorld(), container.xCoord, container.yCoord, container.zCoord
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
|
|
@ -17,7 +17,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import buildcraft.BuildCraftTransport;
|
||||
import buildcraft.api.core.ISerializable;
|
||||
|
|
|
@ -8,9 +8,7 @@
|
|||
*/
|
||||
package buildcraft.transport.statements;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import buildcraft.api.gates.IGate;
|
||||
import buildcraft.api.statements.IStatementContainer;
|
||||
|
|
|
@ -13,7 +13,6 @@ import net.minecraft.item.ItemBlock;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.core.Position;
|
||||
import buildcraft.api.transport.IStripesActivator;
|
||||
import buildcraft.api.transport.IStripesHandler;
|
||||
|
|
|
@ -8,9 +8,7 @@
|
|||
*/
|
||||
package buildcraft.transport.utils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package buildcraft.transport.utils;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class FluidRenderData {
|
||||
public int fluidID, color;
|
||||
public int[] amount = new int[7];
|
||||
|
|
Loading…
Reference in a new issue