diff --git a/src/main/java/dan200/computercraft/client/proxy/CCTurtleProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/CCTurtleProxyClient.java index ab89a1362..282056135 100644 --- a/src/main/java/dan200/computercraft/client/proxy/CCTurtleProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/CCTurtleProxyClient.java @@ -11,7 +11,6 @@ import dan200.computercraft.client.render.TileEntityTurtleRenderer; import dan200.computercraft.client.render.TurtleSmartItemModel; import dan200.computercraft.shared.proxy.CCTurtleProxyCommon; import dan200.computercraft.shared.turtle.blocks.TileTurtle; -import dan200.computercraft.shared.turtle.core.TurtleBrain; import dan200.computercraft.shared.turtle.items.ItemTurtleBase; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -36,7 +35,6 @@ import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; import javax.annotation.Nonnull; @@ -146,15 +144,6 @@ public class CCTurtleProxyClient extends CCTurtleProxyCommon } } - @SubscribeEvent - public void onTick( TickEvent.ClientTickEvent event ) - { - if( event.phase == TickEvent.Phase.END ) - { - TurtleBrain.cleanupBrains(); - } - } - @SubscribeEvent public void onTextureStitchEvent( TextureStitchEvent.Pre event ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java index 65a58cf07..0f55a2a4b 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -32,6 +32,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; @@ -182,7 +183,7 @@ public class TileTurtle extends TileComputerBase public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ ) { // Request description from server - requestTileEntityUpdate(); + // requestTileEntityUpdate(); // Apply dye ItemStack currentItem = player.getHeldItem( hand ); diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java index 72c642fc8..53563f7c0 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java @@ -40,132 +40,38 @@ import net.minecraftforge.common.util.Constants; import net.minecraftforge.items.IItemHandlerModifiable; import javax.annotation.Nonnull; -import java.lang.ref.WeakReference; import java.util.*; public class TurtleBrain implements ITurtleAccess { - private static int s_nextInstanceID = 0; - private static Map> s_allClientBrains = new HashMap<>(); - - public static int assignInstanceID() - { - return s_nextInstanceID++; - } - - public static TurtleBrain getClientBrain( int instanceID ) - { - if( instanceID >= 0 ) - { - WeakReference ref = s_allClientBrains.get( instanceID ); - if( ref != null ) - { - TurtleBrain brain = ref.get(); - if( brain != null ) - { - return brain; - } - else - { - s_allClientBrains.remove( instanceID ); - } - } - } - return null; - } - - public static void setClientBrain( int instanceID, TurtleBrain brain ) - { - if( instanceID >= 0 ) - { - if( getClientBrain( instanceID ) != brain ) - { - s_allClientBrains.put( instanceID, new WeakReference<>( brain ) ); - } - } - } - - public static void cleanupBrains() - { - if( s_allClientBrains.size() > 0 ) - { - Iterator>> it = s_allClientBrains.entrySet().iterator(); - while( it.hasNext() ) - { - Map.Entry> entry = it.next(); - WeakReference ref = entry.getValue(); - if( ref != null ) - { - TurtleBrain brain = ref.get(); - if( brain == null ) - { - it.remove(); - } - } - } - } - } - private static final int ANIM_DURATION = 8; private TileTurtle m_owner; private ComputerProxy m_proxy; private GameProfile m_owningPlayer; - private LinkedList m_commandQueue; - private int m_commandsIssued; + private Queue m_commandQueue = new ArrayDeque<>(); + private int m_commandsIssued = 0; - private Map m_upgrades; - private Map m_peripherals; - private Map m_upgradeNBTData; + private Map m_upgrades = new EnumMap<>( TurtleSide.class ); + private Map m_peripherals = new EnumMap<>( TurtleSide.class ); + private Map m_upgradeNBTData = new EnumMap<>( TurtleSide.class ); - private int m_selectedSlot; - private int m_fuelLevel; - private int m_colourHex; - private ResourceLocation m_overlay; + private int m_selectedSlot = 0; + private int m_fuelLevel = 0; + private int m_colourHex = -1; + private ResourceLocation m_overlay = null; - private int m_instanceID; - private EnumFacing m_direction; - private TurtleAnimation m_animation; - private int m_animationProgress; - private int m_lastAnimationProgress; + private EnumFacing m_direction = EnumFacing.NORTH; + private TurtleAnimation m_animation = TurtleAnimation.None; + private int m_animationProgress = 0; + private int m_lastAnimationProgress = 0; TurtlePlayer m_cachedPlayer; public TurtleBrain( TileTurtle turtle ) { m_owner = turtle; - - m_commandQueue = new LinkedList<>(); - m_commandsIssued = 0; - - m_upgrades = new HashMap<>(); - m_peripherals = new HashMap<>(); - m_upgradeNBTData = new HashMap<>(); - - m_selectedSlot = 0; - m_fuelLevel = 0; - m_colourHex = -1; - m_overlay = null; - - m_instanceID = -1; - m_direction = EnumFacing.NORTH; - m_animation = TurtleAnimation.None; - m_animationProgress = 0; - m_lastAnimationProgress = 0; - } - - public TurtleBrain getFutureSelf() - { - if( getOwner().getWorld().isRemote ) - { - TurtleBrain futureSelf = getClientBrain( m_instanceID ); - if( futureSelf != null ) - { - return futureSelf; - } - } - return this; } public void setOwner( TileTurtle owner ) @@ -437,11 +343,6 @@ public class TurtleBrain implements ITurtleAccess } // Animation - if( m_instanceID < 0 ) - { - m_instanceID = assignInstanceID(); - } - nbttagcompound.setInteger( "brainInstanceID", m_instanceID ); nbttagcompound.setInteger( "animation", m_animation.ordinal() ); nbttagcompound.setInteger( "direction", m_direction.getIndex() ); nbttagcompound.setInteger( "fuelLevel", m_fuelLevel ); @@ -494,9 +395,6 @@ public class TurtleBrain implements ITurtleAccess } // Animation - m_instanceID = nbttagcompound.getInteger( "brainInstanceID" ); - setClientBrain( m_instanceID, this ); - TurtleAnimation anim = TurtleAnimation.values()[nbttagcompound.getInteger( "animation" )]; if( anim != m_animation && anim != TurtleAnimation.Wait && @@ -1079,12 +977,7 @@ public class TurtleBrain implements ITurtleAccess if( m_animation == TurtleAnimation.None ) { // Pull a new command - TurtleCommandQueueEntry nextCommand = null; - if( m_commandQueue.peek() != null ) - { - nextCommand = m_commandQueue.remove(); - } - + TurtleCommandQueueEntry nextCommand = m_commandQueue.poll(); if( nextCommand != null ) { // Execute the command