Merged EntityData and EntityPassiveItem

They have been replaced by TravelingItem. Which means yes, I broke the
various pipe hooks again.

Additionally IPipedItem and IEntityPassiveItemContribution have been
deleted. Contributions were replaced by a simple NBTCompoundTag field in
TravelingItem (which is essentially all that contributions were anyway).
This commit is contained in:
CovertJaguar 2013-07-27 05:59:57 -07:00
parent d9636a7455
commit d62148bb07
21 changed files with 495 additions and 815 deletions

View file

@ -1,20 +0,0 @@
/**
* Copyright (c) SpaceToad, 2012
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.transport;
import net.minecraft.nbt.NBTTagCompound;
public interface IPassiveItemContribution {
public void readFromNBT(NBTTagCompound nbttagcompound);
public void writeToNBT(NBTTagCompound nbttagcompound);
}

View file

@ -1,51 +0,0 @@
package buildcraft.transport;
import buildcraft.core.utils.EnumColor;
import java.util.EnumSet;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
public class EntityData {
// TODO: Move passive data here too, like position, speed and all?
// TODO: Create an object pool?
public boolean toCenter = true;
public final IPipedItem item;
public EnumColor color;
public ForgeDirection input = ForgeDirection.UNKNOWN;
public ForgeDirection output = ForgeDirection.UNKNOWN;
public EnumSet<ForgeDirection> blacklist = EnumSet.noneOf(ForgeDirection.class);
public EntityData(IPipedItem item, ForgeDirection orientation) {
this.item = item;
this.input = orientation;
}
public EntityData(IPipedItem item) {
this.item = item;
}
public void reset() {
toCenter = true;
blacklist.clear();
output = ForgeDirection.UNKNOWN;
}
public void writeToNBT(NBTTagCompound data) {
data.setBoolean("toCenter", toCenter);
data.setInteger("input", input.ordinal());
data.setInteger("output", output.ordinal());
data.setByte("color", color != null ? (byte) color.ordinal() : -1);
}
public void readFromNBT(NBTTagCompound data) {
toCenter = data.getBoolean("toCenter");
input = ForgeDirection.getOrientation(data.getInteger("input"));
output = ForgeDirection.getOrientation(data.getInteger("output"));
byte c = data.getByte("color");
if (c != -1)
color = EnumColor.fromId(c);
}
}

View file

@ -1,366 +0,0 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport;
import buildcraft.BuildCraftCore;
import buildcraft.api.core.Position;
import buildcraft.api.transport.IPassiveItemContribution;
import buildcraft.core.proxy.CoreProxy;
import java.util.TreeMap;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
public class EntityPassiveItem implements IPipedItem {
private TreeMap<String, IPassiveItemContribution> contributions = new TreeMap<String, IPassiveItemContribution>();
protected static int maxId = 0;
protected World worldObj;
protected float speed = 0.01F;
protected ItemStack item;
protected TileEntity container;
protected Position position;
protected int entityId;
/* CONSTRUCTORS */
public EntityPassiveItem(World world) {
this(world, maxId < Short.MAX_VALUE ? ++maxId : (maxId = Short.MIN_VALUE));
}
public EntityPassiveItem(World world, int id) {
setEntityId(id);
// PipeManager.getAllEntities().put(getEntityId(), this);
worldObj = world;
}
public EntityPassiveItem(World world, double d, double d1, double d2) {
this(world);
position = new Position(d, d1, d2);
worldObj = world;
}
public EntityPassiveItem(World world, double d, double d1, double d2, ItemStack itemstack) {
this(world, d, d1, d2);
this.setItemStack(itemstack.copy());
}
/* CREATING & CACHING */
public static IPipedItem getOrCreate(World world, int id) {
// if (PipeManager.getAllEntities().containsKey(id)) {
// return PipeManager.getAllEntities().get(id);
// } else {
return new EntityPassiveItem(world, id);
// }
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#remove()
*/
@Override
public void remove() {
// if (PipeManager.getAllEntities().containsKey(getEntityId())) {
// PipeManager.getAllEntities().remove(getEntityId());
// }
}
/* GETTING & SETTING */
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#setWorld(net.minecraft.src.World)
*/
@Override
public void setWorld(World world) {
worldObj = world;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#getPosition()
*/
@Override
public Position getPosition() {
return position;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#setPosition(double, double, double)
*/
@Override
public void setPosition(double x, double y, double z) {
position = new Position(x, y, z);
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#getSpeed()
*/
@Override
public float getSpeed() {
return speed;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#setSpeed(float)
*/
@Override
public void setSpeed(float speed) {
this.speed = speed;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#getItemStack()
*/
@Override
public ItemStack getItemStack() {
return item;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#setItemStack(net.minecraft.src.ItemStack)
*/
@Override
public void setItemStack(ItemStack item) {
this.item = item;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#getContainer()
*/
@Override
public TileEntity getContainer() {
return container;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#setContainer(net.minecraft.src.TileEntity)
*/
@Override
public void setContainer(TileEntity container) {
this.container = container;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#getEntityId()
*/
@Override
public int getEntityId() {
return entityId;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#setEntityId(int)
*/
@Override
public void setEntityId(int entityId) {
this.entityId = entityId;
}
/* SAVING & LOADING */
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#readFromNBT(net.minecraft.src.NBTTagCompound)
*/
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
setPosition(nbttagcompound.getDouble("x"), nbttagcompound.getDouble("y"), nbttagcompound.getDouble("z"));
setSpeed(nbttagcompound.getFloat("speed"));
setItemStack(ItemStack.loadItemStackFromNBT(nbttagcompound.getCompoundTag("Item")));
NBTTagList contribList = nbttagcompound.getTagList("contribList");
for (int i = 0; i < contribList.tagCount(); ++i) {
NBTTagCompound cpt = (NBTTagCompound) contribList.tagAt(i);
String key = cpt.getString("key");
String className = cpt.getString("class");
if (getClass().getName().startsWith("net.minecraft.src")) {
className = "net.minecraft.src." + className;
}
try {
IPassiveItemContribution contrib = ((IPassiveItemContribution) Class.forName(className).newInstance());
contrib.readFromNBT(cpt);
contributions.put(key, contrib);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#writeToNBT(net.minecraft.src.NBTTagCompound)
*/
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setDouble("x", position.x);
nbttagcompound.setDouble("y", position.y);
nbttagcompound.setDouble("z", position.z);
nbttagcompound.setFloat("speed", getSpeed());
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
getItemStack().writeToNBT(nbttagcompound2);
nbttagcompound.setCompoundTag("Item", nbttagcompound2);
NBTTagList contribList = new NBTTagList();
for (String key : contributions.keySet()) {
IPassiveItemContribution contrib = contributions.get(key);
NBTTagCompound cpt = new NBTTagCompound();
contrib.writeToNBT(cpt);
cpt.setString("key", key);
String className = contrib.getClass().getName();
if (className.startsWith("net.minecraft.src.")) {
className = className.replace("net.minecraft.src.", "");
}
cpt.setString("class", className);
contribList.appendTag(cpt);
}
nbttagcompound.setTag("contribList", contribList);
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#toEntityItem(net.minecraft.src.buildcraft.api.Orientations)
*/
@Override
public EntityItem toEntityItem(ForgeDirection dir) {
if (!CoreProxy.proxy.isRenderWorld(worldObj)) {
if (getItemStack().stackSize <= 0)
return null;
Position motion = new Position(0, 0, 0, dir);
motion.moveForwards(0.1 + getSpeed() * 2F);
EntityItem entityitem = new EntityItem(worldObj, position.x, position.y, position.z, getItemStack());
entityitem.lifespan = BuildCraftCore.itemLifespan;
entityitem.delayBeforeCanPickup = 10;
float f3 = 0.00F + worldObj.rand.nextFloat() * 0.04F - 0.02F;
entityitem.motionX = (float) worldObj.rand.nextGaussian() * f3 + motion.x;
entityitem.motionY = (float) worldObj.rand.nextGaussian() * f3 + motion.y;
entityitem.motionZ = (float) worldObj.rand.nextGaussian() * f3 + +motion.z;
worldObj.spawnEntityInWorld(entityitem);
remove();
return entityitem;
} else
return null;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#getEntityBrightness(float)
*/
@Override
public float getEntityBrightness(float f) {
int i = MathHelper.floor_double(position.x);
int j = MathHelper.floor_double(position.z);
worldObj.getClass();
if (worldObj.blockExists(i, 128 / 2, j)) {
double d = 0.66000000000000003D;
int k = MathHelper.floor_double(position.y + d);
return worldObj.getLightBrightness(i, k, j);
} else
return 0.0F;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#isCorrupted()
*/
@Override
public boolean isCorrupted() {
return getItemStack() == null || getItemStack().stackSize <= 0 || Item.itemsList[getItemStack().itemID] == null;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#addContribution(java.lang.String, net.minecraft.src.buildcraft.api.IPassiveItemContribution)
*/
@Override
public void addContribution(String key, IPassiveItemContribution contribution) {
contributions.put(key, contribution);
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#getContribution(java.lang.String)
*/
@Override
public IPassiveItemContribution getContribution(String key) {
return contributions.get(key);
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.IPipedItem#hasContributions()
*/
@Override
public boolean hasContributions() {
return contributions.size() > 0;
}
@Override
public boolean canSinkTo(TileEntity entity) {
return true; // a passive item can sink anywhere
}
}

View file

@ -4,10 +4,10 @@ import net.minecraft.tileentity.TileEntity;
public interface IItemTravelingHook {
public void drop(PipeTransportItems transport, EntityData data);
public void drop(PipeTransportItems transport, TravelingItem item);
public void centerReached(PipeTransportItems transport, EntityData data);
public void centerReached(PipeTransportItems transport, TravelingItem item);
public void endReached(PipeTransportItems transport, EntityData data, TileEntity tile);
public void endReached(PipeTransportItems transport, TravelingItem item, TileEntity tile);
}

View file

@ -15,9 +15,9 @@ import net.minecraftforge.common.ForgeDirection;
public interface IPipeTransportItemsHook {
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, EntityData data);
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, TravelingItem item);
public void entityEntered(IPipedItem item, ForgeDirection orientation);
public void entityEntered(TravelingItem item, ForgeDirection orientation);
public void readjustSpeed(IPipedItem item);
public void readjustSpeed(TravelingItem item);
}

View file

@ -1,91 +0,0 @@
package buildcraft.transport;
import buildcraft.api.core.Position;
import buildcraft.api.transport.IPassiveItemContribution;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
public interface IPipedItem {
public abstract void remove();
/* GETTING & SETTING */
public abstract void setWorld(World world);
public abstract Position getPosition();
public abstract void setPosition(double x, double y, double z);
/**
* @return the speed
*/
public abstract float getSpeed();
/**
* @param speed
* the speed to set
*/
public abstract void setSpeed(float speed);
/**
* @return the item
*/
public abstract ItemStack getItemStack();
/**
* @param item
* the item to set
*/
public abstract void setItemStack(ItemStack item);
/**
* @return the container
*/
public abstract TileEntity getContainer();
/**
* @param container
* the container to set
*/
public abstract void setContainer(TileEntity container);
/**
* @return the entityId
*/
public abstract int getEntityId();
/**
* @param entityId
* the entityId to set
*/
public abstract void setEntityId(int entityId);
/* SAVING & LOADING */
public abstract void readFromNBT(NBTTagCompound nbttagcompound);
public abstract void writeToNBT(NBTTagCompound nbttagcompound);
public abstract EntityItem toEntityItem(ForgeDirection dir);
public abstract float getEntityBrightness(float f);
public abstract boolean isCorrupted();
public abstract void addContribution(String key, IPassiveItemContribution contribution);
public abstract IPassiveItemContribution getContribution(String key);
public abstract boolean hasContributions();
/**
* @return the can this item be moved into this specific entity type.
* (basic BuildCraft PipedItems always return true)
*/
public abstract boolean canSinkTo(TileEntity entity);
}

View file

@ -23,16 +23,18 @@ import buildcraft.core.utils.Utils;
import buildcraft.transport.network.PacketPipeTransportContent;
import buildcraft.transport.network.PacketPipeTransportNBT;
import buildcraft.transport.network.PacketSimpleId;
import com.google.common.collect.BiMap;
import com.google.common.collect.ForwardingSet;
import com.google.common.collect.HashBiMap;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import net.minecraft.entity.item.EntityItem;
@ -50,18 +52,78 @@ public class PipeTransportItems extends PipeTransport {
public static final int MAX_PIPE_STACKS = 64;
public static final int MAX_PIPE_ITEMS = 1024;
public boolean allowBouncing = false;
public Map<Integer, EntityData> travelingEntities = new HashMap<Integer, EntityData>();
private final List<EntityData> entitiesToLoad = new LinkedList<EntityData>();
private int delay = 0;
// TODO: generalize the use of this hook in particular for obsidian pipe
public IItemTravelingHook travelHook;
public final TravelerSet items = new TravelerSet();
public class TravelerSet extends ForwardingSet<TravelingItem> {
private final BiMap<Integer, TravelingItem> delegate = HashBiMap.create();
private final Set<TravelingItem> toLoad = new HashSet<TravelingItem>();
private final Set<TravelingItem> toRemove = new HashSet<TravelingItem>();
private int delay = 0;
@Override
protected Set<TravelingItem> delegate() {
return delegate.values();
}
@Override
public boolean add(TravelingItem item) {
if (delegate.containsValue(item))
return false;
item.setContainer(container);
delegate.put(item.id, item);
return true;
}
@Override
public boolean addAll(Collection<? extends TravelingItem> collection) {
boolean changed = false;
for (TravelingItem item : collection) {
changed |= add(item);
}
return changed;
}
public TravelingItem get(int id) {
return delegate.get(id);
}
private void scheduleLoad(TravelingItem item) {
delay = 2;
toLoad.add(item);
}
private void performLoad() {
if (delay > 0) {
delay--;
return;
}
addAll(toLoad);
toLoad.clear();
}
public boolean scheduleRemoval(TravelingItem item) {
return toRemove.add(item);
}
public boolean unscheduleRemoval(TravelingItem item) {
return toRemove.remove(item);
}
private void performRemoval() {
removeAll(toRemove);
toRemove.clear();
}
};
@Override
public PipeType getPipeType() {
return PipeType.ITEM;
}
public void readjustSpeed(IPipedItem item) {
public void readjustSpeed(TravelingItem item) {
if (container.pipe instanceof IPipeTransportItemsHook) {
((IPipeTransportItemsHook) container.pipe).readjustSpeed(item);
} else {
@ -69,7 +131,7 @@ public class PipeTransportItems extends PipeTransport {
}
}
public void defaultReajustSpeed(IPipedItem item) {
public void defaultReajustSpeed(TravelingItem item) {
float speed = item.getSpeed();
if (speed > Utils.pipeNormalSpeed) {
@ -83,66 +145,49 @@ public class PipeTransportItems extends PipeTransport {
item.setSpeed(speed);
}
public void entityEntering(IPipedItem item, ForgeDirection inputOrientation) {
EntityData data = travelingEntities.get(item.getEntityId());
if (data == null) {
data = new EntityData(item, inputOrientation);
}
entityEntering(data, inputOrientation);
}
public void entityEntering(EntityData data, ForgeDirection inputOrientation) {
if (data.item.isCorrupted())
public void injectItem(TravelingItem item, ForgeDirection inputOrientation) {
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;
data.reset();
data.input = inputOrientation;
item.reset();
item.input = inputOrientation;
EntityData existingData = travelingEntities.get(data.item.getEntityId());
items.add(item);
if (existingData == null) {
travelingEntities.put(data.item.getEntityId(), data);
} else {
data = existingData;
}
data.item.setContainer(container);
readjustSpeed(data.item);
readjustSpeed(item);
// Reajusting Ypos to make sure the object looks like sitting on the
// pipe.
if (inputOrientation != ForgeDirection.UP && inputOrientation != ForgeDirection.DOWN) {
data.item.setPosition(data.item.getPosition().x, container.yCoord + Utils.getPipeFloorOf(data.item.getItemStack()), data.item.getPosition().z);
item.setPosition(item.getPosition().x, container.yCoord + Utils.getPipeFloorOf(item.getItemStack()), item.getPosition().z);
}
if (!container.worldObj.isRemote) {
data.output = resolveDestination(data);
item.output = resolveDestination(item);
}
if (container.pipe instanceof IPipeTransportItemsHook) {
((IPipeTransportItemsHook) container.pipe).entityEntered(data.item, inputOrientation);
((IPipeTransportItemsHook) container.pipe).entityEntered(item, inputOrientation);
}
if (!container.worldObj.isRemote) {
sendItemPacket(data);
sendItemPacket(item);
if (travelingEntities.size() > BuildCraftTransport.groupItemsTrigger) {
if (items.size() > BuildCraftTransport.groupItemsTrigger) {
groupEntities();
}
if (travelingEntities.size() > MAX_PIPE_STACKS) {
BuildCraftCore.bcLog.log(Level.WARNING, String.format("Pipe exploded at %d,%d,%d because it had too many stacks: %d", container.xCoord, container.yCoord, container.zCoord, travelingEntities.size()));
if (items.size() > MAX_PIPE_STACKS) {
BuildCraftCore.bcLog.log(Level.WARNING, String.format("Pipe exploded at %d,%d,%d because it had too many stacks: %d", container.xCoord, container.yCoord, container.zCoord, items.size()));
destroyPipe();
return;
}
int numItems = 0;
for (EntityData ed : travelingEntities.values()) {
ItemStack stack = ed.item.getItemStack();
for (TravelingItem travellingItem : items) {
ItemStack stack = travellingItem.getItemStack();
if (stack != null && stack.stackSize > 0)
numItems += stack.stackSize;
}
@ -150,7 +195,6 @@ public class PipeTransportItems extends PipeTransport {
if (numItems > MAX_PIPE_ITEMS) {
BuildCraftCore.bcLog.log(Level.WARNING, String.format("Pipe exploded at %d,%d,%d because it had too many items: %d", container.xCoord, container.yCoord, container.zCoord, numItems));
destroyPipe();
return;
}
}
}
@ -161,44 +205,43 @@ public class PipeTransportItems extends PipeTransport {
}
/**
* Bounces the item back into the pipe without changing the
* travelingEntities map.
* Bounces the item back into the pipe without changing the items map.
*
* @param data
* @param item
*/
protected void reverseItem(EntityData data) {
if (data.item.isCorrupted())
protected void reverseItem(TravelingItem item) {
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;
unscheduleRemoval(data.item);
items.unscheduleRemoval(item);
data.toCenter = true;
data.input = data.output.getOpposite();
item.toCenter = true;
item.input = item.output.getOpposite();
readjustSpeed(data.item);
readjustSpeed(item);
// Reajusting Ypos to make sure the object looks like sitting on the
// pipe.
if (data.input != ForgeDirection.UP && data.input != ForgeDirection.DOWN) {
data.item.setPosition(data.item.getPosition().x, container.yCoord + Utils.getPipeFloorOf(data.item.getItemStack()), data.item.getPosition().z);
if (item.input != ForgeDirection.UP && item.input != ForgeDirection.DOWN) {
item.setPosition(item.getPosition().x, container.yCoord + Utils.getPipeFloorOf(item.getItemStack()), item.getPosition().z);
}
if (!container.worldObj.isRemote) {
data.output = resolveDestination(data);
item.output = resolveDestination(item);
}
if (container.pipe instanceof IPipeTransportItemsHook) {
((IPipeTransportItemsHook) container.pipe).entityEntered(data.item, data.input);
((IPipeTransportItemsHook) container.pipe).entityEntered(item, item.input);
}
if (!container.worldObj.isRemote) {
sendItemPacket(data);
sendItemPacket(item);
}
}
public ForgeDirection resolveDestination(EntityData data) {
public ForgeDirection resolveDestination(TravelingItem data) {
LinkedList<ForgeDirection> listOfPossibleMovements = getPossibleMovements(data);
if (listOfPossibleMovements.size() == 0)
@ -213,33 +256,33 @@ public class PipeTransportItems extends PipeTransport {
* Returns a list of all possible movements, that is to say adjacent
* implementers of IPipeEntry or TileEntityChest.
*/
public LinkedList<ForgeDirection> getPossibleMovements(EntityData data) {
public LinkedList<ForgeDirection> getPossibleMovements(TravelingItem item) {
LinkedList<ForgeDirection> result = new LinkedList<ForgeDirection>();
data.blacklist.add(data.input.getOpposite());
item.blacklist.add(item.input.getOpposite());
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
if (!data.blacklist.contains(o) && container.pipe.outputOpen(o))
if (canReceivePipeObjects(o, data.item)) {
if (!item.blacklist.contains(o) && container.pipe.outputOpen(o))
if (canReceivePipeObjects(o, item)) {
result.add(o);
}
}
if (result.size() == 0 && allowBouncing) {
if (canReceivePipeObjects(data.input.getOpposite(), data.item)) {
result.add(data.input.getOpposite());
if (canReceivePipeObjects(item.input.getOpposite(), item)) {
result.add(item.input.getOpposite());
}
}
if (this.container.pipe instanceof IPipeTransportItemsHook) {
Position pos = new Position(container.xCoord, container.yCoord, container.zCoord, data.input);
result = ((IPipeTransportItemsHook) this.container.pipe).filterPossibleMovements(result, pos, data);
Position pos = new Position(container.xCoord, container.yCoord, container.zCoord, item.input);
result = ((IPipeTransportItemsHook) this.container.pipe).filterPossibleMovements(result, pos, item);
}
return result;
}
public boolean canReceivePipeObjects(ForgeDirection o, IPipedItem item) {
public boolean canReceivePipeObjects(ForgeDirection o, TravelingItem item) {
TileEntity entity = container.getTile(o);
if (!Utils.checkPipesConnections(entity, container))
@ -260,130 +303,103 @@ public class PipeTransportItems extends PipeTransport {
public void updateEntity() {
moveSolids();
}
Set<Integer> toRemove = new HashSet<Integer>();
public void scheduleRemoval(IPipedItem item) {
toRemove.add(item.getEntityId());
}
public void unscheduleRemoval(IPipedItem item) {
toRemove.remove(item.getEntityId());
}
public void performRemoval() {
travelingEntities.keySet().removeAll(toRemove);
toRemove.clear();
}
private void moveSolids() {
if (delay > 0) {
delay--;
} else if (!entitiesToLoad.isEmpty()) {
for (EntityData data : entitiesToLoad) {
data.item.setWorld(container.worldObj);
data.item.setContainer(container);
travelingEntities.put(data.item.getEntityId(), data);
}
entitiesToLoad.clear();
}
performRemoval();
items.performLoad();
items.performRemoval();
for (EntityData data : travelingEntities.values()) {
if (data.item.isCorrupted()) {
scheduleRemoval(data.item);
data.item.remove();
for (TravelingItem item : items) {
if (item.isCorrupted()) {
items.scheduleRemoval(item);
continue;
}
if (data.item.getContainer() != this.container) {
scheduleRemoval(data.item);
if (item.getContainer() != this.container) {
items.scheduleRemoval(item);
continue;
}
Position motion = new Position(0, 0, 0, data.toCenter ? data.input : data.output);
motion.moveForwards(data.item.getSpeed());
Position motion = new Position(0, 0, 0, item.toCenter ? item.input : item.output);
motion.moveForwards(item.getSpeed());
Position pos = data.item.getPosition();
data.item.setPosition(pos.x + motion.x, pos.y + motion.y, pos.z + motion.z);
pos = data.item.getPosition();
Position pos = item.getPosition();
item.setPosition(pos.x + motion.x, pos.y + motion.y, pos.z + motion.z);
pos = item.getPosition();
if ((data.toCenter && middleReached(data, pos)) || outOfBounds(pos)) {
data.toCenter = false;
if ((item.toCenter && middleReached(item, pos)) || outOfBounds(pos)) {
item.toCenter = false;
// Reajusting to the middle
data.item.setPosition(container.xCoord + 0.5, container.yCoord + Utils.getPipeFloorOf(data.item.getItemStack()), container.zCoord + 0.5);
item.setPosition(container.xCoord + 0.5, container.yCoord + Utils.getPipeFloorOf(item.getItemStack()), container.zCoord + 0.5);
if (data.output == ForgeDirection.UNKNOWN) {
if (item.output == ForgeDirection.UNKNOWN) {
if (travelHook != null) {
travelHook.drop(this, data);
travelHook.drop(this, item);
}
EntityItem dropped = null;
if (!toRemove.contains(data.item.getEntityId())) {
dropped = data.item.toEntityItem(data.input);
if (items.scheduleRemoval(item)) {
dropped = item.toEntityItem(item.input);
}
scheduleRemoval(data.item);
if (dropped != null) {
onDropped(dropped);
}
} else {
if (travelHook != null) {
travelHook.centerReached(this, data);
travelHook.centerReached(this, item);
}
}
} else if (!data.toCenter && endReached(pos)) {
TileEntity tile = container.getTile(data.output);
} else if (!item.toCenter && endReached(pos)) {
TileEntity tile = container.getTile(item.output);
if (travelHook != null) {
travelHook.endReached(this, data, tile);
travelHook.endReached(this, item, tile);
}
// If the item has not been scheduled to removal by the hook
if (!toRemove.contains(data.item.getEntityId())) {
scheduleRemoval(data.item);
handleTileReached(data, tile);
if (items.scheduleRemoval(item)) {
handleTileReached(item, tile);
}
}
}
performRemoval();
items.performRemoval();
}
private boolean passToNextPipe(EntityData data, TileEntity tile) {
private boolean passToNextPipe(TravelingItem item, TileEntity tile) {
if (tile instanceof TileGenericPipe) {
TileGenericPipe pipe = (TileGenericPipe) tile;
if (BlockGenericPipe.isValid(pipe.pipe) && pipe.pipe.transport instanceof PipeTransportItems) {
((PipeTransportItems) pipe.pipe.transport).entityEntering(data, data.output);
((PipeTransportItems) pipe.pipe.transport).injectItem(item, item.output);
return true;
}
}
return false;
}
private void handleTileReached(EntityData data, TileEntity tile) {
if (passToNextPipe(data, tile)) {
private void handleTileReached(TravelingItem item, TileEntity tile) {
if (passToNextPipe(item, tile)) {
// NOOP
} else if (tile instanceof IInventory) {
if (!CoreProxy.proxy.isRenderWorld(container.worldObj)) {
ItemStack added = Transactor.getTransactorFor(tile).add(data.item.getItemStack(), data.output.getOpposite(), true);
ItemStack added = Transactor.getTransactorFor(tile).add(item.getItemStack(), item.output.getOpposite(), true);
data.item.getItemStack().stackSize -= added.stackSize;
item.getItemStack().stackSize -= added.stackSize;
if (data.item.getItemStack().stackSize > 0) {
reverseItem(data);
if (item.getItemStack().stackSize > 0) {
reverseItem(item);
}
}
} else {
if (travelHook != null) {
travelHook.drop(this, data);
travelHook.drop(this, item);
}
EntityItem dropped = data.item.toEntityItem(data.output);
EntityItem dropped = item.toEntityItem(item.output);
if (dropped != null) {
// On SMP, the client side doesn't actually drops
@ -393,9 +409,9 @@ public class PipeTransportItems extends PipeTransport {
}
}
protected boolean middleReached(EntityData entity, Position pos) {
float middleLimit = entity.item.getSpeed() * 1.01F;
return (Math.abs(container.xCoord + 0.5 - pos.x) < middleLimit && Math.abs(container.yCoord + Utils.getPipeFloorOf(entity.item.getItemStack()) - pos.y) < middleLimit && Math
protected boolean middleReached(TravelingItem item, Position pos) {
float middleLimit = item.getSpeed() * 1.01F;
return (Math.abs(container.xCoord + 0.5 - pos.x) < middleLimit && Math.abs(container.yCoord + Utils.getPipeFloorOf(item.getItemStack()) - pos.y) < middleLimit && Math
.abs(container.zCoord + 0.5 - pos.z) < middleLimit);
}
@ -421,27 +437,19 @@ public class PipeTransportItems extends PipeTransport {
try {
NBTTagCompound dataTag = (NBTTagCompound) nbttaglist.tagAt(j);
IPipedItem entity = new EntityPassiveItem(null);
entity.readFromNBT(dataTag);
TravelingItem item = new TravelingItem();
item.readFromNBT(dataTag);
if (entity.isCorrupted()) {
entity.remove();
if (item.isCorrupted()) {
continue;
}
entity.setContainer(container);
EntityData data = new EntityData(entity);
data.readFromNBT(dataTag);
entitiesToLoad.add(data);
items.scheduleLoad(item);
} catch (Throwable t) {
t.printStackTrace();
// It may be the case that entities cannot be reloaded between
// two versions - ignore these errors.
}
}
delay = 2;
}
@Override
@ -450,11 +458,10 @@ public class PipeTransportItems extends PipeTransport {
NBTTagList nbttaglist = new NBTTagList();
for (EntityData data : travelingEntities.values()) {
for (TravelingItem item : items) {
NBTTagCompound dataTag = new NBTTagCompound();
nbttaglist.appendTag(dataTag);
data.item.writeToNBT(dataTag);
data.writeToNBT(dataTag);
item.writeToNBT(dataTag);
}
nbt.setTag("travelingEntities", nbttaglist);
@ -473,26 +480,22 @@ public class PipeTransportItems extends PipeTransport {
if (packet.getID() != PacketIds.PIPE_CONTENTS)
return;
IPipedItem item;
EntityData data = travelingEntities.get(packet.getEntityId());
if (data == null) {
item = EntityPassiveItem.getOrCreate(container.worldObj, packet.getEntityId());
data = new EntityData(item);
travelingEntities.put(item.getEntityId(), data);
} else {
item = data.item;
TravelingItem item = items.get(packet.getTravellingItemId());
if (item == null) {
item = new TravelingItem(packet.getTravellingItemId());
items.add(item);
}
if (item.getItemStack() == null) {
item.setItemStack(new ItemStack(packet.getItemId(), packet.getStackSize(), packet.getItemDamage()));
if (packet.hasNBT()) {
PacketDispatcher.sendPacketToServer(new PacketSimpleId(PacketIds.REQUEST_ITEM_NBT, container.xCoord, container.yCoord, container.zCoord, packet.getEntityId()).getPacket());
PacketDispatcher.sendPacketToServer(new PacketSimpleId(PacketIds.REQUEST_ITEM_NBT, container.xCoord, container.yCoord, container.zCoord, packet.getTravellingItemId()).getPacket());
}
} else {
if (item.getItemStack().itemID != packet.getItemId() || item.getItemStack().stackSize != packet.getStackSize() || item.getItemStack().getItemDamage() != packet.getItemDamage() || item.getItemStack().hasTagCompound() != packet.hasNBT()) {
item.setItemStack(new ItemStack(packet.getItemId(), packet.getStackSize(), packet.getItemDamage()));
if (packet.hasNBT()) {
PacketDispatcher.sendPacketToServer(new PacketSimpleId(PacketIds.REQUEST_ITEM_NBT, container.xCoord, container.yCoord, container.zCoord, packet.getEntityId()).getPacket());
PacketDispatcher.sendPacketToServer(new PacketSimpleId(PacketIds.REQUEST_ITEM_NBT, container.xCoord, container.yCoord, container.zCoord, packet.getTravellingItemId()).getPacket());
}
}
}
@ -503,31 +506,29 @@ public class PipeTransportItems extends PipeTransport {
item.setSpeed(packet.getSpeed());
item.setContainer(container);
data.input = packet.getInputOrientation();
data.output = packet.getOutputOrientation();
data.color = packet.getColor();
item.input = packet.getInputOrientation();
item.output = packet.getOutputOrientation();
item.color = packet.getColor();
}
/**
* Handles the NBT tag Request from player of the entityId
* Handles the NBT tag Request from player of the id
*/
public void handleNBTRequestPacket(EntityPlayer player, int entityId) {
EntityData data = travelingEntities.get(entityId);
if (data == null || data.item == null || data.item.getItemStack() == null)
TravelingItem item = items.get(entityId);
if (item == null || item.item == null || item.getItemStack() == null)
return;
PacketDispatcher.sendPacketToPlayer(new PacketPipeTransportNBT(PacketIds.PIPE_ITEM_NBT, container.xCoord, container.yCoord, container.zCoord, entityId, data.item.getItemStack().getTagCompound()).getPacket(), (Player) player);
PacketDispatcher.sendPacketToPlayer(new PacketPipeTransportNBT(PacketIds.PIPE_ITEM_NBT, container.xCoord, container.yCoord, container.zCoord, entityId, item.getItemStack().getTagCompound()).getPacket(), (Player) player);
}
/**
* Handles the Item NBT tag information of the packet
*/
public void handleNBTPacket(PacketPipeTransportNBT packet) {
EntityData data = travelingEntities.get(packet.getEntityId());
if (data == null || data.item == null || data.item.getItemStack() == null)
TravelingItem item = items.get(packet.getEntityId());
if (item == null || item.item == null || item.getItemStack() == null)
return;
data.item.getItemStack().setTagCompound(packet.getTagCompound());
item.getItemStack().setTagCompound(packet.getTagCompound());
}
/**
@ -536,18 +537,18 @@ public class PipeTransportItems extends PipeTransport {
* @param data
* @return
*/
public Packet createItemPacket(EntityData data) {
public Packet createItemPacket(TravelingItem data) {
PacketPipeTransportContent packet = new PacketPipeTransportContent(data);
return packet.getPacket();
}
private void sendItemPacket(EntityData data) {
private void sendItemPacket(TravelingItem data) {
int dimension = container.worldObj.provider.dimensionId;
PacketDispatcher.sendPacketToAllAround(container.xCoord, container.yCoord, container.zCoord, DefaultProps.PIPE_CONTENTS_RENDER_DIST, dimension, createItemPacket(data));
}
public int getNumberOfItems() {
return travelingEntities.size();
return items.size();
}
public void onDropped(EntityItem item) {
@ -579,12 +580,11 @@ public class PipeTransportItems extends PipeTransport {
*/
public void groupEntities() {
// determine groupable entities
List<EntityData> entities = new ArrayList<EntityData>();
List<TravelingItem> entities = new ArrayList<TravelingItem>();
for (EntityData entityData : travelingEntities.values()) {
if (!entityData.item.hasContributions()
&& entityData.item.getItemStack().stackSize < entityData.item.getItemStack().getMaxStackSize()) {
entities.add(entityData);
for (TravelingItem item : items) {
if (!item.hasExtraData() && item.getItemStack().stackSize < item.getItemStack().getMaxStackSize()) {
entities.add(item);
}
}
@ -592,12 +592,12 @@ public class PipeTransportItems extends PipeTransport {
return; // nothing groupable
// sort the groupable entities to have all entities with the same id:dmg next to each other (contiguous range)
Collections.sort(entities, new Comparator<EntityData>() {
Collections.sort(entities, new Comparator<TravelingItem>() {
@Override
public int compare(EntityData a, EntityData b) {
public int compare(TravelingItem a, TravelingItem b) {
// the item id is always less than 2^15 so the int won't overflow
int itemA = (a.item.getItemStack().itemID << 16) | a.item.getItemStack().getItemDamage();
int itemB = (b.item.getItemStack().itemID << 16) | b.item.getItemStack().getItemDamage();
int itemA = (a.getItemStack().itemID << 16) | a.getItemStack().getItemDamage();
int itemB = (b.getItemStack().itemID << 16) | b.getItemStack().getItemDamage();
return itemA - itemB;
}
@ -605,10 +605,10 @@ public class PipeTransportItems extends PipeTransport {
// group the entities
int matchStart = 0;
int lastId = (entities.get(0).item.getItemStack().itemID << 16) | entities.get(0).item.getItemStack().getItemDamage();
int lastId = (entities.get(0).getItemStack().itemID << 16) | entities.get(0).getItemStack().getItemDamage();
for (int i = 1; i < entities.size(); i++) {
int id = (entities.get(i).item.getItemStack().itemID << 16) | entities.get(i).item.getItemStack().getItemDamage();
int id = (entities.get(i).getItemStack().itemID << 16) | entities.get(i).getItemStack().getItemDamage();
if (id != lastId) {
// merge within the last matching ID range
@ -631,34 +631,33 @@ public class PipeTransportItems extends PipeTransport {
* @param start start index (inclusive)
* @param end end index (exclusive)
*/
private void groupEntityRange(List<EntityData> entities, int start, int end) {
private void groupEntityRange(List<TravelingItem> entities, int start, int end) {
for (int j = start; j < end; j++) {
EntityData target = entities.get(j);
TravelingItem target = entities.get(j);
if (target == null)
continue;
for (int k = j + 1; k < end; k++) {
EntityData source = entities.get(k);
TravelingItem source = entities.get(k);
if (source == null)
continue;
// only merge if the ItemStack tags match
if (ItemStack.areItemStackTagsEqual(source.item.getItemStack(), target.item.getItemStack())) {
if (ItemStack.areItemStackTagsEqual(source.getItemStack(), target.getItemStack())) {
// merge source to target
int amount = source.item.getItemStack().stackSize;
int space = target.item.getItemStack().getMaxStackSize() - target.item.getItemStack().stackSize;
int amount = source.getItemStack().stackSize;
int space = target.getItemStack().getMaxStackSize() - target.getItemStack().stackSize;
if (amount <= space) {
// source fits completely into target
target.item.getItemStack().stackSize += amount;
target.getItemStack().stackSize += amount;
source.item.remove();
travelingEntities.remove(source.item.getEntityId());
items.remove(source);
entities.set(k, null);
} else {
target.item.getItemStack().stackSize += space;
target.getItemStack().stackSize += space;
source.item.getItemStack().stackSize -= space;
source.getItemStack().stackSize -= space;
}
if (amount >= space) {
@ -674,11 +673,11 @@ public class PipeTransportItems extends PipeTransport {
public void dropContents() {
groupEntities();
for (EntityData data : travelingEntities.values()) {
container.pipe.dropItem(data.item.getItemStack());
for (TravelingItem item : items) {
container.pipe.dropItem(item.getItemStack());
}
travelingEntities.clear();
items.clear();
}
@Override

View file

@ -342,8 +342,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
itemPos.z += 0.5;
itemPos.moveForwards(0.5);
EntityPassiveItem pipedItem = new EntityPassiveItem(worldObj, itemPos.x, itemPos.y, itemPos.z, payload);
((PipeTransportItems) pipe.transport).entityEntering(pipedItem, from.getOpposite());
TravelingItem pipedItem = new TravelingItem(itemPos.x, itemPos.y, itemPos.z, payload);
((PipeTransportItems) pipe.transport).injectItem(pipedItem, from.getOpposite());
}
return payload.stackSize;
}

View file

@ -0,0 +1,219 @@
/**
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
* 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport;
import buildcraft.BuildCraftCore;
import buildcraft.api.core.Position;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.EnumColor;
import java.util.EnumSet;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraftforge.common.ForgeDirection;
public class TravelingItem {
private static int maxId = 0;
protected float speed = 0.01F;
protected ItemStack item;
protected TileEntity container;
protected Position position;
public final int id;
public boolean toCenter = true;
public EnumColor color;
public ForgeDirection input = ForgeDirection.UNKNOWN;
public ForgeDirection output = ForgeDirection.UNKNOWN;
public final EnumSet<ForgeDirection> blacklist = EnumSet.noneOf(ForgeDirection.class);
private NBTTagCompound extraData;
/* CONSTRUCTORS */
public TravelingItem() {
this(maxId < Short.MAX_VALUE ? ++maxId : (maxId = Short.MIN_VALUE));
}
public TravelingItem(int id) {
this.id = id;
}
public TravelingItem(double x, double y, double z, ItemStack stack) {
this();
this.position = new Position(x, y, z);
this.item = stack.copy();
}
/* GETTING & SETTING */
public Position getPosition() {
return position;
}
public void setPosition(double x, double y, double z) {
position = new Position(x, y, z);
}
public float getSpeed() {
return speed;
}
public void setSpeed(float speed) {
this.speed = speed;
}
public ItemStack getItemStack() {
return item;
}
public void setItemStack(ItemStack item) {
this.item = item;
}
public TileEntity getContainer() {
return container;
}
public void setContainer(TileEntity container) {
this.container = container;
}
public NBTTagCompound getExtraData() {
if (extraData == null)
extraData = new NBTTagCompound();
return extraData;
}
public boolean hasExtraData() {
return extraData != null;
}
public void reset() {
toCenter = true;
blacklist.clear();
input = ForgeDirection.UNKNOWN;
output = ForgeDirection.UNKNOWN;
}
/* SAVING & LOADING */
public void readFromNBT(NBTTagCompound data) {
setPosition(data.getDouble("x"), data.getDouble("y"), data.getDouble("z"));
setSpeed(data.getFloat("speed"));
setItemStack(ItemStack.loadItemStackFromNBT(data.getCompoundTag("Item")));
toCenter = data.getBoolean("toCenter");
input = ForgeDirection.getOrientation(data.getInteger("input"));
output = ForgeDirection.getOrientation(data.getInteger("output"));
byte c = data.getByte("color");
if (c != -1)
color = EnumColor.fromId(c);
NBTTagList contribList = data.getTagList("contribList");
for (int i = 0; i < contribList.tagCount(); ++i) {
NBTTagCompound cpt = (NBTTagCompound) contribList.tagAt(i);
String key = cpt.getString("key");
String className = cpt.getString("class");
if (getClass().getName().startsWith("net.minecraft.src")) {
className = "net.minecraft.src." + className;
}
if (data.hasKey("extraData"))
extraData = data.getCompoundTag("extraData");
}
}
public void writeToNBT(NBTTagCompound data) {
data.setDouble("x", position.x);
data.setDouble("y", position.y);
data.setDouble("z", position.z);
data.setFloat("speed", getSpeed());
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
getItemStack().writeToNBT(nbttagcompound2);
data.setCompoundTag("Item", nbttagcompound2);
data.setBoolean("toCenter", toCenter);
data.setInteger("input", input.ordinal());
data.setInteger("output", output.ordinal());
data.setByte("color", color != null ? (byte) color.ordinal() : -1);
if (extraData != null)
data.setTag("extraData", extraData);
}
public EntityItem toEntityItem(ForgeDirection dir) {
if (container != null && !CoreProxy.proxy.isRenderWorld(container.worldObj)) {
if (getItemStack().stackSize <= 0)
return null;
Position motion = new Position(0, 0, 0, dir);
motion.moveForwards(0.1 + getSpeed() * 2F);
EntityItem entityitem = new EntityItem(container.worldObj, position.x, position.y, position.z, getItemStack());
entityitem.lifespan = BuildCraftCore.itemLifespan;
entityitem.delayBeforeCanPickup = 10;
float f3 = 0.00F + container.worldObj.rand.nextFloat() * 0.04F - 0.02F;
entityitem.motionX = (float) container.worldObj.rand.nextGaussian() * f3 + motion.x;
entityitem.motionY = (float) container.worldObj.rand.nextGaussian() * f3 + motion.y;
entityitem.motionZ = (float) container.worldObj.rand.nextGaussian() * f3 + +motion.z;
container.worldObj.spawnEntityInWorld(entityitem);
return entityitem;
}
return null;
}
public float getEntityBrightness(float f) {
int i = MathHelper.floor_double(position.x);
int j = MathHelper.floor_double(position.z);
if (container.worldObj.blockExists(i, 128 / 2, j)) {
double d = 0.66000000000000003D;
int k = MathHelper.floor_double(position.y + d);
return container.worldObj.getLightBrightness(i, k, j);
} else
return 0.0F;
}
public boolean isCorrupted() {
return getItemStack() == null || getItemStack().stackSize <= 0 || Item.itemsList[getItemStack().itemID] == null;
}
/**
* @return the can this item be moved into this specific inventory type.
* (basic BuildCraft PipedItems always return true)
*/
public boolean canSinkTo(TileEntity entity) {
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 67 * hash + this.id;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final TravelingItem other = (TravelingItem) obj;
if (this.id != other.id)
return false;
return true;
}
}

View file

@ -3,7 +3,7 @@ package buildcraft.transport.network;
import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketIds;
import buildcraft.core.utils.EnumColor;
import buildcraft.transport.EntityData;
import buildcraft.transport.TravelingItem;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@ -12,7 +12,7 @@ import net.minecraftforge.common.ForgeDirection;
public class PacketPipeTransportContent extends BuildCraftPacket {
private EntityData entityData;
private TravelingItem item;
private int entityId;
private ForgeDirection input;
private ForgeDirection output;
@ -32,29 +32,29 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
public PacketPipeTransportContent() {
}
public PacketPipeTransportContent(EntityData data) {
this.entityData = data;
public PacketPipeTransportContent(TravelingItem item) {
this.item = item;
}
@Override
public void writeData(DataOutputStream data) throws IOException {
data.writeFloat((float) entityData.item.getPosition().x);
data.writeFloat((float) entityData.item.getPosition().y);
data.writeFloat((float) entityData.item.getPosition().z);
data.writeFloat((float) item.getPosition().x);
data.writeFloat((float) item.getPosition().y);
data.writeFloat((float) item.getPosition().z);
data.writeShort(entityData.item.getEntityId());
data.writeShort(item.id);
data.writeByte((byte) entityData.input.ordinal());
data.writeByte((byte) entityData.output.ordinal());
data.writeByte((byte) item.input.ordinal());
data.writeByte((byte) item.output.ordinal());
data.writeShort(entityData.item.getItemStack().itemID);
data.writeByte((byte) entityData.item.getItemStack().stackSize);
data.writeShort(entityData.item.getItemStack().getItemDamage());
data.writeShort(item.getItemStack().itemID);
data.writeByte((byte) item.getItemStack().stackSize);
data.writeShort(item.getItemStack().getItemDamage());
data.writeByte(entityData.color != null ? entityData.color.ordinal() : -1);
data.writeByte(item.color != null ? item.color.ordinal() : -1);
data.writeFloat(entityData.item.getSpeed());
data.writeBoolean(entityData.item.getItemStack().hasTagCompound());
data.writeFloat(item.getSpeed());
data.writeBoolean(item.getItemStack().hasTagCompound());
}
@Override
@ -84,7 +84,7 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
this.hasNBT = data.readBoolean();
}
public int getEntityId() {
public int getTravellingItemId() {
return entityId;
}

View file

@ -13,16 +13,14 @@ import buildcraft.api.core.Position;
import buildcraft.api.gates.IAction;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.network.TileNetworkData;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.Utils;
import buildcraft.transport.EntityData;
import buildcraft.transport.IPipeTransportItemsHook;
import buildcraft.transport.IPipedItem;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TileGenericPipe;
import buildcraft.transport.TravelingItem;
import buildcraft.transport.triggers.ActionPipeColor;
import buildcraft.transport.triggers.ActionPipeDirection;
import cpw.mods.fml.relauncher.Side;
@ -122,11 +120,11 @@ public class PipeItemsDaizuli extends Pipe<PipeTransportItems> implements IPipeT
}
@Override
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, EntityData data) {
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, TravelingItem item) {
LinkedList<ForgeDirection> newMovements = new LinkedList<ForgeDirection>();
EnumColor c = getColor();
for (ForgeDirection dir : possibleOrientations) {
if (data.color == c) {
if (item.color == c) {
if (dir.ordinal() == container.getBlockMetadata())
newMovements.add(dir);
} else if (dir.ordinal() != container.getBlockMetadata()) {
@ -137,11 +135,11 @@ public class PipeItemsDaizuli extends Pipe<PipeTransportItems> implements IPipeT
}
@Override
public void entityEntered(IPipedItem item, ForgeDirection orientation) {
public void entityEntered(TravelingItem item, ForgeDirection orientation) {
}
@Override
public void readjustSpeed(IPipedItem item) {
public void readjustSpeed(TravelingItem item) {
if (item.getSpeed() > Utils.pipeNormalSpeed) {
item.setSpeed(item.getSpeed() - Utils.pipeNormalSpeed / 4.0F);
}

View file

@ -10,17 +10,16 @@ package buildcraft.transport.pipes;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.transport.IPipedItem;
import buildcraft.core.GuiIds;
import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.network.IClientState;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.EntityData;
import buildcraft.transport.IPipeTransportItemsHook;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TravelingItem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.io.DataInputStream;
@ -90,7 +89,7 @@ public class PipeItemsDiamond extends Pipe<PipeTransportItems> implements IPipeT
}
@Override
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, EntityData data) {
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, TravelingItem item) {
LinkedList<ForgeDirection> filteredOrientations = new LinkedList<ForgeDirection>();
LinkedList<ForgeDirection> defaultOrientations = new LinkedList<ForgeDirection>();
@ -108,10 +107,10 @@ public class PipeItemsDiamond extends Pipe<PipeTransportItems> implements IPipeT
foundFilter = true;
}
if (stack != null && stack.itemID == data.item.getItemStack().itemID)
if ((Item.itemsList[data.item.getItemStack().itemID].isDamageable())) {
if (stack != null && stack.itemID == item.getItemStack().itemID)
if ((Item.itemsList[item.getItemStack().itemID].isDamageable())) {
filteredOrientations.add(dir);
} else if (stack.getItemDamage() == data.item.getItemStack().getItemDamage()) {
} else if (stack.getItemDamage() == item.getItemStack().getItemDamage()) {
filteredOrientations.add(dir);
}
}
@ -126,11 +125,11 @@ public class PipeItemsDiamond extends Pipe<PipeTransportItems> implements IPipeT
}
@Override
public void entityEntered(IPipedItem item, ForgeDirection orientation) {
public void entityEntered(TravelingItem item, ForgeDirection orientation) {
}
@Override
public void readjustSpeed(IPipedItem item) {
public void readjustSpeed(TravelingItem item) {
transport.defaultReajustSpeed(item);
}
/* SAVING & LOADING */

View file

@ -10,13 +10,12 @@ package buildcraft.transport.pipes;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.transport.IPipedItem;
import buildcraft.core.utils.Utils;
import buildcraft.transport.EntityData;
import buildcraft.transport.IPipeTransportItemsHook;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TravelingItem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.LinkedList;
@ -40,17 +39,17 @@ public class PipeItemsGold extends Pipe implements IPipeTransportItemsHook {
}
@Override
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, EntityData data) {
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, TravelingItem item) {
return possibleOrientations;
}
@Override
public void entityEntered(IPipedItem item, ForgeDirection orientation) {
public void entityEntered(TravelingItem item, ForgeDirection orientation) {
item.setSpeed(Math.min(Math.max(Utils.pipeNormalSpeed, item.getSpeed()) * 2f, Utils.pipeNormalSpeed * 30F));
}
@Override
public void readjustSpeed(IPipedItem item) {
public void readjustSpeed(TravelingItem item) {
item.setSpeed(Math.min(Math.max(Utils.pipeNormalSpeed, item.getSpeed()) * 2f, Utils.pipeNormalSpeed * 30F));
}
}

View file

@ -12,15 +12,14 @@ import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.api.gates.IAction;
import buildcraft.api.tools.IToolWrench;
import buildcraft.transport.IPipedItem;
import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.Utils;
import buildcraft.transport.EntityData;
import buildcraft.transport.IItemTravelingHook;
import buildcraft.transport.IPipeTransportItemsHook;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TravelingItem;
import buildcraft.transport.triggers.ActionPipeColor;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -83,20 +82,20 @@ public class PipeItemsLapis extends Pipe<PipeTransportItems> implements IItemTra
}
@Override
public void drop(PipeTransportItems transport, EntityData data) {
public void drop(PipeTransportItems transport, TravelingItem data) {
}
@Override
public void centerReached(PipeTransportItems transport, EntityData data) {
data.color = getColor();
public void centerReached(PipeTransportItems transport, TravelingItem item) {
item.color = getColor();
}
@Override
public void endReached(PipeTransportItems pipe, EntityData data, TileEntity tile) {
public void endReached(PipeTransportItems pipe, TravelingItem item, TileEntity tile) {
}
@Override
public void readjustSpeed(IPipedItem item) {
public void readjustSpeed(TravelingItem item) {
if (item.getSpeed() > Utils.pipeNormalSpeed) {
item.setSpeed(item.getSpeed() - Utils.pipeNormalSpeed / 4.0F);
}
@ -107,12 +106,12 @@ public class PipeItemsLapis extends Pipe<PipeTransportItems> implements IItemTra
}
@Override
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, EntityData data) {
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, TravelingItem travellingItem) {
return possibleOrientations;
}
@Override
public void entityEntered(IPipedItem item, ForgeDirection orientation) {
public void entityEntered(TravelingItem travellingItem, ForgeDirection orientation) {
}
@Override

View file

@ -14,8 +14,7 @@ import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.transport.IPipedItem;
import buildcraft.transport.EntityPassiveItem;
import buildcraft.transport.TravelingItem;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.transport.Pipe;
@ -246,11 +245,11 @@ public class PipeItemsObsidian extends Pipe<PipeTransportItems> implements IPowe
CoreProxy.proxy.removeEntity(entity);
}
IPipedItem passive = new EntityPassiveItem(container.worldObj, container.xCoord + 0.5, container.yCoord + Utils.getPipeFloorOf(stack), container.zCoord + 0.5, stack);
TravelingItem passive = new TravelingItem(container.xCoord + 0.5, container.yCoord + Utils.getPipeFloorOf(stack), container.zCoord + 0.5, stack);
passive.setSpeed((float) speed);
transport.entityEntering(passive, orientation);
transport.injectItem(passive, orientation);
}
}

View file

@ -10,13 +10,12 @@ package buildcraft.transport.pipes;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.transport.IPipedItem;
import buildcraft.core.utils.Utils;
import buildcraft.transport.EntityData;
import buildcraft.transport.IPipeTransportItemsHook;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TravelingItem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.LinkedList;
@ -41,7 +40,7 @@ public class PipeItemsQuartz extends Pipe implements IPipeTransportItemsHook {
}
@Override
public void readjustSpeed(IPipedItem item) {
public void readjustSpeed(TravelingItem item) {
if (item.getSpeed() > Utils.pipeNormalSpeed) {
item.setSpeed(item.getSpeed() - Utils.pipeNormalSpeed / 4.0F);
}
@ -52,11 +51,11 @@ public class PipeItemsQuartz extends Pipe implements IPipeTransportItemsHook {
}
@Override
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, EntityData data) {
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, TravelingItem item) {
return possibleOrientations;
}
@Override
public void entityEntered(IPipedItem item, ForgeDirection orientation) {
public void entityEntered(TravelingItem item, ForgeDirection orientation) {
}
}

View file

@ -10,13 +10,12 @@ package buildcraft.transport.pipes;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.transport.IPipedItem;
import buildcraft.core.utils.Utils;
import buildcraft.transport.EntityData;
import buildcraft.transport.IPipeTransportItemsHook;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TravelingItem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.LinkedList;
@ -40,7 +39,7 @@ public class PipeItemsStone extends Pipe implements IPipeTransportItemsHook {
}
@Override
public void readjustSpeed(IPipedItem item) {
public void readjustSpeed(TravelingItem item) {
if (item.getSpeed() > Utils.pipeNormalSpeed) {
item.setSpeed(item.getSpeed() - Utils.pipeNormalSpeed / 2.0F);
}
@ -51,11 +50,11 @@ public class PipeItemsStone extends Pipe implements IPipeTransportItemsHook {
}
@Override
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, EntityData data) {
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, TravelingItem item) {
return possibleOrientations;
}
@Override
public void entityEntered(IPipedItem item, ForgeDirection orientation) {
public void entityEntered(TravelingItem item, ForgeDirection orientation) {
}
}

View file

@ -9,11 +9,11 @@ package buildcraft.transport.pipes;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.transport.EntityData;
import buildcraft.transport.IItemTravelingHook;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TravelingItem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.tileentity.TileEntity;
@ -39,17 +39,17 @@ public class PipeItemsVoid extends Pipe<PipeTransportItems> implements IItemTrav
// This is called if the void pipe is only connected to one pipe
@Override
public void drop(PipeTransportItems pipe, EntityData data) {
data.item.getItemStack().stackSize = 0;
public void drop(PipeTransportItems pipe, TravelingItem item) {
item.getItemStack().stackSize = 0;
}
// This is called when the void pipe is connected to multiple pipes
@Override
public void centerReached(PipeTransportItems pipe, EntityData data) {
transport.scheduleRemoval(data.item);
public void centerReached(PipeTransportItems pipe, TravelingItem item) {
transport.items.scheduleRemoval(item);
}
@Override
public void endReached(PipeTransportItems pipe, EntityData data, TileEntity tile) {
public void endReached(PipeTransportItems pipe, TravelingItem item, TileEntity tile) {
}
}

View file

@ -15,9 +15,8 @@ import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.transport.IPipedItem;
import buildcraft.api.transport.PipeManager;
import buildcraft.transport.EntityPassiveItem;
import buildcraft.transport.TravelingItem;
import buildcraft.core.inventory.InventoryWrapper;
import buildcraft.core.utils.Utils;
import buildcraft.transport.Pipe;
@ -137,9 +136,9 @@ public class PipeItemsWood extends Pipe<PipeTransportItems> implements IPowerRec
entityPos.moveForwards(0.6);
IPipedItem entity = new EntityPassiveItem(container.worldObj, entityPos.x, entityPos.y, entityPos.z, stack);
TravelingItem entity = new TravelingItem( entityPos.x, entityPos.y, entityPos.z, stack);
transport.entityEntering(entity, entityPos.orientation);
transport.injectItem(entity, entityPos.orientation);
}
}
}

View file

@ -10,18 +10,17 @@ package buildcraft.transport.render;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftCore.RenderMode;
import buildcraft.BuildCraftTransport;
import buildcraft.transport.IPipedItem;
import buildcraft.core.render.RenderEntityBlock;
import buildcraft.core.render.RenderEntityBlock.BlockInterface;
import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.Utils;
import buildcraft.transport.EntityData;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportFluids;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.PipeTransportPower;
import buildcraft.transport.TileGenericPipe;
import buildcraft.transport.TravelingItem;
import com.google.common.collect.Maps;
import java.util.HashMap;
import net.minecraft.block.Block;
@ -410,13 +409,13 @@ public class RenderPipe extends TileEntitySpecialRenderer {
float light = pipe.container.worldObj.getLightBrightness(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
int count = 0;
for (EntityData itemData : pipe.transport.travelingEntities.values()) {
for (TravelingItem travellingItem : pipe.transport.items) {
if (count >= MAX_ITEMS_TO_RENDER) {
break;
}
doRenderItem(itemData.item, x + itemData.item.getPosition().x - pipe.container.xCoord, y + itemData.item.getPosition().y - pipe.container.yCoord, z + itemData.item.getPosition().z
- pipe.container.zCoord, light, itemData.color);
doRenderItem(travellingItem, x + travellingItem.getPosition().x - pipe.container.xCoord, y + travellingItem.getPosition().y - pipe.container.yCoord, z + travellingItem.getPosition().z
- pipe.container.zCoord, light, travellingItem.color);
count++;
}
@ -424,13 +423,13 @@ public class RenderPipe extends TileEntitySpecialRenderer {
GL11.glPopMatrix();
}
public void doRenderItem(IPipedItem entityitem, double x, double y, double z, float light, EnumColor color) {
public void doRenderItem(TravelingItem travellingItem, double x, double y, double z, float light, EnumColor color) {
if (entityitem == null || entityitem.getItemStack() == null)
if (travellingItem == null || travellingItem.getItemStack() == null)
return;
float renderScale = 0.7f;
ItemStack itemstack = entityitem.getItemStack();
ItemStack itemstack = travellingItem.getItemStack();
GL11.glPushMatrix();
GL11.glTranslatef((float) x, (float) y, (float) z);
GL11.glTranslatef(0, 0.25F, 0);

View file

@ -10,12 +10,12 @@ package buildcraft.transport.triggers;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.EntityData;
import buildcraft.transport.ITriggerPipe;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransportFluids;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.PipeTransportPower;
import buildcraft.transport.TravelingItem;
import buildcraft.transport.pipes.PipePowerWood;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -88,16 +88,16 @@ public class TriggerPipeContents extends BCTrigger implements ITriggerPipe {
PipeTransportItems transportItems = (PipeTransportItems) pipe.transport;
if (kind == Kind.Empty)
return transportItems.travelingEntities.isEmpty();
return transportItems.items.isEmpty();
else if (kind == Kind.ContainsItems)
if (parameter != null && parameter.getItem() != null) {
for (EntityData data : transportItems.travelingEntities.values()) {
if (data.item.getItemStack().itemID == parameter.getItem().itemID
&& data.item.getItemStack().getItemDamage() == parameter.getItem().getItemDamage())
for (TravelingItem item : transportItems.items) {
if (item.getItemStack().itemID == parameter.getItem().itemID
&& item.getItemStack().getItemDamage() == parameter.getItem().getItemDamage())
return true;
}
} else
return !transportItems.travelingEntities.isEmpty();
return !transportItems.items.isEmpty();
} else if (pipe.transport instanceof PipeTransportFluids) {
PipeTransportFluids transportFluids = (PipeTransportFluids) pipe.transport;