From 97ae2b78e39eea05499a4efdb6415438cbc59c8e Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Tue, 18 Feb 2014 23:26:43 -0600 Subject: [PATCH] Fixed Crash in Formation Plane. Fixed Bug: #0166 - Combination TPane and FPane seems getting stuck --- helpers/TickHandler.java | 6 +- me/NetworkList.java | 103 +++++++++++++++++++++++ parts/automation/PartFormationPlane.java | 61 +++++++++++--- 3 files changed, 158 insertions(+), 12 deletions(-) create mode 100644 me/NetworkList.java diff --git a/helpers/TickHandler.java b/helpers/TickHandler.java index 8e290e26..ebf7bab7 100644 --- a/helpers/TickHandler.java +++ b/helpers/TickHandler.java @@ -1,5 +1,6 @@ package appeng.helpers; +import java.util.Collection; import java.util.LinkedList; import java.util.Queue; import java.util.concurrent.Callable; @@ -8,6 +9,7 @@ import net.minecraftforge.event.world.WorldEvent; import appeng.api.networking.IGridNode; import appeng.core.AELog; import appeng.me.Grid; +import appeng.me.NetworkList; import appeng.tile.AEBaseTile; import appeng.util.Platform; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -22,12 +24,12 @@ public class TickHandler public Queue tiles = new LinkedList(); - public LinkedList networks = new LinkedList(); + public Collection networks = new NetworkList(); public void clear() { tiles = new LinkedList(); - networks = new LinkedList(); + networks = new NetworkList(); } }; diff --git a/me/NetworkList.java b/me/NetworkList.java new file mode 100644 index 00000000..a2336afb --- /dev/null +++ b/me/NetworkList.java @@ -0,0 +1,103 @@ +package appeng.me; + +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +public class NetworkList implements Collection +{ + + private List networks = new LinkedList(); + + @Override + public boolean add(Grid e) + { + copy(); + return networks.add( e ); + } + + @Override + public boolean addAll(Collection c) + { + copy(); + return networks.addAll( c ); + } + + @Override + public void clear() + { + networks = new LinkedList(); + } + + @Override + public boolean contains(Object o) + { + return networks.contains( o ); + } + + @Override + public boolean containsAll(Collection c) + { + return networks.containsAll( c ); + } + + @Override + public boolean isEmpty() + { + return networks.isEmpty(); + } + + @Override + public Iterator iterator() + { + return networks.iterator(); + } + + @Override + public boolean remove(Object o) + { + copy(); + return networks.remove( o ); + } + + @Override + public boolean removeAll(Collection c) + { + copy(); + return networks.removeAll( c ); + } + + @Override + public boolean retainAll(Collection c) + { + copy(); + return networks.retainAll( c ); + } + + private void copy() + { + List old = networks; + networks = new LinkedList(); + networks.addAll( old ); + } + + @Override + public int size() + { + return networks.size(); + } + + @Override + public Object[] toArray() + { + return networks.toArray(); + } + + @Override + public T[] toArray(T[] a) + { + return networks.toArray( a ); + } + +} diff --git a/parts/automation/PartFormationPlane.java b/parts/automation/PartFormationPlane.java index bebb8707..26d45d30 100644 --- a/parts/automation/PartFormationPlane.java +++ b/parts/automation/PartFormationPlane.java @@ -26,6 +26,7 @@ import appeng.api.config.Upgrades; import appeng.api.networking.events.MENetworkCellArrayUpdate; import appeng.api.networking.events.MENetworkChannelsChanged; import appeng.api.networking.events.MENetworkEventSubscribe; +import appeng.api.networking.events.MENetworkPowerStatusChange; import appeng.api.networking.security.BaseActionSource; import appeng.api.parts.IPart; import appeng.api.parts.IPartCollsionHelper; @@ -96,6 +97,17 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine return super.getInventoryByName( name ); } + @MENetworkEventSubscribe + public void powerRender(MENetworkPowerStatusChange c) + { + boolean currentActive = proxy.isActive(); + if ( wasActive != currentActive ) + { + wasActive = currentActive; + updateHandler();// proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() ); + } + } + @MENetworkEventSubscribe public void updateChannels(MENetworkChannelsChanged chann) { @@ -103,14 +115,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine if ( wasActive != currentActive ) { wasActive = currentActive; - try - { - proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() ); - } - catch (GridAccessException e) - { - // :P - } + updateHandler();// proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() ); } } @@ -375,8 +380,42 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine if ( i instanceof ItemBlock || i instanceof IPlantable ) { EntityPlayer player = Platform.getPlayer( (WorldServer) w ); - player.prevCameraPitch = player.cameraPitch = 0; - player.prevCameraYaw = player.cameraYaw = 0; + + float pitch = 0.0f, yaw = 0.0f; + player.yOffset = 1.8f; + + switch (side) + { + case DOWN: + pitch = 90.0f; + player.yOffset = -1.8f; + break; + case EAST: + yaw = -90.0f; + break; + case NORTH: + yaw = 180.0f; + break; + case SOUTH: + yaw = 0.0f; + break; + case UNKNOWN: + break; + case UP: + pitch = 90.0f; + break; + case WEST: + yaw = 90.0f; + break; + } + + player.posX = (float) tile.xCoord + 0.5; + player.posY = (float) tile.yCoord + 0.5; + player.posZ = (float) tile.zCoord + 0.5; + + player.rotationPitch = player.prevCameraPitch = player.cameraPitch = pitch; + player.rotationYaw = player.prevCameraYaw = player.cameraYaw = yaw; + maxStorage = is.stackSize; worked = true; if ( type == Actionable.MODULATE ) @@ -415,6 +454,8 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine { IAEItemStack out = input.copy(); out.decStackSize( maxStorage ); + if ( out.getStackSize() == 0 ) + return null; return out; }