Added Lapis Item Pipe

This pipe paints passing items pretty colors.

TODO:
Add support to Diamond Pipe for painted items.
Add actions to set the Pipe color.

NOTES:
This required way more changes to the Pipe code that it should have.
This commit is contained in:
CovertJaguar 2013-07-23 21:48:51 -07:00
parent f43e12e9b2
commit 83431cebf0
31 changed files with 534 additions and 171 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

View file

@ -52,6 +52,7 @@ import buildcraft.transport.pipes.PipeItemsDiamond;
import buildcraft.transport.pipes.PipeItemsEmerald;
import buildcraft.transport.pipes.PipeItemsGold;
import buildcraft.transport.pipes.PipeItemsIron;
import buildcraft.transport.pipes.PipeItemsLapis;
import buildcraft.transport.pipes.PipeItemsObsidian;
import buildcraft.transport.pipes.PipeItemsQuartz;
import buildcraft.transport.pipes.PipeItemsSandstone;
@ -123,6 +124,7 @@ public class BuildCraftTransport {
public static Item pipeItemsGold;
public static Item pipeItemsDiamond;
public static Item pipeItemsObsidian;
public static Item pipeItemsLapis;
public static Item pipeItemsVoid;
public static Item pipeItemsSandstone;
public static Item pipeFluidsWood;
@ -277,6 +279,7 @@ public class BuildCraftTransport {
pipeItemsGold = buildPipe(DefaultProps.PIPE_ITEMS_GOLD_ID, PipeItemsGold.class, "Golden Transport Pipe", Item.ingotGold, Block.glass, Item.ingotGold);
pipeItemsDiamond = buildPipe(DefaultProps.PIPE_ITEMS_DIAMOND_ID, PipeItemsDiamond.class, "Diamond Transport Pipe", Item.diamond, Block.glass, Item.diamond);
pipeItemsObsidian = buildPipe(DefaultProps.PIPE_ITEMS_OBSIDIAN_ID, PipeItemsObsidian.class, "Obsidian Transport Pipe", Block.obsidian, Block.glass, Block.obsidian);
pipeItemsLapis = buildPipe(DefaultProps.PIPE_ITEMS_LAPIS_ID, PipeItemsLapis.class, "Lapis Transport Pipe", Block.blockLapis, Block.glass, Block.blockLapis);
pipeItemsSandstone = buildPipe(DefaultProps.PIPE_ITEMS_SANDSTONE_ID, PipeItemsSandstone.class, "Sandstone Transport Pipe", Block.sandStone, Block.glass, Block.sandStone);
pipeItemsVoid = buildPipe(DefaultProps.PIPE_ITEMS_VOID_ID, PipeItemsVoid.class, "Void Transport Pipe", "dyeBlack", Block.glass, Item.redstone);

View file

@ -17,10 +17,8 @@ import net.minecraftforge.common.ForgeDirection;
*/
public interface IPipeEntry {
void entityEntering(ItemStack payload, ForgeDirection orientation);
boolean entityEntering(ItemStack payload, ForgeDirection orientation);
void entityEntering(IPipedItem item, ForgeDirection orientation);
boolean acceptItems();
boolean isItemPipe();
}

View file

@ -61,6 +61,7 @@ public class DefaultProps {
public static int PIPE_ITEMS_OBSIDIAN_ID = 19166;
public static int PIPE_ITEMS_EMERALD_ID = 19167;
public static int PIPE_ITEMS_QUARTZ_ID = 19168;
public static int PIPE_ITEMS_LAPIS_ID = 19169;
public static int PIPE_LIQUIDS_WOOD_ID = 19180;
public static int PIPE_LIQUIDS_COBBLESTONE_ID = 19181;
@ -71,6 +72,7 @@ public class DefaultProps {
public static int PIPE_LIQUIDS_OBSIDIAN_ID = 19186;
public static int PIPE_LIQUIDS_EMERALD_ID = 19187;
public static int PIPE_LIQUIDS_QUARTZ_ID = 19188;
public static int PIPE_LIQUIDS_LAPIS_ID = 19189;
public static int PIPE_POWER_WOOD_ID = 19200;
public static int PIPE_POWER_COBBLESTONE_ID = 19201;
@ -81,6 +83,7 @@ public class DefaultProps {
public static int PIPE_POWER_OBSIDIAN_ID = 19206;
public static int PIPE_POWER_EMERALD_ID = 19207;
public static int PIPE_POWER_QUARTZ_ID = 19208;
public static int PIPE_POWER_LAPIS_ID = 19209;
public static int PIPE_ITEMS_VOID_ID = 19220;
public static int PIPE_LIQUIDS_VOID_ID = 19221;

View file

@ -0,0 +1,173 @@
package buildcraft.core.utils;
import java.util.Locale;
/**
*
* @author CovertJaguar <http://www.railcraft.info>
*/
public enum EnumColor {
BLACK,
RED,
GREEN,
BROWN,
BLUE,
PURPLE,
CYAN,
LIGHT_GRAY,
GRAY,
PINK,
LIME,
YELLOW,
LIGHT_BLUE,
MAGENTA,
ORANGE,
WHITE;
public final static EnumColor[] VALUES = values();
public final static String[] DYES = {
"dyeBlack",
"dyeRed",
"dyeGreen",
"dyeBrown",
"dyeBlue",
"dyePurple",
"dyeCyan",
"dyeLightGray",
"dyeGray",
"dyePink",
"dyeLime",
"dyeYellow",
"dyeLightBlue",
"dyeMagenta",
"dyeOrange",
"dyeWhite"};
public final static String[] NAMES = {
"Black",
"Red",
"Green",
"Brown",
"Blue",
"Purple",
"Cyan",
"LightGray",
"Gray",
"Pink",
"Lime",
"Yellow",
"LightBlue",
"Magenta",
"Orange",
"White"};
public final static int[] DARK_HEX = {
0x2D2D2D,
0xA33835,
0x394C1E,
0x5C3A24,
0x3441A2,
0x843FBF,
0x36809E,
0x888888,
0x444444,
0xE585A0,
0x3FAA36,
0xCFC231,
0x7F9AD1,
0xFF64FF,
0xFF6A00,
0xFFFFFF};
public final static int[] LIGHT_HEX = {
0x181414,
0xBE2B27,
0x007F0E,
0x89502D,
0x253193,
0x7e34bf,
0x299799,
0xa0a7a7,
0x7A7A7A,
0xD97199,
0x39D52E,
0xFFD91C,
0x66AAFF,
0xD943C6,
0xEA7835,
0xe4e4e4};
public int getDarkHex() {
return DARK_HEX[ordinal()];
}
public int getLightHex() {
return LIGHT_HEX[ordinal()];
}
public static EnumColor fromId(int id) {
if (id < 0 || id >= VALUES.length) {
return WHITE;
}
return VALUES[id];
}
public static EnumColor fromDye(String dyeTag) {
for (int id = 0; id < DYES.length; id++) {
if (DYES[id].equals(dyeTag)) {
return VALUES[id];
}
}
return null;
}
public static EnumColor fromName(String name) {
for (int id = 0; id < NAMES.length; id++) {
if (NAMES[id].equals(name)) {
return VALUES[id];
}
}
return null;
}
public static EnumColor getRand() {
return VALUES[Utils.RANDOM.nextInt(VALUES.length)];
}
public EnumColor getNext() {
EnumColor next = VALUES[(ordinal() + 1) % (VALUES.length - 1)];
return next;
}
public EnumColor inverse() {
return EnumColor.VALUES[15 - ordinal()];
}
public String getTag() {
return "color." + name().replace("_", ".").toLowerCase(Locale.ENGLISH);
}
public String getBasicTag() {
return name().replace("_", ".").toLowerCase(Locale.ENGLISH);
}
public String getName() {
return NAMES[ordinal()];
}
public String getTranslatedName() {
return StringUtils.localize(getTag());
}
public String getDye() {
return DYES[ordinal()];
}
@Override
public String toString() {
String s = name().replace("_", " ");
String[] words = s.split(" ");
StringBuilder b = new StringBuilder();
for (String word : words) {
b.append(word.charAt(0)).append(word.substring(1).toLowerCase(Locale.ENGLISH)).append(" ");
}
return b.toString().trim();
}
}

View file

@ -135,10 +135,11 @@ public class Utils {
* isn't used again so that entities doesn't go backwards. Returns true if
* successful, false otherwise.
*/
public static boolean addToRandomPipeEntry(TileEntity tile, ForgeDirection from, ItemStack items) {
World w = tile.worldObj;
public static boolean addToRandomPipeEntry(TileEntity source, ForgeDirection from, ItemStack items) {
World w = source.worldObj;
LinkedList<ForgeDirection> possiblePipes = new LinkedList<ForgeDirection>();
List<IPipeEntry> possiblePipes = new ArrayList<IPipeEntry>();
List<ForgeDirection> pipeDirections = new ArrayList<ForgeDirection>();
for (int j = 0; j < 6; ++j) {
if (from.getOpposite().ordinal() == j) {
@ -146,41 +147,29 @@ public class Utils {
}
ForgeDirection o = ForgeDirection.values()[j];
Position pos = new Position(tile.xCoord, tile.yCoord, tile.zCoord, o);
Position pos = new Position(source.xCoord, source.yCoord, source.zCoord, o);
pos.moveForwards(1.0);
TileEntity pipeEntry = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (pipeEntry instanceof IPipeEntry && ((IPipeEntry) pipeEntry).acceptItems()) {
if (pipeEntry instanceof IPipeConnection) {
if (!((IPipeConnection) pipeEntry).isPipeConnected(o.getOpposite())) {
if (tile instanceof IPipeEntry && ((IPipeEntry) tile).isItemPipe()) {
if (tile instanceof IPipeConnection) {
if (!((IPipeConnection) tile).isPipeConnected(o.getOpposite())) {
continue;
}
}
possiblePipes.add(o);
possiblePipes.add((IPipeEntry) tile);
pipeDirections.add(o);
}
}
if (possiblePipes.size() > 0) {
int choice = w.rand.nextInt(possiblePipes.size());
Position entityPos = new Position(tile.xCoord, tile.yCoord, tile.zCoord, possiblePipes.get(choice));
Position pipePos = new Position(tile.xCoord, tile.yCoord, tile.zCoord, possiblePipes.get(choice));
IPipeEntry pipeEntry = possiblePipes.get(choice);
entityPos.x += 0.5;
entityPos.y += getPipeFloorOf(items);
entityPos.z += 0.5;
entityPos.moveForwards(0.5);
pipePos.moveForwards(1.0);
IPipeEntry pipeEntry = (IPipeEntry) w.getBlockTileEntity((int) pipePos.x, (int) pipePos.y, (int) pipePos.z);
IPipedItem entity = new EntityPassiveItem(w, entityPos.x, entityPos.y, entityPos.z, items);
pipeEntry.entityEntering(entity, entityPos.orientation);
pipeEntry.entityEntering(items, pipeDirections.get(choice));
items.stackSize = 0;
return true;
} else {

View file

@ -1,7 +1,9 @@
package buildcraft.transport;
import buildcraft.api.transport.IPipedItem;
import buildcraft.core.utils.EnumColor;
import java.util.EnumSet;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
public class EntityData {
@ -9,16 +11,42 @@ public class EntityData {
// TODO: Move passive data here too, like position, speed and all?
// TODO: Create an object pool?
public boolean toCenter = true;
public IPipedItem item;
public ForgeDirection input;
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 citem, ForgeDirection orientation) {
item = citem;
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

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

View file

@ -22,6 +22,23 @@ public class PipeIconProvider implements IIconProvider {
PipeItemsDiamond_West("pipeItemsDiamond_west"),
PipeItemsDiamond_East("pipeItemsDiamond_east"),
//
PipeItemsLapis_Black("pipeItemsLapisBlack"),
PipeItemsLapis_Red("pipeItemsLapisRed"),
PipeItemsLapis_Green("pipeItemsLapisGreen"),
PipeItemsLapis_Brown("pipeItemsLapisBrown"),
PipeItemsLapis_Blue("pipeItemsLapisBlue"),
PipeItemsLapis_Purple("pipeItemsLapisPurple"),
PipeItemsLapis_Cyan("pipeItemsLapisCyan"),
PipeItemsLapis_LightGray("pipeItemsLapisLightGray"),
PipeItemsLapis_Gray("pipeItemsLapisGray"),
PipeItemsLapis_Pink("pipeItemsLapisPink"),
PipeItemsLapis_Lime("pipeItemsLapisLime"),
PipeItemsLapis_Yellow("pipeItemsLapisYellow"),
PipeItemsLapis_LightBlue("pipeItemsLapisLightBlue"),
PipeItemsLapis_Magenta("pipeItemsLapisMagenta"),
PipeItemsLapis_Orange("pipeItemsLapisOrange"),
PipeItemsLapis_White("pipeItemsLapisWhite"),
//
PipeItemsWood_Standard("pipeItemsWood_standard"),
PipeAllWood_Solid("pipeAllWood_solid"),
//
@ -57,8 +74,9 @@ public class PipeIconProvider implements IIconProvider {
//
Power_Normal("texture_cyan"),
Power_Overload("texture_red_lit"),
Stripes("pipeStripes");
Stripes("pipeStripes"),
//
ItemBox("itemBox");
public static final TYPE[] VALUES = values();
private final String iconTag;
private Icon icon;
@ -70,11 +88,17 @@ public class PipeIconProvider implements IIconProvider {
private void registerIcon(IconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:" + iconTag);
}
public Icon getIcon() {
return icon;
}
}
@Override
@SideOnly(Side.CLIENT)
public Icon getIcon(int pipeIconIndex) {
if (pipeIconIndex == -1)
return null;
return TYPE.VALUES[pipeIconIndex].icon;
}

View file

@ -7,7 +7,6 @@
*/
package buildcraft.transport;
import buildcraft.api.transport.IPipedItem;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@ -55,13 +54,6 @@ public abstract class PipeTransport {
return true;
}
public boolean acceptItems() {
return false;
}
public void entityEntering(IPipedItem item, ForgeDirection orientation) {
}
public void dropContents() {
}

View file

@ -1,12 +1,10 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
* 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
* 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;
@ -56,10 +54,7 @@ public class PipeTransportItems extends PipeTransport {
public boolean allowBouncing = false;
public Map<Integer, EntityData> travelingEntities = new HashMap<Integer, EntityData>();
private final List<EntityData> entitiesToLoad = new LinkedList<EntityData>();
private final List<EntityData> delayedEntitiesToLoad = new LinkedList<EntityData>();
private int delay = -1;
private int delay = 0;
// TODO: generalize the use of this hook in particular for obsidian pipe
public IItemTravelingHook travelHook;
@ -85,32 +80,40 @@ public class PipeTransportItems extends PipeTransport {
item.setSpeed(speed);
}
@Override
public void entityEntering(IPipedItem item, ForgeDirection orientation) {
if (item.isCorrupted())
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())
// Safe guard - if for any reason the item is corrupted at this
// stage, avoid adding it to the pipe to avoid further exceptions.
return;
readjustSpeed(item);
data.reset();
data.input = inputOrientation;
EntityData data = travelingEntities.get(item.getEntityId());
EntityData existingData = travelingEntities.get(data.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);
}
item.setContainer(container);
if (existingData == null) {
travelingEntities.put(data.item.getEntityId(), data);
} else {
data = existingData;
}
data.item.setContainer(container);
readjustSpeed(data.item);
// Reajusting Ypos to make sure the object looks like sitting on the
// pipe.
if (orientation != ForgeDirection.UP && orientation != ForgeDirection.DOWN) {
item.setPosition(item.getPosition().x, container.yCoord + Utils.getPipeFloorOf(item.getItemStack()), item.getPosition().z);
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);
}
if (!container.worldObj.isRemote) {
@ -118,7 +121,7 @@ public class PipeTransportItems extends PipeTransport {
}
if (container.pipe instanceof IPipeTransportItemsHook) {
((IPipeTransportItemsHook) container.pipe).entityEntered(item, orientation);
((IPipeTransportItemsHook) container.pipe).entityEntered(data.item, inputOrientation);
}
if (!container.worldObj.isRemote) {
@ -148,14 +151,15 @@ public class PipeTransportItems extends PipeTransport {
}
}
}
private void destroyPipe() {
BlockUtil.explodeBlock(container.worldObj, container.xCoord, container.yCoord, container.zCoord);
container.worldObj.setBlockToAir(container.xCoord, container.yCoord, container.zCoord);
}
/**
* Bounces the item back into the pipe without changing the travelingEntities map.
* Bounces the item back into the pipe without changing the
* travelingEntities map.
*
* @param data
*/
@ -203,7 +207,8 @@ public class PipeTransportItems extends PipeTransport {
}
/**
* Returns a list of all possible movements, that is to say adjacent implementers of IPipeEntry or TileEntityChest.
* Returns a list of all possible movements, that is to say adjacent
* implementers of IPipeEntry or TileEntityChest.
*/
public LinkedList<ForgeDirection> getPossibleMovements(EntityData data) {
LinkedList<ForgeDirection> result = new LinkedList<ForgeDirection>();
@ -254,7 +259,6 @@ public class PipeTransportItems extends PipeTransport {
public void updateEntity() {
moveSolids();
}
Set<Integer> toRemove = new HashSet<Integer>();
public void scheduleRemoval(IPipedItem item) {
@ -271,17 +275,12 @@ public class PipeTransportItems extends PipeTransport {
}
private void moveSolids() {
if(delay > 0) {
if (delay > 0) {
delay--;
if(delay == 0) {
entitiesToLoad.addAll(delayedEntitiesToLoad);
delayedEntitiesToLoad.clear();
delay = -1;
}
}
if (!entitiesToLoad.isEmpty()) {
} 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();
@ -295,6 +294,11 @@ public class PipeTransportItems extends PipeTransport {
continue;
}
if (data.item.getContainer() != this.container) {
scheduleRemoval(data.item);
continue;
}
Position motion = new Position(0, 0, 0, data.toCenter ? data.input : data.output);
motion.moveForwards(data.item.getSpeed());
@ -349,12 +353,20 @@ public class PipeTransportItems extends PipeTransport {
performRemoval();
}
private void handleTileReached(EntityData data, TileEntity tile) {
if (tile instanceof IPipeEntry) {
((IPipeEntry) tile).entityEntering(data.item, data.output);
} else if (tile instanceof TileGenericPipe && ((TileGenericPipe) tile).pipe.transport instanceof PipeTransportItems) {
private boolean passToNextPipe(EntityData data, TileEntity tile) {
if (tile instanceof TileGenericPipe) {
TileGenericPipe pipe = (TileGenericPipe) tile;
((PipeTransportItems) pipe.pipe.transport).entityEntering(data.item, data.output);
if (BlockGenericPipe.isValid(pipe.pipe) && pipe.pipe.transport instanceof PipeTransportItems) {
((PipeTransportItems) pipe.pipe.transport).entityEntering(data, data.output);
return true;
}
}
return false;
}
private void handleTileReached(EntityData data, TileEntity tile) {
if (passToNextPipe(data, 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);
@ -418,11 +430,10 @@ public class PipeTransportItems extends PipeTransport {
entity.setContainer(container);
EntityData data = new EntityData(entity, ForgeDirection.getOrientation(dataTag.getInteger("input")));
data.output = ForgeDirection.getOrientation(dataTag.getInteger("output"));
data.toCenter = dataTag.getBoolean("toCenter");
EntityData data = new EntityData(entity);
data.readFromNBT(dataTag);
delayedEntitiesToLoad.add(data);
entitiesToLoad.add(data);
} catch (Throwable t) {
t.printStackTrace();
// It may be the case that entities cannot be reloaded between
@ -442,9 +453,7 @@ public class PipeTransportItems extends PipeTransport {
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());
data.writeToNBT(dataTag);
}
nbt.setTag("travelingEntities", nbttaglist);
@ -463,26 +472,27 @@ public class PipeTransportItems extends PipeTransport {
if (packet.getID() != PacketIds.PIPE_CONTENTS)
return;
EntityData data = travelingEntities.remove(packet.getEntityId());
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;
}
if(item.getItemStack() == null) {
if (item.getItemStack() == null) {
item.setItemStack(new ItemStack(packet.getItemId(), packet.getStackSize(), packet.getItemDamage()));
if(packet.hasNBT()) {
if (packet.hasNBT()) {
PacketDispatcher.sendPacketToServer(new PacketSimpleId(PacketIds.REQUEST_ITEM_NBT, container.xCoord, container.yCoord, container.zCoord, packet.getEntityId()).getPacket());
}
} else {
if(item.getItemStack().itemID != packet.getItemId() || item.getItemStack().stackSize != packet.getStackSize() || item.getItemStack().getItemDamage() != packet.getItemDamage() || item.getItemStack().hasTagCompound() != packet.hasNBT()) {
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()) {
if (packet.hasNBT()) {
PacketDispatcher.sendPacketToServer(new PacketSimpleId(PacketIds.REQUEST_ITEM_NBT, container.xCoord, container.yCoord, container.zCoord, packet.getEntityId()).getPacket());
}
}
}
}
@ -492,14 +502,11 @@ public class PipeTransportItems extends PipeTransport {
item.setSpeed(packet.getSpeed());
if (item.getContainer() != null && item.getContainer() != container) {
((PipeTransportItems) ((TileGenericPipe) item.getContainer()).pipe.transport).scheduleRemoval(item);
item.setContainer(container);
}
item.setContainer(container);
data = new EntityData(item, packet.getInputOrientation());
data.input = packet.getInputOrientation();
data.output = packet.getOutputOrientation();
travelingEntities.put(item.getEntityId(), data);
data.color = packet.getColor();
}
/**
@ -507,7 +514,8 @@ public class PipeTransportItems extends PipeTransport {
*/
public void handleNBTRequestPacket(EntityPlayer player, int entityId) {
EntityData data = travelingEntities.get(entityId);
if(data == null || data.item == null || data.item.getItemStack() == null) return;
if (data == null || data.item == null || data.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);
}
@ -516,10 +524,11 @@ public class PipeTransportItems extends PipeTransport {
*/
public void handleNBTPacket(PacketPipeTransportNBT packet) {
EntityData data = travelingEntities.get(packet.getEntityId());
if(data == null || data.item == null || data.item.getItemStack() == null) return;
if (data == null || data.item == null || data.item.getItemStack() == null)
return;
data.item.getItemStack().setTagCompound(packet.getTagCompound());
}
/**
* Creates a packet describing a stack of items inside a pipe.
*
@ -559,30 +568,27 @@ public class PipeTransportItems extends PipeTransport {
|| (tile instanceof IMachine && ((IMachine) tile).manageSolids());
}
@Override
public boolean acceptItems() {
return true;
}
public boolean isTriggerActive(ITrigger trigger) {
return false;
}
/**
* Group all items that are similar, that is to say same dmg, same id, same nbt and no contribution controlling them
* Group all items that are similar, that is to say same dmg, same id, same
* nbt and no contribution controlling them
*/
public void groupEntities() {
// determine groupable entities
List<EntityData> entities = new ArrayList<EntityData>();
for (EntityData entityData : travelingEntities.values()) {
if (!entityData.item.hasContributions() &&
entityData.item.getItemStack().stackSize < entityData.item.getItemStack().getMaxStackSize()) {
if (!entityData.item.hasContributions()
&& entityData.item.getItemStack().stackSize < entityData.item.getItemStack().getMaxStackSize()) {
entities.add(entityData);
}
}
if (entities.isEmpty()) return; // nothing groupable
if (entities.isEmpty())
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>() {
@ -627,11 +633,13 @@ public class PipeTransportItems extends PipeTransport {
private void groupEntityRange(List<EntityData> entities, int start, int end) {
for (int j = start; j < end; j++) {
EntityData target = entities.get(j);
if (target == null) continue;
if (target == null)
continue;
for (int k = j + 1; k < end; k++) {
EntityData source = entities.get(k);
if (source == null) continue;
if (source == null)
continue;
// only merge if the ItemStack tags match
if (ItemStack.areItemStackTagsEqual(source.item.getItemStack(), target.item.getItemStack())) {
@ -670,8 +678,8 @@ public class PipeTransportItems extends PipeTransport {
}
travelingEntities.clear();
}
}
@Override
public boolean delveIntoUnloadedChunks() {
return true;

View file

@ -92,42 +92,42 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
if (pipe != null) {
nbttagcompound.setInteger("pipeId", pipe.itemID);
pipe.writeToNBT(nbttagcompound);
nbt.setInteger("pipeId", pipe.itemID);
pipe.writeToNBT(nbt);
} else {
nbttagcompound.setInteger("pipeId", coreState.pipeId);
nbt.setInteger("pipeId", coreState.pipeId);
}
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
nbttagcompound.setInteger("facadeBlocks[" + i + "]", facadeBlocks[i]);
nbttagcompound.setInteger("facadeMeta[" + i + "]", facadeMeta[i]);
nbttagcompound.setBoolean("plug[" + i + "]", plugs[i]);
nbt.setInteger("facadeBlocks[" + i + "]", facadeBlocks[i]);
nbt.setInteger("facadeMeta[" + i + "]", facadeMeta[i]);
nbt.setBoolean("plug[" + i + "]", plugs[i]);
}
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
coreState.pipeId = nbttagcompound.getInteger("pipeId");
coreState.pipeId = nbt.getInteger("pipeId");
pipe = BlockGenericPipe.createPipe(coreState.pipeId);
if (pipe != null) {
pipe.readFromNBT(nbttagcompound);
pipe.readFromNBT(nbt);
} else {
BuildCraftCore.bcLog.log(Level.WARNING, "Pipe failed to load from NBT at {0},{1},{2}", new Object[]{xCoord, yCoord, zCoord});
deletePipe = true;
}
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
facadeBlocks[i] = nbttagcompound.getInteger("facadeBlocks[" + i + "]");
facadeMeta[i] = nbttagcompound.getInteger("facadeMeta[" + i + "]");
plugs[i] = nbttagcompound.getBoolean("plug[" + i + "]");
facadeBlocks[i] = nbt.getInteger("facadeBlocks[" + i + "]");
facadeMeta[i] = nbt.getInteger("facadeMeta[" + i + "]");
plugs[i] = nbt.getBoolean("plug[" + i + "]");
}
}
@ -207,7 +207,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
}
// Pipe Textures
for (ForgeDirection o : ForgeDirection.values()) {
for (int i = 0; i < 7; i++) {
ForgeDirection o = ForgeDirection.getOrientation(i);
renderState.textureMatrix.setIconIndex(o, pipe.getIconIndex(o));
}
@ -254,7 +255,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
}
if (renderState.isDirty()) {
worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
markBlockForUpdate();
renderState.clean();
}
}
@ -335,32 +336,28 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
/* IPIPEENTRY */
@Override
public void entityEntering(IPipedItem item, ForgeDirection orientation) {
if (BlockGenericPipe.isValid(pipe)) {
pipe.transport.entityEntering(item, orientation);
public boolean entityEntering(ItemStack payload, ForgeDirection orientation) {
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof PipeTransportItems) {
/* FIXME: This is untested guesswork */
Position itemPos = new Position(xCoord, yCoord, zCoord, orientation);
itemPos.moveBackwards(1.0);
itemPos.x += 0.5;
itemPos.y += Utils.getPipeFloorOf(payload);
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, orientation);
return true;
}
return false;
}
@Override
public void entityEntering(ItemStack payload, ForgeDirection orientation) {
/* FIXME: This is untested guesswork */
Position itemPos = new Position(xCoord, yCoord, zCoord, orientation);
itemPos.moveBackwards(1.0);
itemPos.x += 0.5;
itemPos.y += 0.25;
itemPos.z += 0.5;
itemPos.moveForwards(0.5);
EntityPassiveItem pipedItem = new EntityPassiveItem(worldObj, itemPos.x, itemPos.y, itemPos.z, payload);
entityEntering(pipedItem, orientation);
}
@Override
public boolean acceptItems() {
public boolean isItemPipe() {
if (BlockGenericPipe.isValid(pipe))
return pipe.transport.acceptItems();
return pipe.transport instanceof PipeTransportItems;
else
return false;
}
@ -679,7 +676,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
}
public boolean hasPlug(ForgeDirection side) {
if(side == null || side == ForgeDirection.UNKNOWN)
if (side == null || side == ForgeDirection.UNKNOWN)
return false;
if (this.worldObj.isRemote)
return renderState.plugMatrix.isConnected(side);
@ -724,4 +721,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
public boolean isUseableByPlayer(EntityPlayer player) {
return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this;
}
public void markBlockForUpdate() {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}

View file

@ -2,6 +2,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 java.io.DataInputStream;
import java.io.DataOutputStream;
@ -18,6 +19,7 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
private int itemId;
private byte stackSize;
private int itemDamage;
private EnumColor color;
private float itemX;
private float itemY;
private float itemZ;
@ -49,6 +51,8 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
data.writeByte((byte) entityData.item.getItemStack().stackSize);
data.writeShort(entityData.item.getItemStack().getItemDamage());
data.writeByte(entityData.color != null ? entityData.color.ordinal() : -1);
data.writeFloat(entityData.item.getSpeed());
data.writeBoolean(entityData.item.getItemStack().hasTagCompound());
}
@ -72,6 +76,10 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
this.stackSize = data.readByte();
this.itemDamage = data.readShort();
byte c = data.readByte();
if (c != -1)
this.color = EnumColor.fromId(c);
this.speed = data.readFloat();
this.hasNBT = data.readBoolean();
}
@ -100,6 +108,10 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
return itemDamage;
}
public EnumColor getColor() {
return color;
}
public double getPosX() {
return itemX;
}
@ -119,7 +131,7 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
public boolean hasNBT() {
return hasNBT;
}
@Override
public int getID() {
return PacketIds.PIPE_CONTENTS;

View file

@ -0,0 +1,105 @@
/**
* 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.pipes;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.api.tools.IToolWrench;
import buildcraft.api.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 cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
public class PipeItemsLapis extends Pipe implements IItemTravelingHook, IPipeTransportItemsHook {
public PipeItemsLapis(int itemID) {
super(new PipeTransportItems(), itemID);
((PipeTransportItems) transport).travelHook = this;
}
@Override
@SideOnly(Side.CLIENT)
public IIconProvider getIconProvider() {
return BuildCraftTransport.instance.pipeIconProvider;
}
@Override
public int getIconIndex(ForgeDirection direction) {
if (direction == ForgeDirection.UNKNOWN)
return PipeIconProvider.TYPE.PipeItemsLapis_White.ordinal();
return PipeIconProvider.TYPE.PipeItemsLapis_Black.ordinal() + container.getBlockMetadata();
}
@Override
public boolean blockActivated(EntityPlayer entityplayer) {
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, container.xCoord, container.yCoord, container.zCoord)) {
setColor(getColor().getNext());
((IToolWrench) equipped).wrenchUsed(entityplayer, container.xCoord, container.yCoord, container.zCoord);
return true;
}
return false;
}
public EnumColor getColor() {
return EnumColor.fromId(container.getBlockMetadata());
}
public void setColor(EnumColor color) {
container.worldObj.setBlockMetadataWithNotify(container.xCoord, container.yCoord, container.zCoord, color.ordinal(), 3);
container.scheduleRenderUpdate();
container.markBlockForUpdate();
}
@Override
public void drop(PipeTransportItems transport, EntityData data) {
}
@Override
public void centerReached(PipeTransportItems transport, EntityData data) {
data.color = getColor();
}
@Override
public void endReached(PipeTransportItems pipe, EntityData data, TileEntity tile) {
}
@Override
public void readjustSpeed(IPipedItem item) {
if (item.getSpeed() > Utils.pipeNormalSpeed) {
item.setSpeed(item.getSpeed() - Utils.pipeNormalSpeed / 4.0F);
}
if (item.getSpeed() < Utils.pipeNormalSpeed) {
item.setSpeed(Utils.pipeNormalSpeed);
}
}
@Override
public LinkedList<ForgeDirection> filterPossibleMovements(LinkedList<ForgeDirection> possibleOrientations, Position pos, IPipedItem item) {
return possibleOrientations;
}
@Override
public void entityEntered(IPipedItem item, ForgeDirection orientation) {
}
}

View file

@ -13,6 +13,7 @@ import buildcraft.BuildCraftTransport;
import buildcraft.api.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;
@ -409,13 +410,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 data : ((PipeTransportItems) pipe.transport).travelingEntities.values()) {
for (EntityData itemData : ((PipeTransportItems) pipe.transport).travelingEntities.values()) {
if (count >= MAX_ITEMS_TO_RENDER) {
break;
}
doRenderItem(data.item, x + data.item.getPosition().x - pipe.container.xCoord, y + data.item.getPosition().y - pipe.container.yCoord, z + data.item.getPosition().z
- pipe.container.zCoord, light);
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);
count++;
}
@ -423,7 +424,7 @@ public class RenderPipe extends TileEntitySpecialRenderer {
GL11.glPopMatrix();
}
public void doRenderItem(IPipedItem entityitem, double d, double d1, double d2, float f1) {
public void doRenderItem(IPipedItem entityitem, double x, double y, double z, float light, EnumColor color) {
if (entityitem == null || entityitem.getItemStack() == null)
return;
@ -431,11 +432,37 @@ public class RenderPipe extends TileEntitySpecialRenderer {
float renderScale = 0.7f;
ItemStack itemstack = entityitem.getItemStack();
GL11.glPushMatrix();
GL11.glTranslatef((float) d, (float) d1, (float) d2);
GL11.glTranslatef((float) x, (float) y, (float) z);
GL11.glTranslatef(0, 0.25F, 0);
GL11.glScalef(renderScale, renderScale, renderScale);
dummyEntityItem.setEntityItemStack(itemstack);
customRenderItem.doRenderItem(dummyEntityItem, 0, 0, 0, 0, 0);
if (color != null) {
BlockInterface block = new BlockInterface();
block.texture = PipeIconProvider.TYPE.ItemBox.getIcon();
float pix = 0.0625F;
float min = -4 * pix;
float max = 4 * pix;
block.minY = min;
block.maxY = max;
block.minZ = min;
block.maxZ = max;
block.minX = min;
block.maxX = max;
int cHex = color.getLightHex();
float r = (float) (cHex >> 16 & 0xff) / 255F;
float g = (float) (cHex >> 8 & 0xff) / 255F;
float b = (float) (cHex & 0xff) / 255F;
GL11.glColor4f(r, g, b, 1.0F);
RenderEntityBlock.INSTANCE.renderBlock(block, null, 0, 0, 0, false, true);
}
GL11.glPopMatrix();
}
}