Move controller data to description packet
This commit is contained in:
@@ -1,70 +0,0 @@
|
|||||||
package refinedstorage.network;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
|
||||||
import refinedstorage.RefinedStorageUtils;
|
|
||||||
import refinedstorage.proxy.ClientProxy;
|
|
||||||
import refinedstorage.tile.TileController;
|
|
||||||
|
|
||||||
public class MessageControllerEnergyUpdate implements IMessage, IMessageHandler<MessageControllerEnergyUpdate, IMessage> {
|
|
||||||
public static long LAST_RE_RENDER;
|
|
||||||
|
|
||||||
private int x;
|
|
||||||
private int y;
|
|
||||||
private int z;
|
|
||||||
private int energy;
|
|
||||||
|
|
||||||
public MessageControllerEnergyUpdate() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageControllerEnergyUpdate(TileController controller) {
|
|
||||||
this.x = controller.getPos().getX();
|
|
||||||
this.y = controller.getPos().getY();
|
|
||||||
this.z = controller.getPos().getZ();
|
|
||||||
this.energy = controller.getEnergyStored(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fromBytes(ByteBuf buf) {
|
|
||||||
x = buf.readInt();
|
|
||||||
y = buf.readInt();
|
|
||||||
z = buf.readInt();
|
|
||||||
energy = buf.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void toBytes(ByteBuf buf) {
|
|
||||||
buf.writeInt(x);
|
|
||||||
buf.writeInt(y);
|
|
||||||
buf.writeInt(z);
|
|
||||||
buf.writeInt(energy);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IMessage onMessage(MessageControllerEnergyUpdate message, MessageContext ctx) {
|
|
||||||
BlockPos pos = new BlockPos(message.x, message.y, message.z);
|
|
||||||
|
|
||||||
World world = ClientProxy.getWorld();
|
|
||||||
|
|
||||||
TileEntity tile = world.getTileEntity(pos);
|
|
||||||
|
|
||||||
if (tile instanceof TileController) {
|
|
||||||
int lastEnergy = ((TileController) tile).getEnergyStored(null);
|
|
||||||
|
|
||||||
((TileController) tile).setEnergyStored(message.energy);
|
|
||||||
|
|
||||||
if (lastEnergy != message.energy && System.currentTimeMillis() - LAST_RE_RENDER > 3000) {
|
|
||||||
RefinedStorageUtils.updateBlock(world, pos);
|
|
||||||
|
|
||||||
LAST_RE_RENDER = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -36,7 +36,6 @@ public class CommonProxy {
|
|||||||
int id = 0;
|
int id = 0;
|
||||||
|
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageTileContainerUpdate.class, MessageTileContainerUpdate.class, id++, Side.CLIENT);
|
RefinedStorage.NETWORK.registerMessage(MessageTileContainerUpdate.class, MessageTileContainerUpdate.class, id++, Side.CLIENT);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageControllerEnergyUpdate.class, MessageControllerEnergyUpdate.class, id++, Side.CLIENT);
|
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageRedstoneModeUpdate.class, MessageRedstoneModeUpdate.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageRedstoneModeUpdate.class, MessageRedstoneModeUpdate.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridStoragePush.class, MessageGridStoragePush.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridStoragePush.class, MessageGridStoragePush.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridStoragePull.class, MessageGridStoragePull.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridStoragePull.class, MessageGridStoragePull.class, id++, Side.SERVER);
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import refinedstorage.container.ContainerController;
|
|||||||
import refinedstorage.item.ItemPattern;
|
import refinedstorage.item.ItemPattern;
|
||||||
import refinedstorage.item.ItemWirelessGrid;
|
import refinedstorage.item.ItemWirelessGrid;
|
||||||
import refinedstorage.network.GridPullFlags;
|
import refinedstorage.network.GridPullFlags;
|
||||||
import refinedstorage.network.MessageControllerEnergyUpdate;
|
|
||||||
import refinedstorage.network.MessageWirelessGridItems;
|
import refinedstorage.network.MessageWirelessGridItems;
|
||||||
import refinedstorage.storage.IStorage;
|
import refinedstorage.storage.IStorage;
|
||||||
import refinedstorage.storage.IStorageProvider;
|
import refinedstorage.storage.IStorageProvider;
|
||||||
@@ -65,6 +64,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
public static final int ENERGY_CAPACITY = 32000;
|
public static final int ENERGY_CAPACITY = 32000;
|
||||||
|
|
||||||
public static final String NBT_CRAFTING_TASKS = "CraftingTasks";
|
public static final String NBT_CRAFTING_TASKS = "CraftingTasks";
|
||||||
|
public static final String NBT_DESC_ENERGY = "Energy";
|
||||||
|
|
||||||
public static final int MAX_CRAFTING_QUANTITY_PER_REQUEST = 100;
|
public static final int MAX_CRAFTING_QUANTITY_PER_REQUEST = 100;
|
||||||
|
|
||||||
@@ -94,6 +94,8 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
|
|
||||||
private boolean couldRun;
|
private boolean couldRun;
|
||||||
|
|
||||||
|
private long lastEnergyUpdate;
|
||||||
|
|
||||||
private int wirelessGridRange;
|
private int wirelessGridRange;
|
||||||
|
|
||||||
public void addMachine(TileMachine machine) {
|
public void addMachine(TileMachine machine) {
|
||||||
@@ -190,12 +192,14 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
energy.setEnergyStored(energy.getMaxEnergyStored());
|
energy.setEnergyStored(energy.getMaxEnergyStored());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ticks % 4 == 0) {
|
if (energy.getEnergyStored() != lastEnergy) {
|
||||||
RefinedStorageUtils.sendToAllAround(worldObj, pos, new MessageControllerEnergyUpdate(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastEnergy != energy.getEnergyStored()) {
|
|
||||||
worldObj.updateComparatorOutputLevel(pos, RefinedStorageBlocks.CONTROLLER);
|
worldObj.updateComparatorOutputLevel(pos, RefinedStorageBlocks.CONTROLLER);
|
||||||
|
|
||||||
|
if (System.currentTimeMillis() - lastEnergyUpdate > 5000) {
|
||||||
|
lastEnergyUpdate = System.currentTimeMillis();
|
||||||
|
|
||||||
|
RefinedStorageUtils.updateBlock(worldObj, pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -531,6 +535,20 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
nbt.setTag(NBT_CRAFTING_TASKS, list);
|
nbt.setTag(NBT_CRAFTING_TASKS, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToDescriptionPacketNBT(NBTTagCompound tag) {
|
||||||
|
super.writeToDescriptionPacketNBT(tag);
|
||||||
|
|
||||||
|
tag.setInteger(NBT_DESC_ENERGY, getEnergyStored(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromDescriptionPacketNBT(NBTTagCompound tag) {
|
||||||
|
super.readFromDescriptionPacketNBT(tag);
|
||||||
|
|
||||||
|
setEnergyStored(tag.getInteger(NBT_DESC_ENERGY));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
|
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
|
||||||
return energy.receiveEnergy(maxReceive, simulate);
|
return energy.receiveEnergy(maxReceive, simulate);
|
||||||
@@ -586,6 +604,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveContainerData(ByteBuf buf) {
|
public void receiveContainerData(ByteBuf buf) {
|
||||||
|
setEnergyStored(buf.readInt());
|
||||||
energyUsage = buf.readInt();
|
energyUsage = buf.readInt();
|
||||||
|
|
||||||
redstoneMode = RedstoneMode.getById(buf.readInt());
|
redstoneMode = RedstoneMode.getById(buf.readInt());
|
||||||
@@ -610,6 +629,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendContainerData(ByteBuf buf) {
|
public void sendContainerData(ByteBuf buf) {
|
||||||
|
buf.writeInt(getEnergyStored(null));
|
||||||
buf.writeInt(energyUsage);
|
buf.writeInt(energyUsage);
|
||||||
|
|
||||||
buf.writeInt(redstoneMode.id);
|
buf.writeInt(redstoneMode.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user