From f3d14f105abb7392d63c3b943fde51ee383047a8 Mon Sep 17 00:00:00 2001 From: asiekierka Date: Sun, 15 Mar 2015 15:58:51 +0100 Subject: [PATCH] improvements in APIs, threaded packet sending, light sensor expansion, highly optimized pipe code --- api/buildcraft/api/facades/FacadeAPI.java | 5 + api/buildcraft/api/facades/package-info.java | 2 +- api/buildcraft/api/gates/GateExpansions.java | 13 +- api/buildcraft/api/gates/IGate.java | 7 +- api/buildcraft/api/gates/package-info.java | 2 +- .../api/robots/IDockingStationPluggable.java | 5 + api/buildcraft/api/robots/package-info.java | 2 +- .../IRedstoneStatementContainer.java | 19 +++ .../containers/ISidedStatementContainer.java | 11 ++ .../api/statements/package-info.java | 2 +- common/buildcraft/BuildCraftMod.java | 151 +++++++++++++----- common/buildcraft/BuildCraftTransport.java | 48 ++++-- .../core/statements/ActionRedstoneOutput.java | 11 +- .../statements/DefaultActionProvider.java | 3 +- .../statements/DefaultTriggerProvider.java | 6 + .../core/statements/TriggerRedstoneInput.java | 23 +-- .../robotics/RobotIntegrationRecipe.java | 2 +- .../robotics/RobotStationPluggable.java | 5 +- .../recipes/IntegrationTableRecipe.java | 2 +- common/buildcraft/transport/Gate.java | 20 ++- .../transport/PipeTransportItems.java | 14 +- .../transport/PipeTriggerProvider.java | 3 - common/buildcraft/transport/TravelerSet.java | 27 +--- .../buildcraft/transport/TravelingItem.java | 4 +- .../gates/GateExpansionLightSensor.java | 46 ++++++ .../buildcraft/transport/gates/ItemGate.java | 35 ++-- .../transport/pipes/PipeItemsEmerald.java | 11 +- .../transport/pipes/PipeItemsWood.java | 44 ++++- .../recipes/AdvancedFacadeRecipe.java | 1 + .../recipes/GateExpansionRecipe.java | 25 +++ .../recipes/GateLogicSwapRecipe.java | 13 ++ .../transport/render/PipeRendererTESR.java | 2 +- .../statements/TriggerLightSensor.java | 49 ++++++ 33 files changed, 477 insertions(+), 136 deletions(-) create mode 100644 api/buildcraft/api/facades/FacadeAPI.java create mode 100644 api/buildcraft/api/robots/IDockingStationPluggable.java create mode 100644 api/buildcraft/api/statements/containers/IRedstoneStatementContainer.java create mode 100644 api/buildcraft/api/statements/containers/ISidedStatementContainer.java rename common/buildcraft/{transport => silicon}/recipes/IntegrationTableRecipe.java (97%) create mode 100644 common/buildcraft/transport/gates/GateExpansionLightSensor.java create mode 100644 common/buildcraft/transport/statements/TriggerLightSensor.java diff --git a/api/buildcraft/api/facades/FacadeAPI.java b/api/buildcraft/api/facades/FacadeAPI.java new file mode 100644 index 00000000..f5749255 --- /dev/null +++ b/api/buildcraft/api/facades/FacadeAPI.java @@ -0,0 +1,5 @@ +package buildcraft.api.facades; + +public class FacadeAPI { + public static IFacadeItem facadeItem; +} diff --git a/api/buildcraft/api/facades/package-info.java b/api/buildcraft/api/facades/package-info.java index 8c68c5fb..8c85ff54 100644 --- a/api/buildcraft/api/facades/package-info.java +++ b/api/buildcraft/api/facades/package-info.java @@ -6,7 +6,7 @@ * Please check the contents of the license, which should be located * as "LICENSE.API" in the BuildCraft source code distribution. */ -@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|facades") +@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|facades") package buildcraft.api.facades; import cpw.mods.fml.common.API; diff --git a/api/buildcraft/api/gates/GateExpansions.java b/api/buildcraft/api/gates/GateExpansions.java index 1fcbafec..ebcd53eb 100644 --- a/api/buildcraft/api/gates/GateExpansions.java +++ b/api/buildcraft/api/gates/GateExpansions.java @@ -13,11 +13,13 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; public final class GateExpansions { - private static final Map expansions = new HashMap(); private static final ArrayList expansionIDs = new ArrayList(); + private static final Map recipes = new HashMap(); private GateExpansions() { } @@ -31,6 +33,11 @@ public final class GateExpansions { expansionIDs.add(expansion); } + public static void registerExpansion(IGateExpansion expansion, ItemStack addedRecipe) { + registerExpansion(expansion.getUniqueIdentifier(), expansion); + recipes.put(expansion, addedRecipe); + } + public static IGateExpansion getExpansion(String identifier) { return expansions.get(identifier); } @@ -40,6 +47,10 @@ public final class GateExpansions { set.addAll(expansionIDs); return set; } + + public static Map getRecipesForPostInit() { + return recipes; + } // The code below is used by networking. diff --git a/api/buildcraft/api/gates/IGate.java b/api/buildcraft/api/gates/IGate.java index f5a00f12..7f456fae 100644 --- a/api/buildcraft/api/gates/IGate.java +++ b/api/buildcraft/api/gates/IGate.java @@ -8,15 +8,12 @@ */ package buildcraft.api.gates; -import net.minecraftforge.common.util.ForgeDirection; - +import buildcraft.api.statements.containers.ISidedStatementContainer; import buildcraft.api.transport.IPipe; -public interface IGate { +public interface IGate extends ISidedStatementContainer { @Deprecated void setPulsing(boolean pulse); - - ForgeDirection getSide(); IPipe getPipe(); } diff --git a/api/buildcraft/api/gates/package-info.java b/api/buildcraft/api/gates/package-info.java index a7d4c23d..83cb2a2c 100644 --- a/api/buildcraft/api/gates/package-info.java +++ b/api/buildcraft/api/gates/package-info.java @@ -6,7 +6,7 @@ * Please check the contents of the license, which should be located * as "LICENSE.API" in the BuildCraft source code distribution. */ -@API(apiVersion = "4.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|gates") +@API(apiVersion = "4.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|gates") package buildcraft.api.gates; import cpw.mods.fml.common.API; diff --git a/api/buildcraft/api/robots/IDockingStationPluggable.java b/api/buildcraft/api/robots/IDockingStationPluggable.java new file mode 100644 index 00000000..71314019 --- /dev/null +++ b/api/buildcraft/api/robots/IDockingStationPluggable.java @@ -0,0 +1,5 @@ +package buildcraft.api.robots; + +public interface IDockingStationPluggable { + IDockingStation getStation(); +} diff --git a/api/buildcraft/api/robots/package-info.java b/api/buildcraft/api/robots/package-info.java index d95b45ad..3713a724 100644 --- a/api/buildcraft/api/robots/package-info.java +++ b/api/buildcraft/api/robots/package-info.java @@ -6,7 +6,7 @@ * Please check the contents of the license, which should be located * as "LICENSE.API" in the BuildCraft source code distribution. */ -@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|robotics") +@API(apiVersion = "1.2", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|robotics") package buildcraft.api.robots; import cpw.mods.fml.common.API; diff --git a/api/buildcraft/api/statements/containers/IRedstoneStatementContainer.java b/api/buildcraft/api/statements/containers/IRedstoneStatementContainer.java new file mode 100644 index 00000000..0856041c --- /dev/null +++ b/api/buildcraft/api/statements/containers/IRedstoneStatementContainer.java @@ -0,0 +1,19 @@ +package buildcraft.api.statements.containers; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IRedstoneStatementContainer { + /** + * Get the redstone input from a given side. + * @param side The side - use "UNKNOWN" for maximum input. + * @return The redstone input, from 0 to 15. + */ + int getRedstoneInput(ForgeDirection side); + + /** + * Set the redstone input for a given side. + * @param side The side - use "UNKNOWN" for all sides. + * @return Whether the set was successful. + */ + boolean setRedstoneOutput(ForgeDirection side, int value); +} diff --git a/api/buildcraft/api/statements/containers/ISidedStatementContainer.java b/api/buildcraft/api/statements/containers/ISidedStatementContainer.java new file mode 100644 index 00000000..e92c7da4 --- /dev/null +++ b/api/buildcraft/api/statements/containers/ISidedStatementContainer.java @@ -0,0 +1,11 @@ +package buildcraft.api.statements.containers; + +import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.statements.IStatementContainer; + +/** + * Created by asie on 3/14/15. + */ +public interface ISidedStatementContainer extends IStatementContainer { + ForgeDirection getSide(); +} diff --git a/api/buildcraft/api/statements/package-info.java b/api/buildcraft/api/statements/package-info.java index 475deb29..ed7613ea 100644 --- a/api/buildcraft/api/statements/package-info.java +++ b/api/buildcraft/api/statements/package-info.java @@ -6,7 +6,7 @@ * Please check the contents of the license, which should be located * as "LICENSE.API" in the BuildCraft source code distribution. */ -@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|statements") +@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|statements") package buildcraft.api.statements; import cpw.mods.fml.common.API; diff --git a/common/buildcraft/BuildCraftMod.java b/common/buildcraft/BuildCraftMod.java index 661abd23..8a70dd3e 100644 --- a/common/buildcraft/BuildCraftMod.java +++ b/common/buildcraft/BuildCraftMod.java @@ -31,20 +31,118 @@ import buildcraft.core.lib.network.Packet; public class BuildCraftMod { public EnumMap channels; - public void sendToPlayers(Packet packet, World world, int x, int y, int z, int maxDistance) { - try { - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET) - .set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS) - .set(new NetworkRegistry.TargetPoint(world.provider.dimensionId, x, y, z, maxDistance)); - channels.get(Side.SERVER).writeOutbound(packet); - } catch (Throwable t) { - BCLog.logger.log(Level.WARN, "sendToPlayers crash", t); + static abstract class SendRequest { + final Packet packet; + final BuildCraftMod source; + + SendRequest(BuildCraftMod source, Packet packet) { + this.packet = packet; + this.source = source; + } + + abstract void send(); + + void run() { + try { + send(); + } catch(Exception e) { + e.printStackTrace(); + } } } + class PlayerSendRequest extends SendRequest { + EntityPlayer player; + + PlayerSendRequest(BuildCraftMod source, Packet packet, EntityPlayer player) { + super(source, packet); + this.player = player; + } + + void send() { + source.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET) + .set(FMLOutboundHandler.OutboundTarget.PLAYER); + source.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); + source.channels.get(Side.SERVER).writeOutbound(packet); + } + } + + class WorldSendRequest extends SendRequest { + final int dimensionId; + + WorldSendRequest(BuildCraftMod source, Packet packet, int dimensionId) { + super(source, packet); + this.dimensionId = dimensionId; + } + + void send() { + source.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET) + .set(FMLOutboundHandler.OutboundTarget.DIMENSION); + source.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS) + .set(dimensionId); + source.channels.get(Side.SERVER).writeOutbound(packet); + } + } + + class LocationSendRequest extends SendRequest { + final int dimensionId; + final int x, y, z, md; + + LocationSendRequest(BuildCraftMod source, Packet packet, int dimensionId, int x, int y, int z, int md) { + super(source, packet); + this.dimensionId = dimensionId; + this.x = x; + this.y = y; + this.z = z; + this.md = md; + } + + @Override + void send() { + source.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET) + .set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); + source.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS) + .set(new NetworkRegistry.TargetPoint(dimensionId, x, y, z, md)); + source.channels.get(Side.SERVER).writeOutbound(packet); + } + } + + static class PacketSender implements Runnable { + private Queue packets = new ConcurrentLinkedDeque(); + + @Override + public void run() { + while(true) { + try { + Thread.sleep(20); + } catch(Exception e) { + + } + + while (!packets.isEmpty()) { + packets.remove().run(); + } + } + } + + public boolean add(SendRequest r) { + return packets.offer(r); + } + } + + private static PacketSender sender = new PacketSender(); + private static Thread senderThread = new Thread(sender); + + static { + senderThread.start(); + } + + public void sendToPlayers(Packet packet, World world, int x, int y, int z, int maxDistance) { + sender.add(new LocationSendRequest(this, packet, world.provider.dimensionId, x, y, z, maxDistance)); + } + public void sendToPlayersNear(Packet packet, TileEntity tileEntity, int maxDistance) { - sendToPlayers(packet, tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, maxDistance); + sender.add(new LocationSendRequest(this, packet, tileEntity.getWorldObj().provider.dimensionId, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, maxDistance)); } public void sendToPlayersNear(Packet packet, TileEntity tileEntity) { @@ -52,35 +150,14 @@ public class BuildCraftMod { } public void sendToWorld(Packet packet, World world) { - try { - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET) - .set(FMLOutboundHandler.OutboundTarget.DIMENSION); - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS) - .set(world.provider.dimensionId); - channels.get(Side.SERVER).writeOutbound(packet); - } catch (Throwable t) { - BCLog.logger.log(Level.WARN, "sendToWorld crash", t); - } + sender.add(new WorldSendRequest(this, packet, world.provider.dimensionId)); } public void sendToPlayer(EntityPlayer entityplayer, Packet packet) { - try { - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET) - .set(FMLOutboundHandler.OutboundTarget.PLAYER); - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(entityplayer); - channels.get(Side.SERVER).writeOutbound(packet); - } catch (Throwable t) { - String name = entityplayer.getDisplayName(); - - if (name == null) { - name = ""; - } - - BCLog.logger.log(Level.WARN, "sendToPlayer \"" + name + "\" crash", t); - } + sender.add(new PlayerSendRequest(this, packet, entityplayer)); } - public void sendToAll(Packet packet) { + /* public void sendToAll(Packet packet) { try { channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET) .set(FMLOutboundHandler.OutboundTarget.ALL); @@ -88,14 +165,14 @@ public class BuildCraftMod { } catch (Throwable t) { BCLog.logger.log(Level.WARN, "sendToAll crash", t); } - } + } */ public void sendToServer(Packet packet) { try { channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.TOSERVER); channels.get(Side.CLIENT).writeOutbound(packet); - } catch (Throwable t) { - BCLog.logger.log(Level.WARN, "sendToServer crash", t); + } catch (Exception e) { + e.printStackTrace(); } } } \ No newline at end of file diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index 01ac89fd..38fca05d 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -12,6 +12,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Map; import net.minecraft.block.Block; import net.minecraft.init.Blocks; @@ -41,7 +42,9 @@ import buildcraft.api.core.BCLog; import buildcraft.api.core.EnumColor; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.JavaTools; +import buildcraft.api.facades.FacadeAPI; import buildcraft.api.gates.GateExpansions; +import buildcraft.api.gates.IGateExpansion; import buildcraft.api.recipes.BuildcraftRecipeRegistry; import buildcraft.api.statements.IActionInternal; import buildcraft.api.statements.ITriggerInternal; @@ -79,6 +82,7 @@ import buildcraft.transport.TransportProxy; import buildcraft.transport.WireIconProvider; import buildcraft.transport.gates.GateDefinition.GateLogic; import buildcraft.transport.gates.GateDefinition.GateMaterial; +import buildcraft.transport.gates.GateExpansionLightSensor; import buildcraft.transport.gates.GateExpansionPulsar; import buildcraft.transport.gates.GateExpansionRedstoneFader; import buildcraft.transport.gates.GateExpansionTimer; @@ -150,6 +154,7 @@ import buildcraft.transport.statements.ActionValve; import buildcraft.transport.statements.ActionValve.ValveState; import buildcraft.transport.statements.TriggerClockTimer; import buildcraft.transport.statements.TriggerClockTimer.Time; +import buildcraft.transport.statements.TriggerLightSensor; import buildcraft.transport.statements.TriggerParameterSignal; import buildcraft.transport.statements.TriggerPipeContents; import buildcraft.transport.statements.TriggerPipeContents.PipeContents; @@ -227,6 +232,7 @@ public class BuildCraftTransport extends BuildCraftMod { public static int groupItemsTrigger; public static String[] facadeBlacklist; + public static ITriggerInternal triggerLightSensorBright, triggerLightSensorDark; public static ITriggerInternal[] triggerPipe = new ITriggerInternal[PipeContents.values().length]; public static ITriggerInternal[] triggerPipeWireActive = new ITriggerInternal[PipeWire.values().length]; public static ITriggerInternal[] triggerPipeWireInactive = new ITriggerInternal[PipeWire.values().length]; @@ -265,6 +271,9 @@ public class BuildCraftTransport extends BuildCraftMod { public void preInit(FMLPreInitializationEvent evt) { new BCCreativeTab("pipes"); new BCCreativeTab("facades"); + if (Loader.isModLoaded("BuildCraft|Silicon")) { + new BCCreativeTab("gates"); + } try { Property durability = BuildCraftCore.mainConfiguration.get("general", "pipes.durability", DefaultProps.PIPES_DURABILITY); @@ -286,10 +295,6 @@ public class BuildCraftTransport extends BuildCraftMod { filteredBufferBlock = new BlockFilteredBuffer(); CoreProxy.proxy.registerBlock(filteredBufferBlock.setBlockName("filteredBufferBlock")); - GateExpansions.registerExpansion(GateExpansionPulsar.INSTANCE); - GateExpansions.registerExpansion(GateExpansionTimer.INSTANCE); - GateExpansions.registerExpansion(GateExpansionRedstoneFader.INSTANCE); - Property groupItemsTriggerProp = BuildCraftCore.mainConfiguration.get("general", "pipes.groupItemsTrigger", 32); groupItemsTriggerProp.comment = "when reaching this amount of objects in a pipes, items will be automatically grouped"; groupItemsTrigger = groupItemsTriggerProp.getInt(); @@ -387,6 +392,7 @@ public class BuildCraftTransport extends BuildCraftMod { facadeItem = new ItemFacade(); facadeItem.setUnlocalizedName("pipeFacade"); CoreProxy.proxy.registerItem(facadeItem); + FacadeAPI.facadeItem = facadeItem; plugItem = new ItemPlug(); plugItem.setUnlocalizedName("pipePlug"); @@ -437,6 +443,9 @@ public class BuildCraftTransport extends BuildCraftMod { for (PowerMode limit : PowerMode.VALUES) { actionPowerLimiter[limit.ordinal()] = new ActionPowerLimiter(limit); } + + triggerLightSensorBright = new TriggerLightSensor(true); + triggerLightSensorDark = new TriggerLightSensor(false); } finally { BuildCraftCore.mainConfiguration.save(); } @@ -474,6 +483,7 @@ public class BuildCraftTransport extends BuildCraftMod { BCCreativeTab.get("pipes").setIcon(new ItemStack(BuildCraftTransport.pipeItemsDiamond, 1)); BCCreativeTab.get("facades").setIcon(facadeItem.getFacadeForBlock(Blocks.brick_block, 0)); + BCCreativeTab.get("gates").setIcon(ItemGate.makeGateItem(GateMaterial.DIAMOND, GateLogic.AND)); StatementManager.registerParameterClass(TriggerParameterSignal.class); StatementManager.registerParameterClass(ActionParameterSignal.class); @@ -493,7 +503,12 @@ public class BuildCraftTransport extends BuildCraftMod { PipeManager.registerPipePluggable(GatePluggable.class, "gate"); PipeManager.registerPipePluggable(LensPluggable.class, "lens"); PipeManager.registerPipePluggable(PlugPluggable.class, "plug"); - + + GateExpansions.registerExpansion(GateExpansionPulsar.INSTANCE, Chipset.PULSATING.getStack()); + GateExpansions.registerExpansion(GateExpansionTimer.INSTANCE, Chipset.QUARTZ.getStack()); + GateExpansions.registerExpansion(GateExpansionRedstoneFader.INSTANCE, Chipset.COMP.getStack()); + GateExpansions.registerExpansion(GateExpansionLightSensor.INSTANCE, new ItemStack(Blocks.daylight_detector)); + if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); } @@ -506,6 +521,10 @@ public class BuildCraftTransport extends BuildCraftMod { public void postInit(FMLPostInitializationEvent evt) { facadeItem.initialize(); + if (Loader.isModLoaded("BuildCraft|Silicon")) { + postInitSilicon(); + } + if (debugPrintFacadeList) { try { PrintWriter writer = new PrintWriter("FacadeDebug.txt", "UTF-8"); @@ -522,6 +541,17 @@ public class BuildCraftTransport extends BuildCraftMod { } } + private void postInitSilicon() { + Map recipes = GateExpansions.getRecipesForPostInit(); + int recipeId = 0; + + for (IGateExpansion expansion : recipes.keySet()) { + BuildcraftRecipeRegistry.integrationTable.addRecipe(new GateExpansionRecipe("buildcraft:expansion_" + recipeId, + expansion, recipes.get(expansion))); + recipeId++; + } + } + public void loadRecipes() { // Add base recipe for pipe waterproof. GameRegistry.addShapelessRecipe(new ItemStack(pipeWaterproof, 1), new ItemStack(Items.dye, 1, 2)); @@ -622,14 +652,6 @@ public class BuildCraftTransport extends BuildCraftMod { // REVERSAL RECIPE BuildcraftRecipeRegistry.integrationTable.addRecipe(new GateLogicSwapRecipe("buildcraft:gateSwap")); - // EXPANSIONS - BuildcraftRecipeRegistry.integrationTable.addRecipe(new GateExpansionRecipe("buildcraft:expansionPulsar", - GateExpansionPulsar.INSTANCE, Chipset.PULSATING.getStack())); - BuildcraftRecipeRegistry.integrationTable.addRecipe(new GateExpansionRecipe("buildcraft:expansionQuartz", - GateExpansionTimer.INSTANCE, Chipset.QUARTZ.getStack())); - BuildcraftRecipeRegistry.integrationTable.addRecipe(new GateExpansionRecipe("buildcraft:expansionComp", - GateExpansionRedstoneFader.INSTANCE, Chipset.COMP.getStack())); - // FACADE BuildcraftRecipeRegistry.integrationTable.addRecipe(new AdvancedFacadeRecipe("buildcraft:advancedFacade")); } diff --git a/common/buildcraft/core/statements/ActionRedstoneOutput.java b/common/buildcraft/core/statements/ActionRedstoneOutput.java index 49b29b6c..56f749f7 100644 --- a/common/buildcraft/core/statements/ActionRedstoneOutput.java +++ b/common/buildcraft/core/statements/ActionRedstoneOutput.java @@ -13,9 +13,12 @@ import net.minecraft.client.renderer.texture.IIconRegister; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.statements.IActionInternal; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementParameter; +import buildcraft.api.statements.containers.IRedstoneStatementContainer; +import buildcraft.api.statements.containers.ISidedStatementContainer; import buildcraft.core.lib.utils.StringUtils; import buildcraft.transport.Gate; @@ -62,8 +65,12 @@ public class ActionRedstoneOutput extends BCStatement implements IActionInternal @Override public void actionActivate(IStatementContainer source, IStatementParameter[] parameters) { - if (source instanceof Gate) { - ((Gate) source).setRedstoneOutput(isSideOnly(parameters), getSignalLevel()); + if (source instanceof IRedstoneStatementContainer) { + ForgeDirection side = ForgeDirection.UNKNOWN; + if (source instanceof ISidedStatementContainer && isSideOnly(parameters)) { + side = ((ISidedStatementContainer) source).getSide(); + } + ((IRedstoneStatementContainer) source).setRedstoneOutput(side, getSignalLevel()); } } diff --git a/common/buildcraft/core/statements/DefaultActionProvider.java b/common/buildcraft/core/statements/DefaultActionProvider.java index 13ba4ced..4ac73d12 100644 --- a/common/buildcraft/core/statements/DefaultActionProvider.java +++ b/common/buildcraft/core/statements/DefaultActionProvider.java @@ -21,6 +21,7 @@ import buildcraft.api.statements.IActionExternal; import buildcraft.api.statements.IActionInternal; import buildcraft.api.statements.IActionProvider; import buildcraft.api.statements.IStatementContainer; +import buildcraft.api.statements.containers.IRedstoneStatementContainer; import buildcraft.api.tiles.IControllable; import buildcraft.api.transport.IPipeTile; @@ -30,7 +31,7 @@ public class DefaultActionProvider implements IActionProvider { public Collection getInternalActions(IStatementContainer container) { LinkedList res = new LinkedList(); - if (container.getTile() instanceof IPipeTile) { + if (container instanceof IRedstoneStatementContainer) { res.add(BuildCraftCore.actionRedstone); } diff --git a/common/buildcraft/core/statements/DefaultTriggerProvider.java b/common/buildcraft/core/statements/DefaultTriggerProvider.java index 947c8382..f3d28bbc 100644 --- a/common/buildcraft/core/statements/DefaultTriggerProvider.java +++ b/common/buildcraft/core/statements/DefaultTriggerProvider.java @@ -22,6 +22,7 @@ import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.ITriggerExternal; import buildcraft.api.statements.ITriggerInternal; import buildcraft.api.statements.ITriggerProvider; +import buildcraft.api.statements.containers.IRedstoneStatementContainer; import buildcraft.api.tiles.IHasWork; public class DefaultTriggerProvider implements ITriggerProvider { @@ -65,6 +66,11 @@ public class DefaultTriggerProvider implements ITriggerProvider { public LinkedList getInternalTriggers(IStatementContainer container) { LinkedList res = new LinkedList(); + if (container instanceof IRedstoneStatementContainer) { + res.add(BuildCraftCore.triggerRedstoneActive); + res.add(BuildCraftCore.triggerRedstoneInactive); + } + if (TriggerEnergy.isTriggeringPipe(container.getTile()) || TriggerEnergy.getTriggeringNeighbor(container.getTile()) != null) { res.add((ITriggerInternal) BuildCraftCore.triggerEnergyHigh); res.add((ITriggerInternal) BuildCraftCore.triggerEnergyLow); diff --git a/common/buildcraft/core/statements/TriggerRedstoneInput.java b/common/buildcraft/core/statements/TriggerRedstoneInput.java index b3d9371a..410c8e90 100644 --- a/common/buildcraft/core/statements/TriggerRedstoneInput.java +++ b/common/buildcraft/core/statements/TriggerRedstoneInput.java @@ -10,10 +10,13 @@ package buildcraft.core.statements; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.gates.IGate; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementParameter; import buildcraft.api.statements.ITriggerInternal; +import buildcraft.api.statements.containers.IRedstoneStatementContainer; +import buildcraft.api.statements.containers.ISidedStatementContainer; import buildcraft.core.lib.utils.StringUtils; import buildcraft.transport.TileGenericPipe; @@ -49,18 +52,18 @@ public class TriggerRedstoneInput extends BCStatement implements ITriggerInterna @Override public boolean isTriggerActive(IStatementContainer container, IStatementParameter[] parameters) { - if (!(container.getTile() instanceof TileGenericPipe)) { + if (container instanceof IRedstoneStatementContainer) { + int level = ((IRedstoneStatementContainer) container).getRedstoneInput(ForgeDirection.UNKNOWN); + if (parameters.length > 0 && parameters[0] instanceof StatementParameterRedstoneGateSideOnly && + ((StatementParameterRedstoneGateSideOnly) parameters[0]).isOn && + container instanceof ISidedStatementContainer) { + level = ((IRedstoneStatementContainer) container).getRedstoneInput(((ISidedStatementContainer) container).getSide()); + } + + return active ? level > 0 : level == 0; + } else { return false; } - - TileGenericPipe tile = (TileGenericPipe) container.getTile(); - int level = tile.redstoneInput; - if (parameters.length > 0 && parameters[0] instanceof StatementParameterRedstoneGateSideOnly && - ((StatementParameterRedstoneGateSideOnly) parameters[0]).isOn) { - level = tile.redstoneInputSide[((IGate) container).getSide().ordinal()]; - } - - return active ? level > 0 : level == 0; } @Override diff --git a/common/buildcraft/robotics/RobotIntegrationRecipe.java b/common/buildcraft/robotics/RobotIntegrationRecipe.java index 00df74ae..0a7d525e 100755 --- a/common/buildcraft/robotics/RobotIntegrationRecipe.java +++ b/common/buildcraft/robotics/RobotIntegrationRecipe.java @@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack; import buildcraft.BuildCraftRobotics; import buildcraft.api.recipes.CraftingResult; import buildcraft.silicon.TileIntegrationTable; -import buildcraft.transport.recipes.IntegrationTableRecipe; +import buildcraft.silicon.recipes.IntegrationTableRecipe; public class RobotIntegrationRecipe extends IntegrationTableRecipe { diff --git a/common/buildcraft/robotics/RobotStationPluggable.java b/common/buildcraft/robotics/RobotStationPluggable.java index f9e3b256..111b928c 100644 --- a/common/buildcraft/robotics/RobotStationPluggable.java +++ b/common/buildcraft/robotics/RobotStationPluggable.java @@ -15,6 +15,7 @@ import cofh.api.energy.IEnergyReceiver; import buildcraft.BuildCraftRobotics; import buildcraft.BuildCraftTransport; import buildcraft.api.core.render.ITextureStates; +import buildcraft.api.robots.IDockingStationPluggable; import buildcraft.api.robots.RobotManager; import buildcraft.api.tiles.IDebuggable; import buildcraft.api.transport.IPipe; @@ -26,7 +27,8 @@ import buildcraft.core.lib.utils.MatrixTranformations; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.TileGenericPipe; -public class RobotStationPluggable extends PipePluggable implements IPipePluggableItem, IEnergyReceiver, IDebuggable { +public class RobotStationPluggable extends PipePluggable implements IPipePluggableItem, IEnergyReceiver, IDebuggable, + IDockingStationPluggable { public class RobotStationPluggableRenderer implements IPipePluggableRenderer { private float zFightOffset = 1 / 4096.0F; @@ -175,6 +177,7 @@ public class RobotStationPluggable extends PipePluggable implements IPipePluggab return new ItemStack[] { new ItemStack(BuildCraftRobotics.robotStationItem) }; } + @Override public DockingStation getStation() { return station; } diff --git a/common/buildcraft/transport/recipes/IntegrationTableRecipe.java b/common/buildcraft/silicon/recipes/IntegrationTableRecipe.java similarity index 97% rename from common/buildcraft/transport/recipes/IntegrationTableRecipe.java rename to common/buildcraft/silicon/recipes/IntegrationTableRecipe.java index 3171e6dc..5dc1426b 100755 --- a/common/buildcraft/transport/recipes/IntegrationTableRecipe.java +++ b/common/buildcraft/silicon/recipes/IntegrationTableRecipe.java @@ -6,7 +6,7 @@ * 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.recipes; +package buildcraft.silicon.recipes; import net.minecraft.item.ItemStack; diff --git a/common/buildcraft/transport/Gate.java b/common/buildcraft/transport/Gate.java index e820c963..95e7e975 100644 --- a/common/buildcraft/transport/Gate.java +++ b/common/buildcraft/transport/Gate.java @@ -31,8 +31,9 @@ import buildcraft.api.gates.IGateExpansion; import buildcraft.api.statements.IActionExternal; import buildcraft.api.statements.IActionInternal; import buildcraft.api.statements.IActionReceptor; +import buildcraft.api.statements.containers.IRedstoneStatementContainer; +import buildcraft.api.statements.containers.ISidedStatementContainer; import buildcraft.api.statements.IStatement; -import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementParameter; import buildcraft.api.statements.ITriggerExternal; import buildcraft.api.statements.ITriggerInternal; @@ -48,7 +49,7 @@ import buildcraft.transport.gates.StatementSlot; import buildcraft.transport.gui.ContainerGateInterface; import buildcraft.transport.statements.ActionValve; -public final class Gate implements IGate, IStatementContainer { +public final class Gate implements IGate, ISidedStatementContainer, IRedstoneStatementContainer { public static int MAX_STATEMENTS = 8; public static int MAX_PARAMETERS = 3; @@ -641,4 +642,19 @@ public final class Gate implements IGate, IStatementContainer { public TileEntity getTile() { return pipe.container; } + + @Override + public int getRedstoneInput(ForgeDirection side) { + return side == ForgeDirection.UNKNOWN ? pipe.container.redstoneInput : pipe.container.redstoneInputSide[side.ordinal()]; + } + + @Override + public boolean setRedstoneOutput(ForgeDirection side, int value) { + if (side != this.getSide() && side != ForgeDirection.UNKNOWN) { + return false; + } + + setRedstoneOutput(side != ForgeDirection.UNKNOWN, value); + return true; + } } diff --git a/common/buildcraft/transport/PipeTransportItems.java b/common/buildcraft/transport/PipeTransportItems.java index 421ab5d5..aa36a012 100644 --- a/common/buildcraft/transport/PipeTransportItems.java +++ b/common/buildcraft/transport/PipeTransportItems.java @@ -253,10 +253,6 @@ public class PipeTransportItems extends PipeTransport implements IDebuggable { private void moveSolids() { items.flush(); - if (!container.getWorldObj().isRemote) { - items.purgeCorruptedItems(); - } - items.iterating = true; for (TravelingItem item : items) { if (item.getContainer() != this.container) { @@ -270,6 +266,11 @@ public class PipeTransportItems extends PipeTransport implements IDebuggable { item.movePosition(motion.x, motion.y, motion.z); if ((item.toCenter && middleReached(item)) || outOfBounds(item)) { + if (item.isCorrupted()) { + items.remove(item); + continue; + } + item.toCenter = false; // Reajusting to the middle @@ -285,6 +286,11 @@ public class PipeTransportItems extends PipeTransport implements IDebuggable { } } else if (!item.toCenter && endReached(item)) { + if (item.isCorrupted()) { + items.remove(item); + continue; + } + TileEntity tile = container.getTile(item.output); PipeEventItem.ReachedEnd event = new PipeEventItem.ReachedEnd(item, tile); diff --git a/common/buildcraft/transport/PipeTriggerProvider.java b/common/buildcraft/transport/PipeTriggerProvider.java index 74809760..315fe207 100644 --- a/common/buildcraft/transport/PipeTriggerProvider.java +++ b/common/buildcraft/transport/PipeTriggerProvider.java @@ -43,9 +43,6 @@ public class PipeTriggerProvider implements ITriggerProvider { gate.addTriggers(result); } } - - result.add(BuildCraftCore.triggerRedstoneActive); - result.add(BuildCraftCore.triggerRedstoneInactive); switch (((TileGenericPipe) tile).getPipeType()) { case ITEM: diff --git a/common/buildcraft/transport/TravelerSet.java b/common/buildcraft/transport/TravelerSet.java index 798047ed..501125a1 100644 --- a/common/buildcraft/transport/TravelerSet.java +++ b/common/buildcraft/transport/TravelerSet.java @@ -21,7 +21,7 @@ public class TravelerSet extends ForwardingSet { public boolean iterating; - private final BiMap items = HashBiMap.create(); + private final Set items = new HashSet(); private final Set toLoad = new HashSet(); private final Set toAdd = new HashSet(); private final Set toRemove = new HashSet(); @@ -34,7 +34,7 @@ public class TravelerSet extends ForwardingSet { @Override protected Set delegate() { - return items.values(); + return items; } @Override @@ -42,11 +42,8 @@ public class TravelerSet extends ForwardingSet { if (iterating) { return toAdd.add(item); } - if (items.containsValue(item)) { - return false; - } item.setContainer(transport.container); - items.put(item.id, item); + items.add(item); return true; } @@ -76,10 +73,6 @@ public class TravelerSet extends ForwardingSet { throw new UnsupportedOperationException(); } - public TravelingItem get(int id) { - return items.get(id); - } - void scheduleLoad(TravelingItem item) { delay = 10; toLoad.add(item); @@ -108,20 +101,10 @@ public class TravelerSet extends ForwardingSet { } void removeScheduledItems() { - items.values().removeAll(toRemove); + items.removeAll(toRemove); toRemove.clear(); } - void purgeCorruptedItems() { - Iterator it = items.values().iterator(); - while (it.hasNext()) { - TravelingItem item = it.next(); - if (item.isCorrupted()) { - it.remove(); - } - } - } - void flush() { loadScheduledItems(); addScheduledItems(); @@ -130,7 +113,7 @@ public class TravelerSet extends ForwardingSet { @Override public Iterator iterator() { - return items.values().iterator(); + return items.iterator(); } @Override diff --git a/common/buildcraft/transport/TravelingItem.java b/common/buildcraft/transport/TravelingItem.java index cc9f7372..07b8194f 100644 --- a/common/buildcraft/transport/TravelingItem.java +++ b/common/buildcraft/transport/TravelingItem.java @@ -285,9 +285,7 @@ public class TravelingItem { @Override public int hashCode() { - int hash = 7; - hash = 67 * hash + this.id; - return hash; + return this.id; } @Override diff --git a/common/buildcraft/transport/gates/GateExpansionLightSensor.java b/common/buildcraft/transport/gates/GateExpansionLightSensor.java new file mode 100644 index 00000000..03d28a91 --- /dev/null +++ b/common/buildcraft/transport/gates/GateExpansionLightSensor.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2011-2015, 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.gates; + +import java.util.Arrays; +import java.util.List; +import net.minecraft.tileentity.TileEntity; +import buildcraft.BuildCraftTransport; +import buildcraft.api.gates.GateExpansionController; +import buildcraft.api.gates.IGateExpansion; +import buildcraft.api.statements.IActionInternal; +import buildcraft.api.statements.ITriggerInternal; + +public final class GateExpansionLightSensor extends GateExpansionBuildcraft implements IGateExpansion { + + public static GateExpansionLightSensor INSTANCE = new GateExpansionLightSensor(); + + private GateExpansionLightSensor() { + super("light_sensor"); + } + + @Override + public GateExpansionController makeController(TileEntity pipeTile) { + return new GateExpansionControllerLightSensor(pipeTile); + } + + private class GateExpansionControllerLightSensor extends GateExpansionController { + + public GateExpansionControllerLightSensor(TileEntity pipeTile) { + super(GateExpansionLightSensor.this, pipeTile); + } + + @Override + public void addTriggers(List list) { + super.addTriggers(list); + list.add(BuildCraftTransport.triggerLightSensorBright); + list.add(BuildCraftTransport.triggerLightSensorDark); + } + } +} diff --git a/common/buildcraft/transport/gates/ItemGate.java b/common/buildcraft/transport/gates/ItemGate.java index 9f0bcac0..f468ee53 100755 --- a/common/buildcraft/transport/gates/ItemGate.java +++ b/common/buildcraft/transport/gates/ItemGate.java @@ -37,6 +37,7 @@ import buildcraft.api.statements.StatementManager; import buildcraft.api.transport.IPipe; import buildcraft.api.transport.pluggable.IPipePluggableItem; import buildcraft.api.transport.pluggable.PipePluggable; +import buildcraft.core.BCCreativeTab; import buildcraft.core.lib.items.ItemBuildCraft; import buildcraft.core.lib.inventory.InvUtils; import buildcraft.core.lib.utils.StringUtils; @@ -50,12 +51,14 @@ public class ItemGate extends ItemBuildCraft implements IPipePluggableItem { protected static final String NBT_TAG_MAT = "mat"; protected static final String NBT_TAG_LOGIC = "logic"; protected static final String NBT_TAG_EX = "ex"; + private static ArrayList allGates; public ItemGate() { super(); setHasSubtypes(false); setMaxDamage(0); setPassSneakClick(true); + setCreativeTab(BCCreativeTab.get("gates")); } private static NBTTagCompound getNBT(ItemStack stack) { @@ -207,22 +210,6 @@ public class ItemGate extends ItemBuildCraft implements IPipePluggableItem { } } - public static ItemStack[] getGateVarients() { - ArrayList gates = new ArrayList(); - - for (GateMaterial material : GateMaterial.VALUES) { - for (GateLogic logic : GateLogic.VALUES) { - if (material == GateMaterial.REDSTONE && logic == GateLogic.OR) { - continue; - } - - gates.add(makeGateItem(material, logic)); - } - } - - return gates.toArray(new ItemStack[gates.size()]); - } - @Override public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean adv) { super.addInformation(stack, player, list, adv); @@ -269,4 +256,20 @@ public class ItemGate extends ItemBuildCraft implements IPipePluggableItem { return new GatePluggable(GateFactory.makeGate(realPipe, stack, side)); } + + public static ArrayList getAllGates() { + if (allGates == null) { + allGates = new ArrayList(); + for (GateDefinition.GateMaterial m : GateDefinition.GateMaterial.VALUES) { + for (GateDefinition.GateLogic l : GateDefinition.GateLogic.VALUES) { + if (m == GateMaterial.REDSTONE && l == GateLogic.OR) { + continue; + } + + allGates.add(ItemGate.makeGateItem(m, l)); + } + } + } + return allGates; + } } diff --git a/common/buildcraft/transport/pipes/PipeItemsEmerald.java b/common/buildcraft/transport/pipes/PipeItemsEmerald.java index 29b50397..da0f96ac 100644 --- a/common/buildcraft/transport/pipes/PipeItemsEmerald.java +++ b/common/buildcraft/transport/pipes/PipeItemsEmerald.java @@ -131,8 +131,12 @@ public class PipeItemsEmerald extends PipeItemsWood implements ISerializable, IG } if (doRemove) { - int stackSize = (int) Math.floor(battery.useEnergy(10, 10 * stack.stackSize, false) / 10); - + int maxStackSize = stack.stackSize; + int stackSize = Math.min(maxStackSize, battery.getEnergyStored() / 10); + speedMultiplier = Math.min(4.0F, battery.getEnergyStored() * 10 / stackSize); + int energyUsed = (int) (stackSize * 10 * speedMultiplier); + battery.useEnergy(energyUsed, energyUsed, false); + stack = inventory.decrStackSize(k, stackSize); } @@ -165,6 +169,9 @@ public class PipeItemsEmerald extends PipeItemsWood implements ISerializable, IG // In Round Robin mode, extract only 1 item regardless of power level. stack = inventory.decrStackSize(i, 1); incrementFilter(); + } else { + stack = stack.copy(); + stack.stackSize = 1; } return new ItemStack[]{ stack }; diff --git a/common/buildcraft/transport/pipes/PipeItemsWood.java b/common/buildcraft/transport/pipes/PipeItemsWood.java index c374d63f..ed29c840 100644 --- a/common/buildcraft/transport/pipes/PipeItemsWood.java +++ b/common/buildcraft/transport/pipes/PipeItemsWood.java @@ -35,10 +35,11 @@ import buildcraft.transport.PipeTransportItems; import buildcraft.transport.TravelingItem; public class PipeItemsWood extends Pipe implements IEnergyHandler { - protected RFBattery battery = new RFBattery(640, 80, 0); + protected RFBattery battery = new RFBattery(2560, 2560 / 8, 0); protected int standardIconIndex = PipeIconProvider.TYPE.PipeItemsWood_Standard.ordinal(); protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal(); + protected float speedMultiplier = 1.0F; private int ticksSincePull = 0; @@ -114,15 +115,40 @@ public class PipeItemsWood extends Pipe implements IEnergyHa battery.setEnergy(0); ticksSincePull = 0; + speedMultiplier = 1.0F; } } private boolean shouldTick() { - if (battery.getEnergyStored() >= 64 * 10) { - return true; + if (ticksSincePull < 8) { + return false; } else { - return ticksSincePull >= 16 && battery.getEnergyStored() >= 10; + // Check if we have just enough energy for the next stack. + int meta = container.getBlockMetadata(); + + if (meta <= 5) { + ForgeDirection side = ForgeDirection.getOrientation(meta); + TileEntity tile = container.getTile(side); + + if (tile instanceof IInventory) { + int stackSize = 0; + IInventory inventory = (IInventory) tile; + ItemStack[] extracted = checkExtract(inventory, false, side.getOpposite()); + if (extracted != null) { + for (ItemStack s : extracted) { + stackSize += s.stackSize; + } + } + + if (battery.getEnergyStored() >= stackSize * 10) { + return true; + } + } + } + } + + return ticksSincePull >= 16 && battery.getEnergyStored() >= 10; } private void extractItems() { @@ -157,7 +183,7 @@ public class PipeItemsWood extends Pipe implements IEnergyHa entityPos.moveForwards(0.6); TravelingItem entity = makeItem(entityPos.x, entityPos.y, entityPos.z, stack); - + entity.setSpeed(entity.getSpeed() * speedMultiplier); transport.injectItem(entity, entityPos.orientation); } } @@ -197,8 +223,12 @@ public class PipeItemsWood extends Pipe implements IEnergyHa if (slot != null && slot.stackSize > 0 && inventory.canExtractItem(k, slot, from.ordinal())) { if (doRemove) { - int stackSize = (int) Math.floor(battery.useEnergy(10, slot.stackSize * 10, false) / 10); - + int maxStackSize = slot.stackSize; + int stackSize = Math.min(maxStackSize, battery.getEnergyStored() / 10); + speedMultiplier = Math.min(4.0F, battery.getEnergyStored() * 10 / stackSize); + int energyUsed = (int) (stackSize * 10 * speedMultiplier); + battery.useEnergy(energyUsed, energyUsed, false); + return inventory.decrStackSize(k, stackSize); } else { return slot; diff --git a/common/buildcraft/transport/recipes/AdvancedFacadeRecipe.java b/common/buildcraft/transport/recipes/AdvancedFacadeRecipe.java index 4c513f7e..45d150bb 100644 --- a/common/buildcraft/transport/recipes/AdvancedFacadeRecipe.java +++ b/common/buildcraft/transport/recipes/AdvancedFacadeRecipe.java @@ -20,6 +20,7 @@ import buildcraft.api.recipes.CraftingResult; import buildcraft.api.transport.PipeWire; import buildcraft.silicon.ItemRedstoneChipset; import buildcraft.silicon.TileIntegrationTable; +import buildcraft.silicon.recipes.IntegrationTableRecipe; import buildcraft.transport.ItemFacade; import buildcraft.transport.ItemFacade.FacadeState; import buildcraft.transport.ItemPipeWire; diff --git a/common/buildcraft/transport/recipes/GateExpansionRecipe.java b/common/buildcraft/transport/recipes/GateExpansionRecipe.java index 3c879407..81797e55 100644 --- a/common/buildcraft/transport/recipes/GateExpansionRecipe.java +++ b/common/buildcraft/transport/recipes/GateExpansionRecipe.java @@ -8,6 +8,8 @@ */ package buildcraft.transport.recipes; +import java.util.ArrayList; +import java.util.Collection; import net.minecraft.item.ItemStack; import buildcraft.BuildCraftTransport; @@ -15,6 +17,7 @@ import buildcraft.api.gates.IGateExpansion; import buildcraft.api.recipes.CraftingResult; import buildcraft.core.lib.inventory.StackHelper; import buildcraft.silicon.TileIntegrationTable; +import buildcraft.silicon.recipes.IntegrationTableRecipe; import buildcraft.transport.gates.ItemGate; public class GateExpansionRecipe extends IntegrationTableRecipe { @@ -68,4 +71,26 @@ public class GateExpansionRecipe extends IntegrationTableRecipe { return result; } + + @Override + public Collection getInputs() { + ArrayList inputs = new ArrayList(); + + inputs.add(ItemGate.getAllGates()); + inputs.add(chipset); + + return inputs; + } + + /*@Override + public Collection getOutput() { + ArrayList gates = new ArrayList(); + for (ItemStack stack : ItemGate.getAllGates()) { + ItemStack newStack = stack.copy(); + ItemGate.addGateExpansion(stack, expansion); + gates.add(newStack); + } + + return gates; + }*/ } diff --git a/common/buildcraft/transport/recipes/GateLogicSwapRecipe.java b/common/buildcraft/transport/recipes/GateLogicSwapRecipe.java index 556a0109..7493cab4 100644 --- a/common/buildcraft/transport/recipes/GateLogicSwapRecipe.java +++ b/common/buildcraft/transport/recipes/GateLogicSwapRecipe.java @@ -8,6 +8,8 @@ */ package buildcraft.transport.recipes; +import java.util.ArrayList; +import java.util.Collection; import net.minecraft.item.ItemStack; import buildcraft.BuildCraftTransport; @@ -15,6 +17,7 @@ import buildcraft.api.recipes.CraftingResult; import buildcraft.core.lib.inventory.StackHelper; import buildcraft.silicon.ItemRedstoneChipset; import buildcraft.silicon.TileIntegrationTable; +import buildcraft.silicon.recipes.IntegrationTableRecipe; import buildcraft.transport.gates.GateDefinition.GateLogic; import buildcraft.transport.gates.GateDefinition.GateMaterial; import buildcraft.transport.gates.ItemGate; @@ -53,4 +56,14 @@ public class GateLogicSwapRecipe extends IntegrationTableRecipe { return result; } + + @Override + public Collection getInputs() { + ArrayList inputs = new ArrayList(); + + inputs.add(ItemGate.getAllGates()); + inputs.add(ItemRedstoneChipset.Chipset.RED.getStack()); + + return inputs; + } } diff --git a/common/buildcraft/transport/render/PipeRendererTESR.java b/common/buildcraft/transport/render/PipeRendererTESR.java index 8c60593b..5168a4d1 100644 --- a/common/buildcraft/transport/render/PipeRendererTESR.java +++ b/common/buildcraft/transport/render/PipeRendererTESR.java @@ -796,7 +796,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { Position motion = new Position(0, 0, 0, item.toCenter ? item.input : item.output); motion.moveForwards(item.getSpeed() * f); - doRenderItem(item, x + item.xCoord - pipe.container.xCoord + motion.x,y + item.yCoord - pipe.container.yCoord, z + item.zCoord - pipe.container.zCoord, light, item.color); + doRenderItem(item, x + item.xCoord - pipe.container.xCoord + motion.x, y + item.yCoord - pipe.container.yCoord + motion.y, z + item.zCoord - pipe.container.zCoord + motion.z, light, item.color); count++; } diff --git a/common/buildcraft/transport/statements/TriggerLightSensor.java b/common/buildcraft/transport/statements/TriggerLightSensor.java new file mode 100644 index 00000000..6dd27b58 --- /dev/null +++ b/common/buildcraft/transport/statements/TriggerLightSensor.java @@ -0,0 +1,49 @@ +package buildcraft.transport.statements; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.tileentity.TileEntity; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import buildcraft.api.core.Position; +import buildcraft.api.statements.containers.ISidedStatementContainer; +import buildcraft.api.statements.IStatementContainer; +import buildcraft.api.statements.IStatementParameter; +import buildcraft.api.statements.ITriggerInternal; +import buildcraft.core.lib.utils.StringUtils; +import buildcraft.core.statements.BCStatement; + +/** + * Created by asie on 3/14/15. + */ +public class TriggerLightSensor extends BCStatement implements ITriggerInternal { + private final boolean bright; + + public TriggerLightSensor(boolean bright) { + super("buildcraft:light_" + (bright ? "bright" : "dark")); + this.bright = bright; + } + + @Override + public String getDescription() { + return StringUtils.localize("gate.trigger.light." + (bright ? "bright" : "dark")); + } + + @Override + public boolean isTriggerActive(IStatementContainer source, IStatementParameter[] parameters) { + TileEntity tile = source.getTile(); + Position pos = new Position(tile); + pos.orientation = ((ISidedStatementContainer) source).getSide(); + pos.moveForwards(1.0); + + int lightLevel = tile.getWorldObj().getBlockLightValue((int) pos.x, (int) pos.y, (int) pos.z); + + return (lightLevel < 8) ^ bright; + } + + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconRegister) { + icon = iconRegister.registerIcon("buildcrafttransport:triggers/trigger_light_" + (bright ? "bright" : "dark")); + } +}