the ByteBuf shenanigans begin!!

This commit is contained in:
BallOfEnergy 2024-09-02 21:39:28 -05:00
parent 931bbb3d8c
commit 47657366cc
12 changed files with 322 additions and 202 deletions

View File

@ -11,6 +11,7 @@ import com.hbm.tileentity.TileEntityMachineBase;
import api.hbm.energymk2.IBatteryItem; import api.hbm.energymk2.IBatteryItem;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
@ -54,22 +55,29 @@ public class TileEntityNukeBalefire extends TileEntityMachineBase implements IGU
if(timer <= 0) { if(timer <= 0) {
explode(); explode();
} }
NBTTagCompound data = new NBTTagCompound(); networkPackNT(250);
data.setInteger("timer", timer);
data.setBoolean("loaded", this.isLoaded());
data.setBoolean("started", started);
networkPack(data, 250);
} }
} }
public void networkUnpack(NBTTagCompound data) { @Override
super.networkUnpack(data); public void serialize(ByteBuf buf) {
timer = data.getInteger("timer"); super.serialize(buf);
started = data.getBoolean("started");
loaded = data.getBoolean("loaded"); buf.writeInt(this.timer);
buf.writeBoolean(this.started);
buf.writeBoolean(this.loaded);
} }
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
this.timer = buf.readInt();
this.started = buf.readBoolean();
this.loaded = buf.readBoolean();
}
public void handleButtonPacket(int value, int meta) { public void handleButtonPacket(int value, int meta) {
if(meta == 0 && this.isLoaded()) { if(meta == 0 && this.isLoaded()) {

View File

@ -15,6 +15,7 @@ import com.hbm.tileentity.TileEntityMachineBase;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
@ -103,11 +104,8 @@ public class TileEntityAshpit extends TileEntityMachineBase implements IGUIProvi
for(int i = 0; i < 5; i++) { for(int i = 0; i < 5; i++) {
if(slots[i] != null) isFull = true; if(slots[i] != null) isFull = true;
} }
NBTTagCompound data = new NBTTagCompound(); this.networkPackNT(50);
data.setInteger("playersUsing", this.playersUsing);
data.setBoolean("isFull", this.isFull);
this.networkPack(data, 50);
} else { } else {
this.prevDoorAngle = this.doorAngle; this.prevDoorAngle = this.doorAngle;
@ -142,10 +140,19 @@ public class TileEntityAshpit extends TileEntityMachineBase implements IGUIProvi
} }
@Override @Override
public void networkUnpack(NBTTagCompound nbt) { public void serialize(ByteBuf buf) {
super.networkUnpack(nbt); super.serialize(buf);
this.playersUsing = nbt.getInteger("playersUsing");
this.isFull = nbt.getBoolean("isFull"); buf.writeInt(this.playersUsing);
buf.writeBoolean(this.isFull);
}
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
this.playersUsing = buf.readInt();
this.isFull = buf.readBoolean();
} }
@Override @Override

View File

@ -7,13 +7,16 @@ import com.hbm.inventory.recipes.PressRecipes;
import com.hbm.items.machine.ItemStamp; import com.hbm.items.machine.ItemStamp;
import com.hbm.lib.Library; import com.hbm.lib.Library;
import com.hbm.tileentity.TileEntityMachineBase; import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.util.BufferUtil;
import com.hbm.util.fauxpointtwelve.DirPos; import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.energymk2.IEnergyReceiverMK2; import api.hbm.energymk2.IEnergyReceiverMK2;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
@ -84,16 +87,7 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE
delay--; delay--;
} }
NBTTagCompound data = new NBTTagCompound(); this.networkPackNT(50);
data.setLong("power", power);
data.setDouble("press", press);
if(slots[0] != null) {
NBTTagCompound stack = new NBTTagCompound();
slots[0].writeToNBT(stack);
data.setTag("stack", stack);
}
this.networkPack(data, 50);
} else { } else {
// approach-based interpolation, GO! // approach-based interpolation, GO!
@ -174,23 +168,26 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE
} }
public boolean canRetract() { public boolean canRetract() {
if(this.power < usage) return false; return this.power >= usage;
return true;
} }
@Override @Override
public void networkUnpack(NBTTagCompound nbt) { public void serialize(ByteBuf buf) {
super.networkUnpack(nbt); super.serialize(buf);
this.power = nbt.getLong("power");
this.syncPress = nbt.getInteger("press"); buf.writeLong(this.power);
buf.writeDouble(this.syncPress);
if(nbt.hasKey("stack")) { BufferUtil.writeItemStack(buf, syncStack);
NBTTagCompound stack = nbt.getCompoundTag("stack"); }
this.syncStack = ItemStack.loadItemStackFromNBT(stack);
} else { @Override
this.syncStack = null; public void deserialize(ByteBuf buf) {
} super.deserialize(buf);
this.power = buf.readLong();
this.syncPress = buf.readDouble();
this.syncStack = BufferUtil.readItemStack(buf);
this.turnProgress = 2; this.turnProgress = 2;
} }

