Major pipe routing and net sync rework
This commit is contained in:
parent
7e06d2c2d7
commit
0c8ac25122
9 changed files with 231 additions and 215 deletions
|
@ -53,21 +53,25 @@ public interface IPipedItem {
|
|||
/**
|
||||
* @return the synchroTracker
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract SafeTimeTracker getSynchroTracker();
|
||||
|
||||
/**
|
||||
* @param synchroTracker the synchroTracker to set
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract void setSynchroTracker(SafeTimeTracker synchroTracker);
|
||||
|
||||
/**
|
||||
* @return the deterministicRandomization
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract int getDeterministicRandomization();
|
||||
|
||||
/**
|
||||
* @param deterministicRandomization the deterministicRandomization to set
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract void setDeterministicRandomization(int deterministicRandomization);
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,9 +11,11 @@ import net.minecraft.src.World;
|
|||
|
||||
public abstract class PipeManager {
|
||||
|
||||
@Deprecated
|
||||
private static TreeMap<Integer, IPipedItem> allServerEntities = new TreeMap<Integer, IPipedItem>();
|
||||
@Deprecated
|
||||
private static TreeMap<Integer, IPipedItem> allClientEntities = new TreeMap<Integer, IPipedItem>();
|
||||
|
||||
|
||||
public static List<IExtractionHandler> extractionHandlers = new ArrayList<IExtractionHandler>();
|
||||
|
||||
public static void registerExtractionHandler(IExtractionHandler handler) {
|
||||
|
@ -35,7 +37,8 @@ public abstract class PipeManager {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static TreeMap<Integer, IPipedItem> getAllEntities(){
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
|
||||
return allClientEntities;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/**
|
||||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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
|
||||
* 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.transport.IPassiveItemContribution;
|
||||
import buildcraft.api.transport.IPipedItem;
|
||||
import buildcraft.api.transport.PipeManager;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
|
||||
import net.minecraft.src.EntityItem;
|
||||
|
@ -39,8 +38,10 @@ public class EntityPassiveItem implements IPipedItem {
|
|||
|
||||
protected TileEntity container;
|
||||
|
||||
@Deprecated
|
||||
protected SafeTimeTracker synchroTracker = new SafeTimeTracker();
|
||||
|
||||
@Deprecated
|
||||
protected int deterministicRandomization = 0;
|
||||
|
||||
protected Position position;
|
||||
|
@ -53,7 +54,7 @@ public class EntityPassiveItem implements IPipedItem {
|
|||
|
||||
public EntityPassiveItem(World world, int id) {
|
||||
setEntityId(id);
|
||||
PipeManager.getAllEntities().put(getEntityId(), this);
|
||||
// PipeManager.getAllEntities().put(getEntityId(), this);
|
||||
worldObj = world;
|
||||
}
|
||||
|
||||
|
@ -70,11 +71,11 @@ public class EntityPassiveItem implements IPipedItem {
|
|||
|
||||
/* CREATING & CACHING */
|
||||
public static IPipedItem getOrCreate(World world, int id) {
|
||||
if (PipeManager.getAllEntities().containsKey(id)) {
|
||||
return PipeManager.getAllEntities().get(id);
|
||||
} else {
|
||||
// if (PipeManager.getAllEntities().containsKey(id)) {
|
||||
// return PipeManager.getAllEntities().get(id);
|
||||
// } else {
|
||||
return new EntityPassiveItem(world, id);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -82,9 +83,9 @@ public class EntityPassiveItem implements IPipedItem {
|
|||
*/
|
||||
@Override
|
||||
public void remove() {
|
||||
if (PipeManager.getAllEntities().containsKey(getEntityId())) {
|
||||
PipeManager.getAllEntities().remove(getEntityId());
|
||||
}
|
||||
// if (PipeManager.getAllEntities().containsKey(getEntityId())) {
|
||||
// PipeManager.getAllEntities().remove(getEntityId());
|
||||
// }
|
||||
}
|
||||
|
||||
/* GETTING & SETTING */
|
||||
|
@ -103,7 +104,7 @@ public class EntityPassiveItem implements IPipedItem {
|
|||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @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()
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public SafeTimeTracker getSynchroTracker() {
|
||||
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)
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setSynchroTracker(SafeTimeTracker synchroTracker) {
|
||||
this.synchroTracker = synchroTracker;
|
||||
}
|
||||
|
@ -180,6 +183,7 @@ public class EntityPassiveItem implements IPipedItem {
|
|||
* @see net.minecraft.src.buildcraft.api.IPipedItem#getDeterministicRandomization()
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getDeterministicRandomization() {
|
||||
return deterministicRandomization;
|
||||
}
|
||||
|
@ -188,6 +192,7 @@ public class EntityPassiveItem implements IPipedItem {
|
|||
* @see net.minecraft.src.buildcraft.api.IPipedItem#setDeterministicRandomization(int)
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setDeterministicRandomization(int deterministicRandomization) {
|
||||
this.deterministicRandomization = deterministicRandomization;
|
||||
}
|
||||
|
@ -216,8 +221,8 @@ public class EntityPassiveItem implements IPipedItem {
|
|||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
setPosition(nbttagcompound.getDouble("x"),
|
||||
nbttagcompound.getDouble("y"),
|
||||
nbttagcompound.getDouble("z"));
|
||||
|
||||
nbttagcompound.getDouble("z"));
|
||||
|
||||
setSpeed(nbttagcompound.getFloat("speed"));
|
||||
setItemStack(ItemStack.loadItemStackFromNBT(nbttagcompound.getCompoundTag("Item")));
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
|
@ -2,18 +2,23 @@ package buildcraft.transport;
|
|||
|
||||
import buildcraft.api.core.Orientations;
|
||||
import buildcraft.api.transport.IPipedItem;
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class EntityData {
|
||||
|
||||
// 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 Orientations orientation;
|
||||
public Orientations input;
|
||||
public Orientations output = Orientations.Unknown;
|
||||
|
||||
public EnumSet<Orientations> blacklist = EnumSet.noneOf(Orientations.class);
|
||||
|
||||
public EntityData(IPipedItem citem, Orientations orientation) {
|
||||
item = citem;
|
||||
|
||||
this.orientation = orientation;
|
||||
this.input = orientation;
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ import buildcraft.api.gates.ITriggerParameter;
|
|||
import buildcraft.api.gates.Trigger;
|
||||
import buildcraft.api.gates.TriggerParameter;
|
||||
import buildcraft.api.transport.IPipe;
|
||||
import buildcraft.api.transport.IPipeConnection
|
||||
import buildcraft.api.transport.IPipeConnection;
|
||||
import buildcraft.core.IDropControlInventory;
|
||||
import buildcraft.core.network.TilePacketWrapper;
|
||||
import buildcraft.core.triggers.ActionRedstoneOutput;
|
||||
|
|
|
@ -13,7 +13,9 @@ import java.util.HashSet;
|
|||
import java.util.LinkedList;
|
||||
import java.util.TreeMap;
|
||||
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;
|
||||
|
||||
|
@ -25,14 +27,15 @@ import buildcraft.api.gates.ITrigger;
|
|||
import buildcraft.api.inventory.ISpecialInventory;
|
||||
import buildcraft.api.transport.IPipeEntry;
|
||||
import buildcraft.api.transport.IPipedItem;
|
||||
import buildcraft.api.transport.PipeManager;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.EntityPassiveItem;
|
||||
import buildcraft.core.IMachine;
|
||||
import buildcraft.core.inventory.Transactor;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketPipeTransportContent;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import buildcraft.transport.network.PacketPipeTransportContent;
|
||||
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.IInventory;
|
||||
|
@ -46,8 +49,8 @@ import net.minecraftforge.common.ISidedInventory;
|
|||
public class PipeTransportItems extends PipeTransport {
|
||||
|
||||
public boolean allowBouncing = false;
|
||||
public TreeMap<Integer, EntityData> travelingEntities = new TreeMap<Integer, EntityData>();
|
||||
private final Vector<EntityData> entitiesToLoad = new Vector<EntityData>();
|
||||
public Map<Integer, EntityData> travelingEntities = new TreeMap<Integer, EntityData>();
|
||||
private final List<EntityData> entitiesToLoad = new ArrayList<EntityData>();
|
||||
|
||||
// TODO: generalize the use of this hook in particular for obsidian pipe
|
||||
public IItemTravelingHook travelHook;
|
||||
|
@ -77,8 +80,11 @@ public class PipeTransportItems extends PipeTransport {
|
|||
|
||||
readjustSpeed(item);
|
||||
|
||||
if (!travelingEntities.containsKey(new Integer(item.getEntityId()))) {
|
||||
travelingEntities.put(new Integer(item.getEntityId()), new EntityData(item, orientation));
|
||||
EntityData data = travelingEntities.get(item.getEntityId());
|
||||
|
||||
if (data == null) {
|
||||
data = new EntityData(item, orientation);
|
||||
travelingEntities.put(item.getEntityId(), data);
|
||||
|
||||
if (item.getContainer() != null && item.getContainer() != this.container)
|
||||
((PipeTransportItems) ((TileGenericPipe) item.getContainer()).pipe.transport).scheduleRemoval(item);
|
||||
|
@ -91,20 +97,16 @@ public class PipeTransportItems extends PipeTransport {
|
|||
if (orientation != Orientations.YPos && orientation != Orientations.YNeg)
|
||||
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)
|
||||
((IPipeTransportItemsHook) container.pipe).entityEntered(item, orientation);
|
||||
|
||||
if (!worldObj.isRemote && item.getSynchroTracker().markTimeIfDelay(worldObj, 6 * BuildCraftCore.updateFactor)) {
|
||||
int dimension = worldObj.provider.dimensionId;
|
||||
PacketDispatcher.sendPacketToAllAround(xCoord, yCoord, zCoord, DefaultProps.NETWORK_UPDATE_RANGE, dimension, createItemPacket(item, orientation));
|
||||
if (!worldObj.isRemote) {
|
||||
sendItemPacket(data);
|
||||
}
|
||||
|
||||
// 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) {
|
||||
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
|
||||
* 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>();
|
||||
|
||||
data.blacklist.add(data.input.reverse());
|
||||
|
||||
for (Orientations o : Orientations.dirs())
|
||||
if (o != pos.orientation.reverse() && container.pipe.outputOpen(o))
|
||||
if (canReceivePipeObjects(o, item))
|
||||
if (!data.blacklist.contains(o) && container.pipe.outputOpen(o))
|
||||
if (canReceivePipeObjects(o, data.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 (canReceivePipeObjects(data.input.reverse(), data.item))
|
||||
result.add(data.input.reverse());
|
||||
}
|
||||
|
||||
if (this.container.pipe instanceof IPipeTransportItemsHook)
|
||||
result = ((IPipeTransportItemsHook) this.container.pipe).filterPossibleMovements(result, pos, item);
|
||||
if (this.container.pipe instanceof IPipeTransportItemsHook) {
|
||||
Position pos = new Position(xCoord, yCoord, zCoord, data.input);
|
||||
result = ((IPipeTransportItemsHook) this.container.pipe).filterPossibleMovements(result, pos, data.item);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -146,14 +159,15 @@ public class PipeTransportItems extends PipeTransport {
|
|||
if (!Utils.checkPipesConnections(entity, container))
|
||||
return false;
|
||||
|
||||
if (entity instanceof TileGenericPipe)
|
||||
if (container.pipe.transport instanceof PipeTransportItems)
|
||||
return container.pipe.transport.inputOpen(o);
|
||||
if (entity instanceof IPipeEntry)
|
||||
return ((IPipeEntry) entity).acceptItems();
|
||||
if (entity instanceof IInventory)
|
||||
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(Transactor.getTransactorFor(entity).add(item.getItemStack(), o.reverse(), false).stackSize > 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -166,19 +180,22 @@ public class PipeTransportItems extends PipeTransport {
|
|||
HashSet<Integer> toRemove = new HashSet<Integer>();
|
||||
|
||||
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() {
|
||||
travelingEntities.keySet().removeAll(toRemove);
|
||||
toRemove = new HashSet<Integer>();
|
||||
toRemove.clear();
|
||||
}
|
||||
|
||||
private void moveSolids() {
|
||||
for (EntityData data : entitiesToLoad) {
|
||||
data.item.setWorld(worldObj);
|
||||
travelingEntities.put(new Integer(data.item.getEntityId()), data);
|
||||
travelingEntities.put(data.item.getEntityId(), data);
|
||||
}
|
||||
|
||||
entitiesToLoad.clear();
|
||||
|
@ -191,7 +208,7 @@ public class PipeTransportItems extends PipeTransport {
|
|||
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());
|
||||
|
||||
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;
|
||||
|
||||
// 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);
|
||||
|
||||
Orientations nextOrientation = resolveDestination(data);
|
||||
|
||||
if (nextOrientation == Orientations.Unknown) {
|
||||
if (data.output == Orientations.Unknown) {
|
||||
if (travelHook != null)
|
||||
travelHook.drop(this, data);
|
||||
|
||||
EntityItem dropped = null;
|
||||
|
||||
if (!toRemove.contains(data.item.getEntityId()))
|
||||
dropped = data.item.toEntityItem(data.orientation);
|
||||
dropped = data.item.toEntityItem(data.input);
|
||||
|
||||
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);
|
||||
Position destPos = new Position(xCoord, yCoord, zCoord, data.output);
|
||||
|
||||
destPos.moveForwards(1.0);
|
||||
|
||||
|
@ -249,31 +261,28 @@ public class PipeTransportItems extends PipeTransport {
|
|||
|
||||
private void handleTileReached(EntityData data, TileEntity tile) {
|
||||
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) {
|
||||
TileGenericPipe pipe = (TileGenericPipe) tile;
|
||||
|
||||
((PipeTransportItems) pipe.pipe.transport).entityEntering(data.item, data.orientation);
|
||||
((PipeTransportItems) pipe.pipe.transport).entityEntering(data.item, data.output);
|
||||
} 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))
|
||||
if(added.stackSize >= data.item.getItemStack().stackSize)
|
||||
data.item.remove();
|
||||
else {
|
||||
data.item.getItemStack().stackSize -= added.stackSize;
|
||||
EntityItem dropped = data.item.toEntityItem(data.orientation);
|
||||
data.item.getItemStack().stackSize -= added.stackSize;
|
||||
|
||||
if (dropped != null)
|
||||
// On SMP, the client side doesn't actually drops
|
||||
// items
|
||||
onDropped(dropped);
|
||||
if(data.item.getItemStack().stackSize > 0) {
|
||||
data.toCenter = true;
|
||||
data.input = data.output.reverse();
|
||||
unscheduleRemoval(data.item);
|
||||
entityEntering(data.item, data.output.reverse());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (travelHook != null)
|
||||
travelHook.drop(this, data);
|
||||
|
||||
EntityItem dropped = data.item.toEntityItem(data.orientation);
|
||||
EntityItem dropped = data.item.toEntityItem(data.output);
|
||||
|
||||
if (dropped != null)
|
||||
// On SMP, the client side doesn't actually drops
|
||||
|
@ -304,17 +313,17 @@ public class PipeTransportItems extends PipeTransport {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("travelingEntities");
|
||||
NBTTagList nbttaglist = nbt.getTagList("travelingEntities");
|
||||
|
||||
for (int j = 0; j < nbttaglist.tagCount(); ++j)
|
||||
try {
|
||||
NBTTagCompound nbttagcompound2 = (NBTTagCompound) nbttaglist.tagAt(j);
|
||||
NBTTagCompound dataTag = (NBTTagCompound) nbttaglist.tagAt(j);
|
||||
|
||||
IPipedItem entity = new EntityPassiveItem(null);
|
||||
entity.readFromNBT(nbttagcompound2);
|
||||
entity.readFromNBT(dataTag);
|
||||
|
||||
if (entity.isCorrupted()) {
|
||||
entity.remove();
|
||||
|
@ -323,8 +332,9 @@ public class PipeTransportItems extends PipeTransport {
|
|||
|
||||
entity.setContainer(container);
|
||||
|
||||
EntityData data = new EntityData(entity, Orientations.values()[nbttagcompound2.getInteger("orientation")]);
|
||||
data.toCenter = nbttagcompound2.getBoolean("toCenter");
|
||||
EntityData data = new EntityData(entity, Orientations.values()[dataTag.getInteger("input")]);
|
||||
data.output = Orientations.values()[dataTag.getInteger("output")];
|
||||
data.toCenter = dataTag.getBoolean("toCenter");
|
||||
|
||||
entitiesToLoad.add(data);
|
||||
} catch (Throwable t) {
|
||||
|
@ -335,43 +345,21 @@ public class PipeTransportItems extends PipeTransport {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
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 dataTag = new NBTTagCompound();
|
||||
nbttaglist.appendTag(dataTag);
|
||||
data.item.writeToNBT(dataTag);
|
||||
dataTag.setBoolean("toCenter", data.toCenter);
|
||||
dataTag.setInteger("input", data.input.ordinal());
|
||||
dataTag.setInteger("output", data.output.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 (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);
|
||||
}
|
||||
nbt.setTag("travelingEntities", nbttaglist);
|
||||
}
|
||||
|
||||
protected void doWork() {}
|
||||
|
@ -386,43 +374,48 @@ public class PipeTransportItems extends PipeTransport {
|
|||
if (packet.getID() != PacketIds.PIPE_CONTENTS)
|
||||
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.setPosition(packet.getPosX(), packet.getPosY(), packet.getPosZ());
|
||||
if(item.getPosition() == null)
|
||||
item.setPosition(packet.getPosX(), packet.getPosY(), packet.getPosZ());
|
||||
|
||||
item.setSpeed(packet.getSpeed());
|
||||
item.setDeterministicRandomization(packet.getRandomization());
|
||||
|
||||
if (item.getContainer() != this.container || !travelingEntities.containsKey(item.getEntityId())) {
|
||||
|
||||
if (item.getContainer() != null)
|
||||
((PipeTransportItems) ((TileGenericPipe) item.getContainer()).pipe.transport).scheduleRemoval(item);
|
||||
|
||||
travelingEntities.put(new Integer(item.getEntityId()), new EntityData(item, packet.getOrientation()));
|
||||
if (item.getContainer() != null && item.getContainer() != container) {
|
||||
((PipeTransportItems) ((TileGenericPipe) item.getContainer()).pipe.transport).scheduleRemoval(item);
|
||||
item.setContainer(container);
|
||||
}
|
||||
|
||||
} else
|
||||
travelingEntities.get(new Integer(item.getEntityId())).orientation = packet.getOrientation();
|
||||
|
||||
data = new EntityData(item, packet.getInputOrientation());
|
||||
data.output = packet.getOutputOrientation();
|
||||
travelingEntities.put(item.getEntityId(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a packet describing a stack of items inside a pipe.
|
||||
*
|
||||
* @param item
|
||||
* @param orientation
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public Packet createItemPacket(IPipedItem item, Orientations orientation) {
|
||||
|
||||
item.setDeterministicRandomization(item.getDeterministicRandomization() + worldObj.rand.nextInt(6));
|
||||
PacketPipeTransportContent packet = new PacketPipeTransportContent(container.xCoord, container.yCoord, container.zCoord,
|
||||
item, orientation);
|
||||
|
||||
public Packet createItemPacket(EntityData data) {
|
||||
PacketPipeTransportContent packet = new PacketPipeTransportContent(container.xCoord, container.yCoord, container.zCoord, data);
|
||||
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() {
|
||||
return travelingEntities.size();
|
||||
}
|
||||
|
@ -432,7 +425,6 @@ public class PipeTransportItems extends PipeTransport {
|
|||
}
|
||||
|
||||
protected void neighborChange() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,7 +13,6 @@ import net.minecraft.src.World;
|
|||
import buildcraft.core.network.PacketCoordinates;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketNBT;
|
||||
import buildcraft.core.network.PacketPipeTransportContent;
|
||||
import buildcraft.core.network.PacketSlotChange;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.transport.PipeTransportItems;
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue