Revert "Merge branch 'TransportSecure'"
This reverts commita6872c5053
, reversing changes made toff20f682fc
.
This commit is contained in:
parent
999d26eb23
commit
73506ba153
20 changed files with 504 additions and 720 deletions
|
@ -231,7 +231,7 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
if (pipe.pipe.transport instanceof PipeTransportLiquids)
|
||||
renderLiquids(pipe.pipe, x, y, z);
|
||||
|
||||
if (pipe.pipe.transport instanceof PipeTransportSolids)
|
||||
if (pipe.pipe.transport instanceof PipeTransportItems)
|
||||
renderSolids(pipe.pipe, x, y, z);
|
||||
|
||||
if (pipe.pipe.transport instanceof PipeTransportPower)
|
||||
|
@ -371,7 +371,7 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
GL11.glPushMatrix();
|
||||
GL11.glDisable(2896 /* GL_LIGHTING */);
|
||||
|
||||
for (EntityData data : ((PipeTransportSolids) pipe.transport).travelingEntities
|
||||
for (EntityData data : ((PipeTransportItems) pipe.transport).travelingEntities
|
||||
.values())
|
||||
doRenderItem(data.item, x + data.item.posX - pipe.xCoord, y
|
||||
+ data.item.posY - pipe.yCoord, z + data.item.posZ
|
||||
|
|
|
@ -52,11 +52,6 @@ public class mod_BuildCraftTransport extends NetworkMod implements IItemRenderer
|
|||
MinecraftForgeClient.registerItemRenderer(
|
||||
BuildCraftTransport.pipeItemsObsidian.shiftedIndex, this);
|
||||
|
||||
MinecraftForgeClient.registerItemRenderer(
|
||||
BuildCraftTransport.pipeItemsSteel.shiftedIndex, this);
|
||||
MinecraftForgeClient.registerItemRenderer(
|
||||
BuildCraftTransport.pipeItemsRedstone.shiftedIndex, this);
|
||||
|
||||
MinecraftForgeClient.registerItemRenderer(
|
||||
BuildCraftTransport.pipeLiquidsWood.shiftedIndex, this);
|
||||
MinecraftForgeClient.registerItemRenderer(
|
||||
|
|
|
@ -44,8 +44,6 @@ import net.minecraft.src.buildcraft.transport.pipes.PipeItemsDiamond;
|
|||
import net.minecraft.src.buildcraft.transport.pipes.PipeItemsGold;
|
||||
import net.minecraft.src.buildcraft.transport.pipes.PipeItemsIron;
|
||||
import net.minecraft.src.buildcraft.transport.pipes.PipeItemsObsidian;
|
||||
import net.minecraft.src.buildcraft.transport.pipes.PipeItemsRedstone;
|
||||
import net.minecraft.src.buildcraft.transport.pipes.PipeItemsSteel;
|
||||
import net.minecraft.src.buildcraft.transport.pipes.PipeItemsStone;
|
||||
import net.minecraft.src.buildcraft.transport.pipes.PipeItemsStripes;
|
||||
import net.minecraft.src.buildcraft.transport.pipes.PipeItemsWood;
|
||||
|
@ -89,9 +87,6 @@ public class BuildCraftTransport {
|
|||
public static Item pipeItemsDiamond;
|
||||
public static Item pipeItemsObsidian;
|
||||
|
||||
public static Item pipeItemsSteel;
|
||||
public static Item pipeItemsRedstone;
|
||||
|
||||
public static Item pipeLiquidsWood;
|
||||
public static Item pipeLiquidsCobblestone;
|
||||
public static Item pipeLiquidsStone;
|
||||
|
@ -207,22 +202,19 @@ public class BuildCraftTransport {
|
|||
mod_BuildCraftTransport.registerTilePipe(TileGenericPipe.class,
|
||||
"net.minecraft.src.buildcraft.transport.GenericPipe");
|
||||
|
||||
pipeItemsWood = createPipe(DefaultProps.PIPE_ITEMS_WOOD_ID, PipeItemsWood.class, "Wooden Transport Pipe", Block.planks, Block.glass, Block.planks);
|
||||
pipeItemsWood = createPipe (DefaultProps.PIPE_ITEMS_WOOD_ID, PipeItemsWood.class, "Wooden Transport Pipe", Block.planks, Block.glass, Block.planks);
|
||||
pipeItemsCobblestone = createPipe(DefaultProps.PIPE_ITEMS_COBBLESTONE_ID, PipeItemsCobblestone.class, "Cobblestone Transport Pipe", Block.cobblestone, Block.glass, Block.cobblestone);
|
||||
pipeItemsStone = createPipe(DefaultProps.PIPE_ITEMS_STONE_ID, PipeItemsStone.class, "Stone Transport Pipe", Block.stone, Block.glass, Block.stone);
|
||||
pipeItemsIron = createPipe(DefaultProps.PIPE_ITEMS_IRON_ID, PipeItemsIron.class, "Iron Transport Pipe", Item.ingotIron, Block.glass, Item.ingotIron);
|
||||
pipeItemsGold = createPipe(DefaultProps.PIPE_ITEMS_GOLD_ID, PipeItemsGold.class, "Golden Transport Pipe", Item.ingotGold, Block.glass, Item.ingotGold);
|
||||
pipeItemsDiamond = createPipe(DefaultProps.PIPE_ITEMS_DIAMOND_ID, PipeItemsDiamond.class, "Diamond Transport Pipe", Item.diamond, Block.glass, Item.diamond);
|
||||
pipeItemsObsidian = createPipe(DefaultProps.PIPE_ITEMS_OBSIDIAN_ID, PipeItemsObsidian.class, "Obsidian Transport Pipe", Block.obsidian, Block.glass, Block.obsidian);
|
||||
pipeItemsStone = createPipe (DefaultProps.PIPE_ITEMS_STONE_ID, PipeItemsStone.class, "Stone Transport Pipe", Block.stone, Block.glass, Block.stone);
|
||||
pipeItemsIron = createPipe (DefaultProps.PIPE_ITEMS_IRON_ID, PipeItemsIron.class, "Iron Transport Pipe", Item.ingotIron, Block.glass, Item.ingotIron);
|
||||
pipeItemsGold = createPipe (DefaultProps.PIPE_ITEMS_GOLD_ID, PipeItemsGold.class, "Golden Transport Pipe", Item.ingotGold, Block.glass, Item.ingotGold);
|
||||
pipeItemsDiamond = createPipe (DefaultProps.PIPE_ITEMS_DIAMOND_ID, PipeItemsDiamond.class, "Diamond Transport Pipe", Item.diamond, Block.glass, Item.diamond);
|
||||
pipeItemsObsidian = createPipe (DefaultProps.PIPE_ITEMS_OBSIDIAN_ID, PipeItemsObsidian.class, "Obsidian Transport Pipe", Block.obsidian, Block.glass, Block.obsidian);
|
||||
|
||||
pipeItemsSteel = createPipe(DefaultProps.PIPE_ITEMS_STEEL_ID, PipeItemsSteel.class, "Steel Transport Pipe", Item.clay, Block.glass, Item.clay);
|
||||
pipeItemsRedstone = createPipe(DefaultProps.PIPE_ITEMS_REDSTONE_ID, PipeItemsRedstone.class, "Redstone Transport Pipe", Item.redstone, Block.glass, Item.redstone);
|
||||
|
||||
pipeLiquidsWood = createPipe(DefaultProps.PIPE_LIQUIDS_WOOD_ID, PipeLiquidsWood.class, "Wooden Waterproof Pipe", pipeWaterproof, pipeItemsWood, null);
|
||||
pipeLiquidsCobblestone = createPipe(DefaultProps.PIPE_LIQUIDS_COBBLESTONE_ID, PipeLiquidsCobblestone.class, "Cobblestone Waterproof Pipe", pipeWaterproof, pipeItemsCobblestone, null);
|
||||
pipeLiquidsStone = createPipe(DefaultProps.PIPE_LIQUIDS_STONE_ID, PipeLiquidsStone.class, "Stone Waterproof Pipe", pipeWaterproof, pipeItemsStone, null);
|
||||
pipeLiquidsIron = createPipe(DefaultProps.PIPE_LIQUIDS_IRON_ID, PipeLiquidsIron.class, "Iron Waterproof Pipe", pipeWaterproof, pipeItemsIron, null);
|
||||
pipeLiquidsGold = createPipe(DefaultProps.PIPE_LIQUIDS_GOLD_ID, PipeLiquidsGold.class, "Golden Waterproof Pipe", pipeWaterproof, pipeItemsGold, null);
|
||||
pipeLiquidsWood = createPipe (DefaultProps.PIPE_LIQUIDS_WOOD_ID, PipeLiquidsWood.class, "Wooden Waterproof Pipe", pipeWaterproof, pipeItemsWood, null);
|
||||
pipeLiquidsCobblestone = createPipe (DefaultProps.PIPE_LIQUIDS_COBBLESTONE_ID, PipeLiquidsCobblestone.class, "Cobblestone Waterproof Pipe", pipeWaterproof, pipeItemsCobblestone, null);
|
||||
pipeLiquidsStone = createPipe (DefaultProps.PIPE_LIQUIDS_STONE_ID, PipeLiquidsStone.class, "Stone Waterproof Pipe", pipeWaterproof, pipeItemsStone, null);
|
||||
pipeLiquidsIron = createPipe (DefaultProps.PIPE_LIQUIDS_IRON_ID, PipeLiquidsIron.class, "Iron Waterproof Pipe", pipeWaterproof, pipeItemsIron, null);
|
||||
pipeLiquidsGold = createPipe (DefaultProps.PIPE_LIQUIDS_GOLD_ID, PipeLiquidsGold.class, "Golden Waterproof Pipe", pipeWaterproof, pipeItemsGold, null);
|
||||
// diamond
|
||||
// obsidian
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
package net.minecraft.src.buildcraft.api.pipes;
|
||||
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
|
||||
public interface IOwnable {
|
||||
|
||||
boolean isSecure();
|
||||
String getOwnerName();
|
||||
void setOwner(EntityPlayer player);
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package net.minecraft.src.buildcraft.api.pipes;
|
||||
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.buildcraft.api.ISpecialInventory;
|
||||
import net.minecraft.src.buildcraft.api.Orientations;
|
||||
|
||||
public interface ISecuredInventory extends ISpecialInventory {
|
||||
|
||||
boolean allowsInteraction(String username);
|
||||
public boolean addItem (ItemStack stack, boolean doAdd, Orientations from, String owner);
|
||||
public ItemStack extractItem(boolean doRemove, Orientations from, String owner);
|
||||
|
||||
}
|
|
@ -45,8 +45,6 @@ public class DefaultProps {
|
|||
public static int PIPE_ITEMS_GOLD_ID = 4054;
|
||||
public static int PIPE_ITEMS_DIAMOND_ID = 4055;
|
||||
public static int PIPE_ITEMS_OBSIDIAN_ID = 4056;
|
||||
public static int PIPE_ITEMS_STEEL_ID = 4073;
|
||||
public static int PIPE_ITEMS_REDSTONE_ID = 4074;
|
||||
|
||||
public static int PIPE_LIQUIDS_WOOD_ID = 4057;
|
||||
public static int PIPE_LIQUIDS_COBBLESTONE_ID = 4058;
|
||||
|
@ -66,9 +64,6 @@ public class DefaultProps {
|
|||
|
||||
public static int PIPE_ITEMS_STRIPES_ID = 4071;
|
||||
public static int PIPE_STRUCTURE_COBBLESTONE_ID = 4072;
|
||||
|
||||
/// 4073 = PIPE_ITEMS_STEEL_ID
|
||||
/// 4074 = PIPE_ITEMS_REDSTONE_ID
|
||||
|
||||
public static int WOODEN_PIPE_ID = 145; // LEGACY
|
||||
public static int STONE_PIPE_ID = 146; // LEGACY
|
||||
|
|
|
@ -18,7 +18,6 @@ import net.minecraft.src.BlockContainer;
|
|||
import net.minecraft.src.BuildCraftCore;
|
||||
import net.minecraft.src.BuildCraftTransport;
|
||||
import net.minecraft.src.Entity;
|
||||
import net.minecraft.src.EntityLiving;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.IBlockAccess;
|
||||
import net.minecraft.src.Item;
|
||||
|
@ -300,18 +299,6 @@ public class BlockGenericPipe extends BlockContainer implements
|
|||
pipe.onBlockPlaced();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving) {
|
||||
|
||||
if(APIProxy.isClient(world))
|
||||
return;
|
||||
|
||||
TileGenericPipe tile = (TileGenericPipe)world.getBlockTileEntity(i, j, k);
|
||||
if(entityliving instanceof EntityPlayer)
|
||||
tile.setOwner((EntityPlayer)entityliving);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer) {
|
||||
super.blockActivated(world, i, j, k, entityplayer);
|
||||
|
|
|
@ -4,10 +4,10 @@ import net.minecraft.src.TileEntity;
|
|||
|
||||
public interface IItemTravelingHook {
|
||||
|
||||
public void drop (PipeTransportSolids pipe, EntityData data);
|
||||
public void drop (PipeTransportItems pipe, EntityData data);
|
||||
|
||||
public void centerReached (PipeTransportSolids pipe, EntityData data);
|
||||
public void centerReached (PipeTransportItems pipe, EntityData data);
|
||||
|
||||
public void endReached(PipeTransportSolids pipe, EntityData data, TileEntity tile);
|
||||
public void endReached(PipeTransportItems pipe, EntityData data, TileEntity tile);
|
||||
|
||||
}
|
||||
|
|
|
@ -142,10 +142,6 @@ public class Pipe extends PersistentTile implements IPipe, IDropControlInventory
|
|||
updateSignalState();
|
||||
}
|
||||
|
||||
/// OWNERSHIP
|
||||
public boolean isSecure() { return logic.isSecure(); }
|
||||
|
||||
/// CONNECTING
|
||||
public boolean isPipeConnected(TileEntity tile) {
|
||||
return logic.isPipeConnected(tile) && transport.isPipeConnected (tile);
|
||||
}
|
||||
|
|
|
@ -40,9 +40,6 @@ public class PipeLogic implements IDropControlInventory {
|
|||
return false;
|
||||
}
|
||||
|
||||
/// OWNERSHIP
|
||||
public boolean isSecure() { return false; }
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package net.minecraft.src.buildcraft.transport;
|
||||
|
||||
public class PipeLogicSteel extends PipeLogic {
|
||||
@Override public boolean isSecure() { return true; }
|
||||
}
|
|
@ -122,6 +122,4 @@ public class PipeLogicWood extends PipeLogic {
|
|||
if (!APIProxy.isClient(worldObj))
|
||||
switchSourceIfNeeded();
|
||||
}
|
||||
|
||||
@Override public boolean isSecure() { return true; }
|
||||
}
|
||||
|
|
|
@ -41,7 +41,422 @@ import net.minecraft.src.buildcraft.core.network.PacketPipeTransportContent;
|
|||
import net.minecraft.src.buildcraft.core.network.PacketUpdate;
|
||||
import net.minecraft.src.buildcraft.core.network.TilePacketWrapper;
|
||||
|
||||
public class PipeTransportItems extends PipeTransportSolids {
|
||||
public class PipeTransportItems extends PipeTransport {
|
||||
|
||||
public boolean allowBouncing = false;
|
||||
public TreeMap<Integer, EntityData> travelingEntities = new TreeMap<Integer, EntityData> ();
|
||||
private Vector <EntityData> entitiesToLoad = new Vector <EntityData> ();
|
||||
|
||||
// TODO: generalize the use of this hook in particular for obsidian pipe
|
||||
public IItemTravelingHook travelHook;
|
||||
|
||||
public void readjustSpeed (EntityPassiveItem item) {
|
||||
if (container.pipe instanceof IPipeTransportItemsHook)
|
||||
((IPipeTransportItemsHook) container.pipe).readjustSpeed(item);
|
||||
else
|
||||
defaultReajustSpeed(item);
|
||||
}
|
||||
|
||||
public void defaultReajustSpeed (EntityPassiveItem item) {
|
||||
|
||||
if (item.speed > Utils.pipeNormalSpeed)
|
||||
item.speed = item.speed - Utils.pipeNormalSpeed;
|
||||
|
||||
if (item.speed < Utils.pipeNormalSpeed)
|
||||
item.speed = Utils.pipeNormalSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entityEntering (EntityPassiveItem item, Orientations orientation) {
|
||||
if (item.isCorrupted())
|
||||
// Safe guard - if for any reason the item is corrupted at this
|
||||
// stage, avoid adding it to the pipe to avoid further exceptions.
|
||||
return;
|
||||
|
||||
readjustSpeed(item);
|
||||
|
||||
if (!travelingEntities.containsKey(new Integer(item.entityId))) {
|
||||
travelingEntities.put(new Integer(item.entityId), new EntityData(
|
||||
item, orientation));
|
||||
|
||||
if (item.container != null && item.container != this.container)
|
||||
((PipeTransportItems) ((TileGenericPipe) item.container).pipe.transport)
|
||||
.scheduleRemoval(item);
|
||||
|
||||
item.container = container;
|
||||
}
|
||||
|
||||
// Reajusting Ypos to make sure the object looks like sitting on the
|
||||
// pipe.
|
||||
if (orientation != Orientations.YPos && orientation != Orientations.YNeg)
|
||||
item.setPosition(item.posX, yCoord + Utils.getPipeFloorOf(item.item), item.posZ);
|
||||
|
||||
if (container.pipe instanceof IPipeTransportItemsHook)
|
||||
((IPipeTransportItemsHook) container.pipe).entityEntered(item,
|
||||
orientation);
|
||||
|
||||
if (APIProxy.isServerSide())
|
||||
if (item.synchroTracker.markTimeIfDelay(worldObj, 6 * BuildCraftCore.updateFactor))
|
||||
CoreProxy.sendToPlayers(createItemPacket(item, orientation),
|
||||
worldObj, xCoord, yCoord, zCoord, 50,
|
||||
mod_BuildCraftTransport.instance);
|
||||
|
||||
if (travelingEntities.size() > BuildCraftTransport.groupItemsTrigger) {
|
||||
groupEntities();
|
||||
|
||||
if (travelingEntities.size() > BuildCraftTransport.maxItemsInPipes)
|
||||
worldObj.createExplosion(null, xCoord, yCoord, zCoord, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all possible movements, that is to say adjacent
|
||||
* implementers of IPipeEntry or TileEntityChest.
|
||||
*/
|
||||
public LinkedList<Orientations> getPossibleMovements(Position pos,
|
||||
EntityPassiveItem item) {
|
||||
LinkedList<Orientations> result = new LinkedList<Orientations>();
|
||||
|
||||
for (Orientations o : Orientations.dirs())
|
||||
if (o != pos.orientation.reverse()
|
||||
&& container.pipe.outputOpen(o))
|
||||
if (canReceivePipeObjects(o, item))
|
||||
result.add(o);
|
||||
|
||||
if (result.size() == 0 && allowBouncing) {
|
||||
Position newPos = new Position(pos);
|
||||
newPos.orientation = newPos.orientation.reverse();
|
||||
|
||||
if (canReceivePipeObjects(pos.orientation.reverse (), item))
|
||||
result.add(pos.orientation.reverse ());
|
||||
|
||||
}
|
||||
|
||||
if (this.container.pipe instanceof IPipeTransportItemsHook)
|
||||
result = ((IPipeTransportItemsHook) this.container.pipe)
|
||||
.filterPossibleMovements(result, pos, item);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean canReceivePipeObjects(Orientations o,
|
||||
EntityPassiveItem item) {
|
||||
TileEntity entity = container.getTile(o);
|
||||
|
||||
if (!Utils.checkPipesConnections(entity, container))
|
||||
return false;
|
||||
|
||||
if (entity instanceof IPipeEntry)
|
||||
return true;
|
||||
else if (entity instanceof TileGenericPipe) {
|
||||
TileGenericPipe pipe = (TileGenericPipe) entity;
|
||||
|
||||
return pipe.pipe.transport instanceof PipeTransportItems;
|
||||
} else if (entity instanceof IInventory)
|
||||
if (new StackUtil(item.item).checkAvailableSlot((IInventory) entity,
|
||||
false, o.reverse()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
moveSolids();
|
||||
}
|
||||
|
||||
HashSet <Integer> toRemove = new HashSet <Integer> ();
|
||||
|
||||
public void scheduleRemoval (EntityPassiveItem item) {
|
||||
if (!toRemove.contains(item.entityId))
|
||||
toRemove.add(item.entityId);
|
||||
}
|
||||
|
||||
public void performRemoval () {
|
||||
travelingEntities.keySet().removeAll(toRemove);
|
||||
toRemove = new HashSet <Integer> ();
|
||||
}
|
||||
|
||||
private void moveSolids () {
|
||||
for (EntityData data : entitiesToLoad) {
|
||||
data.item.setWorld(worldObj);
|
||||
travelingEntities.put(new Integer(data.item.entityId), data);
|
||||
}
|
||||
|
||||
entitiesToLoad.clear();
|
||||
performRemoval();
|
||||
|
||||
for (EntityData data : travelingEntities.values()) {
|
||||
if (data.item.isCorrupted()) {
|
||||
scheduleRemoval(data.item);
|
||||
data.item.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
Position motion = new Position (0, 0, 0, data.orientation);
|
||||
motion.moveForwards(data.item.speed);
|
||||
|
||||
data.item.setPosition(data.item.posX + motion.x, data.item.posY
|
||||
+ motion.y, data.item.posZ + motion.z);
|
||||
|
||||
if ((data.toCenter && middleReached(data)) || outOfBounds(data)) {
|
||||
data.toCenter = false;
|
||||
|
||||
// Reajusting to the middle
|
||||
|
||||
data.item.setPosition(xCoord + 0.5,
|
||||
yCoord + Utils.getPipeFloorOf(data.item.item),
|
||||
zCoord + + 0.5);
|
||||
|
||||
Orientations nextOrientation = resolveDestination (data);
|
||||
|
||||
if (nextOrientation == Orientations.Unknown) {
|
||||
if (travelHook != null)
|
||||
travelHook.drop(this, data);
|
||||
|
||||
EntityItem dropped = null;
|
||||
|
||||
if (!toRemove.contains(data.item.entityId))
|
||||
dropped = data.item.toEntityItem(data.orientation);
|
||||
|
||||
scheduleRemoval(data.item);
|
||||
|
||||
if (dropped != null)
|
||||
onDropped(dropped);
|
||||
} else {
|
||||
data.orientation = nextOrientation;
|
||||
|
||||
if (travelHook != null)
|
||||
travelHook.centerReached(this, data);
|
||||
}
|
||||
|
||||
|
||||
} else if (!data.toCenter && endReached (data)) {
|
||||
Position destPos = new Position(xCoord, yCoord, zCoord,
|
||||
data.orientation);
|
||||
|
||||
destPos.moveForwards(1.0);
|
||||
|
||||
TileEntity tile = worldObj.getBlockTileEntity((int) destPos.x,
|
||||
(int) destPos.y, (int) destPos.z);
|
||||
|
||||
if (travelHook != null)
|
||||
travelHook.endReached (this, data, tile);
|
||||
|
||||
// If the item has not been scheduled to removal by the hook
|
||||
if (!toRemove.contains(data.item.entityId)) {
|
||||
scheduleRemoval(data.item);
|
||||
handleTileReached (data, tile);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
performRemoval();
|
||||
}
|
||||
|
||||
private void handleTileReached (EntityData data, TileEntity tile) {
|
||||
if (tile instanceof IPipeEntry)
|
||||
((IPipeEntry) tile).entityEntering(data.item,
|
||||
data.orientation);
|
||||
else if (tile instanceof TileGenericPipe
|
||||
&& ((TileGenericPipe) tile).pipe.transport instanceof PipeTransportItems) {
|
||||
TileGenericPipe pipe = (TileGenericPipe) tile;
|
||||
|
||||
((PipeTransportItems) pipe.pipe.transport).entityEntering(
|
||||
data.item, data.orientation);
|
||||
} else if (tile instanceof IInventory) {
|
||||
StackUtil utils = new StackUtil(data.item.item);
|
||||
|
||||
if (!APIProxy.isClient(worldObj))
|
||||
if (utils.checkAvailableSlot((IInventory) tile, true,
|
||||
data.orientation.reverse())
|
||||
&& utils.items.stackSize == 0)
|
||||
data.item.remove();
|
||||
else {
|
||||
data.item.item = utils.items;
|
||||
EntityItem dropped = data.item.toEntityItem(data.orientation);
|
||||
|
||||
if (dropped != null)
|
||||
// On SMP, the client side doesn't actually drops
|
||||
// items
|
||||
onDropped(dropped);
|
||||
}
|
||||
} else {
|
||||
if (travelHook != null)
|
||||
travelHook.drop (this, data);
|
||||
|
||||
EntityItem dropped = data.item
|
||||
.toEntityItem(data.orientation);
|
||||
|
||||
if (dropped != null)
|
||||
// On SMP, the client side doesn't actually drops
|
||||
// items
|
||||
onDropped(dropped);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean middleReached(EntityData entity) {
|
||||
float middleLimit = entity.item.speed * 1.01F;
|
||||
return (Math.abs(xCoord + 0.5 - entity.item.posX) < middleLimit
|
||||
&& Math.abs(yCoord + Utils.getPipeFloorOf(entity.item.item)
|
||||
- entity.item.posY) < middleLimit && Math.abs(zCoord + 0.5
|
||||
- entity.item.posZ) < middleLimit);
|
||||
}
|
||||
|
||||
public boolean endReached (EntityData entity) {
|
||||
return entity.item.posX > xCoord + 1.0
|
||||
|| entity.item.posX < xCoord
|
||||
|| entity.item.posY > yCoord + 1.0
|
||||
|| entity.item.posY < yCoord
|
||||
|| entity.item.posZ > zCoord + 1.0
|
||||
|| entity.item.posZ < zCoord;
|
||||
}
|
||||
|
||||
public boolean outOfBounds (EntityData entity) {
|
||||
return entity.item.posX > xCoord + 2.0
|
||||
|| entity.item.posX < xCoord - 1.0
|
||||
|| entity.item.posY > yCoord + 2.0
|
||||
|| entity.item.posY < yCoord - 1.0
|
||||
|| entity.item.posZ > zCoord + 2.0
|
||||
|| entity.item.posZ < zCoord - 1.0;
|
||||
}
|
||||
|
||||
public Position getPosition() {
|
||||
return new Position (xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("travelingEntities");
|
||||
|
||||
for (int j = 0; j < nbttaglist.tagCount(); ++j)
|
||||
try {
|
||||
NBTTagCompound nbttagcompound2 = (NBTTagCompound) nbttaglist
|
||||
.tagAt(j);
|
||||
|
||||
EntityPassiveItem entity = new EntityPassiveItem (null);
|
||||
entity.readFromNBT(nbttagcompound2);
|
||||
|
||||
if (entity.isCorrupted()) {
|
||||
entity.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
entity.container = container;
|
||||
|
||||
EntityData data = new EntityData(entity,
|
||||
Orientations.values()[nbttagcompound2.getInteger("orientation")]);
|
||||
data.toCenter = nbttagcompound2.getBoolean("toCenter");
|
||||
|
||||
entitiesToLoad.add(data);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
// It may be the case that entities cannot be reloaded between
|
||||
// two versions - ignore these errors.
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (EntityData data : travelingEntities.values()) {
|
||||
NBTTagCompound nbttagcompound2 = new NBTTagCompound ();
|
||||
nbttaglist.appendTag(nbttagcompound2);
|
||||
data.item.writeToNBT(nbttagcompound2);
|
||||
nbttagcompound2.setBoolean("toCenter", data.toCenter);
|
||||
nbttagcompound2.setInteger("orientation", data.orientation.ordinal());
|
||||
}
|
||||
|
||||
nbttagcompound.setTag("travelingEntities", nbttaglist);
|
||||
}
|
||||
|
||||
public Orientations resolveDestination (EntityData data) {
|
||||
LinkedList<Orientations> listOfPossibleMovements = getPossibleMovements(new Position(
|
||||
xCoord, yCoord, zCoord, data.orientation), data.item);
|
||||
|
||||
if (listOfPossibleMovements.size() == 0)
|
||||
return Orientations.Unknown;
|
||||
else {
|
||||
int i;
|
||||
|
||||
if (APIProxy.isClient(worldObj) || APIProxy.isServerSide())
|
||||
i = Math.abs(data.item.entityId + xCoord + yCoord + zCoord
|
||||
+ data.item.deterministicRandomization)
|
||||
% listOfPossibleMovements.size();
|
||||
else
|
||||
i = worldObj.rand.nextInt(listOfPossibleMovements.size());
|
||||
|
||||
|
||||
return listOfPossibleMovements.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
protected void doWork () {}
|
||||
|
||||
/**
|
||||
* Handles a packet describing a stack of items inside a pipe.
|
||||
* @param packet
|
||||
*/
|
||||
public void handleItemPacket(PacketPipeTransportContent packet) {
|
||||
|
||||
if (packet.getID() != PacketIds.PIPE_CONTENTS)
|
||||
return;
|
||||
|
||||
EntityPassiveItem item = EntityPassiveItem.getOrCreate(worldObj, packet.getEntityId());
|
||||
|
||||
item.item = new ItemStack(packet.getItemId(), packet.getStackSize(), packet.getItemDamage());
|
||||
|
||||
item.setPosition(packet.getPosX(), packet.getPosY(), packet.getPosZ());
|
||||
item.speed = packet.getSpeed();
|
||||
item.deterministicRandomization = packet.getRandomization();
|
||||
|
||||
if (item.container != this.container
|
||||
|| !travelingEntities.containsKey(item.entityId)) {
|
||||
|
||||
if (item.container != null)
|
||||
((PipeTransportItems) ((TileGenericPipe) item.container).pipe.transport)
|
||||
.scheduleRemoval(item);
|
||||
|
||||
travelingEntities.put(new Integer(item.entityId), new EntityData(
|
||||
item, packet.getOrientation()));
|
||||
item.container = container;
|
||||
|
||||
} else
|
||||
travelingEntities.get(new Integer(item.entityId)).orientation = packet.getOrientation();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a packet describing a stack of items inside a pipe.
|
||||
* @param item
|
||||
* @param orientation
|
||||
* @return
|
||||
*/
|
||||
public Packet createItemPacket (EntityPassiveItem item, Orientations orientation) {
|
||||
|
||||
item.deterministicRandomization += worldObj.rand.nextInt(6);
|
||||
PacketPipeTransportContent packet = new PacketPipeTransportContent(container.xCoord, container.yCoord, container.zCoord, item, orientation);
|
||||
|
||||
return packet.getPacket();
|
||||
}
|
||||
|
||||
public int getNumberOfItems () {
|
||||
return travelingEntities.size();
|
||||
}
|
||||
|
||||
public void onDropped (EntityItem item) {
|
||||
this.container.pipe.onDropped (item);
|
||||
}
|
||||
|
||||
protected void neighborChange() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPipeConnected(TileEntity tile) {
|
||||
|
@ -50,7 +465,64 @@ public class PipeTransportItems extends PipeTransportSolids {
|
|||
|| tile instanceof IInventory
|
||||
|| (tile instanceof IMachine && ((IMachine) tile).manageSolids());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean acceptItems() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isTriggerActive (Trigger trigger) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group all items that are similar, that is to say same dmg, same id and
|
||||
* no contribution controlling them
|
||||
*/
|
||||
public void groupEntities () {
|
||||
EntityData [] entities = travelingEntities.values().toArray(new EntityData [travelingEntities.size()]);
|
||||
|
||||
TreeSet <Integer> toRemove = new TreeSet<Integer>();
|
||||
|
||||
for (int i = 0; i < entities.length; ++i) {
|
||||
EntityData data1 = entities [i];
|
||||
|
||||
for (int j = i + 1; j < entities.length; ++j) {
|
||||
EntityData data2 = entities [j];
|
||||
|
||||
if (data1.item.item.itemID == data2.item.item.itemID
|
||||
&& data1.item.item.getItemDamage() == data2.item.item
|
||||
.getItemDamage()
|
||||
&& !toRemove.contains(data1.item.entityId)
|
||||
&& !toRemove.contains(data2.item.entityId)
|
||||
&& !data1.item.hasContributions()
|
||||
&& !data2.item.hasContributions()
|
||||
&& data1.item.item.stackSize
|
||||
+ data2.item.item.stackSize < data1.item.item
|
||||
.getMaxStackSize()) {
|
||||
|
||||
data1.item.item.stackSize += data2.item.item.stackSize;
|
||||
toRemove.add(data2.item.entityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer i : toRemove) {
|
||||
travelingEntities.get(i).item.remove();
|
||||
travelingEntities.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropContents() {
|
||||
groupEntities();
|
||||
|
||||
for (EntityData data : travelingEntities.values())
|
||||
Utils.dropItems(worldObj, data.item.item, xCoord, yCoord, zCoord);
|
||||
|
||||
travelingEntities.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsConnect(PipeTransport with) {
|
||||
return with instanceof PipeTransportItems;
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
package net.minecraft.src.buildcraft.transport;
|
||||
|
||||
import net.minecraft.src.IInventory;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.buildcraft.api.IPipeEntry;
|
||||
import net.minecraft.src.buildcraft.api.pipes.IOwnable;
|
||||
import net.minecraft.src.buildcraft.api.pipes.ISecuredInventory;
|
||||
import net.minecraft.src.buildcraft.core.IMachine;
|
||||
|
||||
public class PipeTransportSecure extends PipeTransportSolids {
|
||||
|
||||
@Override
|
||||
public boolean isPipeConnected(TileEntity tile) {
|
||||
|
||||
if(tile instanceof IOwnable) {
|
||||
IOwnable ownable = (IOwnable)tile;
|
||||
if(ownable.isSecure())
|
||||
return ownable.getOwnerName().equals(container.getOwnerName());
|
||||
}
|
||||
|
||||
if(tile instanceof ISecuredInventory) {
|
||||
ISecuredInventory inventory = (ISecuredInventory)tile;
|
||||
if(inventory.allowsInteraction(container.getOwnerName()))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsConnect(PipeTransport with) {
|
||||
|
||||
if(with instanceof PipeTransportSecure)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,506 +0,0 @@
|
|||
package net.minecraft.src.buildcraft.transport;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.minecraft.src.BuildCraftCore;
|
||||
import net.minecraft.src.BuildCraftTransport;
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.IInventory;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.NBTTagList;
|
||||
import net.minecraft.src.Packet;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.mod_BuildCraftTransport;
|
||||
import net.minecraft.src.buildcraft.api.APIProxy;
|
||||
import net.minecraft.src.buildcraft.api.EntityPassiveItem;
|
||||
import net.minecraft.src.buildcraft.api.IPipeEntry;
|
||||
import net.minecraft.src.buildcraft.api.Orientations;
|
||||
import net.minecraft.src.buildcraft.api.Position;
|
||||
import net.minecraft.src.buildcraft.api.Trigger;
|
||||
import net.minecraft.src.buildcraft.core.CoreProxy;
|
||||
import net.minecraft.src.buildcraft.core.StackUtil;
|
||||
import net.minecraft.src.buildcraft.core.Utils;
|
||||
import net.minecraft.src.buildcraft.core.network.PacketIds;
|
||||
import net.minecraft.src.buildcraft.core.network.PacketPipeTransportContent;
|
||||
|
||||
public abstract class PipeTransportSolids extends PipeTransport {
|
||||
|
||||
public boolean allowBouncing = false;
|
||||
public TreeMap<Integer, EntityData> travelingEntities = new TreeMap<Integer, EntityData> ();
|
||||
private Vector <EntityData> entitiesToLoad = new Vector <EntityData> ();
|
||||
|
||||
// TODO: generalize the use of this hook in particular for obsidian pipe
|
||||
public IItemTravelingHook travelHook;
|
||||
|
||||
public void readjustSpeed (EntityPassiveItem item) {
|
||||
if (container.pipe instanceof IPipeTransportItemsHook)
|
||||
((IPipeTransportItemsHook) container.pipe).readjustSpeed(item);
|
||||
else
|
||||
defaultReajustSpeed(item);
|
||||
}
|
||||
|
||||
public void defaultReajustSpeed (EntityPassiveItem item) {
|
||||
|
||||
if (item.speed > Utils.pipeNormalSpeed)
|
||||
item.speed = item.speed - Utils.pipeNormalSpeed;
|
||||
|
||||
if (item.speed < Utils.pipeNormalSpeed)
|
||||
item.speed = Utils.pipeNormalSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entityEntering (EntityPassiveItem item, Orientations orientation) {
|
||||
if (item.isCorrupted())
|
||||
// Safe guard - if for any reason the item is corrupted at this
|
||||
// stage, avoid adding it to the pipe to avoid further exceptions.
|
||||
return;
|
||||
|
||||
readjustSpeed(item);
|
||||
|
||||
if (!travelingEntities.containsKey(new Integer(item.entityId))) {
|
||||
travelingEntities.put(new Integer(item.entityId), new EntityData(
|
||||
item, orientation));
|
||||
|
||||
if (item.container != null && item.container != this.container)
|
||||
((PipeTransportSolids) ((TileGenericPipe) item.container).pipe.transport)
|
||||
.scheduleRemoval(item);
|
||||
|
||||
item.container = container;
|
||||
}
|
||||
|
||||
// Reajusting Ypos to make sure the object looks like sitting on the
|
||||
// pipe.
|
||||
if (orientation != Orientations.YPos && orientation != Orientations.YNeg)
|
||||
item.setPosition(item.posX, yCoord + Utils.getPipeFloorOf(item.item), item.posZ);
|
||||
|
||||
if (container.pipe instanceof IPipeTransportItemsHook)
|
||||
((IPipeTransportItemsHook) container.pipe).entityEntered(item,
|
||||
orientation);
|
||||
|
||||
if (APIProxy.isServerSide())
|
||||
if (item.synchroTracker.markTimeIfDelay(worldObj, 6 * BuildCraftCore.updateFactor))
|
||||
CoreProxy.sendToPlayers(createItemPacket(item, orientation), container.worldObj,
|
||||
xCoord, yCoord, zCoord, 50, mod_BuildCraftTransport.instance);
|
||||
|
||||
if (travelingEntities.size() > BuildCraftTransport.groupItemsTrigger) {
|
||||
groupEntities();
|
||||
|
||||
if (travelingEntities.size() > BuildCraftTransport.maxItemsInPipes)
|
||||
worldObj.createExplosion(null, xCoord, yCoord, zCoord, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all possible movements, that is to say adjacent
|
||||
* implementers of IPipeEntry or TileEntityChest.
|
||||
*/
|
||||
public LinkedList<Orientations> getPossibleMovements(Position pos,
|
||||
EntityPassiveItem item) {
|
||||
LinkedList<Orientations> result = new LinkedList<Orientations>();
|
||||
|
||||
for (Orientations o : Orientations.dirs())
|
||||
if (o != pos.orientation.reverse()
|
||||
&& container.pipe.outputOpen(o))
|
||||
if (canReceivePipeObjects(o, item))
|
||||
result.add(o);
|
||||
|
||||
if (result.size() == 0 && allowBouncing) {
|
||||
Position newPos = new Position(pos);
|
||||
newPos.orientation = newPos.orientation.reverse();
|
||||
|
||||
if (canReceivePipeObjects(pos.orientation.reverse (), item))
|
||||
result.add(pos.orientation.reverse ());
|
||||
|
||||
}
|
||||
|
||||
if (this.container.pipe instanceof IPipeTransportItemsHook)
|
||||
result = ((IPipeTransportItemsHook) this.container.pipe)
|
||||
.filterPossibleMovements(result, pos, item);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean canReceivePipeObjects(Orientations o,
|
||||
EntityPassiveItem item) {
|
||||
TileEntity entity = container.getTile(o);
|
||||
|
||||
if (!Utils.checkPipesConnections(entity, container))
|
||||
return false;
|
||||
|
||||
if (entity instanceof IPipeEntry)
|
||||
return true;
|
||||
else if (entity instanceof TileGenericPipe) {
|
||||
TileGenericPipe pipe = (TileGenericPipe) entity;
|
||||
|
||||
return pipe.pipe.transport instanceof PipeTransportItems;
|
||||
} else if (entity instanceof IInventory)
|
||||
if (new StackUtil(item.item).checkAvailableSlot((IInventory) entity,
|
||||
false, o.reverse()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
moveSolids();
|
||||
}
|
||||
|
||||
HashSet <Integer> toRemove = new HashSet <Integer> ();
|
||||
|
||||
public void scheduleRemoval (EntityPassiveItem item) {
|
||||
if (!toRemove.contains(item.entityId))
|
||||
toRemove.add(item.entityId);
|
||||
}
|
||||
|
||||
public void performRemoval () {
|
||||
travelingEntities.keySet().removeAll(toRemove);
|
||||
toRemove = new HashSet <Integer> ();
|
||||
}
|
||||
|
||||
private void moveSolids () {
|
||||
for (EntityData data : entitiesToLoad) {
|
||||
data.item.setWorld(worldObj);
|
||||
travelingEntities.put(new Integer(data.item.entityId), data);
|
||||
}
|
||||
|
||||
entitiesToLoad.clear();
|
||||
performRemoval();
|
||||
|
||||
for (EntityData data : travelingEntities.values()) {
|
||||
if (data.item.isCorrupted()) {
|
||||
scheduleRemoval(data.item);
|
||||
data.item.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
Position motion = new Position (0, 0, 0, data.orientation);
|
||||
motion.moveForwards(data.item.speed);
|
||||
|
||||
data.item.setPosition(data.item.posX + motion.x, data.item.posY
|
||||
+ motion.y, data.item.posZ + motion.z);
|
||||
|
||||
if ((data.toCenter && middleReached(data)) || outOfBounds(data)) {
|
||||
data.toCenter = false;
|
||||
|
||||
// Reajusting to the middle
|
||||
|
||||
data.item.setPosition(xCoord + 0.5,
|
||||
yCoord + Utils.getPipeFloorOf(data.item.item),
|
||||
zCoord + + 0.5);
|
||||
|
||||
Orientations nextOrientation = resolveDestination (data);
|
||||
|
||||
if (nextOrientation == Orientations.Unknown) {
|
||||
if (travelHook != null)
|
||||
travelHook.drop(this, data);
|
||||
|
||||
EntityItem dropped = null;
|
||||
|
||||
if (!toRemove.contains(data.item.entityId))
|
||||
dropped = data.item.toEntityItem(data.orientation);
|
||||
|
||||
scheduleRemoval(data.item);
|
||||
|
||||
if (dropped != null)
|
||||
onDropped(dropped);
|
||||
} else {
|
||||
data.orientation = nextOrientation;
|
||||
|
||||
if (travelHook != null)
|
||||
travelHook.centerReached(this, data);
|
||||
}
|
||||
|
||||
|
||||
} else if (!data.toCenter && endReached (data)) {
|
||||
Position destPos = new Position(xCoord, yCoord, zCoord,
|
||||
data.orientation);
|
||||
|
||||
destPos.moveForwards(1.0);
|
||||
|
||||
TileEntity tile = worldObj.getBlockTileEntity((int) destPos.x,
|
||||
(int) destPos.y, (int) destPos.z);
|
||||
|
||||
if (travelHook != null)
|
||||
travelHook.endReached (this, data, tile);
|
||||
|
||||
// If the item has not been scheduled to removal by the hook
|
||||
if (!toRemove.contains(data.item.entityId)) {
|
||||
scheduleRemoval(data.item);
|
||||
handleTileReached (data, tile);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
performRemoval();
|
||||
}
|
||||
|
||||
private void handleTileReached (EntityData data, TileEntity tile) {
|
||||
if (tile instanceof IPipeEntry)
|
||||
((IPipeEntry) tile).entityEntering(data.item,
|
||||
data.orientation);
|
||||
else if (tile instanceof TileGenericPipe
|
||||
&& ((TileGenericPipe) tile).pipe.transport instanceof PipeTransportItems) {
|
||||
TileGenericPipe pipe = (TileGenericPipe) tile;
|
||||
|
||||
((PipeTransportItems) pipe.pipe.transport).entityEntering(
|
||||
data.item, data.orientation);
|
||||
} else if (tile instanceof IInventory) {
|
||||
StackUtil utils = new StackUtil(data.item.item);
|
||||
|
||||
if (!APIProxy.isClient(worldObj))
|
||||
if (utils.checkAvailableSlot((IInventory) tile, true,
|
||||
data.orientation.reverse())
|
||||
&& utils.items.stackSize == 0)
|
||||
data.item.remove();
|
||||
else {
|
||||
data.item.item = utils.items;
|
||||
EntityItem dropped = data.item.toEntityItem(data.orientation);
|
||||
|
||||
if (dropped != null)
|
||||
// On SMP, the client side doesn't actually drops
|
||||
// items
|
||||
onDropped(dropped);
|
||||
}
|
||||
} else {
|
||||
if (travelHook != null)
|
||||
travelHook.drop (this, data);
|
||||
|
||||
EntityItem dropped = data.item
|
||||
.toEntityItem(data.orientation);
|
||||
|
||||
if (dropped != null)
|
||||
// On SMP, the client side doesn't actually drops
|
||||
// items
|
||||
onDropped(dropped);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean middleReached(EntityData entity) {
|
||||
float middleLimit = entity.item.speed * 1.01F;
|
||||
return (Math.abs(xCoord + 0.5 - entity.item.posX) < middleLimit
|
||||
&& Math.abs(yCoord + Utils.getPipeFloorOf(entity.item.item)
|
||||
- entity.item.posY) < middleLimit && Math.abs(zCoord + 0.5
|
||||
- entity.item.posZ) < middleLimit);
|
||||
}
|
||||
|
||||
public boolean endReached (EntityData entity) {
|
||||
return entity.item.posX > xCoord + 1.0
|
||||
|| entity.item.posX < xCoord
|
||||
|| entity.item.posY > yCoord + 1.0
|
||||
|| entity.item.posY < yCoord
|
||||
|| entity.item.posZ > zCoord + 1.0
|
||||
|| entity.item.posZ < zCoord;
|
||||
}
|
||||
|
||||
public boolean outOfBounds (EntityData entity) {
|
||||
return entity.item.posX > xCoord + 2.0
|
||||
|| entity.item.posX < xCoord - 1.0
|
||||
|| entity.item.posY > yCoord + 2.0
|
||||
|| entity.item.posY < yCoord - 1.0
|
||||
|| entity.item.posZ > zCoord + 2.0
|
||||
|| entity.item.posZ < zCoord - 1.0;
|
||||
}
|
||||
|
||||
public Position getPosition() {
|
||||
return new Position (xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("travelingEntities");
|
||||
|
||||
for (int j = 0; j < nbttaglist.tagCount(); ++j)
|
||||
try {
|
||||
NBTTagCompound nbttagcompound2 = (NBTTagCompound) nbttaglist
|
||||
.tagAt(j);
|
||||
|
||||
EntityPassiveItem entity = new EntityPassiveItem (null);
|
||||
entity.readFromNBT(nbttagcompound2);
|
||||
|
||||
if (entity.isCorrupted()) {
|
||||
entity.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
entity.container = container;
|
||||
|
||||
EntityData data = new EntityData(entity,
|
||||
Orientations.values()[nbttagcompound2.getInteger("orientation")]);
|
||||
data.toCenter = nbttagcompound2.getBoolean("toCenter");
|
||||
|
||||
entitiesToLoad.add(data);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
// It may be the case that entities cannot be reloaded between
|
||||
// two versions - ignore these errors.
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (EntityData data : travelingEntities.values()) {
|
||||
NBTTagCompound nbttagcompound2 = new NBTTagCompound ();
|
||||
nbttaglist.appendTag(nbttagcompound2);
|
||||
data.item.writeToNBT(nbttagcompound2);
|
||||
nbttagcompound2.setBoolean("toCenter", data.toCenter);
|
||||
nbttagcompound2.setInteger("orientation", data.orientation.ordinal());
|
||||
}
|
||||
|
||||
nbttagcompound.setTag("travelingEntities", nbttaglist);
|
||||
}
|
||||
|
||||
public Orientations resolveDestination (EntityData data) {
|
||||
LinkedList<Orientations> listOfPossibleMovements = getPossibleMovements(new Position(
|
||||
xCoord, yCoord, zCoord, data.orientation), data.item);
|
||||
|
||||
if (listOfPossibleMovements.size() == 0)
|
||||
return Orientations.Unknown;
|
||||
else {
|
||||
int i;
|
||||
|
||||
if (APIProxy.isClient(worldObj) || APIProxy.isServerSide())
|
||||
i = Math.abs(data.item.entityId + xCoord + yCoord + zCoord
|
||||
+ data.item.deterministicRandomization)
|
||||
% listOfPossibleMovements.size();
|
||||
else
|
||||
i = worldObj.rand.nextInt(listOfPossibleMovements.size());
|
||||
|
||||
|
||||
return listOfPossibleMovements.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
protected void doWork () {}
|
||||
|
||||
/**
|
||||
* Handles a packet describing a stack of items inside a pipe.
|
||||
* @param packet
|
||||
*/
|
||||
public void handleItemPacket(PacketPipeTransportContent packet) {
|
||||
|
||||
if (packet.getID() != PacketIds.PIPE_CONTENTS)
|
||||
return;
|
||||
|
||||
EntityPassiveItem item = EntityPassiveItem.getOrCreate(worldObj, packet.getEntityId());
|
||||
|
||||
item.item = new ItemStack(packet.getItemId(), packet.getStackSize(), packet.getItemDamage());
|
||||
|
||||
item.setPosition(packet.getPosX(), packet.getPosY(), packet.getPosZ());
|
||||
item.speed = packet.getSpeed();
|
||||
item.deterministicRandomization = packet.getRandomization();
|
||||
|
||||
if (item.container != this.container
|
||||
|| !travelingEntities.containsKey(item.entityId)) {
|
||||
|
||||
if (item.container != null)
|
||||
((PipeTransportItems) ((TileGenericPipe) item.container).pipe.transport)
|
||||
.scheduleRemoval(item);
|
||||
|
||||
travelingEntities.put(new Integer(item.entityId), new EntityData(
|
||||
item, packet.getOrientation()));
|
||||
item.container = container;
|
||||
|
||||
} else
|
||||
travelingEntities.get(new Integer(item.entityId)).orientation = packet.getOrientation();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a packet describing a stack of items inside a pipe.
|
||||
* @param item
|
||||
* @param orientation
|
||||
* @return
|
||||
*/
|
||||
public Packet createItemPacket (EntityPassiveItem item, Orientations orientation) {
|
||||
|
||||
item.deterministicRandomization += worldObj.rand.nextInt(6);
|
||||
PacketPipeTransportContent packet = new PacketPipeTransportContent(container.xCoord, container.yCoord, container.zCoord, item, orientation);
|
||||
|
||||
return packet.getPacket();
|
||||
}
|
||||
|
||||
public int getNumberOfItems () {
|
||||
return travelingEntities.size();
|
||||
}
|
||||
|
||||
public void onDropped (EntityItem item) {
|
||||
this.container.pipe.onDropped (item);
|
||||
}
|
||||
|
||||
protected void neighborChange() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean acceptItems() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isTriggerActive (Trigger trigger) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group all items that are similar, that is to say same dmg, same id and
|
||||
* no contribution controlling them
|
||||
*/
|
||||
public void groupEntities () {
|
||||
EntityData [] entities = travelingEntities.values().toArray(new EntityData [travelingEntities.size()]);
|
||||
|
||||
TreeSet <Integer> toRemove = new TreeSet<Integer>();
|
||||
|
||||
for (int i = 0; i < entities.length; ++i) {
|
||||
EntityData data1 = entities [i];
|
||||
|
||||
for (int j = i + 1; j < entities.length; ++j) {
|
||||
EntityData data2 = entities [j];
|
||||
|
||||
if (data1.item.item.itemID == data2.item.item.itemID
|
||||
&& data1.item.item.getItemDamage() == data2.item.item
|
||||
.getItemDamage()
|
||||
&& !toRemove.contains(data1.item.entityId)
|
||||
&& !toRemove.contains(data2.item.entityId)
|
||||
&& !data1.item.hasContributions()
|
||||
&& !data2.item.hasContributions()
|
||||
&& data1.item.item.stackSize
|
||||
+ data2.item.item.stackSize < data1.item.item
|
||||
.getMaxStackSize()) {
|
||||
|
||||
data1.item.item.stackSize += data2.item.item.stackSize;
|
||||
toRemove.add(data2.item.entityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer i : toRemove) {
|
||||
travelingEntities.get(i).item.remove();
|
||||
travelingEntities.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropContents() {
|
||||
groupEntities();
|
||||
|
||||
for (EntityData data : travelingEntities.values())
|
||||
Utils.dropItems(worldObj, data.item.item, xCoord, yCoord, zCoord);
|
||||
|
||||
travelingEntities.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -34,7 +34,6 @@ import net.minecraft.src.buildcraft.api.PowerProvider;
|
|||
import net.minecraft.src.buildcraft.api.SafeTimeTracker;
|
||||
import net.minecraft.src.buildcraft.api.TileNetworkData;
|
||||
import net.minecraft.src.buildcraft.api.Trigger;
|
||||
import net.minecraft.src.buildcraft.api.pipes.IOwnable;
|
||||
import net.minecraft.src.buildcraft.core.BlockIndex;
|
||||
import net.minecraft.src.buildcraft.core.CoreProxy;
|
||||
import net.minecraft.src.buildcraft.core.IDropControlInventory;
|
||||
|
@ -51,8 +50,7 @@ import net.minecraft.src.buildcraft.core.network.PacketUpdate;
|
|||
|
||||
public class TileGenericPipe extends TileEntity implements IPowerReceptor,
|
||||
ILiquidContainer, ISpecialInventory, IPipeEntry, ISynchronizedTile,
|
||||
IOverrideDefaultTriggers, ITileBufferHolder, IPipeConnection, IDropControlInventory,
|
||||
IOwnable {
|
||||
IOverrideDefaultTriggers, ITileBufferHolder, IPipeConnection, IDropControlInventory {
|
||||
|
||||
public TileBuffer [] tileBuffer;
|
||||
public boolean [] pipeConnectionsBuffer = new boolean [6];
|
||||
|
@ -65,14 +63,14 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor,
|
|||
|
||||
@TileNetworkData public int pipeId = -1;
|
||||
|
||||
public TileGenericPipe () {}
|
||||
public TileGenericPipe () {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
if(owner != null && !owner.isEmpty())
|
||||
nbttagcompound.setString("owner", owner);
|
||||
if (pipe != null) {
|
||||
nbttagcompound.setInteger("pipeId", pipe.itemID);
|
||||
pipe.writeToNBT(nbttagcompound);
|
||||
|
@ -83,8 +81,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor,
|
|||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
if(nbttagcompound.hasKey("owner"))
|
||||
owner = nbttagcompound.getString("owner");
|
||||
int key = nbttagcompound.getInteger("pipeId");
|
||||
if (key > 0) {
|
||||
pipe = BlockGenericPipe.createPipe(key);
|
||||
|
@ -122,26 +118,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor,
|
|||
|
||||
public boolean initialized = false;
|
||||
|
||||
/// OWNERSHIP
|
||||
private String owner;
|
||||
|
||||
@Override
|
||||
public boolean isSecure() {
|
||||
if(pipe != null)
|
||||
return pipe.isSecure();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String getOwnerName() {
|
||||
return owner;
|
||||
}
|
||||
@Override
|
||||
public void setOwner(EntityPlayer player) {
|
||||
owner = player.username;
|
||||
}
|
||||
|
||||
/// UPDATING
|
||||
@Override
|
||||
public void updateEntity () {
|
||||
if (!initialized) {
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package net.minecraft.src.buildcraft.transport.pipes;
|
||||
|
||||
import net.minecraft.src.buildcraft.transport.PipeTransportSecure;
|
||||
import net.minecraft.src.buildcraft.transport.PipeTransportSolids;
|
||||
|
||||
public class PipeItemsRedstone extends PipeItemsWood {
|
||||
|
||||
public PipeItemsRedstone(int itemID) {
|
||||
super(itemID, new PipeTransportSecure());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package net.minecraft.src.buildcraft.transport.pipes;
|
||||
|
||||
import net.minecraft.src.buildcraft.api.Orientations;
|
||||
import net.minecraft.src.buildcraft.transport.Pipe;
|
||||
import net.minecraft.src.buildcraft.transport.PipeLogicSteel;
|
||||
import net.minecraft.src.buildcraft.transport.PipeTransportSecure;
|
||||
|
||||
public class PipeItemsSteel extends Pipe {
|
||||
|
||||
private int baseTexture = 1 * 16 + 2;
|
||||
private int plainTexture = 1 * 16 + 3;
|
||||
private int nextTexture = baseTexture;
|
||||
|
||||
public PipeItemsSteel(int itemID) {
|
||||
super(new PipeTransportSecure(), new PipeLogicSteel(), itemID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareTextureFor(Orientations connection) {
|
||||
if (connection == Orientations.Unknown)
|
||||
nextTexture = baseTexture;
|
||||
else {
|
||||
int metadata = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
||||
|
||||
if (metadata == connection.ordinal())
|
||||
nextTexture = baseTexture;
|
||||
else
|
||||
nextTexture = plainTexture;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMainBlockTexture() {
|
||||
return nextTexture;
|
||||
}
|
||||
|
||||
}
|
|
@ -30,7 +30,6 @@ import net.minecraft.src.buildcraft.transport.ItemPipe;
|
|||
import net.minecraft.src.buildcraft.transport.Pipe;
|
||||
import net.minecraft.src.buildcraft.transport.PipeLogicStripes;
|
||||
import net.minecraft.src.buildcraft.transport.PipeTransportItems;
|
||||
import net.minecraft.src.buildcraft.transport.PipeTransportSolids;
|
||||
|
||||
public class PipeItemsStripes extends Pipe implements IItemTravelingHook, IPowerReceptor {
|
||||
|
||||
|
@ -79,7 +78,7 @@ public class PipeItemsStripes extends Pipe implements IItemTravelingHook, IPower
|
|||
}
|
||||
|
||||
@Override
|
||||
public void drop(PipeTransportSolids pipe, EntityData data) {
|
||||
public void drop(PipeTransportItems pipe, EntityData data) {
|
||||
Position p = new Position (xCoord, yCoord, zCoord, data.orientation);
|
||||
p.moveForwards(1.0);
|
||||
|
||||
|
@ -99,19 +98,19 @@ public class PipeItemsStripes extends Pipe implements IItemTravelingHook, IPower
|
|||
}
|
||||
|
||||
@Override
|
||||
public void centerReached(PipeTransportSolids pipe, EntityData data) {
|
||||
public void centerReached(PipeTransportItems pipe, EntityData data) {
|
||||
convertPipe(pipe, data);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean convertPipe (PipeTransportSolids pipe, EntityData data) {
|
||||
public boolean convertPipe (PipeTransportItems pipe, EntityData data) {
|
||||
if (data.item.item.getItem() instanceof ItemPipe)
|
||||
if (!(data.item.item.itemID == BuildCraftTransport.pipeItemsStipes.shiftedIndex)) {
|
||||
Pipe newPipe = BlockGenericPipe.createPipe(worldObj, xCoord, yCoord, zCoord, data.item.item.itemID);
|
||||
newPipe.setTile(this.container);
|
||||
newPipe.setWorld(worldObj);
|
||||
this.container.pipe = newPipe;
|
||||
((PipeTransportItems)newPipe.transport).travelingEntities = (TreeMap<Integer, EntityData>) pipe.travelingEntities
|
||||
((PipeTransportItems) newPipe.transport).travelingEntities = (TreeMap<Integer, EntityData>) pipe.travelingEntities
|
||||
.clone();
|
||||
|
||||
data.item.item.stackSize--;
|
||||
|
@ -144,6 +143,8 @@ public class PipeItemsStripes extends Pipe implements IItemTravelingHook, IPower
|
|||
}
|
||||
|
||||
@Override
|
||||
public void endReached(PipeTransportSolids pipe, EntityData data,
|
||||
TileEntity tile) {}
|
||||
public void endReached(PipeTransportItems pipe, EntityData data,
|
||||
TileEntity tile) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import net.minecraft.src.buildcraft.core.Utils;
|
|||
import net.minecraft.src.buildcraft.transport.Pipe;
|
||||
import net.minecraft.src.buildcraft.transport.PipeLogicWood;
|
||||
import net.minecraft.src.buildcraft.transport.PipeTransportItems;
|
||||
import net.minecraft.src.buildcraft.transport.PipeTransportSolids;
|
||||
import net.minecraft.src.forge.ISidedInventory;
|
||||
|
||||
public class PipeItemsWood extends Pipe implements IPowerReceptor {
|
||||
|
@ -36,7 +35,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
|
|||
private int plainTexture = 1 * 16 + 15;
|
||||
private int nextTexture = baseTexture;
|
||||
|
||||
protected PipeItemsWood(int itemID, PipeTransportSolids transport) {
|
||||
protected PipeItemsWood(int itemID, PipeTransportItems transport) {
|
||||
super(transport, new PipeLogicWood(), itemID);
|
||||
|
||||
powerProvider = PowerFramework.currentFramework.createPowerProvider();
|
||||
|
@ -123,7 +122,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
|
|||
EntityPassiveItem entity = new EntityPassiveItem(w, entityPos.x,
|
||||
entityPos.y, entityPos.z, stack);
|
||||
|
||||
((PipeTransportSolids) transport).entityEntering(entity,
|
||||
((PipeTransportItems) transport).entityEntering(entity,
|
||||
entityPos.orientation);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue