mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-22 04:52:26 +00:00
Fix #519 Analyzer block display does not update when bee changes
This commit is contained in:
1 parent
6593d75234
commit
714206d8c8
3 files changed
+103
-132
No files matched your search
@@ -10,8 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gadgets;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
@@ -19,7 +17,6 @@ import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
@@ -28,10 +25,10 @@ import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.fluids.FluidHelper;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.fluids.TankManager;
|
||||
@@ -42,8 +39,13 @@ import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.inventory.wrappers.IInvSlot;
|
||||
import forestry.core.inventory.wrappers.InventoryIterator;
|
||||
import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketTileUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.GuiUtil;
|
||||
import forestry.plugins.PluginApiculture;
|
||||
|
||||
public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiquidTankContainer {
|
||||
|
||||
@@ -65,9 +67,8 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
|
||||
private final TankManager tankManager;
|
||||
|
||||
private final Stack<ItemStack> pendingProducts = new Stack<ItemStack>();
|
||||
|
||||
private final IInventory invInput;
|
||||
private final IInventory invOutput;
|
||||
|
||||
/* CONSTRUCTOR */
|
||||
public TileAnalyzer() {
|
||||
@@ -92,7 +93,8 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
});
|
||||
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, Fluids.HONEY.getFluid());
|
||||
tankManager = new TankManager(resourceTank);
|
||||
invInput = new InventoryMapper(getInternalInventory(), SLOT_INPUT_1, 6);
|
||||
invInput = new InventoryMapper(getInternalInventory(), SLOT_INPUT_1, SLOT_INPUT_COUNT);
|
||||
invOutput = new InventoryMapper(getInternalInventory(), SLOT_OUTPUT_1, SLOT_OUTPUT_COUNT);
|
||||
}
|
||||
|
||||
/* GUI */
|
||||
@@ -109,19 +111,6 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
nbttagcompound.setInteger("AnalyzeTime", analyzeTime);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
|
||||
// / Pending Products
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
ItemStack[] pending = pendingProducts.toArray(new ItemStack[pendingProducts.size()]);
|
||||
for (int i = 0; i < pending.length; i++) {
|
||||
if (pending[i] != null) {
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("Slot", (byte) i);
|
||||
pending[i].writeToNBT(nbttagcompound1);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
nbttagcompound.setTag("PendingProducts", nbttaglist);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,116 +120,74 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
analyzeTime = nbttagcompound.getInteger("AnalyzeTime");
|
||||
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
|
||||
// / Pending Products
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("PendingProducts", 10);
|
||||
for (int i = 0; i < nbttaglist.tagCount(); i++) {
|
||||
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||
pendingProducts.add(ItemStack.loadItemStackFromNBT(nbttagcompound1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateServerSide() {
|
||||
// Check if we have suitable items waiting in the can slot
|
||||
FluidHelper.drainContainers(tankManager, this, SLOT_CAN);
|
||||
ItemStack can = getStackInSlot(SLOT_CAN);
|
||||
if (ForestryItem.honeyDrop.isItemEqual(can) && resourceTank.fill(Fluids.HONEY.getFluid(Defaults.FLUID_PER_HONEY_DROP), false) == Defaults.FLUID_PER_HONEY_DROP) {
|
||||
setInventorySlotContents(SLOT_CAN, InvTools.depleteItem(can));
|
||||
resourceTank.fill(Fluids.HONEY.getFluid(Defaults.FLUID_PER_HONEY_DROP), true);
|
||||
if (updateOnInterval(20)) {
|
||||
// Check if we have suitable items waiting in the can slot
|
||||
FluidHelper.drainContainers(tankManager, this, SLOT_CAN);
|
||||
}
|
||||
|
||||
for (int i = 0; i < invInput.getSizeInventory(); i++) {
|
||||
ItemStack inputStack = invInput.getStackInSlot(i);
|
||||
if (inputStack == null || !AlleleManager.alleleRegistry.isIndividual(inputStack)) {
|
||||
continue;
|
||||
}
|
||||
// Analyzed bees in the input buffer are added to the output queue.
|
||||
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(inputStack);
|
||||
if (individual.isAnalyzed()) {
|
||||
pendingProducts.push(inputStack);
|
||||
invInput.decrStackSize(i, inputStack.stackSize);
|
||||
}
|
||||
}
|
||||
|
||||
tryAddPending();
|
||||
if (!pendingProducts.isEmpty()) {
|
||||
setErrorState(EnumErrorCode.NOSPACE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (analyzeTime == 0) {
|
||||
// Look for bees in input slots.
|
||||
IInvSlot slot = getInputSlot();
|
||||
if (slot == null) {
|
||||
// Nothing to analyze
|
||||
setErrorState(EnumErrorCode.NOTHINGANALYZE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// We need our liquid honey
|
||||
if (resourceTank.getFluidAmount() < HONEY_REQUIRED) {
|
||||
setErrorState(EnumErrorCode.NORESOURCE);
|
||||
return;
|
||||
}
|
||||
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
}
|
||||
|
||||
/* WORKING */
|
||||
@Override
|
||||
public boolean workCycle() {
|
||||
ItemStack stackToAnalyze = getStackInSlot(SLOT_ANALYZE);
|
||||
if (analyzeTime > 0 && stackToAnalyze != null && AlleleManager.alleleRegistry.isIndividual(stackToAnalyze)) {
|
||||
|
||||
analyzeTime--;
|
||||
|
||||
// Still not done
|
||||
if (analyzeTime > 0) {
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Analyzation is done.
|
||||
if (stackToAnalyze != null) {
|
||||
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(stackToAnalyze);
|
||||
// No bee, abort
|
||||
if (individual == null) {
|
||||
setErrorState(EnumErrorCode.UNKNOWN);
|
||||
return false;
|
||||
}
|
||||
|
||||
individual.analyze();
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
individual.writeToNBT(nbttagcompound);
|
||||
stackToAnalyze.setTagCompound(nbttagcompound);
|
||||
if (analyzeTime > 0) {
|
||||
analyzeTime--;
|
||||
return true;
|
||||
} else {
|
||||
// Analysis complete.
|
||||
if (!individual.isAnalyzed()) {
|
||||
individual.analyze();
|
||||
|
||||
pendingProducts.push(stackToAnalyze);
|
||||
setInventorySlotContents(SLOT_ANALYZE, null);
|
||||
sendNetworkUpdate();
|
||||
return true;
|
||||
}
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
individual.writeToNBT(nbttagcompound);
|
||||
stackToAnalyze.setTagCompound(nbttagcompound);
|
||||
}
|
||||
|
||||
analyzeTime = 0;
|
||||
|
||||
// Don't start if analyze slot already occupied
|
||||
if (stackToAnalyze != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getErrorState() != EnumErrorCode.OK) {
|
||||
return false;
|
||||
if (InvTools.tryAddStack(invOutput, stackToAnalyze, true)) {
|
||||
setInventorySlotContents(SLOT_ANALYZE, null);
|
||||
sendNetworkUpdate();
|
||||
return true;
|
||||
} else {
|
||||
setErrorState(EnumErrorCode.NOSPACE);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Look for bees in input slots.
|
||||
IInvSlot slot = getInputSlot();
|
||||
if (slot != null) {
|
||||
ItemStack inputStack = slot.getStackInSlot();
|
||||
setInventorySlotContents(SLOT_ANALYZE, inputStack);
|
||||
slot.setStackInSlot(null);
|
||||
if (slot == null) {
|
||||
// Nothing to analyze
|
||||
setErrorState(EnumErrorCode.NOTHINGANALYZE);
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack inputStack = slot.getStackInSlot();
|
||||
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(inputStack);
|
||||
if (!individual.isAnalyzed()) {
|
||||
if (resourceTank.getFluidAmount() < HONEY_REQUIRED) {
|
||||
setErrorState(EnumErrorCode.NORESOURCE);
|
||||
return false;
|
||||
}
|
||||
resourceTank.drain(HONEY_REQUIRED, true);
|
||||
analyzeTime = TIME_TO_ANALYZE;
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
setInventorySlotContents(SLOT_ANALYZE, inputStack);
|
||||
slot.setStackInSlot(null);
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
sendNetworkUpdate();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -254,17 +201,43 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean tryAddPending() {
|
||||
if (pendingProducts.isEmpty()) {
|
||||
return false;
|
||||
/* Network */
|
||||
public PacketPayload getPacketPayload() {
|
||||
ItemStack displayStack = getIndividualOnDisplay();
|
||||
if (displayStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack next = pendingProducts.peek();
|
||||
if (InvTools.tryAddStack(getInternalInventory(), next, SLOT_OUTPUT_1, getInternalInventory().getSizeInventory() - SLOT_OUTPUT_1, true)) {
|
||||
pendingProducts.pop();
|
||||
return true;
|
||||
IIndividual displayIndividual = AlleleManager.alleleRegistry.getIndividual(displayStack);
|
||||
int type = PluginApiculture.beeInterface.getType(displayStack).ordinal();
|
||||
|
||||
PacketPayload payload = new PacketPayload();
|
||||
payload.stringPayload = new String[1];
|
||||
payload.shortPayload = new short[2];
|
||||
payload.stringPayload[0] = displayIndividual.getIdent();
|
||||
payload.shortPayload[0] = (short)type;
|
||||
payload.shortPayload[1] = (short)displayStack.stackSize;
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
ItemStack newIndividualOnDisplay = null;
|
||||
if (!payload.isEmpty()) {
|
||||
String individualUID = payload.stringPayload[0];
|
||||
int type = payload.shortPayload[0];
|
||||
int stackSize = payload.shortPayload[1];
|
||||
|
||||
IAllele[] template = PluginApiculture.beeInterface.getTemplate(individualUID);
|
||||
IIndividual individual = PluginApiculture.beeInterface.templateAsIndividual(template);
|
||||
|
||||
newIndividualOnDisplay = PluginApiculture.beeInterface.getMemberStack(individual, type);
|
||||
newIndividualOnDisplay.stackSize = stackSize;
|
||||
}
|
||||
|
||||
if (!ItemStack.areItemStacksEqual(newIndividualOnDisplay, individualOnDisplayClient)) {
|
||||
individualOnDisplayClient = newIndividualOnDisplay;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* STATE INFORMATION */
|
||||
@@ -276,13 +249,6 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
|
||||
@Override
|
||||
public boolean hasWork() {
|
||||
if (!pendingProducts.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (analyzeTime > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return getErrorState() == EnumErrorCode.OK || getErrorState() == EnumErrorCode.NOPOWER;
|
||||
}
|
||||
|
||||
@@ -290,12 +256,16 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
return (analyzeTime * i) / TIME_TO_ANALYZE;
|
||||
}
|
||||
|
||||
private ItemStack individualOnDisplayClient;
|
||||
|
||||
public ItemStack getIndividualOnDisplay() {
|
||||
if (worldObj.isRemote) {
|
||||
return individualOnDisplayClient;
|
||||
}
|
||||
return getStackInSlot(SLOT_ANALYZE);
|
||||
}
|
||||
|
||||
/* SMP */
|
||||
/* ILiquidTankContainer */
|
||||
@Override
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
i -= tankManager.maxMessageId() + 1;
|
||||
@@ -313,12 +283,12 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
|
||||
}
|
||||
|
||||
/* ILIQUIDCONTAINER */
|
||||
@Override
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
/* IFluidHandler */
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
|
||||
@@ -162,22 +162,18 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
|
||||
}
|
||||
}
|
||||
|
||||
// / SMP
|
||||
@Override
|
||||
public void sendNetworkUpdate() {
|
||||
PacketTileUpdate packet = new PacketTileUpdate(this);
|
||||
Proxies.net.sendNetworkPacket(packet, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
PacketTileUpdate packet = new PacketTileUpdate(this);
|
||||
return packet.getPacket();
|
||||
}
|
||||
|
||||
public abstract PacketPayload getPacketPayload();
|
||||
|
||||
public abstract void fromPacketPayload(PacketPayload payload);
|
||||
/* INetworkedEntity */
|
||||
@Override
|
||||
public void sendNetworkUpdate() {
|
||||
PacketTileUpdate packet = new PacketTileUpdate(this);
|
||||
Proxies.net.sendNetworkPacket(packet, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacket(ForestryPacket packetRaw) {
|
||||
@@ -192,6 +188,10 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
|
||||
fromPacketPayload(packet.payload);
|
||||
}
|
||||
|
||||
public abstract PacketPayload getPacketPayload();
|
||||
|
||||
public abstract void fromPacketPayload(PacketPayload payload);
|
||||
|
||||
public void onRemoval() {
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.minecraft.inventory.Slot;
|
||||
import forestry.core.gadgets.TileAnalyzer;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.gui.slots.SlotWorking;
|
||||
|
||||
public class ContainerAnalyzer extends ContainerLiquidTanks {
|
||||
|
||||
@@ -30,7 +31,7 @@ public class ContainerAnalyzer extends ContainerLiquidTanks {
|
||||
}
|
||||
|
||||
// Analyze slot
|
||||
addSlotToContainer(new SlotFiltered(tile, TileAnalyzer.SLOT_ANALYZE, 73, 59));
|
||||
addSlotToContainer(new SlotWorking(tile, TileAnalyzer.SLOT_ANALYZE, 73, 59));
|
||||
|
||||
// Can slot
|
||||
addSlotToContainer(new SlotFiltered(tile, TileAnalyzer.SLOT_CAN, 143, 24));
|
||||
|
||||
Reference in new issue
Block a user