mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-28 15:56:07 +00:00
#1213 NPE on inserting ingredients into a Vat
This commit is contained in:
1 parent
e7a26793c2
commit
92a0ce8f1c
10 files changed
+157
-61
No files matched your search
@@ -59,7 +59,7 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
|
||||
static {
|
||||
PacketHandler.INSTANCE.registerMessage(PacketIoMode.class, PacketIoMode.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketPowerStorage.class, PacketPowerStorage.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketCurrentTask.class,PacketCurrentTask.class,PacketHandler.nextID(),Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketCurrentTaskProgress.class,PacketCurrentTaskProgress.class,PacketHandler.nextID(),Side.CLIENT);
|
||||
}
|
||||
|
||||
protected AbstractMachineBlock(ModObject mo, Class<T> teClass, Material mat) {
|
||||
|
||||
@@ -69,6 +69,10 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity {
|
||||
return currentTask == null ? 0 : currentTask.getProgress();
|
||||
}
|
||||
|
||||
public IPoweredTask getCurrentTask() {
|
||||
return currentTask;
|
||||
}
|
||||
|
||||
public float getExperienceForOutput(ItemStack output) {
|
||||
if(lastCompletedRecipe == null) {
|
||||
return 0;
|
||||
@@ -108,7 +112,7 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity {
|
||||
IMachineRecipe nextRecipe = canStartNextTask(chance);
|
||||
if(nextRecipe != null) {
|
||||
boolean started = startNextTask(nextRecipe, chance);
|
||||
PacketHandler.sendToAllAround(new PacketCurrentTask(this), this);
|
||||
sendTaskProgressPacket();
|
||||
startFailed = !started;
|
||||
} else {
|
||||
startFailed = true;
|
||||
@@ -117,6 +121,10 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity {
|
||||
return requiresClientSync;
|
||||
}
|
||||
|
||||
protected void sendTaskProgressPacket() {
|
||||
PacketHandler.sendToAllAround(new PacketCurrentTaskProgress(this), this);
|
||||
}
|
||||
|
||||
protected boolean checkProgress(boolean redstoneChecksPassed) {
|
||||
if(currentTask == null || !hasPower()) {
|
||||
return false;
|
||||
@@ -132,7 +140,7 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity {
|
||||
|
||||
int curScaled = getProgressScaled(16);
|
||||
if(curScaled != lastProgressScaled) {
|
||||
PacketHandler.sendToAllAround(new PacketCurrentTask(this), this);
|
||||
sendTaskProgressPacket();
|
||||
lastProgressScaled = curScaled;
|
||||
}
|
||||
|
||||
@@ -164,7 +172,7 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity {
|
||||
markDirty();
|
||||
currentTask = null;
|
||||
lastProgressScaled = 0;
|
||||
PacketHandler.sendToAllAround(new PacketCurrentTask(this), this);
|
||||
sendTaskProgressPacket();
|
||||
}
|
||||
|
||||
protected void mergeResults(ResultStack[] results) {
|
||||
|
||||
+6
-6
@@ -7,18 +7,18 @@ import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
|
||||
public class PacketCurrentTask extends MessageTileEntity<AbstractPoweredTaskEntity> implements IMessageHandler<PacketCurrentTask, IMessage> {
|
||||
public class PacketCurrentTaskProgress extends MessageTileEntity<AbstractPoweredTaskEntity> implements IMessageHandler<PacketCurrentTaskProgress, IMessage> {
|
||||
|
||||
private float progress;
|
||||
|
||||
public PacketCurrentTask() {
|
||||
public PacketCurrentTaskProgress() {
|
||||
}
|
||||
|
||||
public PacketCurrentTask(AbstractPoweredTaskEntity tile) {
|
||||
public PacketCurrentTaskProgress(AbstractPoweredTaskEntity tile) {
|
||||
super(tile);
|
||||
progress = -1;
|
||||
if(tile.currentTask != null) {
|
||||
progress = tile.currentTask.getProgress();
|
||||
if(tile.getCurrentTask() != null) {
|
||||
progress = tile.getCurrentTask().getProgress();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class PacketCurrentTask extends MessageTileEntity<AbstractPoweredTaskEnti
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketCurrentTask message, MessageContext ctx) {
|
||||
public IMessage onMessage(PacketCurrentTaskProgress message, MessageContext ctx) {
|
||||
AbstractPoweredTaskEntity tile = message.getTileEntity(EnderIO.proxy.getClientWorld());
|
||||
if(tile != null) {
|
||||
if(message.progress < 0) {
|
||||
@@ -20,10 +20,9 @@ import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.AbstractPoweredTaskEntity;
|
||||
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
import crazypants.enderio.machine.ContinuousTask;
|
||||
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
import crazypants.enderio.machine.IPoweredTask;
|
||||
import crazypants.enderio.machine.PacketCurrentTask;
|
||||
import crazypants.enderio.machine.SlotDefinition;
|
||||
import crazypants.enderio.machine.farm.farmers.FarmersCommune;
|
||||
import crazypants.enderio.machine.farm.farmers.IHarvestResult;
|
||||
@@ -161,8 +160,9 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
public void damageTool(Class<?> class1, Block blk, BlockCoord bc, int damage) {
|
||||
|
||||
float rand = worldObj.rand.nextFloat();
|
||||
if(rand >= Config.farmToolTakeDamageChance)
|
||||
if(rand >= Config.farmToolTakeDamageChance) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack tool = getTool(class1);
|
||||
if(tool == null) {
|
||||
@@ -286,7 +286,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
}
|
||||
int curScaled = getProgressScaled(16);
|
||||
if(curScaled != lastProgressScaled) {
|
||||
PacketHandler.sendToAllAround(new PacketCurrentTask(this), this);
|
||||
sendTaskProgressPacket();
|
||||
lastProgressScaled = curScaled;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -31,6 +31,7 @@ public class BlockVat extends AbstractMachineBlock<TileVat> {
|
||||
|
||||
public static BlockVat create() {
|
||||
PacketHandler.INSTANCE.registerMessage(PacketTanks.class,PacketTanks.class,PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketVatProgress.class, PacketVatProgress.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketDumpTank.class,PacketDumpTank.class,PacketHandler.nextID(), Side.SERVER);
|
||||
BlockVat res = new BlockVat();
|
||||
res.init();
|
||||
|
||||
@@ -15,11 +15,8 @@ import crazypants.enderio.fluid.Fluids;
|
||||
import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.machine.GuiMachineBase;
|
||||
import crazypants.enderio.machine.IMachineRecipe;
|
||||
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
import crazypants.enderio.machine.IPoweredTask;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.MachineRecipeInput;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
import crazypants.render.ColorUtil;
|
||||
@@ -31,7 +28,7 @@ public class GuiVat extends GuiMachineBase {
|
||||
private static final String GUI_TEXTURE = "enderio:textures/gui/vat.png";
|
||||
|
||||
private final TileVat vat;
|
||||
|
||||
|
||||
private IconButtonEIO dump1, dump2;
|
||||
|
||||
public GuiVat(InventoryPlayer inventory, TileVat te) {
|
||||
@@ -67,13 +64,13 @@ public class GuiVat extends GuiMachineBase {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
dump1 = new IconButtonEIO(this, 1, 29, 62, IconEIO.REDSTONE_MODE_NEVER);
|
||||
dump1.setToolTip(Lang.localize("gui.machine.vat.dump.1"));
|
||||
dump2 = new IconButtonEIO(this, 2, 131, 62, IconEIO.REDSTONE_MODE_NEVER);
|
||||
dump2.setToolTip(Lang.localize("gui.machine.vat.dump.2"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
@@ -113,19 +110,12 @@ public class GuiVat extends GuiMachineBase {
|
||||
drawTexturedModalRect(guiLeft + 81, guiTop + 76 - scaled, 176, 12 - scaled, 14, scaled + 2);
|
||||
|
||||
IIcon inputIcon = null;
|
||||
IPoweredTask task = vat.getCurrentTask();
|
||||
for (MachineRecipeInput input : task.getInputs()) {
|
||||
if(input.fluid != null && input.fluid.getFluid() != null) {
|
||||
inputIcon = input.fluid.getFluid().getStillIcon();
|
||||
break;
|
||||
}
|
||||
if(vat.currentTaskInputFluid != null) {
|
||||
inputIcon = vat.currentTaskInputFluid.getStillIcon();
|
||||
}
|
||||
IMachineRecipe rec = task.getRecipe();
|
||||
IIcon outputIcon = null;
|
||||
for (ResultStack res : rec.getCompletedResult(1.0f, task.getInputs())) {
|
||||
if(res.fluid != null && res.fluid.getFluid() != null) {
|
||||
outputIcon = res.fluid.getFluid().getStillIcon();
|
||||
}
|
||||
if(vat.currentTaskOutputFluid != null) {
|
||||
outputIcon = vat.currentTaskOutputFluid.getStillIcon();
|
||||
}
|
||||
|
||||
if(inputIcon != null && outputIcon != null) {
|
||||
@@ -140,14 +130,13 @@ public class GuiVat extends GuiMachineBase {
|
||||
x = guiLeft + 132;
|
||||
RenderUtil.renderGuiTank(vat.outputTank, x, y, zLevel, 15, 47);
|
||||
|
||||
if(vat.getCurrentTask() != null || vat.outputTank.getFluidAmount() > 0) {
|
||||
if(vat.currentTaskOutputFluid != null || vat.outputTank.getFluidAmount() > 0) {
|
||||
|
||||
Fluid outputFluid;
|
||||
if(vat.outputTank.getFluidAmount() > 0) {
|
||||
outputFluid = vat.outputTank.getFluid().getFluid();
|
||||
} else {
|
||||
ResultStack[] res = vat.getCurrentTask().getRecipe().getCompletedResult(1, vat.getCurrentTask().getInputs());
|
||||
outputFluid = res[0].fluid.getFluid();
|
||||
} else {
|
||||
outputFluid = vat.currentTaskOutputFluid;
|
||||
}
|
||||
|
||||
float mult;
|
||||
@@ -155,14 +144,14 @@ public class GuiVat extends GuiMachineBase {
|
||||
if(inStack != null) {
|
||||
mult = VatRecipeManager.instance.getMultiplierForInput(inStack, outputFluid);
|
||||
String str = "x" + mult;
|
||||
x = guiLeft + 63 - fontRendererObj.getStringWidth(str)/2;
|
||||
x = guiLeft + 63 - fontRendererObj.getStringWidth(str) / 2;
|
||||
fontRendererObj.drawString(str, x, guiTop + 32, ColorUtil.getRGB(Color.gray), false);
|
||||
}
|
||||
inStack = vat.getStackInSlot(1);
|
||||
if(inStack != null) {
|
||||
mult = VatRecipeManager.instance.getMultiplierForInput(inStack, outputFluid);
|
||||
String str = "x" + mult;
|
||||
x = guiLeft + 113 - fontRendererObj.getStringWidth(str)/2;
|
||||
x = guiLeft + 113 - fontRendererObj.getStringWidth(str) / 2;
|
||||
fontRendererObj.drawString(str, x, guiTop + 32, ColorUtil.getRGB(Color.gray), false);
|
||||
}
|
||||
}
|
||||
@@ -190,14 +179,14 @@ public class GuiVat extends GuiMachineBase {
|
||||
RenderUtil.bindTexture(GUI_TEXTURE);
|
||||
drawTexturedModalRect(x, y, 0, 256 - 28, 26, 28);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton b) {
|
||||
super.actionPerformed(b);
|
||||
|
||||
if (b == dump1) {
|
||||
|
||||
if(b == dump1) {
|
||||
dump(1);
|
||||
} else if (b == dump2) {
|
||||
} else if(b == dump2) {
|
||||
dump(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package crazypants.enderio.machine.still;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
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.machine.IMachineRecipe;
|
||||
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
import crazypants.enderio.machine.IPoweredTask;
|
||||
import crazypants.enderio.machine.MachineRecipeInput;
|
||||
import crazypants.enderio.machine.PoweredTaskProgress;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
|
||||
public class PacketVatProgress extends MessageTileEntity<TileVat> implements IMessageHandler<PacketVatProgress, IMessage> {
|
||||
|
||||
private float progress = 0;
|
||||
|
||||
private int inputFluidId = -1;
|
||||
private int outputFluidId = -1;
|
||||
|
||||
public PacketVatProgress() {
|
||||
|
||||
}
|
||||
|
||||
public PacketVatProgress(TileVat vat) {
|
||||
super(vat);
|
||||
progress = vat.getProgress();
|
||||
|
||||
IPoweredTask task = vat.getCurrentTask();
|
||||
if(task == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (MachineRecipeInput input : task.getInputs()) {
|
||||
if(input.fluid != null && input.fluid.getFluid() != null) {
|
||||
inputFluidId = input.fluid.getFluid().getID();
|
||||
break;
|
||||
}
|
||||
}
|
||||
IMachineRecipe rec = task.getRecipe();
|
||||
for (ResultStack res : rec.getCompletedResult(1.0f, task.getInputs())) {
|
||||
if(res.fluid != null && res.fluid.getFluid() != null) {
|
||||
outputFluidId = res.fluid.getFluid().getID();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeFloat(progress);
|
||||
buf.writeInt(inputFluidId);
|
||||
buf.writeInt(outputFluidId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
progress = buf.readFloat();
|
||||
inputFluidId = buf.readInt();
|
||||
outputFluidId = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketVatProgress message, MessageContext ctx) {
|
||||
TileVat tile = message.getTileEntity(EnderIO.proxy.getClientWorld());
|
||||
if(tile != null) {
|
||||
tile.currentTaskInputFluid = null;
|
||||
tile.currentTaskOutputFluid = null;
|
||||
if(message.progress < 0) {
|
||||
tile.setClientTask(null);
|
||||
} else {
|
||||
tile.setClientTask(new PoweredTaskProgress(message.progress));
|
||||
if(message.inputFluidId > 0) {
|
||||
tile.currentTaskInputFluid = FluidRegistry.getFluid(message.inputFluidId);
|
||||
}
|
||||
if(message.outputFluidId > 0) {
|
||||
tile.currentTaskOutputFluid = FluidRegistry.getFluid(message.outputFluidId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -26,9 +26,13 @@ public class TileVat extends AbstractPoweredTaskEntity implements IFluidHandler
|
||||
final FluidTank outputTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 8);
|
||||
|
||||
private static int IO_MB_TICK = 100;
|
||||
|
||||
|
||||
boolean tanksDirty = false;
|
||||
|
||||
//Used client side in the vat gui to render progress
|
||||
Fluid currentTaskInputFluid;
|
||||
Fluid currentTaskOutputFluid;
|
||||
|
||||
public TileVat() {
|
||||
super(new SlotDefinition(0, 1, -1, -1, -1, -1));
|
||||
}
|
||||
@@ -171,8 +175,8 @@ public class TileVat extends AbstractPoweredTaskEntity implements IFluidHandler
|
||||
}
|
||||
FluidStack res = outputTank.drain(maxDrain, doDrain);
|
||||
if(res != null && res.amount > 0 && doDrain) {
|
||||
tanksDirty = true;
|
||||
}
|
||||
tanksDirty = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -182,10 +186,15 @@ public class TileVat extends AbstractPoweredTaskEntity implements IFluidHandler
|
||||
if(tanksDirty && worldObj.getTotalWorldTime() % 10 == 0) {
|
||||
PacketHandler.sendToAllAround(new PacketTanks(this), this);
|
||||
tanksDirty = false;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendTaskProgressPacket() {
|
||||
PacketHandler.sendToAllAround(new PacketVatProgress(this), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mergeFluidResult(ResultStack result) {
|
||||
outputTank.fill(result.fluid, true);
|
||||
@@ -294,10 +303,6 @@ public class TileVat extends AbstractPoweredTaskEntity implements IFluidHandler
|
||||
}
|
||||
}
|
||||
|
||||
public IPoweredTask getCurrentTask() {
|
||||
return currentTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPowerUsePerTick() {
|
||||
return Config.vatPowerUserPerTickRF;
|
||||
@@ -307,13 +312,19 @@ public class TileVat extends AbstractPoweredTaskEntity implements IFluidHandler
|
||||
public String getSoundName() {
|
||||
return "machine.vat";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getPitch() {
|
||||
return 0.3f;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getVolume() {
|
||||
return super.getVolume() * 0.3f;
|
||||
}
|
||||
|
||||
void setClientTask(IPoweredTask currentTask) {
|
||||
this.currentTask = currentTask;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +1,11 @@
|
||||
package crazypants.enderio.machine.transceiver;
|
||||
|
||||
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 net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.AbstractPoweredTaskEntity;
|
||||
import crazypants.enderio.machine.PacketCurrentTask;
|
||||
import crazypants.enderio.machine.PoweredTask;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
|
||||
|
||||
Reference in new issue
Block a user