I lied, I'm not signing off. Packets for Battery multiblock

This commit is contained in:
Aidan Brady 2013-08-04 03:35:33 -04:00
parent 796ab2eee2
commit ca44ee4cf4
2 changed files with 51 additions and 7 deletions

View file

@ -20,6 +20,11 @@ public class SynchronizedBatteryData
public boolean didTick;
public int getVolume()
{
return length*width*height;
}
@Override
public int hashCode()
{

View file

@ -3,6 +3,7 @@
*/
package resonantinduction.battery;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
@ -10,33 +11,36 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import resonantinduction.PacketHandler;
import resonantinduction.api.IBattery;
import resonantinduction.base.IPacketReceiver;
import resonantinduction.base.TileEntityBase;
import com.google.common.io.ByteArrayDataInput;
/**
* A modular battery with no GUI.
*
* @author Calclavia
* @author AidanBrady
*/
public class TileEntityBattery extends TileEntityBase
public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
{
public Set<ItemStack> inventory = new HashSet<ItemStack>();
private byte[] sideStatus = new byte[] { 0, 0, 0, 0, 0, 0 };
public SynchronizedBatteryData structure;
public boolean prevStructure;
public boolean clientHasStructure;
public int inventoryID;
public int inventoryID = BatteryManager.WILDCARD;
@Override
public void updateEntity()
{
//DO NOT SUPER, CALCLAVIA!
ticks++;
//DO NOT SUPER
if(worldObj.isRemote)
{
@ -70,7 +74,7 @@ public class TileEntityBattery extends TileEntityBase
if(prevStructure != (structure != null))
{
//packet
PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList()));
}
prevStructure = structure != null;
@ -165,4 +169,39 @@ public class TileEntityBattery extends TileEntityBase
return max;
}
@Override
public void handle(ByteArrayDataInput input)
{
try {
if(structure == null)
{
structure = new SynchronizedBatteryData();
}
clientHasStructure = input.readBoolean();
if(clientHasStructure)
{
structure.height = input.readInt();
structure.length = input.readInt();
structure.width = input.readInt();
}
} catch(Exception e) {}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add(structure != null);
if(structure != null)
{
data.add(structure.height);
data.add(structure.length);
data.add(structure.width);
}
return data;
}
}