Fix AWB dupe

And make it less likely to happen again in the future.

Also cleaned up some fluid stuff.
This commit is contained in:
CovertJaguar 2013-08-08 17:30:30 -07:00
parent 2023ccb79a
commit c1e6c5d498
17 changed files with 88 additions and 75 deletions

View file

@ -1,15 +1,18 @@
package buildcraft.core.liquids;
package buildcraft.core.fluids;
import buildcraft.core.TileBuffer;
import buildcraft.core.utils.Utils;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fluids.IFluidTank;
/**
*
@ -72,4 +75,23 @@ public class FluidUtils {
return moving ? Block.lavaMoving.blockID : Block.lavaStill.blockID;
return fluid.getBlockID();
}
public static void pushFluidToConsumers(IFluidTank tank, int flowCap, TileBuffer[] tileBuffer) {
int amountToPush = flowCap;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
FluidStack fluidStack = tank.drain(amountToPush, false);
if (fluidStack != null && fluidStack.amount > 0) {
TileEntity tile = tileBuffer[side.ordinal()].getTile();
if (tile instanceof IFluidHandler) {
int used = ((IFluidHandler) tile).fill(side.getOpposite(), fluidStack, true);
if (used > 0) {
amountToPush -= used;
tank.drain(used, true);
if (amountToPush <= 0)
return;
}
}
}
}
}
}

View file

@ -6,7 +6,7 @@
* 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.core.liquids;
package buildcraft.core.fluids;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

View file

@ -6,7 +6,7 @@
* 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.core.liquids;
package buildcraft.core.fluids;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.Fluid;

View file

@ -6,7 +6,7 @@
* 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.core.liquids;
package buildcraft.core.fluids;
import buildcraft.core.gui.tooltips.ToolTip;
import buildcraft.core.gui.tooltips.ToolTipLine;

View file

@ -6,7 +6,7 @@
* 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.core.liquids;
package buildcraft.core.fluids;
import com.google.common.collect.ForwardingList;
import cpw.mods.fml.relauncher.Side;

View file

@ -3,8 +3,10 @@ package buildcraft.core.inventory;
import buildcraft.core.inventory.InventoryIterator.IInvSlot;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.IStackFilter;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
/**
@ -82,4 +84,36 @@ public class InvUtils {
public static ItemStack moveOneItem(IInventory source, ForgeDirection output, IInventory dest, ForgeDirection intput, ItemStack... filter) {
return moveOneItem(source, output, dest, intput, new ArrayStackFilter(filter));
}
/* STACK DROPS */
public static void dropItems(World world, ItemStack stack, int i, int j, int k) {
if (stack.stackSize <= 0) {
return;
}
float f1 = 0.7F;
double d = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
double d1 = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
double d2 = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
EntityItem entityitem = new EntityItem(world, i + d, j + d1, k + d2, stack);
entityitem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityitem);
}
public static void dropItems(World world, IInventory inv, int i, int j, int k) {
for (int slot = 0; slot < inv.getSizeInventory(); ++slot) {
ItemStack items = inv.getStackInSlot(slot);
if (items != null && items.stackSize > 0) {
dropItems(world, inv.getStackInSlot(slot).copy(), i, j, k);
}
}
}
public static void wipeInventory(IInventory inv) {
for (int slot = 0; slot < inv.getSizeInventory(); ++slot) {
inv.setInventorySlotContents(slot, null);
}
}
}

View file

