From 76de1cf185f8d5240385515b328dc40d6a44a974 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sun, 8 Jun 2014 18:54:38 -0500 Subject: [PATCH] Item Tunnels now cycle Outputs. --- core/settings/TickRates.java | 45 ++++++++++++++------------ parts/layers/LayerISidedInventory.java | 4 +-- parts/p2p/PartP2PItems.java | 34 ++++++++++++++++--- util/inv/WrapperChainedInventory.java | 13 ++++++++ 4 files changed, 69 insertions(+), 27 deletions(-) diff --git a/core/settings/TickRates.java b/core/settings/TickRates.java index ddad506c7..7e9fa1fed 100644 --- a/core/settings/TickRates.java +++ b/core/settings/TickRates.java @@ -2,41 +2,46 @@ package appeng.core.settings; import appeng.core.AEConfig; -public enum TickRates { +public enum TickRates +{ + + Interface(5, 120), - Interface(5,120), - ImportBus(5, 40), - + ExportBus(5, 60), - + AnnihilationPlane(2, 120), MJTunnel(1, 20), - + METunnel(5, 20), - + Inscriber(1, 1), - + IOPort(1, 5), - + VibrationChamber(10, 40), - - StorageBus(5, 60); - + + StorageBus(5, 60), + + ItemTunnel(5, 60); + public int min; public int max; - - private TickRates( int min, int max ) { + + private TickRates(int min, int max) { this.min = min; this.max = max; } - - public void Load( AEConfig config ) + + public void Load(AEConfig config) { - config.addCustomCategoryComment("TickRates", " Min / Max Tickrates for dynamic ticking, most of these components also use sleeping, to prevent constant ticking, adjust with care, non standard rates are not supported or tested." ); - min = config.get( "TickRates", name()+".min", min ).getInt(min); - max = config.get( "TickRates", name()+".max", max ).getInt(max); + config.addCustomCategoryComment( + "TickRates", + " Min / Max Tickrates for dynamic ticking, most of these components also use sleeping, to prevent constant ticking, adjust with care, non standard rates are not supported or tested." ); + min = config.get( "TickRates", name() + ".min", min ).getInt( min ); + max = config.get( "TickRates", name() + ".max", max ).getInt( max ); } - + } diff --git a/parts/layers/LayerISidedInventory.java b/parts/layers/LayerISidedInventory.java index 2b6494ad8..1812763fa 100644 --- a/parts/layers/LayerISidedInventory.java +++ b/parts/layers/LayerISidedInventory.java @@ -38,7 +38,7 @@ public class LayerISidedInventory extends LayerBase implements ISidedInventory * Recalculate inventory wrapper cache. */ @Override - public void partChanged() + public void notifyNeighbors() { invs = new ArrayList(); int slotCount = 0; @@ -90,7 +90,7 @@ public class LayerISidedInventory extends LayerBase implements ISidedInventory } // make sure inventory is updated before we call FMP. - super.partChanged(); + super.notifyNeighbors(); } /** diff --git a/parts/p2p/PartP2PItems.java b/parts/p2p/PartP2PItems.java index a36ae1ee8..9e95d2917 100644 --- a/parts/p2p/PartP2PItems.java +++ b/parts/p2p/PartP2PItems.java @@ -13,11 +13,16 @@ import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.IIcon; import net.minecraftforge.common.util.ForgeDirection; import appeng.api.config.TunnelType; +import appeng.api.networking.IGridNode; import appeng.api.networking.events.MENetworkBootingStatusChange; import appeng.api.networking.events.MENetworkChannelsChanged; import appeng.api.networking.events.MENetworkEventSubscribe; import appeng.api.networking.events.MENetworkPowerStatusChange; +import appeng.api.networking.ticking.IGridTickable; +import appeng.api.networking.ticking.TickRateModulation; +import appeng.api.networking.ticking.TickingRequest; import appeng.core.AppEng; +import appeng.core.settings.TickRates; import appeng.integration.abstraction.IBC; import appeng.me.GridAccessException; import appeng.me.cache.helpers.TunnelCollection; @@ -34,7 +39,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @Interface(iface = "buildcraft.api.transport.IPipeConnection", iname = "BC") -public class PartP2PItems extends PartP2PTunnel implements IPipeConnection, IInventory, ISidedInventory +public class PartP2PItems extends PartP2PTunnel implements IPipeConnection, IInventory, ISidedInventory, IGridTickable { public TunnelType getTunnelType() @@ -47,6 +52,7 @@ public class PartP2PItems extends PartP2PTunnel implements IPipeCo } int oldSize = 0; + boolean requsted; IInventory cachedInv; LinkedList which = new LinkedList(); @@ -119,8 +125,28 @@ public class PartP2PItems extends PartP2PTunnel implements IPipeCo input.onTunnelNetworkChange(); } + @Override + public TickingRequest getTickingRequest(IGridNode node) + { + return new TickingRequest( TickRates.ItemTunnel.min, TickRates.ItemTunnel.max, false, false ); + } + + @Override + public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) + { + boolean wasReq = requsted; + + if ( requsted && cachedInv != null ) + ((WrapperChainedInventory) cachedInv).cycleOrder(); + + requsted = false; + return wasReq ? TickRateModulation.FASTER : TickRateModulation.SLOWER; + } + IInventory getDest() { + requsted = true; + if ( cachedInv != null ) return cachedInv; @@ -191,8 +217,7 @@ public class PartP2PItems extends PartP2PTunnel implements IPipeCo oldSize = getDest().getSizeInventory(); if ( olderSize != oldSize ) { - getHost().partChanged(); - tile.getWorldObj().notifyBlocksOfNeighborChange( tile.xCoord, tile.yCoord, tile.zCoord, Platform.air ); + getHost().notifyNeighbors(); } } } @@ -207,8 +232,7 @@ public class PartP2PItems extends PartP2PTunnel implements IPipeCo oldSize = getDest().getSizeInventory(); if ( olderSize != oldSize ) { - getHost().partChanged(); - tile.getWorldObj().notifyBlocksOfNeighborChange( tile.xCoord, tile.yCoord, tile.zCoord, Platform.air ); + getHost().notifyNeighbors(); } } else diff --git a/util/inv/WrapperChainedInventory.java b/util/inv/WrapperChainedInventory.java index a1e71c4f6..66e0adf9b 100644 --- a/util/inv/WrapperChainedInventory.java +++ b/util/inv/WrapperChainedInventory.java @@ -32,6 +32,18 @@ public class WrapperChainedInventory implements IInventory setInventory( ilist ); } + public void cycleOrder() + { + if ( l.size() > 1 ) + { + List newOrder = new ArrayList( l.size() ); + newOrder.add( l.get( l.size() - 1 ) ); + for (int x = 0; x < l.size() - 1; x++) + newOrder.add( l.get( x ) ); + setInventory( newOrder ); + } + } + public void calculateSizes() { offsets = new HashMap(); @@ -195,4 +207,5 @@ public class WrapperChainedInventory implements IInventory } return false; } + }