initial resurection of stripes pipe, for #1491

This commit is contained in:
SpaceToad 2014-03-15 21:20:42 +01:00
parent 63d4a5a055
commit 5822a0806a
7 changed files with 240 additions and 42 deletions

View file

@ -81,6 +81,7 @@ import buildcraft.transport.pipes.PipeItemsObsidian;
import buildcraft.transport.pipes.PipeItemsQuartz;
import buildcraft.transport.pipes.PipeItemsSandstone;
import buildcraft.transport.pipes.PipeItemsStone;
import buildcraft.transport.pipes.PipeItemsStripes;
import buildcraft.transport.pipes.PipeItemsVoid;
import buildcraft.transport.pipes.PipeItemsWood;
import buildcraft.transport.pipes.PipePowerCobblestone;
@ -140,6 +141,7 @@ public class BuildCraftTransport extends BuildCraftMod {
public static Item pipeItemsVoid;
public static Item pipeItemsSandstone;
public static Item pipeItemsEmzuli;
public static Item pipeItemsStripes;
public static Item pipeFluidsWood;
public static Item pipeFluidsCobblestone;
public static Item pipeFluidsStone;
@ -333,6 +335,7 @@ public class BuildCraftTransport extends BuildCraftMod {
pipeItemsSandstone = buildPipe(DefaultProps.PIPE_ITEMS_SANDSTONE_ID, PipeItemsSandstone.class, "Sandstone Transport Pipe", CreativeTabBuildCraft.TIER_1, Blocks.sandstone, Blocks.glass, Blocks.sandstone);
pipeItemsVoid = buildPipe(DefaultProps.PIPE_ITEMS_VOID_ID, PipeItemsVoid.class, "Void Transport Pipe", CreativeTabBuildCraft.TIER_1, "dyeBlack", Blocks.glass, Items.redstone);
pipeItemsEmzuli = buildPipe(DefaultProps.PIPE_ITEMS_EMZULI_ID, PipeItemsEmzuli.class, "Emzuli Transport Pipe", CreativeTabBuildCraft.MISC, Blocks.lapis_block, Blocks.glass, Items.emerald);
pipeItemsStripes = buildPipe(0, PipeItemsStripes.class, "Stripes Transport Pipe", CreativeTabBuildCraft.TIER_3, Items.dye, Blocks.glass, Items.dye);
pipeFluidsWood = buildPipe(DefaultProps.PIPE_LIQUIDS_WOOD_ID, PipeFluidsWood.class, "Wooden Waterproof Pipe", CreativeTabBuildCraft.TIER_2, pipeWaterproof, pipeItemsWood);
pipeFluidsCobblestone = buildPipe(DefaultProps.PIPE_LIQUIDS_COBBLESTONE_ID, PipeFluidsCobblestone.class, "Cobblestone Waterproof Pipe", CreativeTabBuildCraft.TIER_2, pipeWaterproof, pipeItemsCobblestone);

View file

@ -27,7 +27,6 @@ import net.minecraft.world.WorldSettings.GameType;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.transport.PipeWire;
@ -51,7 +50,6 @@ public abstract class Pipe<T extends PipeTransport> implements IDropControlInven
public Gate gate;
@SuppressWarnings("rawtypes")
private static Map<Class, TilePacketWrapper> networkWrappers = new HashMap<Class, TilePacketWrapper>();
public SafeTimeTracker actionTracker = new SafeTimeTracker();
private static Map<Class<? extends Pipe>, Map<Class<? extends PipeEvent>, EventHandler>> eventHandlers = new HashMap<Class<? extends Pipe>, Map<Class<? extends PipeEvent>, EventHandler>>();
public Pipe(T transport, Item item) {
@ -65,9 +63,7 @@ public abstract class Pipe<T extends PipeTransport> implements IDropControlInven
}
public void setTile(TileEntity tile) {
this.container = (TileGenericPipe) tile;
transport.setTile((TileGenericPipe) tile);
}

View file

@ -154,8 +154,9 @@ public class PipeIconProvider implements IIconProvider {
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int pipeIconIndex) {
if (pipeIconIndex == -1)
if (pipeIconIndex == -1) {
return null;
}
return TYPE.VALUES[pipeIconIndex].icon;
}

View file

@ -59,8 +59,9 @@ public class PipeTransportItems extends PipeTransport {
}
PipeEventItem.AdjustSpeed event = new PipeEventItem.AdjustSpeed(item);
container.pipe.handlePipeEvent(event);
if (!event.handled)
if (!event.handled) {
defaultReajustSpeed(item);
}
}
public void defaultReajustSpeed(TravelingItem item) {
@ -90,10 +91,11 @@ public class PipeTransportItems extends PipeTransport {
}
public void injectItem(TravelingItem item, ForgeDirection inputOrientation) {
if (item.isCorrupted())
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;
}
item.reset();
item.input = inputOrientation;
@ -112,16 +114,18 @@ public class PipeTransportItems extends PipeTransport {
PipeEventItem.Entered event = new PipeEventItem.Entered(item);
container.pipe.handlePipeEvent(event);
if (event.cancelled)
if (event.cancelled) {
return;
}
items.add(item);
if (!container.getWorldObj().isRemote) {
sendTravelerPacket(item, false);
if (items.size() > BuildCraftTransport.groupItemsTrigger)
if (items.size() > BuildCraftTransport.groupItemsTrigger) {
groupEntities();
}
if (items.size() > MAX_PIPE_STACKS) {
BCLog.logger.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()));
@ -132,8 +136,9 @@ public class PipeTransportItems extends PipeTransport {
int numItems = 0;
for (TravelingItem travellingItem : items) {
ItemStack stack = travellingItem.getItemStack();
if (stack != null && stack.stackSize > 0)
if (stack != null && stack.stackSize > 0) {
numItems += stack.stackSize;
}
}
if (numItems > MAX_PIPE_ITEMS) {
@ -154,10 +159,11 @@ public class PipeTransportItems extends PipeTransport {
* @param item
*/
protected void reverseItem(TravelingItem item) {
if (item.isCorrupted())
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;
}
item.toCenter = true;
item.input = item.output.getOpposite();
@ -174,20 +180,23 @@ public class PipeTransportItems extends PipeTransport {
}
PipeEventItem.Entered event = new PipeEventItem.Entered(item);
container.pipe.handlePipeEvent(event);
if (event.cancelled)
if (event.cancelled) {
return;
}
items.unscheduleRemoval(item);
if (!container.getWorldObj().isRemote)
if (!container.getWorldObj().isRemote) {
sendTravelerPacket(item, true);
}
}
public ForgeDirection resolveDestination(TravelingItem data) {
List<ForgeDirection> validDestinations = getPossibleMovements(data);
if (validDestinations.isEmpty())
if (validDestinations.isEmpty()) {
return ForgeDirection.UNKNOWN;
}
return validDestinations.get(0);
}
@ -205,8 +214,9 @@ public class PipeTransportItems extends PipeTransport {
sides.remove(ForgeDirection.UNKNOWN);
for (ForgeDirection o : sides) {
if (container.pipe.outputOpen(o) && canReceivePipeObjects(o, item))
if (container.pipe.outputOpen(o) && canReceivePipeObjects(o, item)) {
result.add(o);
}
}
if (this.container.pipe instanceof IPipeTransportItemsHook) {
@ -230,16 +240,19 @@ public class PipeTransportItems extends PipeTransport {
public boolean canReceivePipeObjects(ForgeDirection o, TravelingItem item) {
TileEntity entity = container.getTile(o);
if (!container.isPipeConnected(o))
if (!container.isPipeConnected(o)) {
return false;
}
if (entity instanceof TileGenericPipe) {
TileGenericPipe pipe = (TileGenericPipe) entity;
return pipe.pipe.transport instanceof PipeTransportItems;
} else if (entity instanceof IInventory && item.getInsertionHandler().canInsertItem(item, (IInventory) entity))
if (Transactor.getTransactorFor(entity).add(item.getItemStack(), o.getOpposite(), false).stackSize > 0)
} else if (entity instanceof IInventory && item.getInsertionHandler().canInsertItem(item, (IInventory) entity)) {
if (Transactor.getTransactorFor(entity).add(item.getItemStack(), o.getOpposite(), false).stackSize > 0) {
return true;
}
}
return false;
}
@ -275,8 +288,9 @@ public class PipeTransportItems extends PipeTransport {
item.setPosition(container.xCoord + 0.5, container.yCoord + TransportUtils.getPipeFloorOf(item.getItemStack()), container.zCoord + 0.5);
if (item.output == ForgeDirection.UNKNOWN) {
if (items.scheduleRemoval(item))
if (items.scheduleRemoval(item)) {
dropItem(item);
}
} else {
if (travelHook != null) {
travelHook.centerReached(this, item);
@ -332,13 +346,15 @@ public class PipeTransportItems extends PipeTransport {
reverseItem(item);
}
}
} else
} else {
dropItem(item);
}
}
private void dropItem(TravelingItem item) {
if (container.getWorldObj().isRemote)
if (container.getWorldObj().isRemote) {
return;
}
if (travelHook != null) {
travelHook.drop(this, item);
@ -346,8 +362,11 @@ public class PipeTransportItems extends PipeTransport {
PipeEventItem.DropItem event = new PipeEventItem.DropItem(item, item.toEntityItem());
container.pipe.handlePipeEvent(event);
if (event.entity == null)
if (event.entity == null) {
return;
}
container.getWorldObj().spawnEntityInWorld(event.entity);
}
@ -381,8 +400,9 @@ public class PipeTransportItems extends PipeTransport {
TravelingItem item = TravelingItem.make(dataTag);
if (item.isCorrupted())
if (item.isCorrupted()) {
continue;
}
items.scheduleLoad(item);
} catch (Throwable t) {
@ -453,8 +473,9 @@ public class PipeTransportItems extends PipeTransport {
public int getNumberOfItems() {
int num = 0;
for (TravelingItem item : items) {
if (item.getItemStack() == null)
if (item.getItemStack() == null) {
continue;
}
num += item.getItemStack().stackSize;
}
return num;
@ -467,8 +488,9 @@ public class PipeTransportItems extends PipeTransport {
public boolean canPipeConnect(TileEntity tile, ForgeDirection side) {
if (tile instanceof TileGenericPipe) {
Pipe pipe2 = ((TileGenericPipe) tile).pipe;
if (BlockGenericPipe.isValid(pipe2) && !(pipe2.transport instanceof PipeTransportItems))
if (BlockGenericPipe.isValid(pipe2) && !(pipe2.transport instanceof PipeTransportItems)) {
return false;
}
}
if (tile instanceof ISidedInventory) {
@ -490,11 +512,13 @@ public class PipeTransportItems extends PipeTransport {
*/
public void groupEntities() {
for (TravelingItem item : items) {
if (item.isCorrupted())
if (item.isCorrupted()) {
continue;
}
for (TravelingItem otherItem : items) {
if (item.tryMergeInto(otherItem))
if (item.tryMergeInto(otherItem)) {
break;
}
}
}
}
@ -504,8 +528,9 @@ public class PipeTransportItems extends PipeTransport {
groupEntities();
for (TravelingItem item : items) {
if (!item.isCorrupted())
if (!item.isCorrupted()) {
container.pipe.dropItem(item.getItemStack());
}
}
items.clear();

View file

@ -10,9 +10,6 @@ package buildcraft.transport.pipes;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.LinkedList;
import net.minecraft.block.Block;
@ -20,7 +17,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
@ -29,7 +25,6 @@ import buildcraft.core.GuiIds;
import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.network.IClientState;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.Pipe;
@ -86,9 +81,11 @@ public class PipeItemsDiamond extends Pipe<PipeTransportItems> implements IClien
@Override
public boolean blockActivated(EntityPlayer entityplayer) {
if (entityplayer.getCurrentEquippedItem() != null)
if (Block.getBlockFromItem(entityplayer.getCurrentEquippedItem().getItem()) instanceof BlockGenericPipe)
if (entityplayer.getCurrentEquippedItem() != null) {
if (Block.getBlockFromItem(entityplayer.getCurrentEquippedItem().getItem()) instanceof BlockGenericPipe) {
return false;
}
}
if (!container.getWorldObj().isRemote) {
entityplayer.openGui(BuildCraftTransport.instance, GuiIds.PIPE_DIAMOND, container.getWorldObj(), container.xCoord, container.yCoord, container.zCoord);
@ -111,20 +108,26 @@ public class PipeItemsDiamond extends Pipe<PipeTransportItems> implements IClien
for (int slot = 0; slot < 9; ++slot) {
ItemStack filter = getFilters().getStackInSlot(dir.ordinal() * 9 + slot);
if (filter != null)
if (filter != null) {
foundFilter = true;
}
if (StackHelper.instance().isMatchingItem(filter, event.item.getItemStack(), true, false))
if (StackHelper.instance().isMatchingItem(filter, event.item.getItemStack(), true, false)) {
filteredOrientations.add(dir);
}
}
if (!foundFilter)
if (!foundFilter) {
defaultOrientations.add(dir);
}
}
event.destinations.clear();
if (!filteredOrientations.isEmpty())
if (!filteredOrientations.isEmpty()) {
event.destinations.addAll(filteredOrientations);
else
} else {
event.destinations.addAll(defaultOrientations);
}
}
/* SAVING & LOADING */
@ -149,7 +152,7 @@ public class PipeItemsDiamond extends Pipe<PipeTransportItems> implements IClien
}
@Override
public void readData(ByteBuf data) {
public void readData(ByteBuf data) {
NBTTagCompound nbt = Utils.readNBT(data);
readFromNBT(nbt);
}

View file

@ -0,0 +1,159 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* 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 net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TileGenericPipe;
import buildcraft.transport.pipes.events.PipeEventItem;
public class PipeItemsStripes extends Pipe {
public PipeItemsStripes(Item item) {
super(new PipeTransportItems(), item);
//((PipeTransportItems) transport).travelHook = this;
}
/*@Override
public void doWork() {
if (powerProvider.useEnergy(1, 1, true) == 1) {
ForgeDirection o = getOpenOrientation();
if (o != ForgeDirection.Unknown) {
Position p = new Position(xCoord, yCoord, zCoord, o);
p.moveForwards(1.0);
ArrayList<ItemStack> stacks = BuildCraftBlockUtil
.getItemStackFromBlock(worldObj, (int) p.x, (int) p.y,
(int) p.z);
if (stacks != null) {
for (ItemStack s : stacks) {
if (s != null) {
IPipedItem newItem = new EntityPassiveItem(
worldObj, xCoord + 0.5, yCoord
+ Utils.getPipeFloorOf(s),
zCoord + 0.5, s);
this.container.entityEntering(newItem, o.reverse());
}
}
}
worldObj.setBlock((int) p.x, (int) p.y, (int) p.z, 0);
}
}
}*/
public void eventHandler(PipeEventItem.DropItem event) {
System.out.println ("EVENT " + event.direction);
Position p = new Position(container.xCoord, container.yCoord,
container.zCoord, ForgeDirection.UP);
Position from = new Position (p);
p.moveForwards(1.0);
//if (getWorld().getBlock((int) p.x, (int) p.y, (int) p.z) == Blocks.air) {
System.out.println ("TRY PLACE");
event.entity.getEntityItem().tryPlaceItemIntoWorld(
CoreProxy.proxy.getBuildCraftPlayer(getWorld()),
getWorld(),
(int) p.x, (int) p.y - 1, (int) p.z, 1, 0.0f, 0.0f, 0.0f);
//}
/*if (convertPipe(pipe, data)) {
BuildCraftTransport.pipeItemsStipes.onItemUse(new ItemStack(
BuildCraftTransport.pipeItemsStipes), CoreProxy
.getBuildCraftPlayer(worldObj), worldObj, (int) p.x,
(int) p.y - 1, (int) p.z, 1);
} else else {
data.item
.getItemStack()
.getItem()
.tryPlaceIntoWorld(data.item.getItemStack(),
CoreProxy.getBuildCraftPlayer(worldObj), worldObj,
(int) p.x, (int) p.y, (int) p.z, 1, 0.0f, 0.0f,
0.0f);
}*/
}
/*@Override
public void centerReached(PipeTransportItems pipe, EntityData data) {
convertPipe(pipe, data);
}
@SuppressWarnings("unchecked")
public boolean convertPipe(PipeTransportItems pipe, EntityData data) {
if (data.item.getItemStack().getItem() instanceof ItemPipe) {
if (!(data.item.getItemStack().itemID == BuildCraftTransport.pipeItemsStipes.shiftedIndex)) {
Pipe newPipe = BlockGenericPipe.createPipe(data.item
.getItemStack().itemID);
newPipe.setTile(this.container);
this.container.pipe = newPipe;
((PipeTransportItems) newPipe.transport).travelingEntities = (TreeMap<Integer, EntityData>) pipe.travelingEntities
.clone();
data.item.getItemStack().stackSize--;
if (data.item.getItemStack().stackSize <= 0) {
((PipeTransportItems) newPipe.transport).travelingEntities
.remove(data.item.getEntityId());
}
pipe.scheduleRemoval(data.item);
return true;
}
}
return false;
}
@Override
public void endReached(PipeTransportItems pipe, EntityData data,
TileEntity tile) {
}*/
@Override
public IIconProvider getIconProvider() {
return BuildCraftTransport.instance.pipeIconProvider;
}
@Override
public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.TYPE.Stripes.ordinal();
}
@Override
public boolean canPipeConnect(TileEntity tile, ForgeDirection side) {
if (tile instanceof TileGenericPipe) {
TileGenericPipe tilePipe = (TileGenericPipe) tile;
if (tilePipe.pipe instanceof PipeItemsStripes) {
return false;
}
}
return super.canPipeConnect(tile, side);
}
}

View file

@ -8,11 +8,12 @@
*/
package buildcraft.transport.pipes.events;
import buildcraft.transport.TravelingItem;
import java.util.List;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.transport.TravelingItem;
public abstract class PipeEventItem extends PipeEvent {
@ -52,10 +53,20 @@ public abstract class PipeEventItem extends PipeEvent {
public static class DropItem extends PipeEventItem {
public EntityItem entity;
public ForgeDirection direction = ForgeDirection.UNKNOWN;
public DropItem(TravelingItem item, EntityItem entity) {
super(item);
this.entity = entity;
System.out.println ("OUTPUT = " + item.output);
System.out.println ("INPUT = " + item.output);
if (item.output != ForgeDirection.UNKNOWN) {
this.direction = item.output;
} else {
this.direction = item.input.getOpposite();
}
}
}