mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-27 23:45:55 +00:00
#1197 Fixed packet size for machine progress updates.
This commit is contained in:
1 parent
3b21d6e04a
commit
696cb8764a
2 files changed
+74
-16
No files matched your search
@@ -1,54 +1,48 @@
|
||||
package crazypants.enderio.machine;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
|
||||
public class PacketCurrentTask extends MessageTileEntity<AbstractPoweredTaskEntity> implements IMessageHandler<PacketCurrentTask, IMessage> {
|
||||
|
||||
private NBTTagCompound nbtRoot;
|
||||
private float progress;
|
||||
|
||||
public PacketCurrentTask() {
|
||||
}
|
||||
|
||||
public PacketCurrentTask(AbstractPoweredTaskEntity tile) {
|
||||
super(tile);
|
||||
nbtRoot = new NBTTagCompound();
|
||||
progress = -1;
|
||||
if(tile.currentTask != null) {
|
||||
NBTTagCompound tankRoot = new NBTTagCompound();
|
||||
tile.currentTask.writeToNBT(tankRoot);
|
||||
nbtRoot.setTag("currentTask", tankRoot);
|
||||
progress = tile.currentTask.getProgress();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
NetworkUtil.writeNBTTagCompound(nbtRoot, buf);
|
||||
buf.writeFloat(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
nbtRoot = NetworkUtil.readNBTTagCompound(buf);
|
||||
progress = buf.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketCurrentTask message, MessageContext ctx) {
|
||||
|
||||
AbstractPoweredTaskEntity tile = message.getTileEntity(EnderIO.proxy.getClientWorld());
|
||||
if (tile != null) {
|
||||
if(message.nbtRoot.hasKey("currentTask")) {
|
||||
NBTTagCompound tankRoot = message.nbtRoot.getCompoundTag("currentTask");
|
||||
tile.currentTask = PoweredTask.readFromNBT(message.nbtRoot.getCompoundTag("currentTask"));
|
||||
} else {
|
||||
if(tile != null) {
|
||||
if(message.progress < 0) {
|
||||
tile.currentTask = null;
|
||||
}
|
||||
} else {
|
||||
tile.currentTask = new PoweredTaskProgress(message.progress);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package crazypants.enderio.machine;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
|
||||
/**
|
||||
* Client side stub for reporting progress.
|
||||
*/
|
||||
public class PoweredTaskProgress implements IPoweredTask {
|
||||
|
||||
private float progress;
|
||||
|
||||
public PoweredTaskProgress(IPoweredTask task) {
|
||||
progress = task.getProgress();
|
||||
}
|
||||
|
||||
public PoweredTaskProgress(float progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float availableEnergy) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
return getProgress() >= 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultStack[] getCompletedResult() {
|
||||
return new ResultStack[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRequiredEnergy() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtRoot) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMachineRecipe getRecipe() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MachineRecipeInput[] getInputs() {
|
||||
return new MachineRecipeInput[0];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user