From 5cb7c9fe004d8d950dff76d6ac47f0f0decf301d Mon Sep 17 00:00:00 2001 From: asiekierka Date: Fri, 20 Mar 2015 17:03:32 +0100 Subject: [PATCH] add stripes pipe direction control, add stripes handler priority system to API, add IBlueprintItem API thing --- api/buildcraft/api/items/IBlueprintItem.java | 11 +++++ api/buildcraft/api/transport/PipeManager.java | 22 ++++++++++ buildcraft_resources/changelog/7.0.0 | 3 +- common/buildcraft/BuildCraftTransport.java | 18 ++++---- .../transport/pipes/PipeItemsStripes.java | 42 +++++++++++++++++-- .../transport/pipes/PipeItemsWood.java | 5 ++- .../stripes/PipeExtensionListener.java | 2 +- 7 files changed, 87 insertions(+), 16 deletions(-) create mode 100644 api/buildcraft/api/items/IBlueprintItem.java diff --git a/api/buildcraft/api/items/IBlueprintItem.java b/api/buildcraft/api/items/IBlueprintItem.java new file mode 100644 index 00000000..a7f4088d --- /dev/null +++ b/api/buildcraft/api/items/IBlueprintItem.java @@ -0,0 +1,11 @@ +package buildcraft.api.items; + +import net.minecraft.item.ItemStack; + +public interface IBlueprintItem extends INamedItem { + public enum Type { + TEMPLATE, BLUEPRINT; + } + + Type getType(ItemStack stack); +} diff --git a/api/buildcraft/api/transport/PipeManager.java b/api/buildcraft/api/transport/PipeManager.java index 82b9d525..896f0821 100755 --- a/api/buildcraft/api/transport/PipeManager.java +++ b/api/buildcraft/api/transport/PipeManager.java @@ -9,6 +9,8 @@ package buildcraft.api.transport; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,6 +27,8 @@ public abstract class PipeManager { new HashMap>(); private static Map, String> pipePluggableByNames = new HashMap, String>(); + private static Map stripesHandlerPriorities = + new HashMap(); @Deprecated public static boolean canExtractItems(Object extractor, World world, int i, int j, int k) { @@ -36,8 +40,26 @@ public abstract class PipeManager { return true; } + @Deprecated public static void registerStripesHandler(IStripesHandler handler) { + registerStripesHandler(handler, 0); + } + + /** + * Register a Stripes Pipe handler. + * @param handler The handler. + * @param priority The priority - 0 is normal, higher numbers have higher priority. + */ + public static void registerStripesHandler(IStripesHandler handler, int priority) { stripesHandlers.add(handler); + stripesHandlerPriorities.put(handler, priority); + + Collections.sort(stripesHandlers, new Comparator() { + @Override + public int compare(IStripesHandler o1, IStripesHandler o2) { + return stripesHandlerPriorities.get(o2) - stripesHandlerPriorities.get(o1); + } + }); } public static void registerPipePluggable(Class pluggable, String name) { diff --git a/buildcraft_resources/changelog/7.0.0 b/buildcraft_resources/changelog/7.0.0 index 1b452083..60687016 100644 --- a/buildcraft_resources/changelog/7.0.0 +++ b/buildcraft_resources/changelog/7.0.0 @@ -18,7 +18,8 @@ Additions: * Extending or retracting a Stripes Pipe now carries over all its gates, pipe wires and pluggables (asie) * You can now extend pipe wires by putting them into a Stripes Pipe (asie) * PlaceBlock now works directly in front of a block again (asie) - * Made items in pipes move at a much smoother rate (asie) + * Stripes Pipes can now have their output direction controlled with Gates (asie) + * Made items in pipes move at a much smoother rate (rendering) (asie) * Robots: * Improved robot light handling - the light now denotes sleep state and battery charge level (asie) * New Robot triggers and actions: Linked, Reserved, In Station and Robot Mandatory (asie) diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index 4effb727..c2356199 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -502,15 +502,15 @@ public class BuildCraftTransport extends BuildCraftMod { StatementManager.registerTriggerProvider(new PipeTriggerProvider()); StatementManager.registerActionProvider(new PipeActionProvider()); - PipeManager.registerStripesHandler(new StripesHandlerRightClick()); - PipeManager.registerStripesHandler(new StripesHandlerBucket()); - PipeManager.registerStripesHandler(new StripesHandlerArrow()); - PipeManager.registerStripesHandler(new StripesHandlerShears()); - PipeManager.registerStripesHandler(new StripesHandlerPipes()); - PipeManager.registerStripesHandler(new StripesHandlerPipeWires()); - PipeManager.registerStripesHandler(new StripesHandlerEntityInteract()); - PipeManager.registerStripesHandler(new StripesHandlerPlaceBlock()); - PipeManager.registerStripesHandler(new StripesHandlerHoe()); + PipeManager.registerStripesHandler(new StripesHandlerRightClick(), -65536); + PipeManager.registerStripesHandler(new StripesHandlerBucket(), 0); + PipeManager.registerStripesHandler(new StripesHandlerArrow(), 0); + PipeManager.registerStripesHandler(new StripesHandlerShears(), 0); + PipeManager.registerStripesHandler(new StripesHandlerPipes(), 0); + PipeManager.registerStripesHandler(new StripesHandlerPipeWires(), 0); + PipeManager.registerStripesHandler(new StripesHandlerEntityInteract(), 0); + PipeManager.registerStripesHandler(new StripesHandlerPlaceBlock(), -32768); + PipeManager.registerStripesHandler(new StripesHandlerHoe(), 0); PipeManager.registerPipePluggable(FacadePluggable.class, "facade"); PipeManager.registerPipePluggable(GatePluggable.class, "gate"); diff --git a/common/buildcraft/transport/pipes/PipeItemsStripes.java b/common/buildcraft/transport/pipes/PipeItemsStripes.java index 1c20733e..40953519 100644 --- a/common/buildcraft/transport/pipes/PipeItemsStripes.java +++ b/common/buildcraft/transport/pipes/PipeItemsStripes.java @@ -9,6 +9,8 @@ package buildcraft.transport.pipes; import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedList; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; @@ -24,6 +26,7 @@ import cofh.api.energy.IEnergyHandler; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.Position; +import buildcraft.api.statements.IActionInternal; import buildcraft.api.transport.IStripesHandler; import buildcraft.api.transport.IStripesHandler.StripesHandlerType; import buildcraft.api.transport.IStripesPipe; @@ -36,10 +39,14 @@ import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTransportItems; import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TravelingItem; +import buildcraft.transport.gates.StatementSlot; import buildcraft.transport.pipes.events.PipeEventItem; +import buildcraft.transport.statements.ActionPipeDirection; import buildcraft.transport.utils.TransportUtils; public class PipeItemsStripes extends Pipe implements IEnergyHandler, IStripesPipe { + private ForgeDirection actionDir = ForgeDirection.UNKNOWN; + public PipeItemsStripes(Item item) { super(new PipeTransportItems(), item); } @@ -57,16 +64,21 @@ public class PipeItemsStripes extends Pipe implements IEnerg if (container.getWorldObj().isRemote) { return; } + + ForgeDirection direction = actionDir; + if (direction == ForgeDirection.UNKNOWN) { + direction = event.direction; + } Position p = new Position(container.xCoord, container.yCoord, - container.zCoord, event.direction); + container.zCoord, direction); p.moveForwards(1.0); ItemStack stack = event.entity.getEntityItem(); EntityPlayer player = CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld(), (int) p.x, (int) p.y, (int) p.z).get(); - switch (event.direction) { + switch (direction) { case DOWN: player.rotationPitch = 90; player.rotationYaw = 0; @@ -102,7 +114,7 @@ public class PipeItemsStripes extends Pipe implements IEnerg if (handler.getType() == StripesHandlerType.ITEM_USE && handler.shouldHandle(stack)) { if (handler.handle(getWorld(), (int) p.x, (int) p.y, (int) p.z, - event.direction, stack, player, this)) { + direction, stack, player, this)) { event.entity = null; return; } @@ -117,7 +129,31 @@ public class PipeItemsStripes extends Pipe implements IEnerg p.moveForwards(1.0); InvUtils.dropItems(getWorld(), itemStack, (int) p.x, (int) p.y, (int) p.z); + } + @Override + public LinkedList getActions() { + LinkedList action = super.getActions(); + for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { + if (!container.isPipeConnected(direction)) { + action.add(BuildCraftTransport.actionPipeDirection[direction.ordinal()]); + } + } + return action; + } + + @Override + protected void actionsActivated(Collection actions) { + super.actionsActivated(actions); + + actionDir = ForgeDirection.UNKNOWN; + + for (StatementSlot action : actions) { + if (action.statement instanceof ActionPipeDirection) { + actionDir = ((ActionPipeDirection) action.statement).direction; + break; + } + } } @Override diff --git a/common/buildcraft/transport/pipes/PipeItemsWood.java b/common/buildcraft/transport/pipes/PipeItemsWood.java index ed29c840..e1234133 100644 --- a/common/buildcraft/transport/pipes/PipeItemsWood.java +++ b/common/buildcraft/transport/pipes/PipeItemsWood.java @@ -35,7 +35,7 @@ import buildcraft.transport.PipeTransportItems; import buildcraft.transport.TravelingItem; public class PipeItemsWood extends Pipe implements IEnergyHandler { - protected RFBattery battery = new RFBattery(2560, 2560 / 8, 0); + protected RFBattery battery = new RFBattery(2560, 80, 0); protected int standardIconIndex = PipeIconProvider.TYPE.PipeItemsWood_Standard.ordinal(); protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal(); @@ -225,7 +225,8 @@ public class PipeItemsWood extends Pipe implements IEnergyHa if (doRemove) { int maxStackSize = slot.stackSize; int stackSize = Math.min(maxStackSize, battery.getEnergyStored() / 10); - speedMultiplier = Math.min(4.0F, battery.getEnergyStored() * 10 / stackSize); + // TODO: Look into the Speed Multiplier again someday. + //speedMultiplier = Math.min(4.0F, battery.getEnergyStored() * 10 / stackSize); int energyUsed = (int) (stackSize * 10 * speedMultiplier); battery.useEnergy(energyUsed, energyUsed, false); diff --git a/common/buildcraft/transport/stripes/PipeExtensionListener.java b/common/buildcraft/transport/stripes/PipeExtensionListener.java index 8e6925fa..cb12b508 100644 --- a/common/buildcraft/transport/stripes/PipeExtensionListener.java +++ b/common/buildcraft/transport/stripes/PipeExtensionListener.java @@ -119,7 +119,7 @@ public class PipeExtensionListener { if (!retract) { r.stack.stackSize--; } - + if (r.stack.stackSize > 0) { sendItem(items, r.stack, r.o.getOpposite()); }