Major pipe routing and net sync rework

This commit is contained in:
CovertJaguar 2012-10-12 16:05:25 -07:00
parent 7e06d2c2d7
commit 0c8ac25122
9 changed files with 231 additions and 215 deletions

View file

@ -53,21 +53,25 @@ public interface IPipedItem {
/** /**
* @return the synchroTracker * @return the synchroTracker
*/ */
@Deprecated
public abstract SafeTimeTracker getSynchroTracker(); public abstract SafeTimeTracker getSynchroTracker();
/** /**
* @param synchroTracker the synchroTracker to set * @param synchroTracker the synchroTracker to set
*/ */
@Deprecated
public abstract void setSynchroTracker(SafeTimeTracker synchroTracker); public abstract void setSynchroTracker(SafeTimeTracker synchroTracker);
/** /**
* @return the deterministicRandomization * @return the deterministicRandomization
*/ */
@Deprecated
public abstract int getDeterministicRandomization(); public abstract int getDeterministicRandomization();
/** /**
* @param deterministicRandomization the deterministicRandomization to set * @param deterministicRandomization the deterministicRandomization to set
*/ */
@Deprecated
public abstract void setDeterministicRandomization(int deterministicRandomization); public abstract void setDeterministicRandomization(int deterministicRandomization);
/** /**

View file

@ -11,9 +11,11 @@ import net.minecraft.src.World;
public abstract class PipeManager { public abstract class PipeManager {
@Deprecated
private static TreeMap<Integer, IPipedItem> allServerEntities = new TreeMap<Integer, IPipedItem>(); private static TreeMap<Integer, IPipedItem> allServerEntities = new TreeMap<Integer, IPipedItem>();
@Deprecated
private static TreeMap<Integer, IPipedItem> allClientEntities = new TreeMap<Integer, IPipedItem>(); private static TreeMap<Integer, IPipedItem> allClientEntities = new TreeMap<Integer, IPipedItem>();
public static List<IExtractionHandler> extractionHandlers = new ArrayList<IExtractionHandler>(); public static List<IExtractionHandler> extractionHandlers = new ArrayList<IExtractionHandler>();
public static void registerExtractionHandler(IExtractionHandler handler) { public static void registerExtractionHandler(IExtractionHandler handler) {
@ -35,7 +37,8 @@ public abstract class PipeManager {
return true; return true;
} }
@Deprecated
public static TreeMap<Integer, IPipedItem> getAllEntities(){ public static TreeMap<Integer, IPipedItem> getAllEntities(){
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
return allClientEntities; return allClientEntities;

View file

@ -1,8 +1,8 @@
/** /**
* Copyright (c) SpaceToad, 2011 * Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com * http://www.mod-buildcraft.com
* *
* BuildCraft is distributed under the terms of the Minecraft Mod Public * 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 * License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * http://www.mod-buildcraft.com/MMPL-1.0.txt
*/ */
@ -16,7 +16,6 @@ import buildcraft.api.core.Position;
import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.transport.IPassiveItemContribution; import buildcraft.api.transport.IPassiveItemContribution;
import buildcraft.api.transport.IPipedItem; import buildcraft.api.transport.IPipedItem;
import buildcraft.api.transport.PipeManager;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import net.minecraft.src.EntityItem; import net.minecraft.src.EntityItem;
@ -39,8 +38,10 @@ public class EntityPassiveItem implements IPipedItem {
protected TileEntity container; protected TileEntity container;
@Deprecated
protected SafeTimeTracker synchroTracker = new SafeTimeTracker(); protected SafeTimeTracker synchroTracker = new SafeTimeTracker();
@Deprecated
protected int deterministicRandomization = 0; protected int deterministicRandomization = 0;
protected Position position; protected Position position;
@ -53,7 +54,7 @@ public class EntityPassiveItem implements IPipedItem {
public EntityPassiveItem(World world, int id) { public EntityPassiveItem(World world, int id) {
setEntityId(id); setEntityId(id);
PipeManager.getAllEntities().put(getEntityId(), this); // PipeManager.getAllEntities().put(getEntityId(), this);
worldObj = world; worldObj = world;
} }
@ -70,11 +71,11 @@ public class EntityPassiveItem implements IPipedItem {
/* CREATING & CACHING */ /* CREATING & CACHING */
public static IPipedItem getOrCreate(World world, int id) { public static IPipedItem getOrCreate(World world, int id) {
if (PipeManager.getAllEntities().containsKey(id)) { // if (PipeManager.getAllEntities().containsKey(id)) {
return PipeManager.getAllEntities().get(id); // return PipeManager.getAllEntities().get(id);
} else { // } else {
return new EntityPassiveItem(world, id); return new EntityPassiveItem(world, id);
} // }
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -82,9 +83,9 @@ public class EntityPassiveItem implements IPipedItem {
*/ */
@Override @Override
public void remove() { public void remove() {
if (PipeManager.getAllEntities().containsKey(getEntityId())) { // if (PipeManager.getAllEntities().containsKey(getEntityId())) {
PipeManager.getAllEntities().remove(getEntityId()); // PipeManager.getAllEntities().remove(getEntityId());
} // }
} }
/* GETTING & SETTING */ /* GETTING & SETTING */
@ -103,7 +104,7 @@ public class EntityPassiveItem implements IPipedItem {
public Position getPosition() { public Position getPosition() {
return position; return position;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see net.minecraft.src.buildcraft.api.IPipedItem#setPosition(double, double, double) * @see net.minecraft.src.buildcraft.api.IPipedItem#setPosition(double, double, double)
*/ */
@ -164,6 +165,7 @@ public class EntityPassiveItem implements IPipedItem {
* @see net.minecraft.src.buildcraft.api.IPipedItem#getSynchroTracker() * @see net.minecraft.src.buildcraft.api.IPipedItem#getSynchroTracker()
*/ */
@Override @Override
@Deprecated
public SafeTimeTracker getSynchroTracker() { public SafeTimeTracker getSynchroTracker() {
return synchroTracker; return synchroTracker;
} }
@ -172,6 +174,7 @@ public class EntityPassiveItem implements IPipedItem {
* @see net.minecraft.src.buildcraft.api.IPipedItem#setSynchroTracker(net.minecraft.src.buildcraft.api.SafeTimeTracker) * @see net.minecraft.src.buildcraft.api.IPipedItem#setSynchroTracker(net.minecraft.src.buildcraft.api.SafeTimeTracker)
*/ */
@Override @Override
@Deprecated
public void setSynchroTracker(SafeTimeTracker synchroTracker) { public void setSynchroTracker(SafeTimeTracker synchroTracker) {
this.synchroTracker = synchroTracker; this.synchroTracker = synchroTracker;
} }
@ -180,6 +183,7 @@ public class EntityPassiveItem implements IPipedItem {
* @see net.minecraft.src.buildcraft.api.IPipedItem#getDeterministicRandomization() * @see net.minecraft.src.buildcraft.api.IPipedItem#getDeterministicRandomization()
*/ */
@Override @Override
@Deprecated
public int getDeterministicRandomization() { public int getDeterministicRandomization() {
return deterministicRandomization; return deterministicRandomization;
} }
@ -188,6 +192,7 @@ public class EntityPassiveItem implements IPipedItem {
* @see net.minecraft.src.buildcraft.api.IPipedItem#setDeterministicRandomization(int) * @see net.minecraft.src.buildcraft.api.IPipedItem#setDeterministicRandomization(int)
*/ */
@Override @Override
@Deprecated
public void setDeterministicRandomization(int deterministicRandomization) { public void setDeterministicRandomization(int deterministicRandomization) {
this.deterministicRandomization = deterministicRandomization; this.deterministicRandomization = deterministicRandomization;
} }
@ -216,8 +221,8 @@ public class EntityPassiveItem implements IPipedItem {
public void readFromNBT(NBTTagCompound nbttagcompound) { public void readFromNBT(NBTTagCompound nbttagcompound) {
setPosition(nbttagcompound.getDouble("x"), setPosition(nbttagcompound.getDouble("x"),
nbttagcompound.getDouble("y"), nbttagcompound.getDouble("y"),
nbttagcompound.getDouble("z")); nbttagcompound.getDouble("z"));
setSpeed(nbttagcompound.getFloat("speed")); setSpeed(nbttagcompound.getFloat("speed"));
setItemStack(ItemStack.loadItemStackFromNBT(nbttagcompound.getCompoundTag("Item"))); setItemStack(ItemStack.loadItemStackFromNBT(nbttagcompound.getCompoundTag("Item")));

View file

@ -1,73 +0,0 @@
package buildcraft.core.network;
import buildcraft.api.core.Orientations;
import buildcraft.api.transport.IPipedItem;
public class PacketPipeTransportContent extends PacketUpdate {
public PacketPipeTransportContent() {
super(PacketIds.PIPE_CONTENTS);
}
public PacketPipeTransportContent(int x, int y, int z, IPipedItem item, Orientations orientation) {
this();
this.posX = x;
this.posY = y;
this.posZ = z;
this.payload = new PacketPayload(6, 4, 0);
payload.intPayload[0] = item.getEntityId();
payload.intPayload[1] = orientation.ordinal();
payload.intPayload[2] = item.getItemStack().itemID;
payload.intPayload[3] = item.getItemStack().stackSize;
payload.intPayload[4] = item.getItemStack().getItemDamage();
payload.intPayload[5] = item.getDeterministicRandomization();
payload.floatPayload[0] = (float) item.getPosition().x;
payload.floatPayload[1] = (float) item.getPosition().y;
payload.floatPayload[2] = (float) item.getPosition().z;
payload.floatPayload[3] = item.getSpeed();
}
public int getEntityId() {
return payload.intPayload[0];
}
public Orientations getOrientation() {
return Orientations.values()[payload.intPayload[1]];
}
public int getItemId() {
return payload.intPayload[2];
}
public int getStackSize() {
return payload.intPayload[3];
}
public int getItemDamage() {
return payload.intPayload[4];
}
public int getRandomization() {
return payload.intPayload[5];
}
public double getPosX() {
return payload.floatPayload[0];
}
public double getPosY() {
return payload.floatPayload[1];
}
public double getPosZ() {
return payload.floatPayload[2];
}
public float getSpeed() {
return payload.floatPayload[3];
}
}

View file

@ -2,18 +2,23 @@ package buildcraft.transport;
import buildcraft.api.core.Orientations; import buildcraft.api.core.Orientations;
import buildcraft.api.transport.IPipedItem; import buildcraft.api.transport.IPipedItem;
import java.util.EnumSet;
public class EntityData { public class EntityData {
// TODO: Move passive data here too, like position, speed and all? // TODO: Move passive data here too, like position, speed and all?
boolean toCenter = true; // TODO: Create an object pool?
public boolean toCenter = true;
public IPipedItem item; public IPipedItem item;
public Orientations orientation; public Orientations input;
public Orientations output = Orientations.Unknown;
public EnumSet<Orientations> blacklist = EnumSet.noneOf(Orientations.class);
public EntityData(IPipedItem citem, Orientations orientation) { public EntityData(IPipedItem citem, Orientations orientation) {
item = citem; item = citem;
this.orientation = orientation; this.input = orientation;
} }
} }

View file

@ -27,7 +27,7 @@ import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.gates.Trigger; import buildcraft.api.gates.Trigger;
import buildcraft.api.gates.TriggerParameter; import buildcraft.api.gates.TriggerParameter;
import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.IPipeConnection import buildcraft.api.transport.IPipeConnection;
import buildcraft.core.IDropControlInventory; import buildcraft.core.IDropControlInventory;
import buildcraft.core.network.TilePacketWrapper; import buildcraft.core.network.TilePacketWrapper;
import buildcraft.core.triggers.ActionRedstoneOutput; import buildcraft.core.triggers.ActionRedstoneOutput;

View file

@ -13,7 +13,9 @@ import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.Vector; import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.network.PacketDispatcher;
@ -25,14 +27,15 @@ import buildcraft.api.gates.ITrigger;
import buildcraft.api.inventory.ISpecialInventory; import buildcraft.api.inventory.ISpecialInventory;
import buildcraft.api.transport.IPipeEntry; import buildcraft.api.transport.IPipeEntry;
import buildcraft.api.transport.IPipedItem; import buildcraft.api.transport.IPipedItem;
import buildcraft.api.transport.PipeManager;
import buildcraft.core.DefaultProps; import buildcraft.core.DefaultProps;
import buildcraft.core.EntityPassiveItem; import buildcraft.core.EntityPassiveItem;
import buildcraft.core.IMachine; import buildcraft.core.IMachine;
import buildcraft.core.inventory.Transactor; import buildcraft.core.inventory.Transactor;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketPipeTransportContent;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.transport.network.PacketPipeTransportContent;
import net.minecraft.src.EntityItem; import net.minecraft.src.EntityItem;
import net.minecraft.src.IInventory; import net.minecraft.src.IInventory;
@ -46,8 +49,8 @@ import net.minecraftforge.common.ISidedInventory;
public class PipeTransportItems extends PipeTransport { public class PipeTransportItems extends PipeTransport {
public boolean allowBouncing = false; public boolean allowBouncing = false;
public TreeMap<Integer, EntityData> travelingEntities = new TreeMap<Integer, EntityData>(); public Map<Integer, EntityData> travelingEntities = new TreeMap<Integer, EntityData>();
private final Vector<EntityData> entitiesToLoad = new Vector<EntityData>(); private final List<EntityData> entitiesToLoad = new ArrayList<EntityData>();
// TODO: generalize the use of this hook in particular for obsidian pipe // TODO: generalize the use of this hook in particular for obsidian pipe
public IItemTravelingHook travelHook; public IItemTravelingHook travelHook;
@ -77,8 +80,11 @@ public class PipeTransportItems extends PipeTransport {
readjustSpeed(item); readjustSpeed(item);
if (!travelingEntities.containsKey(new Integer(item.getEntityId()))) { EntityData data = travelingEntities.get(item.getEntityId());
travelingEntities.put(new Integer(item.getEntityId()), new EntityData(item, orientation));
if (data == null) {
data = new EntityData(item, orientation);
travelingEntities.put(item.getEntityId(), data);
if (item.getContainer() != null && item.getContainer() != this.container) if (item.getContainer() != null && item.getContainer() != this.container)
((PipeTransportItems) ((TileGenericPipe) item.getContainer()).pipe.transport).scheduleRemoval(item); ((PipeTransportItems) ((TileGenericPipe) item.getContainer()).pipe.transport).scheduleRemoval(item);
@ -91,20 +97,16 @@ public class PipeTransportItems extends PipeTransport {
if (orientation != Orientations.YPos && orientation != Orientations.YNeg) if (orientation != Orientations.YPos && orientation != Orientations.YNeg)
item.setPosition(item.getPosition().x, yCoord + Utils.getPipeFloorOf(item.getItemStack()), item.getPosition().z); item.setPosition(item.getPosition().x, yCoord + Utils.getPipeFloorOf(item.getItemStack()), item.getPosition().z);
if (!worldObj.isRemote)
data.output = resolveDestination(data);
if (container.pipe instanceof IPipeTransportItemsHook) if (container.pipe instanceof IPipeTransportItemsHook)
((IPipeTransportItemsHook) container.pipe).entityEntered(item, orientation); ((IPipeTransportItemsHook) container.pipe).entityEntered(item, orientation);
if (!worldObj.isRemote && item.getSynchroTracker().markTimeIfDelay(worldObj, 6 * BuildCraftCore.updateFactor)) { if (!worldObj.isRemote) {
int dimension = worldObj.provider.dimensionId; sendItemPacket(data);
PacketDispatcher.sendPacketToAllAround(xCoord, yCoord, zCoord, DefaultProps.NETWORK_UPDATE_RANGE, dimension, createItemPacket(item, orientation));
} }
// for (Object player : MinecraftServer.getServer().getConfigurationManager().playerEntityList){
//
// }
// CoreProxy.sendToPlayers(createItemPacket(item, orientation), worldObj, xCoord, yCoord, zCoord,
// DefaultProps.NETWORK_UPDATE_RANGE, mod_BuildCraftTransport.instance);
if (travelingEntities.size() > BuildCraftTransport.groupItemsTrigger) { if (travelingEntities.size() > BuildCraftTransport.groupItemsTrigger) {
groupEntities(); groupEntities();
@ -113,29 +115,40 @@ public class PipeTransportItems extends PipeTransport {
} }
} }
public Orientations resolveDestination(EntityData data) {
LinkedList<Orientations> listOfPossibleMovements = getPossibleMovements(data);
if (listOfPossibleMovements.size() == 0)
return Orientations.Unknown;
else {
int i = worldObj.rand.nextInt(listOfPossibleMovements.size());
return listOfPossibleMovements.get(i);
}
}
/** /**
* Returns a list of all possible movements, that is to say adjacent * Returns a list of all possible movements, that is to say adjacent
* implementers of IPipeEntry or TileEntityChest. * implementers of IPipeEntry or TileEntityChest.
*/ */
public LinkedList<Orientations> getPossibleMovements(Position pos, IPipedItem item) { public LinkedList<Orientations> getPossibleMovements(EntityData data) {
LinkedList<Orientations> result = new LinkedList<Orientations>(); LinkedList<Orientations> result = new LinkedList<Orientations>();
data.blacklist.add(data.input.reverse());
for (Orientations o : Orientations.dirs()) for (Orientations o : Orientations.dirs())
if (o != pos.orientation.reverse() && container.pipe.outputOpen(o)) if (!data.blacklist.contains(o) && container.pipe.outputOpen(o))
if (canReceivePipeObjects(o, item)) if (canReceivePipeObjects(o, data.item))
result.add(o); result.add(o);
if (result.size() == 0 && allowBouncing) { if (result.size() == 0 && allowBouncing) {
Position newPos = new Position(pos); if (canReceivePipeObjects(data.input.reverse(), data.item))
newPos.orientation = newPos.orientation.reverse(); result.add(data.input.reverse());
if (canReceivePipeObjects(pos.orientation.reverse(), item))
result.add(pos.orientation.reverse());
} }
if (this.container.pipe instanceof IPipeTransportItemsHook) if (this.container.pipe instanceof IPipeTransportItemsHook) {
result = ((IPipeTransportItemsHook) this.container.pipe).filterPossibleMovements(result, pos, item); Position pos = new Position(xCoord, yCoord, zCoord, data.input);
result = ((IPipeTransportItemsHook) this.container.pipe).filterPossibleMovements(result, pos, data.item);
}
return result; return result;
} }
@ -146,14 +159,15 @@ public class PipeTransportItems extends PipeTransport {
if (!Utils.checkPipesConnections(entity, container)) if (!Utils.checkPipesConnections(entity, container))
return false; return false;
if (entity instanceof TileGenericPipe) if (entity instanceof IPipeEntry) {
if (container.pipe.transport instanceof PipeTransportItems) return true;
return container.pipe.transport.inputOpen(o); } else if (entity instanceof TileGenericPipe) {
if (entity instanceof IPipeEntry) TileGenericPipe pipe = (TileGenericPipe) entity;
return ((IPipeEntry) entity).acceptItems(); return pipe.pipe.transport instanceof PipeTransportItems;
if (entity instanceof IInventory) } else if (entity instanceof IInventory) {
if(Transactor.getTransactorFor(entity).add(item.getItemStack(), o.reverse(), false).stackSize > 0) if(Transactor.getTransactorFor(entity).add(item.getItemStack(), o.reverse(), false).stackSize > 0)
return true; return true;
}
return false; return false;
} }
@ -166,19 +180,22 @@ public class PipeTransportItems extends PipeTransport {
HashSet<Integer> toRemove = new HashSet<Integer>(); HashSet<Integer> toRemove = new HashSet<Integer>();
public void scheduleRemoval(IPipedItem item) { public void scheduleRemoval(IPipedItem item) {
if (!toRemove.contains(item.getEntityId())) toRemove.add(item.getEntityId());
toRemove.add(item.getEntityId()); }
public void unscheduleRemoval(IPipedItem item) {
toRemove.remove(item.getEntityId());
} }
public void performRemoval() { public void performRemoval() {
travelingEntities.keySet().removeAll(toRemove); travelingEntities.keySet().removeAll(toRemove);
toRemove = new HashSet<Integer>(); toRemove.clear();
} }
private void moveSolids() { private void moveSolids() {
for (EntityData data : entitiesToLoad) { for (EntityData data : entitiesToLoad) {
data.item.setWorld(worldObj); data.item.setWorld(worldObj);
travelingEntities.put(new Integer(data.item.getEntityId()), data); travelingEntities.put(data.item.getEntityId(), data);
} }
entitiesToLoad.clear(); entitiesToLoad.clear();
@ -191,7 +208,7 @@ public class PipeTransportItems extends PipeTransport {
continue; continue;
} }
Position motion = new Position(0, 0, 0, data.orientation); Position motion = new Position(0, 0, 0, data.toCenter ? data.input : data.output);
motion.moveForwards(data.item.getSpeed()); motion.moveForwards(data.item.getSpeed());
data.item.setPosition(data.item.getPosition().x + motion.x, data.item.getPosition().y + motion.y, data.item.getPosition().z + motion.z); data.item.setPosition(data.item.getPosition().x + motion.x, data.item.getPosition().y + motion.y, data.item.getPosition().z + motion.z);
@ -200,33 +217,28 @@ public class PipeTransportItems extends PipeTransport {
data.toCenter = false; data.toCenter = false;
// Reajusting to the middle // Reajusting to the middle
data.item.setPosition(xCoord + 0.5, yCoord + Utils.getPipeFloorOf(data.item.getItemStack()), zCoord + 0.5);
data.item.setPosition(xCoord + 0.5, yCoord + Utils.getPipeFloorOf(data.item.getItemStack()), zCoord + +0.5); if (data.output == Orientations.Unknown) {
Orientations nextOrientation = resolveDestination(data);
if (nextOrientation == Orientations.Unknown) {
if (travelHook != null) if (travelHook != null)
travelHook.drop(this, data); travelHook.drop(this, data);
EntityItem dropped = null; EntityItem dropped = null;
if (!toRemove.contains(data.item.getEntityId())) if (!toRemove.contains(data.item.getEntityId()))
dropped = data.item.toEntityItem(data.orientation); dropped = data.item.toEntityItem(data.input);
scheduleRemoval(data.item); scheduleRemoval(data.item);
if (dropped != null) if (dropped != null)
onDropped(dropped); onDropped(dropped);
} else { } else {
data.orientation = nextOrientation;
if (travelHook != null) if (travelHook != null)
travelHook.centerReached(this, data); travelHook.centerReached(this, data);
} }
} else if (!data.toCenter && endReached(data)) { } else if (!data.toCenter && endReached(data)) {
Position destPos = new Position(xCoord, yCoord, zCoord, data.orientation); Position destPos = new Position(xCoord, yCoord, zCoord, data.output);
destPos.moveForwards(1.0); destPos.moveForwards(1.0);
@ -249,31 +261,28 @@ public class PipeTransportItems extends PipeTransport {
private void handleTileReached(EntityData data, TileEntity tile) { private void handleTileReached(EntityData data, TileEntity tile) {
if (tile instanceof IPipeEntry) if (tile instanceof IPipeEntry)
((IPipeEntry) tile).entityEntering(data.item, data.orientation); ((IPipeEntry) tile).entityEntering(data.item, data.output);
else if (tile instanceof TileGenericPipe && ((TileGenericPipe) tile).pipe.transport instanceof PipeTransportItems) { else if (tile instanceof TileGenericPipe && ((TileGenericPipe) tile).pipe.transport instanceof PipeTransportItems) {
TileGenericPipe pipe = (TileGenericPipe) tile; TileGenericPipe pipe = (TileGenericPipe) tile;
((PipeTransportItems) pipe.pipe.transport).entityEntering(data.item, data.output);
((PipeTransportItems) pipe.pipe.transport).entityEntering(data.item, data.orientation);
} else if (tile instanceof IInventory) { } else if (tile instanceof IInventory) {
ItemStack added = Transactor.getTransactorFor(tile).add(data.item.getItemStack(), data.orientation.reverse(), true); if (!CoreProxy.proxy.isRenderWorld(worldObj)) {
ItemStack added = Transactor.getTransactorFor(tile).add(data.item.getItemStack(), data.output.reverse(), true);
if (!CoreProxy.proxy.isRenderWorld(worldObj)) data.item.getItemStack().stackSize -= added.stackSize;
if(added.stackSize >= data.item.getItemStack().stackSize)
data.item.remove();
else {
data.item.getItemStack().stackSize -= added.stackSize;
EntityItem dropped = data.item.toEntityItem(data.orientation);
if (dropped != null) if(data.item.getItemStack().stackSize > 0) {
// On SMP, the client side doesn't actually drops data.toCenter = true;
// items data.input = data.output.reverse();
onDropped(dropped); unscheduleRemoval(data.item);
entityEntering(data.item, data.output.reverse());
} }
}
} else { } else {
if (travelHook != null) if (travelHook != null)
travelHook.drop(this, data); travelHook.drop(this, data);
EntityItem dropped = data.item.toEntityItem(data.orientation); EntityItem dropped = data.item.toEntityItem(data.output);
if (dropped != null) if (dropped != null)
// On SMP, the client side doesn't actually drops // On SMP, the client side doesn't actually drops
@ -304,17 +313,17 @@ public class PipeTransportItems extends PipeTransport {
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbttagcompound) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbttagcompound); super.readFromNBT(nbt);
NBTTagList nbttaglist = nbttagcompound.getTagList("travelingEntities"); NBTTagList nbttaglist = nbt.getTagList("travelingEntities");
for (int j = 0; j < nbttaglist.tagCount(); ++j) for (int j = 0; j < nbttaglist.tagCount(); ++j)
try { try {
NBTTagCompound nbttagcompound2 = (NBTTagCompound) nbttaglist.tagAt(j); NBTTagCompound dataTag = (NBTTagCompound) nbttaglist.tagAt(j);
IPipedItem entity = new EntityPassiveItem(null); IPipedItem entity = new EntityPassiveItem(null);
entity.readFromNBT(nbttagcompound2); entity.readFromNBT(dataTag);
if (entity.isCorrupted()) { if (entity.isCorrupted()) {
entity.remove(); entity.remove();
@ -323,8 +332,9 @@ public class PipeTransportItems extends PipeTransport {
entity.setContainer(container); entity.setContainer(container);
EntityData data = new EntityData(entity, Orientations.values()[nbttagcompound2.getInteger("orientation")]); EntityData data = new EntityData(entity, Orientations.values()[dataTag.getInteger("input")]);
data.toCenter = nbttagcompound2.getBoolean("toCenter"); data.output = Orientations.values()[dataTag.getInteger("output")];
data.toCenter = dataTag.getBoolean("toCenter");
entitiesToLoad.add(data); entitiesToLoad.add(data);
} catch (Throwable t) { } catch (Throwable t) {
@ -335,43 +345,21 @@ public class PipeTransportItems extends PipeTransport {
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbttagcompound) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbttagcompound); super.writeToNBT(nbt);
NBTTagList nbttaglist = new NBTTagList(); NBTTagList nbttaglist = new NBTTagList();
for (EntityData data : travelingEntities.values()) { for (EntityData data : travelingEntities.values()) {
NBTTagCompound nbttagcompound2 = new NBTTagCompound(); NBTTagCompound dataTag = new NBTTagCompound();
nbttaglist.appendTag(nbttagcompound2); nbttaglist.appendTag(dataTag);
data.item.writeToNBT(nbttagcompound2); data.item.writeToNBT(dataTag);
nbttagcompound2.setBoolean("toCenter", data.toCenter); dataTag.setBoolean("toCenter", data.toCenter);
nbttagcompound2.setInteger("orientation", data.orientation.ordinal()); dataTag.setInteger("input", data.input.ordinal());
dataTag.setInteger("output", data.output.ordinal());
} }
nbttagcompound.setTag("travelingEntities", nbttaglist); nbt.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 (CoreProxy.proxy.isRenderWorld(worldObj) || CoreProxy.proxy.isSimulating(worldObj))
{
i = Math.abs(data.item.getEntityId() + xCoord + yCoord + zCoord + data.item.getDeterministicRandomization())
% listOfPossibleMovements.size();
data.item.setDeterministicRandomization(data.item.getDeterministicRandomization() * 11);
}
else
i = worldObj.rand.nextInt(listOfPossibleMovements.size());
return listOfPossibleMovements.get(i);
}
} }
protected void doWork() {} protected void doWork() {}
@ -386,43 +374,48 @@ public class PipeTransportItems extends PipeTransport {
if (packet.getID() != PacketIds.PIPE_CONTENTS) if (packet.getID() != PacketIds.PIPE_CONTENTS)
return; return;
IPipedItem item = EntityPassiveItem.getOrCreate(worldObj, packet.getEntityId()); EntityData data = travelingEntities.remove(packet.getEntityId());
IPipedItem item = null;
if(data == null) {
item = EntityPassiveItem.getOrCreate(worldObj, packet.getEntityId());
} else {
item = data.item;
}
item.setItemStack(new ItemStack(packet.getItemId(), packet.getStackSize(), packet.getItemDamage())); item.setItemStack(new ItemStack(packet.getItemId(), packet.getStackSize(), packet.getItemDamage()));
item.setPosition(packet.getPosX(), packet.getPosY(), packet.getPosZ()); if(item.getPosition() == null)
item.setPosition(packet.getPosX(), packet.getPosY(), packet.getPosZ());
item.setSpeed(packet.getSpeed()); item.setSpeed(packet.getSpeed());
item.setDeterministicRandomization(packet.getRandomization());
if (item.getContainer() != this.container || !travelingEntities.containsKey(item.getEntityId())) { if (item.getContainer() != null && item.getContainer() != container) {
((PipeTransportItems) ((TileGenericPipe) item.getContainer()).pipe.transport).scheduleRemoval(item);
if (item.getContainer() != null)
((PipeTransportItems) ((TileGenericPipe) item.getContainer()).pipe.transport).scheduleRemoval(item);
travelingEntities.put(new Integer(item.getEntityId()), new EntityData(item, packet.getOrientation()));
item.setContainer(container); item.setContainer(container);
}
} else data = new EntityData(item, packet.getInputOrientation());
travelingEntities.get(new Integer(item.getEntityId())).orientation = packet.getOrientation(); data.output = packet.getOutputOrientation();
travelingEntities.put(item.getEntityId(), data);
} }
/** /**
* Creates a packet describing a stack of items inside a pipe. * Creates a packet describing a stack of items inside a pipe.
* *
* @param item * @param data
* @param orientation
* @return * @return
*/ */
public Packet createItemPacket(IPipedItem item, Orientations orientation) { public Packet createItemPacket(EntityData data) {
PacketPipeTransportContent packet = new PacketPipeTransportContent(container.xCoord, container.yCoord, container.zCoord, data);
item.setDeterministicRandomization(item.getDeterministicRandomization() + worldObj.rand.nextInt(6));
PacketPipeTransportContent packet = new PacketPipeTransportContent(container.xCoord, container.yCoord, container.zCoord,
item, orientation);
return packet.getPacket(); return packet.getPacket();
} }
private void sendItemPacket(EntityData data) {
int dimension = worldObj.provider.dimensionId;
PacketDispatcher.sendPacketToAllAround(xCoord, yCoord, zCoord, DefaultProps.NETWORK_UPDATE_RANGE, dimension, createItemPacket(data));
}
public int getNumberOfItems() { public int getNumberOfItems() {
return travelingEntities.size(); return travelingEntities.size();
} }
@ -432,7 +425,6 @@ public class PipeTransportItems extends PipeTransport {
} }
protected void neighborChange() { protected void neighborChange() {
} }
@Override @Override

View file

@ -13,7 +13,6 @@ import net.minecraft.src.World;
import buildcraft.core.network.PacketCoordinates; import buildcraft.core.network.PacketCoordinates;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketNBT; import buildcraft.core.network.PacketNBT;
import buildcraft.core.network.PacketPipeTransportContent;
import buildcraft.core.network.PacketSlotChange; import buildcraft.core.network.PacketSlotChange;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.PacketUpdate;
import buildcraft.transport.PipeTransportItems; import buildcraft.transport.PipeTransportItems;

View file

@ -0,0 +1,81 @@
package buildcraft.transport.network;
import buildcraft.api.core.Orientations;
import buildcraft.api.transport.IPipedItem;
import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketUpdate;
import buildcraft.transport.EntityData;
import java.util.EnumSet;
public class PacketPipeTransportContent extends PacketUpdate {
public PacketPipeTransportContent() {
super(PacketIds.PIPE_CONTENTS);
}
public PacketPipeTransportContent(int x, int y, int z, EntityData data) {
this();
this.posX = x;
this.posY = y;
this.posZ = z;
this.payload = new PacketPayload(6, 4, 0);
payload.intPayload[0] = data.item.getEntityId();
payload.intPayload[1] = data.input.ordinal();
payload.intPayload[2] = data.output.ordinal();
payload.intPayload[3] = data.item.getItemStack().itemID;
payload.intPayload[4] = data.item.getItemStack().stackSize;
payload.intPayload[5] = data.item.getItemStack().getItemDamage();
payload.floatPayload[0] = (float) data.item.getPosition().x;
payload.floatPayload[1] = (float) data.item.getPosition().y;
payload.floatPayload[2] = (float) data.item.getPosition().z;
payload.floatPayload[3] = data.item.getSpeed();
}
public int getEntityId() {
return payload.intPayload[0];
}
public Orientations getInputOrientation() {
return Orientations.values()[payload.intPayload[1]];
}
public Orientations getOutputOrientation() {
return Orientations.values()[payload.intPayload[2]];
}
public int getItemId() {
return payload.intPayload[3];
}
public int getStackSize() {
return payload.intPayload[4];
}
public int getItemDamage() {
return payload.intPayload[5];
}
public double getPosX() {
return payload.floatPayload[0];
}
public double getPosY() {
return payload.floatPayload[1];
}
public double getPosZ() {
return payload.floatPayload[2];
}
public float getSpeed() {
return payload.floatPayload[3];
}
}