@ -11,7 +11,6 @@ import buildcraft.BuildCraftCore;
import buildcraft.api.core.IAreaProvider;
import buildcraft.api.core.LaserKind;
import buildcraft.api.core.Position;
import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.IPipeTile.PipeType;
import buildcraft.core.BlockIndex;
@ -20,6 +19,7 @@ import buildcraft.core.IDropControlInventory;
import buildcraft.core.IFramePipeConnection;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.network.ISynchronizedTile;
import buildcraft.core.network.PacketUpdate;
@ -32,7 +32,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryLargeChest;
import net.minecraft.item.ItemStack;
@ -162,32 +161,6 @@ public class Utils {
return 0;
}
/* STACK DROPS */
public static void dropItems(World world, ItemStack stack, int i, int j, int k) {
if (stack.stackSize <= 0) {
return;
}
float f1 = 0.7F;
double d = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
double d1 = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
double d2 = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
EntityItem entityitem = new EntityItem(world, i + d, j + d1, k + d2, stack);
entityitem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityitem);
}
public static void dropItems(World world, IInventory inventory, int i, int j, int k) {
for (int l = 0; l < inventory.getSizeInventory(); ++l) {
ItemStack items = inventory.getStackInSlot(l);
if (items != null && items.stackSize > 0) {
dropItems(world, inventory.getStackInSlot(l).copy(), i, j, k);
}
}
}
public static TileEntity getTile(World world, Position pos, ForgeDirection step) {
Position tmp = new Position(pos);
tmp.orientation = step;
@ -364,7 +337,8 @@ public class Utils {
if (tile instanceof IInventory && !CoreProxy.proxy.isRenderWorld(world)) {
if (!(tile instanceof IDropControlInventory) || ((IDropControlInventory) tile).doDrop()) {
dropItems(world, (IInventory) tile, i, j, k);
InvUtils.dropItems(world, (IInventory) tile, i, j, k);
InvUtils.wipeInventory((IInventory)tile);
}
}

View file

@ -21,10 +21,10 @@ import buildcraft.api.transport.IPipeTile.PipeType;
import buildcraft.core.DefaultProps;
import buildcraft.core.TileBuffer;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.network.TileNetworkData;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.energy.gui.ContainerEngine;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
@ -360,7 +360,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
}
public void delete() {
Utils.dropItems(worldObj, inv, xCoord, yCoord, zCoord);
InvUtils.dropItems(worldObj, inv, xCoord, yCoord, zCoord);
}
@Override

View file

@ -16,9 +16,9 @@ import buildcraft.api.fuels.IronEngineFuel.Fuel;
import buildcraft.api.gates.ITrigger;
import buildcraft.core.GuiIds;
import buildcraft.core.IItemPipe;
import buildcraft.core.liquids.FluidUtils;
import buildcraft.core.liquids.Tank;
import buildcraft.core.liquids.TankManager;
import buildcraft.core.fluids.FluidUtils;
import buildcraft.core.fluids.Tank;
import buildcraft.core.fluids.TankManager;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.energy.gui.ContainerEngine;

View file

@ -8,6 +8,7 @@
package buildcraft.factory;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.inventory.InventoryConcatenator;
import buildcraft.core.inventory.InventoryIterator;
import buildcraft.core.inventory.InventoryIterator.IInvSlot;
@ -82,12 +83,6 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
}
}
@Override
public void destroy() {
super.destroy();
Utils.dropItems(worldObj, craftMatrix, xCoord, yCoord, zCoord);
}
@Override
public int getSizeInventory() {
return 10;
@ -268,7 +263,7 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
ItemStack stack = slot.getStackInSlot();
if (stack != null) {
slot.setStackInSlot(null);
Utils.dropItems(worldObj, stack, xCoord, yCoord + 1, zCoord);
InvUtils.dropItems(worldObj, stack, xCoord, yCoord + 1, zCoord);
}
}
}

View file

@ -10,8 +10,8 @@ package buildcraft.factory;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.core.BlockIndex;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.liquids.FluidUtils;
import buildcraft.core.liquids.Tank;
import buildcraft.core.fluids.FluidUtils;
import buildcraft.core.fluids.Tank;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.BlockUtil;
import buildcraft.core.utils.Utils;

View file

@ -20,7 +20,8 @@ import buildcraft.core.EntityBlock;
import buildcraft.core.IMachine;
import buildcraft.core.TileBuffer;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.liquids.SingleUseTank;
import buildcraft.core.fluids.FluidUtils;
import buildcraft.core.fluids.SingleUseTank;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketPayloadStream;
import buildcraft.core.network.PacketUpdate;
@ -132,23 +133,9 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor
}
private void pushToConsumers() {
FluidStack fluidStack = tank.getFluid();
if (fluidStack != null && fluidStack.amount > 0) {
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = getTile(side);
if (tile instanceof IFluidHandler) {
int moved = ((IFluidHandler) tile).fill(side.getOpposite(), fluidStack, true);
if (moved > 0) {
tank.drain(moved, true);
fluidStack = tank.getFluid();
if (fluidStack == null || fluidStack.amount <= 0) {
break;
}
}
}
}
}
if(tileBuffer == null)
tileBuffer = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
FluidUtils.pushFluidToConsumers(tank, 400, tileBuffer);
}
private TileEntity getTile(ForgeDirection side) {

View file

@ -18,8 +18,8 @@ import buildcraft.api.recipes.RefineryRecipes;
import buildcraft.api.recipes.RefineryRecipes.Recipe;
import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.liquids.Tank;
import buildcraft.core.liquids.TankManager;
import buildcraft.core.fluids.Tank;
import buildcraft.core.fluids.TankManager;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketPayloadStream;
import buildcraft.core.network.PacketUpdate;

View file

@ -10,8 +10,8 @@ package buildcraft.factory;
import buildcraft.BuildCraftCore;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.liquids.Tank;
import buildcraft.core.liquids.TankManager;
import buildcraft.core.fluids.Tank;
import buildcraft.core.fluids.TankManager;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketPayloadStream;
import buildcraft.core.network.PacketUpdate;

View file

@ -349,7 +349,7 @@ public class TileAdvancedCraftingTable extends TileEntity implements IInventory,
output.stackSize -= Utils.addToRandomInventoryAround(worldObj, xCoord, yCoord, zCoord, output);
}
if (output.stackSize > 0) {
Utils.dropItems(worldObj, output, xCoord, yCoord + 1, zCoord);
InvUtils.dropItems(worldObj, output, xCoord, yCoord + 1, zCoord);
}
}
}

View file

@ -16,6 +16,7 @@ import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.TriggerParameter;
import buildcraft.api.transport.IPipe;
import buildcraft.core.IDropControlInventory;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.network.TilePacketWrapper;
import buildcraft.core.utils.Utils;
import cpw.mods.fml.relauncher.Side;
@ -374,7 +375,7 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
}
public void dropItem(ItemStack stack) {
Utils.dropItems(container.worldObj, stack, container.xCoord, container.yCoord, container.zCoord);
InvUtils.dropItems(container.worldObj, stack, container.xCoord, container.yCoord, container.zCoord);
}
public void onBlockRemoval() {

View file

@ -25,10 +25,10 @@ import buildcraft.core.DefaultProps;
import buildcraft.core.IDropControlInventory;
import buildcraft.core.ITileBufferHolder;
import buildcraft.core.TileBuffer;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.network.IClientState;
import buildcraft.core.network.ISyncedTile;
import buildcraft.core.network.PacketTileState;
import buildcraft.core.utils.Utils;
import buildcraft.transport.Gate.GateKind;
import buildcraft.transport.network.PipeRenderStatePacket;
import cpw.mods.fml.relauncher.Side;
@ -565,7 +565,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
}
private void dropFacadeItem(ForgeDirection direction) {
Utils.dropItems(worldObj, ItemFacade.getStack(this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()]), this.xCoord, this.yCoord, this.zCoord);
InvUtils.dropItems(worldObj, ItemFacade.getStack(this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()]), this.xCoord, this.yCoord, this.zCoord);
}
public void dropFacade(ForgeDirection direction) {
@ -663,7 +663,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
return;
plugs[side.ordinal()] = false;
Utils.dropItems(worldObj, new ItemStack(BuildCraftTransport.plugItem), this.xCoord, this.yCoord, this.zCoord);
InvUtils.dropItems(worldObj, new ItemStack(BuildCraftTransport.plugItem), this.xCoord, this.yCoord, this.zCoord);
worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlockId());
scheduleNeighborChange(); //To force recalculation of connections
scheduleRenderUpdate();