View File

@ -21,11 +21,13 @@ import com.hbm.lib.ModDamageSource;
import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase; import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.util.ArmorUtil; import com.hbm.util.ArmorUtil;
import com.hbm.util.BufferUtil;
import com.hbm.util.CompatEnergyControl; import com.hbm.util.CompatEnergyControl;
import api.hbm.tile.IInfoProviderEC; import api.hbm.tile.IInfoProviderEC;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -138,15 +140,8 @@ public class TileEntityCore extends TileEntityMachineBase implements IGUIProvide
if(heat > 0) if(heat > 0)
radiation(); radiation();
NBTTagCompound data = new NBTTagCompound(); networkPackNT(250);
tanks[0].writeToNBT(data, "t0");
tanks[1].writeToNBT(data, "t1");
data.setInteger("field", field);
data.setInteger("heat", heat);
data.setInteger("color", color);
data.setBoolean("melt", meltdownTick);
networkPack(data, 250);
heat = 0; heat = 0;
@ -162,15 +157,28 @@ public class TileEntityCore extends TileEntityMachineBase implements IGUIProvide
} }
public void networkUnpack(NBTTagCompound data) { @Override
super.networkUnpack(data); public void serialize(ByteBuf buf) {
super.serialize(buf);
tanks[0].readFromNBT(data, "t0"); tanks[0].serialize(buf);
tanks[1].readFromNBT(data, "t1"); tanks[1].serialize(buf);
field = data.getInteger("field"); buf.writeInt(field);
heat = data.getInteger("heat"); buf.writeInt(heat);
color = data.getInteger("color"); buf.writeInt(color);
meltdownTick = data.getBoolean("melt"); buf.writeBoolean(meltdownTick);
}
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
tanks[0].deserialize(buf);
tanks[1].deserialize(buf);
this.field = buf.readInt();
this.heat = buf.readInt();
this.color = buf.readInt();
this.meltdownTick = buf.readBoolean();
} }
private void radiation() { private void radiation() {

View File

@ -18,6 +18,7 @@ import com.hbm.util.CompatEnergyControl;
import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import li.cil.oc.api.machine.Arguments; import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback; import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context; import li.cil.oc.api.machine.Context;
@ -169,26 +170,32 @@ public class TileEntityCoreEmitter extends TileEntityMachineBase implements IEne
this.markDirty(); this.markDirty();
NBTTagCompound data = new NBTTagCompound(); this.networkPackNT(250);
data.setLong("power", power);
data.setInteger("watts", watts);
data.setLong("prev", prev);
data.setInteger("beam", beam);
data.setBoolean("isOn", isOn);
tank.writeToNBT(data, "tank");
this.networkPack(data, 250);
} }
} }
public void networkUnpack(NBTTagCompound data) {
super.networkUnpack(data);
power = data.getLong("power"); @Override
watts = data.getInteger("watts"); public void serialize(ByteBuf buf) {
prev = data.getLong("prev"); super.serialize(buf);
beam = data.getInteger("beam");
isOn = data.getBoolean("isOn"); buf.writeLong(power);
tank.readFromNBT(data, "tank"); buf.writeInt(watts);
buf.writeLong(prev);
buf.writeInt(beam);
buf.writeBoolean(isOn);
tank.serialize(buf);
}
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
this.power = buf.readLong();
this.watts = buf.readInt();
this.prev = buf.readLong();
this.beam = buf.readInt();
this.isOn = buf.readBoolean();
tank.deserialize(buf);
} }
public long getPowerScaled(long i) { public long getPowerScaled(long i) {

View File

@ -12,6 +12,7 @@ import api.hbm.fluid.IFluidStandardReceiver;
import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import li.cil.oc.api.machine.Arguments; import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback; import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context; import li.cil.oc.api.machine.Context;
@ -101,19 +102,26 @@ public class TileEntityCoreInjector extends TileEntityMachineBase implements IFl
this.markDirty(); this.markDirty();
NBTTagCompound data = new NBTTagCompound(); this.networkPackNT(250);
data.setInteger("beam", beam);
tanks[0].writeToNBT(data, "t0");
tanks[1].writeToNBT(data, "t1");
this.networkPack(data, 250);
} }
} }
public void networkUnpack(NBTTagCompound data) { @Override
super.networkUnpack(data); public void serialize(ByteBuf buf) {
beam = data.getInteger("beam"); super.serialize(buf);
tanks[0].readFromNBT(data, "t0");
tanks[1].readFromNBT(data, "t1"); buf.writeInt(beam);
tanks[0].serialize(buf);
tanks[1].serialize(buf);
}
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
this.beam = buf.readInt();
tanks[0].deserialize(buf);
tanks[1].deserialize(buf);
} }
@Override @Override

