diff --git a/src/main/java/com/glodblock/github/client/gui/GuiSuperStoker.java b/src/main/java/com/glodblock/github/client/gui/GuiSuperStoker.java index 7be7a2e6..e50c4796 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiSuperStoker.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiSuperStoker.java @@ -75,7 +75,7 @@ public class GuiSuperStoker extends AEBaseGui { int slotInt = slotIn.slotNumber; if (itemstack != null) { String s = "0%"; - if (slotInt > 0 && slotInt < 9) { + if (slotInt > 0 && slotInt < 10) { IAEStack aeStack = list.get(slotInt - 1); if (aeStack != null) s = (int) (((float) aeStack.getStackSize() / ItemFluidPacket.getFluidAmount(itemstack)) * 100) diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerSuperStoker.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerSuperStoker.java index feacf186..1702302e 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerSuperStoker.java +++ b/src/main/java/com/glodblock/github/client/gui/container/ContainerSuperStoker.java @@ -6,12 +6,13 @@ import java.util.Map; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import com.glodblock.github.FluidCraft; -import com.glodblock.github.common.item.ItemBasicFluidStorageCell; +import com.glodblock.github.common.item.FCBaseItemCell; import com.glodblock.github.common.tile.TileSuperStoker; import com.glodblock.github.inventory.slot.OptionalFluidSlotFake; import com.glodblock.github.network.SPacketSuperStokerUpdate; @@ -26,9 +27,9 @@ import appeng.items.storage.ItemBasicStorageCell; public class ContainerSuperStoker extends AEBaseContainer implements IOptionalSlotHost { private final TileSuperStoker tile; - private IInventory configFluids; - private IInventory configItems; - private Map> list; + private final IInventory configFluids; + private final IInventory configItems; + private int lastUpdated = 0; public ContainerSuperStoker(InventoryPlayer ipl, TileSuperStoker tile) { super(ipl, tile); @@ -76,21 +77,35 @@ public class ContainerSuperStoker extends AEBaseContainer implements IOptionalSl return true; } + @Override + public void addCraftingToCrafters(ICrafting p_75132_1_) { + super.addCraftingToCrafters(p_75132_1_); + lastUpdated = 24; + } + @Override public void detectAndSendChanges() { super.detectAndSendChanges(); - Map> tmp = new HashMap<>(); - for (int i = 0; i < tile.getInternalFluid().getSlots(); i++) { - tmp.put(i, tile.getInternalFluid().getFluidInSlot(i)); - } - for (int i = 0; i < tile.getInternalInventory().getSizeInventory(); i++) { - tmp.put(i + 100, tile.getInternalAEInventory().getAEStackInSlot(i)); - } - for (final Object g : this.crafters) { - if (g instanceof EntityPlayer) { - FluidCraft.proxy.netHandler.sendTo(new SPacketSuperStokerUpdate(tmp), (EntityPlayerMP) g); + + if (lastUpdated > 20) { + lastUpdated = 0; + Map> tmp = new HashMap<>(); + + for (int i = 0; i < tile.getInternalFluid().getSlots(); i++) { + tmp.put(i, tile.getInternalFluid().getFluidInSlot(i)); + } + + for (int i = 0; i < tile.getInternalInventory().getSizeInventory(); i++) { + tmp.put(i + 100, tile.getInternalAEInventory().getAEStackInSlot(i)); + } + + for (final Object g : this.crafters) { + if (g instanceof EntityPlayer) { + FluidCraft.proxy.netHandler.sendTo(new SPacketSuperStokerUpdate(tmp), (EntityPlayerMP) g); + } } } + lastUpdated++; } private boolean isConfigurated() { @@ -111,18 +126,18 @@ public class ContainerSuperStoker extends AEBaseContainer implements IOptionalSl public boolean isValidForSlot(Slot s, ItemStack is) { if (s.slotNumber == 0 && s.getHasStack() && isConfigurated()) { long currentBytes = 0; - long newBytes = 0; + long newBytes = -1; if (s.getStack().getItem() instanceof ItemBasicStorageCell ibsc) { currentBytes = ibsc.getBytesLong(is); - } else if (s.getStack().getItem() instanceof ItemBasicFluidStorageCell ibfsc) { - currentBytes = ibfsc.getBytes(is); + } else if (s.getStack().getItem() instanceof FCBaseItemCell fcbic) { + currentBytes = fcbic.getBytes(is); } if (is.getItem() instanceof ItemBasicStorageCell ibsc) { newBytes = ibsc.getBytesLong(is); - } else if (is.getItem() instanceof ItemBasicFluidStorageCell ibfsc) { - newBytes = ibfsc.getBytes(is); + } else if (is.getItem() instanceof FCBaseItemCell fcbic) { + newBytes = fcbic.getBytes(is); } if (currentBytes > newBytes) { diff --git a/src/main/java/com/glodblock/github/common/tile/TileSuperStoker.java b/src/main/java/com/glodblock/github/common/tile/TileSuperStoker.java index 61c0ccd7..d1f8b41b 100644 --- a/src/main/java/com/glodblock/github/common/tile/TileSuperStoker.java +++ b/src/main/java/com/glodblock/github/common/tile/TileSuperStoker.java @@ -15,7 +15,7 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -import com.glodblock.github.common.item.ItemBasicFluidStorageCell; +import com.glodblock.github.common.item.FCBaseItemCell; import com.glodblock.github.common.item.ItemFluidPacket; import com.glodblock.github.inventory.AEFluidInventory; import com.glodblock.github.inventory.IAEFluidInventory; @@ -99,7 +99,7 @@ public class TileSuperStoker extends AENetworkInvTile if (configItem != null) { IAEItemStack is = configItem.copy(); if (invItem == null) requestItem(is, i); - else if (invItem.getItem() == is.getItem()) { + else if (invItem.equals(is)) { if (invItem.getStackSize() < is.getStackSize() / 2) { is.setStackSize(is.getStackSize() - invItem.getStackSize()); requestItem(is, i); @@ -125,7 +125,7 @@ public class TileSuperStoker extends AENetworkInvTile .injectItems(ias, Actionable.MODULATE, this.source); if (notInserted != null) { invFluids.fill(index, notInserted, true); - storedFluidCount += ias.getStackSize(); + storedFluidCount += notInserted.getStackSize(); } } catch (final GridAccessException ignored) {} } @@ -146,22 +146,24 @@ public class TileSuperStoker extends AENetworkInvTile private void returnItem(int index, long amount) { try { - IAEItemStack ias = invItems.getAEStackInSlot(index); + IAEItemStack ais = invItems.getAEStackInSlot(index); + long originalSize = ais.getStackSize(); if (amount != Long.MAX_VALUE) { - ias.decStackSize(amount); - ias = ias.copy(); - ias.setStackSize(amount); + ais.decStackSize(amount); + ais = ais.copy(); + ais.setStackSize(amount); } else { - amount = ias.getStackSize(); + amount = ais.getStackSize(); invItems.setInventorySlotContents(index, null); } storedItemCount -= amount; IAEItemStack notInserted = this.getProxy().getStorage().getItemInventory() - .injectItems(ias, Actionable.MODULATE, this.source); + .injectItems(ais, Actionable.MODULATE, this.source); if (notInserted != null) { + long notInsertedAmount = notInserted.getStackSize(); invItems.setInventorySlotContents(index, notInserted.getItemStack()); - invItems.getAEStackInSlot(index).setStackSize(notInserted.getStackSize()); - storedItemCount += notInserted.getStackSize(); + invItems.getAEStackInSlot(index).setStackSize(originalSize - (amount - notInsertedAmount)); + storedItemCount += notInsertedAmount; } } catch (final GridAccessException ignored) {} } @@ -253,8 +255,8 @@ public class TileSuperStoker extends AENetworkInvTile if (inv == cell && added != null) { if (added.getItem() instanceof ItemBasicStorageCell ibsc) { totalBytes = ibsc.getBytesLong(added); - } else if (added.getItem() instanceof ItemBasicFluidStorageCell ibfsc) { - totalBytes = ibfsc.getBytes(added); + } else if (added.getItem() instanceof FCBaseItemCell fcbic) { + totalBytes = fcbic.getBytes(added); } getProxy().setIdlePowerUsage(Math.sqrt(Math.pow(totalBytes, 0.576D))); } @@ -267,9 +269,7 @@ public class TileSuperStoker extends AENetworkInvTile if (inv == invItems && invItems.getAEStackInSlot(slot) != null) invItems.getAEStackInSlot(slot).decStackSize(removed.stackSize); } - case markDirty -> { - - } + case markDirty -> {} } try { @@ -284,19 +284,20 @@ public class TileSuperStoker extends AENetworkInvTile public void fullRefund() { for (int i = 0; i < 9; i++) { if (invFluids.getFluidStackInSlot(i) != null) { - returnFluid(i, Integer.MAX_VALUE); + returnFluid(i, Long.MAX_VALUE); } } for (int i = 0; i < 63; i++) { if (invItems.getAEStackInSlot(i) != null) { - returnItem(i, Integer.MAX_VALUE); + returnItem(i, Long.MAX_VALUE); } } } @Override public void getDrops(World w, int x, int y, int z, List drops) { + if (cell.getStackInSlot(0) != null) drops.add(cell.getStackInSlot(0)); for (int i = 0; i < 9; i++) { ItemStack ifp = ItemFluidPacket.newStack(invFluids.getFluidStackInSlot(i)); if (ifp != null) drops.add(ifp);