From 64706f7a376e4cada035d611fe0ee9e87d4f65d6 Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Sun, 4 Aug 2013 02:48:17 -0400 Subject: [PATCH] More battery work, algorithm semi-working --- .../battery/BatteryManager.java | 2 +- .../battery/BatteryUpdateProtocol.java | 8 ++- .../battery/TileEntityBattery.java | 63 +++++++++++++++++-- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/resonantinduction/battery/BatteryManager.java b/src/resonantinduction/battery/BatteryManager.java index 4d6903b0..511b76e3 100644 --- a/src/resonantinduction/battery/BatteryManager.java +++ b/src/resonantinduction/battery/BatteryManager.java @@ -53,7 +53,7 @@ public class BatteryManager implements ITickHandler * @param inventory - inventory of the battery * @param tileEntity - battery TileEntity */ - public static void updateCache(int inventoryID, HashSet inventory, TileEntityBattery tileEntity) + public static void updateCache(int inventoryID, Set inventory, TileEntityBattery tileEntity) { if(!dynamicInventories.containsKey(inventoryID)) { diff --git a/src/resonantinduction/battery/BatteryUpdateProtocol.java b/src/resonantinduction/battery/BatteryUpdateProtocol.java index eb81fc54..e5c7a13d 100644 --- a/src/resonantinduction/battery/BatteryUpdateProtocol.java +++ b/src/resonantinduction/battery/BatteryUpdateProtocol.java @@ -156,8 +156,14 @@ public class BatteryUpdateProtocol structure.height = Math.abs(ymax-ymin)+1; structure.width = Math.abs(zmax-zmin)+1; - if(structure.locations.contains(new Vector3(pointer))) + if(structure.locations.contains(new Vector3(pointer)) && structure.height > 1 && structure.length > 1 && structure.width > 1) { + System.out.println("Bingo"); + System.out.println("Height: " + structure.height); + System.out.println("Length: " + structure.length); + System.out.println("Width: " + structure.width); + System.out.println("Volume: " + structure.locations.size()); + structureFound = structure; return; } diff --git a/src/resonantinduction/battery/TileEntityBattery.java b/src/resonantinduction/battery/TileEntityBattery.java index dc3665ae..01a528c2 100644 --- a/src/resonantinduction/battery/TileEntityBattery.java +++ b/src/resonantinduction/battery/TileEntityBattery.java @@ -6,6 +6,7 @@ package resonantinduction.battery; import java.util.HashSet; import java.util.Set; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -25,17 +26,67 @@ public class TileEntityBattery extends TileEntityBase public SynchronizedBatteryData structure; - public int inventoryID; + public boolean prevStructure; - public TileEntityBattery() - { - doPacket = false; - } + public boolean clientHasStructure; + + public int inventoryID; @Override public void updateEntity() { - super.updateEntity(); + ticks++; + //DO NOT SUPER + + if(worldObj.isRemote) + { + if(structure == null) + { + structure = new SynchronizedBatteryData(); + } + + prevStructure = clientHasStructure; + } + + if(playersUsing.size() > 0 && ((worldObj.isRemote && !clientHasStructure) || (!worldObj.isRemote && structure == null))) + { + for(EntityPlayer player : playersUsing) + { + player.closeScreen(); + } + } + + if(!worldObj.isRemote) + { + if(inventoryID != -1 && structure == null) + { + BatteryManager.updateCache(inventoryID, inventory, this); + } + + if(structure == null && ticks == 5) + { + update(); + } + + if(prevStructure != (structure != null)) + { + //packet + } + + prevStructure = structure != null; + + if(structure != null) + { + structure.didTick = false; + + if(inventoryID != -1) + { + BatteryManager.updateCache(inventoryID, structure.inventory, this); + + inventory = structure.inventory; + } + } + } } @Override