View File

@ -16,6 +16,7 @@ import api.hbm.tile.IInfoProviderEC;
import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import li.cil.oc.api.machine.Arguments; import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback; import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context; import li.cil.oc.api.machine.Context;
@ -69,19 +70,26 @@ public class TileEntityCoreReceiver extends TileEntityMachineBase implements IEn
} }
} }
NBTTagCompound data = new NBTTagCompound(); this.networkPackNT(50);
data.setLong("joules", joules);
tank.writeToNBT(data, "t");
this.networkPack(data, 50);
joules = 0; joules = 0;
} }
} }
public void networkUnpack(NBTTagCompound data) { @Override
super.networkUnpack(data); public void serialize(ByteBuf buf) {
joules = data.getLong("joules"); super.serialize(buf);
tank.readFromNBT(data, "t");
buf.writeLong(joules);
tank.serialize(buf);
}
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
joules = buf.readLong();
tank.deserialize(buf);
} }
@Override @Override

View File

@ -14,6 +14,7 @@ import api.hbm.tile.IInfoProviderEC;
import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import li.cil.oc.api.machine.Arguments; import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback; import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context; import li.cil.oc.api.machine.Context;
@ -93,11 +94,7 @@ public class TileEntityCoreStabilizer extends TileEntityMachineBase implements I
} }
} }
NBTTagCompound data = new NBTTagCompound(); this.networkPackNT(250);
data.setLong("power", power);
data.setInteger("watts", watts);
data.setInteger("beam", beam);
this.networkPack(data, 250);
} }
} }
@ -106,13 +103,23 @@ public class TileEntityCoreStabilizer extends TileEntityMachineBase implements I
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir); this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir);
} }
public void networkUnpack(NBTTagCompound data) {
super.networkUnpack(data);
power = data.getLong("power"); @Override
watts = data.getInteger("watts"); public void serialize(ByteBuf buf) {
beam = data.getInteger("beam"); super.serialize(buf);
buf.writeLong(power);
buf.writeInt(watts);
buf.writeInt(beam);
}
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
this.power = buf.readLong();
this.watts = buf.readInt();
this.beam = buf.readInt();
} }
public long getPowerScaled(long i) { public long getPowerScaled(long i) {

View File

@ -22,6 +22,7 @@ import com.hbm.module.ModulePatternMatcher;
import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachinePolluting; import com.hbm.tileentity.TileEntityMachinePolluting;
import com.hbm.tileentity.TileEntityProxyBase; import com.hbm.tileentity.TileEntityProxyBase;
import com.hbm.util.BufferUtil;
import com.hbm.util.Compat; import com.hbm.util.Compat;
import com.hbm.util.fauxpointtwelve.BlockPos; import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.util.fauxpointtwelve.DirPos; import com.hbm.util.fauxpointtwelve.DirPos;
@ -31,6 +32,7 @@ import api.hbm.energymk2.IEnergyReceiverMK2;
import api.hbm.fluid.IFluidStandardTransceiver; import api.hbm.fluid.IFluidStandardTransceiver;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -221,23 +223,44 @@ public class TileEntityCustomMachine extends TileEntityMachinePolluting implemen
} else { } else {
this.progress = 0; this.progress = 0;
} }
this.networkPackNT(50);
NBTTagCompound data = new NBTTagCompound();
data.setString("type", this.machineType);
data.setLong("power", power);
data.setBoolean("structureOK", structureOK);
data.setInteger("flux", flux);
data.setInteger("heat", heat);
data.setInteger("progress", progress);
data.setInteger("maxProgress", maxProgress);
for (int i = 0; i < inputTanks.length; i++) inputTanks[i].writeToNBT(data, "i" + i);
for (int i = 0; i < outputTanks.length; i++) outputTanks[i].writeToNBT(data, "o" + i);
this.matcher.writeToNBT(data);
this.networkPack(data, 50);
} }
} }
@Override
public void serialize(ByteBuf buf) {
super.serialize(buf);
buf.writeLong(power);
buf.writeInt(progress);
buf.writeInt(flux);
buf.writeInt(heat);
buf.writeBoolean(structureOK);
buf.writeInt(maxProgress);
for (FluidTank inputTank : inputTanks) inputTank.serialize(buf);
for (FluidTank outputTank : outputTanks) outputTank.serialize(buf);
this.matcher.serialize(buf);
}
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
this.machineType = BufferUtil.readString(buf);
if(this.config == null) this.init();
this.power = buf.readLong();
this.progress = buf.readInt();
this.flux = buf.readInt();
this.heat = buf.readInt();
this.structureOK = buf.readBoolean();
this.maxProgress = buf.readInt();
for (FluidTank inputTank : inputTanks) inputTank.deserialize(buf);
for (FluidTank outputTank : outputTanks) outputTank.deserialize(buf);
this.matcher.deserialize(buf);
}
/** Only accepts inputs in a fixed order, saves a ton of performance because there's no permutations to check for */ /** Only accepts inputs in a fixed order, saves a ton of performance because there's no permutations to check for */
public CustomMachineRecipe getMatchingRecipe() { public CustomMachineRecipe getMatchingRecipe() {
List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(this.config.recipeKey); List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(this.config.recipeKey);
@ -459,25 +482,6 @@ public class TileEntityCustomMachine extends TileEntityMachinePolluting implemen
return matcher.isValidForFilter(slots[filterSlot], index, stack); return matcher.isValidForFilter(slots[filterSlot], index, stack);
} }
@Override
public void networkUnpack(NBTTagCompound nbt) {
super.networkUnpack(nbt);
this.machineType = nbt.getString("type");
if(this.config == null) this.init();
this.power = nbt.getLong("power");
this.progress = nbt.getInteger("progress");
this.flux = nbt.getInteger("flux");
this.heat = nbt.getInteger("heat");
this.structureOK = nbt.getBoolean("structureOK");
this.maxProgress = nbt.getInteger("maxProgress");
for(int i = 0; i < inputTanks.length; i++) inputTanks[i].readFromNBT(nbt, "i" + i);
for(int i = 0; i < outputTanks.length; i++) outputTanks[i].readFromNBT(nbt, "o" + i);
this.matcher.readFromNBT(nbt);
}
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {

View File

@ -18,6 +18,7 @@ import com.hbm.util.fauxpointtwelve.DirPos;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -110,19 +111,18 @@ public class TileEntityMachinePumpjack extends TileEntityOilDrillBase {
} }
} }
} }
@Override
public void networkPack(NBTTagCompound nbt, int range) {
nbt.setFloat("speed", this.indicator == 0 ? (5F + (2F * this.speedLevel)) + (this.overLevel - 1F) * 10: 0F);
super.networkPack(nbt, range);
}
@Override @Override
public void networkUnpack(NBTTagCompound nbt) { public void serialize(ByteBuf buf) {
super.networkUnpack(nbt); super.serialize(buf);
buf.writeFloat(this.indicator == 0 ? (5F + (2F * this.speedLevel)) + (this.overLevel - 1F) * 10: 0F);
this.speed = nbt.getFloat("speed"); }
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
this.speed = buf.readFloat();
} }
@Override @Override

View File

@ -23,6 +23,7 @@ import api.hbm.energymk2.IEnergyReceiverMK2;
import api.hbm.fluid.IFluidStandardTransceiver; import api.hbm.fluid.IFluidStandardTransceiver;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -90,83 +91,87 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if (!worldObj.isRemote) {
this.updateConnections(); this.updateConnections();
this.tanks[0].unloadTank(1, 2, slots); this.tanks[0].unloadTank(1, 2, slots);
this.tanks[1].unloadTank(3, 4, slots); this.tanks[1].unloadTank(3, 4, slots);
UpgradeManager.eval(slots, 5, 7); UpgradeManager.eval(slots, 5, 7);
this.speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); this.speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
this.energyLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); this.energyLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
this.overLevel = Math.min(UpgradeManager.getLevel(UpgradeType.OVERDRIVE), 3) + 1; this.overLevel = Math.min(UpgradeManager.getLevel(UpgradeType.OVERDRIVE), 3) + 1;
int abLevel = Math.min(UpgradeManager.getLevel(UpgradeType.AFTERBURN), 3); int abLevel = Math.min(UpgradeManager.getLevel(UpgradeType.AFTERBURN), 3);
int toBurn = Math.min(tanks[1].getFill(), abLevel * 10); int toBurn = Math.min(tanks[1].getFill(), abLevel * 10);
if(toBurn > 0) { if (toBurn > 0) {
tanks[1].setFill(tanks[1].getFill() - toBurn); tanks[1].setFill(tanks[1].getFill() - toBurn);
this.power += toBurn * 5; this.power += toBurn * 5;
if(this.power > this.getMaxPower()) if (this.power > this.getMaxPower())
this.power = this.getMaxPower(); this.power = this.getMaxPower();
} }
power = Library.chargeTEFromItems(slots, 0, power, this.getMaxPower()); power = Library.chargeTEFromItems(slots, 0, power, this.getMaxPower());
for(DirPos pos : getConPos()) { for (DirPos pos : getConPos()) {
if(tanks[0].getFill() > 0) this.sendFluid(tanks[0], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if (tanks[0].getFill() > 0)
if(tanks[1].getFill() > 0) this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.sendFluid(tanks[0], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
if (tanks[1].getFill() > 0)
this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
if(this.power >= this.getPowerReqEff() && this.tanks[0].getFill() < this.tanks[0].getMaxFill() && this.tanks[1].getFill() < this.tanks[1].getMaxFill()) { if (this.power >= this.getPowerReqEff() && this.tanks[0].getFill() < this.tanks[0].getMaxFill() && this.tanks[1].getFill() < this.tanks[1].getMaxFill()) {
this.power -= this.getPowerReqEff(); this.power -= this.getPowerReqEff();
if(worldObj.getTotalWorldTime() % getDelayEff() == 0) { if (worldObj.getTotalWorldTime() % getDelayEff() == 0) {
this.indicator = 0; this.indicator = 0;
for(int y = yCoord - 1; y >= getDrillDepth(); y--) { for (int y = yCoord - 1; y >= getDrillDepth(); y--) {
if(worldObj.getBlock(xCoord, y, zCoord) != ModBlocks.oil_pipe) { if (worldObj.getBlock(xCoord, y, zCoord) != ModBlocks.oil_pipe) {
if(trySuck(y)) { if (trySuck(y)) {
break; break;
} else { } else {
tryDrill(y); tryDrill(y);
break; break;
} }
} }
if(y == getDrillDepth()) if (y == getDrillDepth())
this.indicator = 1; this.indicator = 1;
} }
} }
} else { } else {
this.indicator = 2; this.indicator = 2;
} }
this.sendUpdate(); this.networkPackNT(25);
} }
} }
public void sendUpdate() { @Override
NBTTagCompound data = new NBTTagCompound(); public void serialize(ByteBuf buf) {
data.setLong("power", power); super.serialize(buf);
data.setInteger("indicator", this.indicator);
for(int i = 0; i < tanks.length; i++) tanks[i].writeToNBT(data, "t" + i); buf.writeLong(this.power);
this.networkPack(data, 25); buf.writeInt(this.indicator);
for (FluidTank tank : tanks) tank.serialize(buf);
} }
public void networkUnpack(NBTTagCompound nbt) { @Override
super.networkUnpack(nbt); public void deserialize(ByteBuf buf) {
super.deserialize(buf);
this.power = nbt.getLong("power");
this.indicator = nbt.getInteger("indicator"); this.power = buf.readLong();
for(int i = 0; i < tanks.length; i++) tanks[i].readFromNBT(nbt, "t" + i); this.indicator = buf.readInt();
for (FluidTank tank : tanks) tank.deserialize(buf);
} }
public boolean canPump() { public boolean canPump() {

View File

@ -1,15 +1,22 @@
package com.hbm.util; package com.hbm.util;
import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTSizeTracker;
import net.minecraft.nbt.NBTTagCompound;
public class BufferUtil { public class BufferUtil {
private static final Charset CHARSET = Charset.forName("UTF-8"); private static final Charset CHARSET = StandardCharsets.UTF_8;
// Writes a string to a byte buffer by encoding the length and raw bytes // Writes a string to a byte buffer by encoding the length and raw bytes
public static final void writeString(ByteBuf buf, String value) { public static void writeString(ByteBuf buf, String value) {
if(value == null) { if(value == null) {
buf.writeInt(-1); buf.writeInt(-1);
return; return;
@ -20,7 +27,7 @@ public class BufferUtil {
} }
// Reads a string from a byte buffer via the written length and raw bytes // Reads a string from a byte buffer via the written length and raw bytes
public static final String readString(ByteBuf buf) { public static String readString(ByteBuf buf) {
final int count = buf.readInt(); final int count = buf.readInt();
if(count < 0) return null; if(count < 0) return null;
@ -30,4 +37,58 @@ public class BufferUtil {
return new String(bytes, CHARSET); return new String(bytes, CHARSET);
} }
} /**
* Writes the ItemStack to the buffer.
*/
public static void writeItemStack(ByteBuf buf, ItemStack item) {
if (item == null)
buf.writeShort(-1);
else {
buf.writeShort(Item.getIdFromItem(item.getItem()));
buf.writeByte(item.stackSize);
buf.writeShort(item.getItemDamage());
NBTTagCompound nbtTagCompound = null;
if (item.getItem().isDamageable() || item.getItem().getShareTag())
nbtTagCompound = item.stackTagCompound;
if(nbtTagCompound != null) {
byte[] nbtData = new byte[0];
try {
nbtData = CompressedStreamTools.compress(nbtTagCompound);
} catch(IOException e) {
e.printStackTrace();
}
buf.writeShort((short) nbtData.length);
buf.writeBytes(nbtData);
} else {
buf.writeShort(-1);
}
}
}
/**
* Reads an ItemStack from a buffer
*/
public static ItemStack readItemStack(ByteBuf buf) {
ItemStack item = null;
short id = buf.readShort();
if (id >= 0) {
byte quantity = buf.readByte();
short meta = buf.readShort();
item = new ItemStack(Item.getItemById(id), quantity, meta);
short nbtLength = buf.readByte();
byte[] tags = new byte[nbtLength];
buf.readBytes(tags);
try {
item.stackTagCompound = CompressedStreamTools.func_152457_a(tags, new NBTSizeTracker(2097152L));
} catch(IOException e) {
e.printStackTrace();
}
}
return item;
}
}