mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-18 11:29:30 +00:00
Merge pull request #2337 from MatthiasMann/nutrient_tank
consolidate nutrient tank code, reduce client sync packet size
This commit is contained in:
commit
e3f3847210
10 files changed
+109
-165
No files matched your search
@@ -155,6 +155,7 @@ import crazypants.enderio.teleport.telepad.ItemCoordSelector;
|
||||
import crazypants.enderio.thaumcraft.ThaumcraftCompat;
|
||||
import crazypants.util.EntityUtil;
|
||||
import static crazypants.enderio.EnderIO.*;
|
||||
import crazypants.enderio.machine.generator.zombie.PacketNutrientTank;
|
||||
|
||||
@Mod(modid = MODID, name = MOD_NAME, version = VERSION, dependencies = "required-after:[email protected],);after:MineFactoryReloaded;after:Waila@[1.5.8,);after:Thaumcraft", guiFactory = "crazypants.enderio.config.ConfigFactoryEIO")
|
||||
public class EnderIO {
|
||||
@@ -436,6 +437,8 @@ public class EnderIO {
|
||||
fluidNutrientDistillation = FluidRegistry.getFluid(f.getName());
|
||||
blockNutrientDistillation = BlockFluidEio.create(fluidNutrientDistillation, Material.water);
|
||||
|
||||
PacketHandler.INSTANCE.registerMessage(PacketNutrientTank.class, PacketNutrientTank.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
|
||||
f = new Fluid(Fluids.HOOTCH_NAME).setDensity(900).setViscosity(1000);
|
||||
FluidRegistry.registerFluid(f);
|
||||
fluidHootch = FluidRegistry.getFluid(f.getName());
|
||||
|
||||
@@ -18,15 +18,11 @@ import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.AbstractMachineBlock;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class BlockZombieGenerator extends AbstractMachineBlock<TileZombieGenerator> {
|
||||
|
||||
public static BlockZombieGenerator create() {
|
||||
|
||||
PacketHandler.INSTANCE.registerMessage(PacketZombieTank.class, PacketZombieTank.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
|
||||
BlockZombieGenerator gen = new BlockZombieGenerator();
|
||||
gen.init();
|
||||
return gen;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package crazypants.enderio.machine.generator.zombie;
|
||||
|
||||
public interface IHasNutrientTank {
|
||||
|
||||
NutrientTank getNutrientTank();
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package crazypants.enderio.machine.generator.zombie;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import crazypants.enderio.EnderIO;
|
||||
@@ -10,9 +12,13 @@ public class NutrientTank extends FluidTank {
|
||||
super(capacity);
|
||||
}
|
||||
|
||||
public boolean canFill(Fluid fluid) {
|
||||
return fluid != null && fluid.getID() == EnderIO.fluidNutrientDistillation.getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill) {
|
||||
if(resource == null || resource.getFluid().getID() != EnderIO.fluidNutrientDistillation.getID()) {
|
||||
if(resource == null || !canFill(resource.getFluid())) {
|
||||
return 0;
|
||||
}
|
||||
return super.fill(resource, doFill);
|
||||
@@ -21,7 +27,29 @@ public class NutrientTank extends FluidTank {
|
||||
public float getFilledRatio() {
|
||||
return (float) getFluidAmount() / getCapacity();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setFluidAmount(int amount) {
|
||||
if(amount > 0) {
|
||||
setFluid(new FluidStack(EnderIO.fluidNutrientDistillation, Math.min(capacity, amount)));
|
||||
} else {
|
||||
setFluid(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeCommon(String name, NBTTagCompound nbtRoot) {
|
||||
if(getFluidAmount() > 0) {
|
||||
NBTTagCompound tankRoot = new NBTTagCompound();
|
||||
writeToNBT(tankRoot);
|
||||
nbtRoot.setTag(name, tankRoot);
|
||||
}
|
||||
}
|
||||
|
||||
public void readCommon(String name, NBTTagCompound nbtRoot) {
|
||||
NBTTagCompound tankRoot = (NBTTagCompound) nbtRoot.getTag(name);
|
||||
if(tankRoot != null) {
|
||||
readFromNBT(tankRoot);
|
||||
} else {
|
||||
setFluid(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package crazypants.enderio.machine.generator.zombie;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
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 net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class PacketNutrientTank extends MessageTileEntity<TileEntity> implements IMessageHandler<PacketNutrientTank, IMessage> {
|
||||
|
||||
private int amount;
|
||||
|
||||
public PacketNutrientTank() {
|
||||
}
|
||||
|
||||
public<T extends TileEntity & IHasNutrientTank> PacketNutrientTank(T tile) {
|
||||
super(tile);
|
||||
amount = tile.getNutrientTank().getFluidAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeInt(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
amount = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketNutrientTank message, MessageContext ctx) {
|
||||
EntityPlayer player = EnderIO.proxy.getClientPlayer();
|
||||
TileEntity tile = message.getTileEntity(player.worldObj);
|
||||
if (tile instanceof IHasNutrientTank) {
|
||||
((IHasNutrientTank) tile).getNutrientTank().setFluidAmount(message.amount);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package crazypants.enderio.machine.generator.zombie;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
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 PacketZombieTank extends MessageTileEntity<TileZombieGenerator> implements IMessageHandler<PacketZombieTank, IMessage> {
|
||||
|
||||
private NBTTagCompound nbtRoot;
|
||||
|
||||
public PacketZombieTank() {
|
||||
}
|
||||
|
||||
public PacketZombieTank(TileZombieGenerator tile) {
|
||||
super(tile);
|
||||
nbtRoot = new NBTTagCompound();
|
||||
if(tile.fuelTank.getFluidAmount() > 0) {
|
||||
NBTTagCompound tankRoot = new NBTTagCompound();
|
||||
tile.fuelTank.writeToNBT(tankRoot);
|
||||
nbtRoot.setTag("tank", tankRoot);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
NetworkUtil.writeNBTTagCompound(nbtRoot, buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
nbtRoot = NetworkUtil.readNBTTagCompound(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketZombieTank message, MessageContext ctx) {
|
||||
EntityPlayer player = EnderIO.proxy.getClientPlayer();
|
||||
TileZombieGenerator tile = message.getTileEntity(player.worldObj);
|
||||
if (tile != null) {
|
||||
if(message.nbtRoot.hasKey("tank")) {
|
||||
NBTTagCompound tankRoot = message.nbtRoot.getCompoundTag("tank");
|
||||
tile.fuelTank.readFromNBT(tankRoot);
|
||||
} else {
|
||||
tile.fuelTank.setFluid(null);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+10
-23
@@ -22,7 +22,7 @@ import crazypants.util.BlockCoord;
|
||||
import crazypants.util.FluidUtil;
|
||||
import crazypants.util.ITankAccess;
|
||||
|
||||
public class TileZombieGenerator extends AbstractGeneratorEntity implements IFluidHandler, ITankAccess {
|
||||
public class TileZombieGenerator extends AbstractGeneratorEntity implements IFluidHandler, ITankAccess, IHasNutrientTank {
|
||||
|
||||
private static int IO_MB_TICK = 250;
|
||||
|
||||
@@ -134,7 +134,7 @@ public class TileZombieGenerator extends AbstractGeneratorEntity implements IFlu
|
||||
}
|
||||
|
||||
if(tanksDirty) {
|
||||
PacketHandler.sendToAllAround(new PacketZombieTank(this), this);
|
||||
PacketHandler.sendToAllAround(new PacketNutrientTank(this), this);
|
||||
tanksDirty = false;
|
||||
}
|
||||
|
||||
@@ -183,9 +183,6 @@ public class TileZombieGenerator extends AbstractGeneratorEntity implements IFlu
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
if(resource == null || resource.getFluid() == null || !canFill(from, resource.getFluid())) {
|
||||
return 0;
|
||||
}
|
||||
int res = fuelTank.fill(resource, doFill);
|
||||
if(res > 0 && doFill) {
|
||||
tanksDirty = true;
|
||||
@@ -205,7 +202,7 @@ public class TileZombieGenerator extends AbstractGeneratorEntity implements IFlu
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return fluid != null && fluid.getID() == EnderIO.fluidNutrientDistillation.getID();
|
||||
return fuelTank.canFill(fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -243,28 +240,13 @@ public class TileZombieGenerator extends AbstractGeneratorEntity implements IFlu
|
||||
@Override
|
||||
public void readCommon(NBTTagCompound nbtRoot) {
|
||||
super.readCommon(nbtRoot);
|
||||
|
||||
if(nbtRoot.hasKey("fuelTank")) {
|
||||
NBTTagCompound tankRoot = (NBTTagCompound) nbtRoot.getTag("fuelTank");
|
||||
if(tankRoot != null) {
|
||||
fuelTank.readFromNBT(tankRoot);
|
||||
} else {
|
||||
fuelTank.setFluid(null);
|
||||
}
|
||||
} else {
|
||||
fuelTank.setFluid(null);
|
||||
}
|
||||
|
||||
fuelTank.readCommon("fuelTank", nbtRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCommon(NBTTagCompound nbtRoot) {
|
||||
super.writeCommon(nbtRoot);
|
||||
if(fuelTank.getFluidAmount() > 0) {
|
||||
NBTTagCompound tankRoot = new NBTTagCompound();
|
||||
fuelTank.writeToNBT(tankRoot);
|
||||
nbtRoot.setTag("fuelTank", tankRoot);
|
||||
}
|
||||
fuelTank.writeCommon("fuelTank", nbtRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -291,4 +273,9 @@ public class TileZombieGenerator extends AbstractGeneratorEntity implements IFlu
|
||||
tanksDirty = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NutrientTank getNutrientTank() {
|
||||
return fuelTank;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,6 @@ public class BlockKillerJoe extends AbstractMachineBlock<TileKillerJoe> {
|
||||
static final String USERNAME = "KillerJoe";
|
||||
|
||||
public static BlockKillerJoe create() {
|
||||
PacketHandler.INSTANCE.registerMessage(PacketNutrientLevel.class, PacketNutrientLevel.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketSwing.class, PacketSwing.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketGivePlayerXP.register();
|
||||
PacketExperianceContainer.register();
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package crazypants.enderio.machine.killera;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
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 PacketNutrientLevel extends MessageTileEntity<TileKillerJoe> implements IMessageHandler<PacketNutrientLevel, IMessage> {
|
||||
|
||||
private NBTTagCompound nbtRoot;
|
||||
|
||||
public PacketNutrientLevel() {
|
||||
}
|
||||
|
||||
public PacketNutrientLevel(TileKillerJoe tile) {
|
||||
super(tile);
|
||||
nbtRoot = new NBTTagCompound();
|
||||
if(tile.fuelTank.getFluidAmount() > 0) {
|
||||
NBTTagCompound tankRoot = new NBTTagCompound();
|
||||
tile.fuelTank.writeToNBT(tankRoot);
|
||||
nbtRoot.setTag("tank", tankRoot);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
NetworkUtil.writeNBTTagCompound(nbtRoot, buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
nbtRoot = NetworkUtil.readNBTTagCompound(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketNutrientLevel message, MessageContext ctx) {
|
||||
EntityPlayer player = EnderIO.proxy.getClientPlayer();
|
||||
TileKillerJoe tile = message.getTileEntity(player.worldObj);
|
||||
if (tile != null) {
|
||||
if(message.nbtRoot.hasKey("tank")) {
|
||||
NBTTagCompound tankRoot = message.nbtRoot.getCompoundTag("tank");
|
||||
tile.fuelTank.readFromNBT(tankRoot);
|
||||
} else {
|
||||
tile.fuelTank.setFluid(null);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,7 +32,9 @@ import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.AbstractMachineEntity;
|
||||
import crazypants.enderio.machine.SlotDefinition;
|
||||
import crazypants.enderio.machine.generator.zombie.IHasNutrientTank;
|
||||
import crazypants.enderio.machine.generator.zombie.NutrientTank;
|
||||
import crazypants.enderio.machine.generator.zombie.PacketNutrientTank;
|
||||
import crazypants.enderio.machine.wireless.WirelessChargedLocation;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.xp.ExperienceContainer;
|
||||
@@ -46,7 +48,7 @@ import crazypants.util.ForgeDirectionOffsets;
|
||||
import crazypants.util.ITankAccess;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
|
||||
public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandler, IEntitySelector, IHaveExperience, ITankAccess {
|
||||
public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandler, IEntitySelector, IHaveExperience, ITankAccess, IHasNutrientTank {
|
||||
|
||||
private static final int IO_MB_TICK = 250;
|
||||
|
||||
@@ -146,7 +148,7 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
}
|
||||
|
||||
if(tanksDirty) {
|
||||
PacketHandler.sendToAllAround(new PacketNutrientLevel(this), this);
|
||||
PacketHandler.sendToAllAround(new PacketNutrientTank(this), this);
|
||||
tanksDirty = false;
|
||||
}
|
||||
if(xpCon.isDirty()) {
|
||||
@@ -442,9 +444,6 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
if(resource == null || resource.getFluid() == null || !canFill(from, resource.getFluid())) {
|
||||
return 0;
|
||||
}
|
||||
int res = fuelTank.fill(resource, doFill);
|
||||
if(res > 0 && doFill) {
|
||||
tanksDirty = true;
|
||||
@@ -454,7 +453,7 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return fluid != null && fluid.getID() == EnderIO.fluidNutrientDistillation.getID();
|
||||
return fuelTank.canFill(fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -482,27 +481,14 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
@Override
|
||||
public void readCommon(NBTTagCompound nbtRoot) {
|
||||
super.readCommon(nbtRoot);
|
||||
if(nbtRoot.hasKey("fuelTank")) {
|
||||
NBTTagCompound tankRoot = (NBTTagCompound) nbtRoot.getTag("fuelTank");
|
||||
if(tankRoot != null) {
|
||||
fuelTank.readFromNBT(tankRoot);
|
||||
} else {
|
||||
fuelTank.setFluid(null);
|
||||
}
|
||||
} else {
|
||||
fuelTank.setFluid(null);
|
||||
}
|
||||
fuelTank.readCommon("fuelTank", nbtRoot);
|
||||
xpCon.readFromNBT(nbtRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCommon(NBTTagCompound nbtRoot) {
|
||||
super.writeCommon(nbtRoot);
|
||||
if(fuelTank.getFluidAmount() > 0) {
|
||||
NBTTagCompound tankRoot = new NBTTagCompound();
|
||||
fuelTank.writeToNBT(tankRoot);
|
||||
nbtRoot.setTag("fuelTank", tankRoot);
|
||||
}
|
||||
fuelTank.writeCommon("fuelTank", nbtRoot);
|
||||
xpCon.writeToNBT(nbtRoot);
|
||||
}
|
||||
|
||||
@@ -576,4 +562,10 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle
|
||||
public void setTanksDirty() {
|
||||
tanksDirty = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NutrientTank getNutrientTank() {
|
||||
return fuelTank;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user