I lied, I'm not signing off. Packets for Battery multiblock
This commit is contained in:
parent
796ab2eee2
commit
ca44ee4cf4
2 changed files with 51 additions and 7 deletions
|
@ -20,6 +20,11 @@ public class SynchronizedBatteryData
|
||||||
|
|
||||||
public boolean didTick;
|
public boolean didTick;
|
||||||
|
|
||||||
|
public int getVolume()
|
||||||
|
{
|
||||||
|
return length*width*height;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
package resonantinduction.battery;
|
package resonantinduction.battery;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -10,33 +11,36 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import resonantinduction.PacketHandler;
|
||||||
import resonantinduction.api.IBattery;
|
import resonantinduction.api.IBattery;
|
||||||
|
import resonantinduction.base.IPacketReceiver;
|
||||||
import resonantinduction.base.TileEntityBase;
|
import resonantinduction.base.TileEntityBase;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A modular battery with no GUI.
|
* 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>();
|
public Set<ItemStack> inventory = new HashSet<ItemStack>();
|
||||||
|
|
||||||
private byte[] sideStatus = new byte[] { 0, 0, 0, 0, 0, 0 };
|
|
||||||
|
|
||||||
public SynchronizedBatteryData structure;
|
public SynchronizedBatteryData structure;
|
||||||
|
|
||||||
public boolean prevStructure;
|
public boolean prevStructure;
|
||||||
|
|
||||||
public boolean clientHasStructure;
|
public boolean clientHasStructure;
|
||||||
|
|
||||||
public int inventoryID;
|
public int inventoryID = BatteryManager.WILDCARD;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity()
|
public void updateEntity()
|
||||||
{
|
{
|
||||||
|
//DO NOT SUPER, CALCLAVIA!
|
||||||
|
|
||||||
ticks++;
|
ticks++;
|
||||||
//DO NOT SUPER
|
|
||||||
|
|
||||||
if(worldObj.isRemote)
|
if(worldObj.isRemote)
|
||||||
{
|
{
|
||||||
|
@ -70,7 +74,7 @@ public class TileEntityBattery extends TileEntityBase
|
||||||
|
|
||||||
if(prevStructure != (structure != null))
|
if(prevStructure != (structure != null))
|
||||||
{
|
{
|
||||||
//packet
|
PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
prevStructure = structure != null;
|
prevStructure = structure != null;
|
||||||
|
@ -165,4 +169,39 @@ public class TileEntityBattery extends TileEntityBase
|
||||||
|
|
||||||
return max;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue