Compare commits

..
Author SHA1 Message Date
Martin Robertz 24670fdf5e Merge branch 'master' into dev 2025-10-04 18:01:16 +02:00
0d91a7dd43 Compatibility with ae native fluid (#293)
Co-authored-by: lordIcocain <[email protected]>
Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: Kogepan229 <[email protected]>
2025-10-04 15:57:41 +00:00
Martin Robertz 10ba37661a Merge branch 'ae-navite-fluid-support' into dev 2025-10-04 17:55:19 +02:00
Martin Robertz 7d0dba6315 Merge remote-tracking branch 'origin/levelterminal-improve' into dev 2025-10-04 17:55:15 +02:00
Martin Robertz bd26307feb Merge remote-tracking branch 'origin/levelmaintainer-memorycard' into dev 2025-10-04 17:55:11 +02:00
Martin Robertz d5b0f39f05 Merge branch 'master' into ae-navite-fluid-support 2025-10-04 17:52:37 +02:00
Martin Robertz d49b319954 update 2025-10-04 17:51:22 +02:00
Kogepan229 2e8c6ffdb0 Fix dropping stacks 2025-10-03 15:11:39 +09:00
Kogepan229 6c2b1ff84d Merge branch 'master' into ae-navite-fluid-support 2025-10-03 15:08:58 +09:00
Martin Robertz a29dd16d1b update 2025-10-01 23:50:40 +02:00
Martin Robertz 9e6320d1b6 Merge remote-tracking branch 'origin/levelmaintainer-memorycard' into dev 2025-10-01 23:50:19 +02:00
Martin Robertz 7b9b7615ce Merge remote-tracking branch 'origin/levelterminal-improve' into dev 2025-10-01 23:50:14 +02:00
Martin Robertz 8e337bf6c8 Merge branch 'master' into levelterminal-improve 2025-10-01 23:49:17 +02:00
Martin Robertz de6ae72fb0 Merge branch 'master' into levelmaintainer-memorycard 2025-10-01 23:49:12 +02:00
a955757cd7 Refactor: Replace Ae2Reflect usages with direct method calls (#326)
Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: Kogepan229 <[email protected]>
Co-authored-by: Kogepan229 <[email protected]>
2025-10-01 19:02:48 +02:00
Martin Robertz 855fe03f75 fix 2025-10-01 18:43:50 +02:00
Martin Robertz 9a7630bdfa update 2025-10-01 18:29:07 +02:00
Martin Robertz 766c2ff9ce Merge branch 'master' into ae-navite-fluid-support 2025-09-30 19:19:14 +02:00
Kogepan229 d7d01d484e Merge branch 'master' into levelmaintainer-memorycard 2025-09-29 21:36:32 +09:00
Kogepan229 c6b8e89db2 Merge branch 'master' into levelterminal-improve 2025-09-29 21:36:30 +09:00
Kogepan229 7c103ea79c Fix Wireless Level Terminal Icon 2025-08-23 23:08:22 +09:00
Kogepan229 5f194d0f95 Allows open the Level Emitter GUI from Level Terminal 2025-08-23 23:03:40 +09:00
Kogepan229 6c19f69ad6 Remove restriction imposed by Infinity Booster Card 2025-08-23 22:57:34 +09:00
Martin Robertz b28110ed67 Merge branch 'master' into levelmaintainer-memorycard 2025-08-08 23:07:56 +07:00
Kogepan229 c96f3659e2 Merge branch 'master' into levelmaintainer-memorycard 2025-08-06 17:00:19 +09:00
Kogepan229 230713aa11 Add Memory Card support to Level Maintainer 2025-08-06 14:55:33 +09:00
lordIcocain e8f25f8487 fix patterning without inputs/outputs 2025-06-06 21:13:39 +03:00
lordIcocain a6c36d3af5 fix fluid export bus crafting mode 2025-06-03 06:37:39 +03:00
lordIcocain 0779b10ebc fluid packet long 2025-06-01 12:57:10 +03:00
lordIcocain 67072ce99b Merge branch 'master' into ae-navite-fluid-support 2025-06-01 09:48:06 +03:00
lordIcocain 09f7642c67 Interface fluid support 2025-05-31 21:40:43 +03:00
lordIcocain fb6f5aa356 fix ultra pattern rewrite 2025-05-27 05:11:38 +03:00
lordIcocain e6d4119617 introduce Ultimate pattern 2025-05-25 11:09:23 +03:00
lordIcocain 60a89bf2f9 use fluid in patterns 2025-05-19 03:22:44 +03:00
lordIcocain bc1f6adf9d compatibility with ae native fluid 2025-05-16 06:46:09 +03:00
53 changed files with 1059 additions and 1869 deletions

No files matched your search

+11 -11
View File
@@ -34,30 +34,30 @@
* For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
api('com.github.GTNewHorizons:NotEnoughItems:2.8.25-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-695-GTNH:dev')
api('com.github.GTNewHorizons:NotEnoughItems:2.8.6-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-704-GTNH:dev')
api('curse.maven:cofh-core-69162:2388751')
api('com.github.GTNewHorizons:waila:1.9.7:dev')
api("com.github.GTNewHorizons:GTNHLib:0.7.3:dev")
api('com.github.GTNewHorizons:waila:1.9.0:dev')
api("com.github.GTNewHorizons:GTNHLib:0.7.0:dev")
implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.12.7:dev") {
exclude group: 'com.github.GTNewHorizons', module: 'Applied-Energistics-2-Unofficial'
}
compileOnly('com.github.GTNewHorizons:Baubles-Expanded:2.2.2-GTNH:dev')
compileOnly('com.github.GTNewHorizons:Baubles-Expanded:2.2.0-GTNH:dev')
compileOnly('com.github.GTNewHorizons:ExtraCells2:2.5.35:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:ForestryMC:4.11.0:dev')
compileOnly('com.github.GTNewHorizons:EnderIO:2.10.3:dev')
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.52.83:dev') {
compileOnly('com.github.GTNewHorizons:ForestryMC:4.10.17:dev')
compileOnly('com.github.GTNewHorizons:EnderIO:2.10.0:dev')
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.52.12:dev') {
exclude group: 'com.github.GTNewHorizons', module: 'AE2FluidCraft-Rework'
exclude group: 'com.github.GTNewHorizons', module: 'Applied-Energistics-2-Unofficial'
}
compileOnly('thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev')
compileOnly('com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:OpenComputers:1.12.4-GTNH:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:OpenComputers:1.12.0-GTNH:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:ThaumicEnergistics:1.7.14-GTNH:dev') { transitive = false }
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.7.7:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.7.2:dev") { transitive = false }
runtimeOnlyNonPublishable("com.github.GTNewHorizons:DuraDisplay:1.4.0:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:DuraDisplay:1.3.4:dev")
}
+1 -3
View File
@@ -96,9 +96,7 @@ usesMixinDebug = false
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
mixinPlugin =
# Specify the package that contains all of your Mixins. The package must exist or
# the build will fail. If you have a package property defined in your mixins.<modid>.json,
# it must match with this or the build will fail.
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
mixinsPackage =
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
+1 -1
View File
@@ -17,7 +17,7 @@ pluginManagement {
}
plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.47'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.43'
}
@@ -22,13 +22,11 @@ import com.glodblock.github.util.Ae2ReflectClient;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.AEBaseContainer;
import appeng.helpers.InventoryAction;
public class GuiCraftingStatus extends appeng.client.gui.implementations.GuiCraftingStatus {
private GuiTabButton originalGuiBtn;
private final ITerminalHost host;
public GuiCraftingStatus(InventoryPlayer inventoryPlayer, ITerminalHost te) {
@@ -38,26 +36,21 @@ public class GuiCraftingStatus extends appeng.client.gui.implementations.GuiCraf
@Override
public void initGui() {
if (host instanceof PartFluidPatternTerminal)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.FLUID_TERMINAL.stack());
else if (host instanceof PartFluidPatternTerminalEx)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.FLUID_TERMINAL_EX.stack());
else if (host instanceof PartFluidTerminal)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.FLUID_TERM.stack());
else if (host instanceof PartLevelTerminal)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.LEVEL_TERMINAL.stack());
if (host instanceof PartFluidPatternTerminal) this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL.stack();
else if (host instanceof PartFluidPatternTerminalEx) this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL_EX.stack();
else if (host instanceof PartFluidTerminal) this.myIcon = ItemAndBlockHolder.FLUID_TERM.stack();
else if (host instanceof PartLevelTerminal) this.myIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack();
else if (host instanceof IWirelessTerminal terminal && terminal.isUniversal(host))
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack());
this.myIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack();
else if (host instanceof WirelessFluidTerminalInventory)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.WIRELESS_FLUID_TERM.stack());
this.myIcon = ItemAndBlockHolder.WIRELESS_FLUID_TERM.stack();
else if (host instanceof WirelessPatternTerminalInventory)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.WIRELESS_PATTERN_TERM.stack());
this.myIcon = ItemAndBlockHolder.WIRELESS_PATTERN_TERM.stack();
else if (host instanceof WirelessInterfaceTerminalInventory)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.WIRELESS_INTERFACE_TERM.stack());
this.myIcon = ItemAndBlockHolder.WIRELESS_INTERFACE_TERM.stack();
else if (host instanceof WirelessLevelTerminalInventory)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack());
this.myIcon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack();
super.initGui();
originalGuiBtn = Ae2ReflectClient.getOriginalGuiButton(this);
}
@Override
@@ -2,22 +2,35 @@ package com.glodblock.github.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerFluidLevelEmitter;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import com.glodblock.github.common.parts.PartFluidLevelEmitter;
import com.glodblock.github.common.parts.PartLevelTerminal;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.network.CPacketLevelTerminalCommands;
import com.glodblock.github.network.CPacketValueConfig;
import com.glodblock.github.util.NameConst;
import com.glodblock.github.util.Util;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.util.DimensionalCoord;
import appeng.client.gui.implementations.GuiUpgradeable;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.container.AEBaseContainer;
import appeng.core.AEConfig;
import appeng.core.localization.GuiColors;
import appeng.core.localization.GuiText;
@@ -28,6 +41,11 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable {
private MEGuiTextField amountTextField;
protected GuiType originalGui;
protected Util.DimensionalCoordSide originalBlockPos;
protected ItemStack originalGuiIcon;
protected GuiTabButton originalGuiBtn;
private GuiButton plus1;
private GuiButton plus10;
private GuiButton plus100;
@@ -43,6 +61,43 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable {
public GuiFluidLevelEmitter(final InventoryPlayer inventoryPlayer, final PartFluidLevelEmitter te) {
super(new ContainerFluidLevelEmitter(inventoryPlayer, te));
if (inventoryPlayer.player.openContainer instanceof AEBaseContainer container) {
var target = container.getTarget();
if (target instanceof PartLevelTerminal terminal) {
originalGuiIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack();
originalGui = GuiType.LEVEL_TERMINAL;
DimensionalCoord blockPos = new DimensionalCoord(terminal.getTile());
originalBlockPos = new Util.DimensionalCoordSide(
blockPos.x,
blockPos.y,
blockPos.z,
blockPos.getDimension(),
terminal.getSide(),
"");
} else if (target instanceof IWirelessTerminal terminal && terminal.isUniversal(target)) {
originalGuiIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack();
originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack());
originalBlockPos = new Util.DimensionalCoordSide(
terminal.getInventorySlot(),
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
0,
inventoryPlayer.player.worldObj.provider.dimensionId,
ForgeDirection.UNKNOWN,
"");
} else if (target instanceof WirelessLevelTerminalInventory terminal) {
originalGuiIcon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack();
originalGui = GuiType.WIRELESS_LEVEL_TERMINAL;
originalBlockPos = new Util.DimensionalCoordSide(
terminal.getInventorySlot(),
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
0,
inventoryPlayer.player.worldObj.provider.dimensionId,
ForgeDirection.UNKNOWN,
"");
}
}
}
@Override
@@ -55,6 +110,17 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable {
this.amountTextField.setFocused(true);
((ContainerFluidLevelEmitter) this.inventorySlots).setTextField(this.amountTextField);
this.validateText();
if (this.originalGuiIcon != null) {
this.originalGuiBtn = new GuiTabButton(
this.guiLeft + 151,
this.guiTop - 4,
this.originalGuiIcon,
this.originalGuiIcon.getDisplayName(),
itemRender);
this.originalGuiBtn.setHideEdge(13);
this.buttonList.add(originalGuiBtn);
}
}
@Override
@@ -143,9 +209,18 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable {
@Override
protected void actionPerformed(final GuiButton btn) {
super.actionPerformed(btn);
if (btn == this.setButton && this.setButton.enabled) {
if (btn == this.originalGuiBtn) {
CPacketLevelTerminalCommands message = new CPacketLevelTerminalCommands(
CPacketLevelTerminalCommands.Action.BACK,
originalBlockPos.x,
originalBlockPos.y,
originalBlockPos.z,
originalBlockPos.getDimension(),
originalBlockPos.getSide());
message.setOriginalGui(originalGui.ordinal());
FluidCraft.proxy.netHandler.sendToServer(message);
} else if (btn == this.setButton && this.setButton.enabled) {
final long amount = this.getAmountLong();
this.amountTextField.setText(Long.toString(amount));
@@ -161,6 +236,8 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable {
if (isPlus || isMinus) {
long result = addOrderAmount(this.getQty(btn));
this.amountTextField.setText(Long.toString(result));
} else {
super.actionPerformed(btn);
}
}
}
@@ -0,0 +1,104 @@
package com.glodblock.github.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import com.glodblock.github.common.parts.PartLevelTerminal;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.network.CPacketLevelTerminalCommands;
import com.glodblock.github.util.Util;
import appeng.api.util.DimensionalCoord;
import appeng.client.gui.implementations.GuiLevelEmitter;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.AEBaseContainer;
import appeng.parts.automation.PartLevelEmitter;
public class GuiLevelEmitterProxy extends GuiLevelEmitter {
protected GuiType originalGui;
protected Util.DimensionalCoordSide originalBlockPos;
protected ItemStack originalGuiIcon;
protected GuiTabButton originalGuiBtn;
public GuiLevelEmitterProxy(final InventoryPlayer inventoryPlayer, final PartLevelEmitter te) {
super(inventoryPlayer, te);
if (inventoryPlayer.player.openContainer instanceof AEBaseContainer container) {
var target = container.getTarget();
if (target instanceof PartLevelTerminal terminal) {
originalGuiIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack();
originalGui = GuiType.LEVEL_TERMINAL;
DimensionalCoord blockPos = new DimensionalCoord(terminal.getTile());
originalBlockPos = new Util.DimensionalCoordSide(
blockPos.x,
blockPos.y,
blockPos.z,
blockPos.getDimension(),
terminal.getSide(),
"");
} else if (target instanceof IWirelessTerminal terminal && terminal.isUniversal(target)) {
originalGuiIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack();
originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack());
originalBlockPos = new Util.DimensionalCoordSide(
terminal.getInventorySlot(),
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
0,
inventoryPlayer.player.worldObj.provider.dimensionId,
ForgeDirection.UNKNOWN,
"");
} else if (target instanceof WirelessLevelTerminalInventory terminal) {
originalGuiIcon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack();
originalGui = GuiType.WIRELESS_LEVEL_TERMINAL;
originalBlockPos = new Util.DimensionalCoordSide(
terminal.getInventorySlot(),
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
0,
inventoryPlayer.player.worldObj.provider.dimensionId,
ForgeDirection.UNKNOWN,
"");
}
}
}
@Override
public void initGui() {
super.initGui();
if (this.originalGuiIcon != null) {
this.originalGuiBtn = new GuiTabButton(
this.guiLeft + 151,
this.guiTop - 4,
this.originalGuiIcon,
this.originalGuiIcon.getDisplayName(),
itemRender);
this.originalGuiBtn.setHideEdge(13);
this.buttonList.add(originalGuiBtn);
}
}
@Override
protected void actionPerformed(GuiButton btn) {
if (btn == this.originalGuiBtn) {
CPacketLevelTerminalCommands message = new CPacketLevelTerminalCommands(
CPacketLevelTerminalCommands.Action.BACK,
originalBlockPos.x,
originalBlockPos.y,
originalBlockPos.z,
originalBlockPos.getDimension(),
originalBlockPos.getSide());
message.setOriginalGui(originalGui.ordinal());
FluidCraft.proxy.netHandler.sendToServer(message);
} else {
super.actionPerformed(btn);
}
}
}
@@ -105,7 +105,7 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
ForgeDirection.UNKNOWN,
"");
} else if (target instanceof WirelessLevelTerminalInventory terminal) {
icon = ItemAndBlockHolder.LEVEL_TERMINAL.stack();
icon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack();
originalGui = GuiType.WIRELESS_LEVEL_TERMINAL;
originalBlockPos = new Util.DimensionalCoordSide(
terminal.getInventorySlot(),
@@ -1241,7 +1241,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
dim,
ForgeDirection.getOrientation(side),
"");
if (isCtrlKeyDown() && isShiftKeyDown() && hasInfinityBoosterCard(mc.thePlayer)) {
if (isCtrlKeyDown() && isShiftKeyDown()) {
FluidCraft.proxy.netHandler.sendToServer(
new CPacketLevelTerminalCommands(
Action.EDIT,
@@ -505,7 +505,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
action = InventoryAction.PICKUP_SINGLE;
}
}
if (Ae2ReflectClient.getDragClick(this).size() > 1) {
if (this.drag_click.size() > 1) {
return;
}
final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0);
@@ -556,7 +556,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
}
if (slot instanceof SlotDisconnected) {
if (Ae2ReflectClient.getDragClick(this).size() > 1) {
if (this.drag_click.size() > 1) {
return;
}
InventoryAction action = null;
@@ -13,11 +13,9 @@ import com.glodblock.github.common.parts.PartLevelTerminal;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.BlockPos;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.security.IActionHost;
import appeng.api.storage.ITerminalHost;
import appeng.container.implementations.ContainerCraftConfirm;
@@ -71,8 +69,8 @@ public class ContainerFluidCraftConfirm extends ContainerCraftConfirm {
@Override
public void optimizePatterns() {
// only V2 supported
IGrid grid = Ae2Reflect.getGrid(this);
ICraftingJob result = Ae2Reflect.getResult(this);
IGrid grid = this.getGrid();
if (result instanceof CraftingJobV2 && !this.isSimulation()
&& grid != null
&& !grid.getMachines(TilePatternOptimizationMatrix.class).isEmpty()) {
@@ -5,7 +5,6 @@ import net.minecraft.entity.player.InventoryPlayer;
import com.glodblock.github.client.gui.container.base.FCContainerFluidConfigurable;
import com.glodblock.github.common.parts.PartFluidExportBus;
import com.glodblock.github.common.parts.base.FCSharedFluidBus;
import com.glodblock.github.util.Ae2Reflect;
import appeng.api.config.SchedulingMode;
import appeng.api.config.Settings;
@@ -34,7 +33,7 @@ public class ContainerFluidIO extends FCContainerFluidConfigurable {
@Override
protected void loadSettingsFromHost(IConfigManager cm) {
super.loadSettingsFromHost(cm);
if (Ae2Reflect.getUpgradeableHost(this) instanceof PartFluidExportBus) {
if (this.getUpgradeable() instanceof PartFluidExportBus) {
this.setCraftingMode((YesNo) cm.getSetting(Settings.CRAFT_ONLY));
this.setSchedulingMode((SchedulingMode) cm.getSetting(Settings.SCHEDULING_MODE));
}
@@ -7,12 +7,10 @@ import net.minecraft.inventory.IInventory;
import com.glodblock.github.client.gui.container.base.FCContainerFluidConfigurable;
import com.glodblock.github.common.parts.PartFluidLevelEmitter;
import com.glodblock.github.inventory.slot.OptionalFluidSlotFakeTypeOnly;
import com.glodblock.github.util.Ae2Reflect;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.implementations.IUpgradeableHost;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.container.guisync.GuiSync;
import appeng.tile.inventory.AppEngInternalAEInventory;
@@ -39,10 +37,6 @@ public class ContainerFluidLevelEmitter extends FCContainerFluidConfigurable {
return this.lvlEmitter;
}
protected IUpgradeableHost getUpgradeable() {
return Ae2Reflect.getUpgradeableHost(this);
}
public AppEngInternalAEInventory getFakeFluidInv() {
return (AppEngInternalAEInventory) this.lvlEmitter.getInventoryByName("config");
}
@@ -84,8 +78,7 @@ public class ContainerFluidLevelEmitter extends FCContainerFluidConfigurable {
if (Platform.isServer()) {
this.EmitterValue = this.lvlEmitter.getReportingValue();
this.setRedStoneMode(
(RedstoneMode) Ae2Reflect.getUpgradeableHost(this).getConfigManager()
.getSetting(Settings.REDSTONE_EMITTER));
(RedstoneMode) this.getUpgradeable().getConfigManager().getSetting(Settings.REDSTONE_EMITTER));
}
this.standardDetectAndSendChanges();
@@ -9,7 +9,6 @@ import com.glodblock.github.client.gui.container.base.FCContainerFluidConfigurab
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.parts.PartFluidStorageBus;
import com.glodblock.github.inventory.slot.OptionalFluidSlotFakeTypeOnly;
import com.glodblock.github.util.Ae2Reflect;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
@@ -51,8 +50,8 @@ public class ContainerFluidStorageBus extends FCContainerFluidConfigurable {
protected void setupConfig() {
final int xo = 8;
final int yo = 23 + 6;
final IInventory upgrades = Ae2Reflect.getUpgradeList(this).getInventoryByName("upgrades");
final IInventory config = Ae2Reflect.getUpgradeList(this).getInventoryByName("config");
final IInventory upgrades = getUpgradeable().getInventoryByName("upgrades");
final IInventory config = getUpgradeable().getInventoryByName("config");
for (int y = 0; y < 7; y++) {
for (int x = 0; x < 9; x++) {
this.addSlotToContainer(
@@ -104,7 +103,7 @@ public class ContainerFluidStorageBus extends FCContainerFluidConfigurable {
@Override
protected boolean isValidForConfig(int slot, IAEFluidStack fs) {
if (this.supportCapacity()) {
final int upgrades = Ae2Reflect.getUpgradeList(this).getInstalledUpgrades(Upgrades.CAPACITY);
final int upgrades = getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
final int y = slot / 9;
return y < upgrades + 2;
}
@@ -126,11 +125,9 @@ public class ContainerFluidStorageBus extends FCContainerFluidConfigurable {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if (Platform.isServer()) {
this.setReadWriteMode(
(AccessRestriction) Ae2Reflect.getUpgradeList(this).getConfigManager().getSetting(Settings.ACCESS));
this.setReadWriteMode((AccessRestriction) getUpgradeable().getConfigManager().getSetting(Settings.ACCESS));
this.setStorageFilter(
(StorageFilter) Ae2Reflect.getUpgradeList(this).getConfigManager()
.getSetting(Settings.STORAGE_FILTER));
(StorageFilter) getUpgradeable().getConfigManager().getSetting(Settings.STORAGE_FILTER));
}
this.standardDetectAndSendChanges();
@@ -138,8 +135,8 @@ public class ContainerFluidStorageBus extends FCContainerFluidConfigurable {
@Override
public boolean isSlotEnabled(final int idx) {
if (Ae2Reflect.getUpgradeList(this).getInstalledUpgrades(Upgrades.ORE_FILTER) > 0) return false;
final int upgrades = Ae2Reflect.getUpgradeList(this).getInstalledUpgrades(Upgrades.CAPACITY);
if (getUpgradeable().getInstalledUpgrades(Upgrades.ORE_FILTER) > 0) return false;
final int upgrades = getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
return upgrades > (idx - 2);
}
@@ -1,5 +1,7 @@
package com.glodblock.github.client.gui.container.base;
import static appeng.util.Platform.writeStackNBT;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -25,13 +27,12 @@ import com.glodblock.github.common.item.ItemFluidEncodedPattern;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.IPatternConsumer;
import com.glodblock.github.inventory.item.IItemPatternTerminal;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.FluidPatternDetails;
import com.glodblock.github.util.Util;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.definitions.IDefinitions;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.guisync.GuiSync;
@@ -43,11 +44,11 @@ import appeng.container.slot.SlotPatternTerm;
import appeng.container.slot.SlotRestrictedInput;
import appeng.helpers.IContainerCraftingPacket;
import appeng.helpers.InventoryAction;
import appeng.items.misc.ItemEncodedPattern;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.item.AEFluidStack;
import appeng.util.item.AEItemStack;
public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
@@ -172,7 +173,7 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
ItemStack is = clickSlot.getStack();
if (is != null && !patternSlotOUT.getHasStack()
&& is.stackSize == 1
&& (is.getItem() instanceof ItemFluidEncodedPattern || is.getItem() instanceof ItemEncodedPattern)) {
&& is.getItem() instanceof ICraftingPatternItem) {
ItemStack output = is.copy();
patternSlotOUT.putStack(output);
p.inventory.setInventorySlotContents(clickSlot.getSlotIndex(), null);
@@ -243,20 +244,6 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
return object > 0;
}
protected boolean checkHasFluidPattern() {
if (this.craftingMode) {
return false;
}
boolean hasFluid = containsFluid(this.craftingSlots);
boolean search = nonNullSlot(this.craftingSlots);
if (!search) { // search=false -> inputs were empty
return false;
}
hasFluid |= containsFluid(this.outputSlots);
search = nonNullSlot(this.outputSlots);
return hasFluid && search; // search=false -> outputs were empty
}
protected ItemStack stampAuthor(ItemStack patternStack) {
if (patternStack.stackTagCompound == null) {
patternStack.stackTagCompound = new NBTTagCompound();
@@ -266,13 +253,52 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
}
protected void encodeFluidPattern() {
ItemStack patternStack = new ItemStack(ItemAndBlockHolder.PATTERN);
FluidPatternDetails pattern = new FluidPatternDetails(patternStack);
pattern.setInputs(collectInventory(this.craftingSlots));
pattern.setOutputs(collectInventory(this.outputSlots));
pattern.setCanBeSubstitute(this.beSubstitute ? 1 : 0);
pattern.setCombine(this.combine ? 1 : 0);
patternSlotOUT.putStack(stampAuthor(pattern.writeToStack()));
ItemStack patternStack = AEApi.instance().definitions().items().encodedUltimatePattern().maybeStack(1).orNull();
if (patternStack != null) {
final NBTTagCompound encodedValue = new NBTTagCompound();
final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs();
final NBTTagList tagIn = new NBTTagList();
final NBTTagList tagOut = new NBTTagList();
for (final ItemStack i : in) {
if (i != null) {
if (i.getItem() instanceof ItemFluidPacket) {
tagIn.appendTag(
writeStackNBT(
AEFluidStack.create(ItemFluidPacket.getFluidStack(i)),
new NBTTagCompound(),
true));
} else {
tagIn.appendTag(writeStackNBT(AEItemStack.create(i), new NBTTagCompound(), true));
}
}
}
for (final ItemStack i : out) {
if (i != null) {
if (i.getItem() instanceof ItemFluidPacket) {
tagOut.appendTag(
writeStackNBT(
AEFluidStack.create(ItemFluidPacket.getFluidStack(i)),
new NBTTagCompound(),
true));
} else {
tagOut.appendTag(writeStackNBT(AEItemStack.create(i), new NBTTagCompound(), true));
}
}
}
encodedValue.setTag("in", tagIn);
encodedValue.setTag("out", tagOut);
encodedValue.setBoolean("substitute", substitute);
encodedValue.setBoolean("beSubstitute", beSubstitute);
encodedValue.setString("author", this.getPlayerInv().player.getCommandSenderName());
patternStack.setTagCompound(encodedValue);
patternSlotOUT.putStack(patternStack);
}
}
protected static IAEItemStack[] collectInventory(Slot[] slots) {
@@ -369,25 +395,27 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
}
public void encode() {
fillPattern();
if (!checkHasFluidPattern()) {
encodeItemPattern();
return;
}
ItemStack stack = this.patternSlotOUT.getStack();
if (stack == null) {
stack = this.patternSlotIN.getStack();
if (notPattern(stack)) {
if (getInputs() != null && getOutputs() != null) {
fillPattern();
if (isCraftingMode()) {
encodeItemPattern();
return;
}
if (stack.stackSize == 1) {
this.patternSlotIN.putStack(null);
} else {
stack.stackSize--;
ItemStack stack = this.patternSlotOUT.getStack();
if (stack == null) {
stack = this.patternSlotIN.getStack();
if (notPattern(stack)) {
return;
}
if (stack.stackSize == 1) {
this.patternSlotIN.putStack(null);
} else {
stack.stackSize--;
}
encodeFluidPattern();
} else if (!notPattern(stack)) {
encodeFluidPattern();
}
encodeFluidPattern();
} else if (!notPattern(stack)) {
encodeFluidPattern();
}
}
@@ -396,10 +424,6 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs();
// if there is no input, this would be silly.
if (in == null || out == null) {
return;
}
// first check the output slots, should either be null, or a pattern
if (output != null && this.notPattern(output)) {
return;
@@ -487,7 +511,10 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
boolean isPattern = definitions.items().encodedPattern().isSameAs(output);
isPattern |= definitions.materials().blankPattern().isSameAs(output);
return !isPattern;
boolean isUltimatePattern = definitions.items().encodedUltimatePattern().isSameAs(output);
isUltimatePattern |= definitions.materials().blankPattern().isSameAs(output);
return !isPattern && !isUltimatePattern;
}
protected NBTBase createItemTag(final ItemStack i) {
@@ -569,7 +596,7 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
for (Slot s : slots) {
ItemStack st = s.getStack();
if (st == null) continue;
final int count;
final long count;
if (st.getItem() instanceof ItemFluidPacket) {
count = ItemFluidPacket.getFluidAmount(st);
} else {
@@ -14,7 +14,6 @@ import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.slot.OptionalFluidSlotFakeTypeOnly;
import com.glodblock.github.network.SPacketFluidUpdate;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.Util;
import appeng.api.config.Upgrades;
@@ -64,7 +63,7 @@ public abstract class FCContainerFluidConfigurable extends ContainerUpgradeable
protected void setupConfig() {
this.setupUpgrades();
final IInventory inv = Ae2Reflect.getUpgradeList(this).getInventoryByName("config");
final IInventory inv = getUpgradeable().getInventoryByName("config");
final int y = 40;
final int x = 80;
this.addSlotToContainer(new OptionalFluidSlotFakeTypeOnly(inv, null, this, 0, x, y, 0, 0, 0));
@@ -84,7 +83,7 @@ public abstract class FCContainerFluidConfigurable extends ContainerUpgradeable
protected boolean isValidForConfig(int slot, IAEFluidStack fs) {
if (this.supportCapacity()) {
// assumes 4 slots per upgrade
final int upgrades = Ae2Reflect.getUpgradeList(this).getInstalledUpgrades(Upgrades.CAPACITY);
final int upgrades = getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
if (slot > 0 && upgrades < 1) {
return false;
@@ -17,7 +17,6 @@ import org.lwjgl.opengl.GL11;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.render.tank.ModelCertusTank;
import com.glodblock.github.common.item.ItemCertusQuartzTank;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.ModAndClassUtil;
@@ -36,7 +35,7 @@ public class ItemCertusQuartzTankRender implements IItemRenderer {
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
return true;
return type != ItemRenderType.EQUIPPED_FIRST_PERSON;
}
@Override
@@ -50,22 +49,21 @@ public class ItemCertusQuartzTankRender implements IItemRenderer {
.bindTexture(FluidCraft.resource("textures/blocks/certus_quartz_tank/map.png"));
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
if (type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON) {
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
}
GL11.glRotatef(180F, 1F, 0F, 0F);
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
GL11.glScalef(1, -1, -1);
this.model.render(0.0625f);
GL11.glScalef(1, -1, 1);
this.model.render(0.0625f);
GL11.glRotatef(180F, 1F, 0F, 0F);
if (item.getItem() instanceof ItemCertusQuartzTank itemCertusQuartzTank) {
FluidStack storedFluid = itemCertusQuartzTank.getFluid(item);
int tankCapacity = itemCertusQuartzTank.getCapacity(item);
if (item != null && item.hasTagCompound()) {
FluidStack storedFluid = FluidStack
.loadFluidStackFromNBT(item.getTagCompound().getCompoundTag("tileEntity"));
int tankCapacity = 32000;
if (storedFluid != null && storedFluid.getFluid() != null) {
IIcon fluidIcon = storedFluid.getFluid().getIcon();
@@ -73,12 +71,9 @@ public class ItemCertusQuartzTankRender implements IItemRenderer {
if (ModAndClassUtil.HODGEPODGE && fluidIcon instanceof IPatchedTextureAtlasSprite) {
((IPatchedTextureAtlasSprite) fluidIcon).markNeedsAnimationUpdate();
}
Tessellator tessellator = Tessellator.instance;
RenderBlocks renderer = new RenderBlocks();
Block waterBlock = FluidRegistry.WATER.getBlock();
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
GL11.glScalef(1, 1, -1);
renderer.setRenderBounds(
0.08F,
0.001F,
@@ -86,12 +81,9 @@ public class ItemCertusQuartzTankRender implements IItemRenderer {
0.92F,
(float) storedFluid.amount / (float) tankCapacity * 0.999F,
0.92F);
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Block waterBlock = FluidRegistry.WATER.getBlock();
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(
(storedFluid.getFluid().getColor() >> 16 & 0xFF) / 255.0F,
@@ -25,7 +25,8 @@ public class ModelCertusTank extends ModelBase {
this.textureHeight = 64;
this.Shape1 = new ModelRenderer(this, 0, 0);
this.Shape1.addBox(-7F, -8F, -7F, 14, 16, 14);
this.Shape1.addBox(0F, 0F, 0F, 14, 16, 14);
this.Shape1.setRotationPoint(-7F, -8F, -7F);
this.Shape1.setTextureSize(this.textureWidth, this.textureHeight);
this.Shape1.mirror = true;
setRotation(this.Shape1, 0F, 0F, 0F);
@@ -2,10 +2,10 @@ package com.glodblock.github.common.block;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@@ -16,12 +16,11 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidContainerItem;
import com.glodblock.github.common.item.ItemCertusQuartzTank;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import com.glodblock.github.loader.ChannelLoader;
import com.glodblock.github.loader.IRegister;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.NameConst;
@@ -107,104 +106,71 @@ public class BlockCertusQuartzTank extends BaseBlockContainer implements IRegist
}
@Override
public boolean onBlockActivated(World worldObj, int x, int y, int z, EntityPlayer player, int side, float offsetX,
float offsetY, float offsetZ) {
ItemStack itemInHand = player.inventory.getCurrentItem();
public boolean onBlockActivated(World worldObj, int x, int y, int z, EntityPlayer entityplayer, int blockID,
float offsetX, float offsetY, float offsetZ) {
ItemStack current = entityplayer.inventory.getCurrentItem();
if (itemInHand == null || itemInHand.getItem() == null) {
return false;
}
// In case if we're holding a IFluidContainerItem which is also a block we'll just allow to place a block
// instead of trying to fill or drain it. In other cases we don't need to handle blocks either way
if (itemInHand.getItem() instanceof ItemBlock) {
return false;
}
if (player.isSneaking()) {
if (itemInHand.getItem() instanceof IAEWrench wrench && wrench.canWrench(itemInHand, player, x, y, z)) {
if (entityplayer.isSneaking() && current != null) {
if (current.getItem() instanceof IAEWrench
&& ((IAEWrench) current.getItem()).canWrench(current, entityplayer, x, y, z)) {
dropBlockAsItem(worldObj, x, y, z, getDropWithNBT(worldObj, x, y, z));
worldObj.setBlockToAir(x, y, z);
return true;
}
}
if (current != null) {
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
TileCertusQuartzTank tank = (TileCertusQuartzTank) worldObj.getTileEntity(x, y, z);
TileCertusQuartzTank tank = (TileCertusQuartzTank) worldObj.getTileEntity(x, y, z);
boolean isCreativeMode = player.capabilities.isCreativeMode;
if (FluidContainerRegistry.isFilledContainer(itemInHand)) {
// Fill the tank from the container in hand
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(itemInHand);
if (fluid == null) {
return false;
}
int amountFilled = tank.fill(ForgeDirection.UNKNOWN, fluid, true);
if (amountFilled > 0 && !isCreativeMode) {
ItemStack empty = FluidContainerRegistry.drainFluidContainer(itemInHand);
replaceItemInInventory(worldObj, player, itemInHand, empty);
}
return true;
} else if (FluidContainerRegistry.isEmptyContainer(itemInHand)) {
// Fill the container in hand from the tank
FluidStack available = tank.getTankInfo(true)[0].fluid;
ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, itemInHand);
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(filled);
if (fluid == null) {
return false;
}
tank.drain(ForgeDirection.UNKNOWN, fluid.amount, true);
if (!isCreativeMode) {
replaceItemInInventory(worldObj, player, itemInHand, filled);
}
return true;
} else if (itemInHand.getItem() instanceof IFluidContainerItem) {
ItemStack singleContainerItem = itemInHand.copy();
singleContainerItem.stackSize = 1;
IFluidContainerItem fluidContainer = (IFluidContainerItem) singleContainerItem.getItem();
assert fluidContainer != null;
FluidStack fluid = fluidContainer.getFluid(itemInHand);
if (fluid != null && fluid.amount > 0) {
// Fill the tank from the container in hand
int filled = tank.fill(ForgeDirection.UNKNOWN, fluid, true);
if (filled > 0 && !isCreativeMode) {
fluidContainer.drain(singleContainerItem, filled, true);
replaceItemInInventory(worldObj, player, itemInHand, singleContainerItem);
if (liquid != null) {
int amountFilled = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
if (amountFilled != 0 && !entityplayer.capabilities.isCreativeMode && current.getItem() != null) {
ItemStack empty;
if (FluidContainerRegistry.isContainer(current)) {
empty = FluidContainerRegistry.drainFluidContainer(current);
} else {
// Try this as a fallback.
entityplayer.inventory.addItemStackToInventory(current.getItem().getContainerItem(current));
empty = current.getItem().getContainerItem(current);
}
if (current.stackSize > 1) {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize -= 1;
entityplayer.inventory.addItemStackToInventory(empty);
} else {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = empty;
}
}
return true;
} else {
// Fill the container in hand from the tank
int containerCapacity = fluidContainer.getCapacity(itemInHand);
FluidStack drained = tank.drain(ForgeDirection.UNKNOWN, containerCapacity, true);
if (drained != null && drained.amount > 0 && !isCreativeMode) {
fluidContainer.fill(singleContainerItem, drained, true);
replaceItemInInventory(worldObj, player, itemInHand, singleContainerItem);
FluidStack available = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;
if (available != null) {
ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current);
liquid = FluidContainerRegistry.getFluidForFilledItem(filled);
if (liquid != null) {
tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
if (!entityplayer.capabilities.isCreativeMode) {
if (current.stackSize == 1) {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = filled;
} else {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize--;
if (!entityplayer.inventory.addItemStackToInventory(filled))
entityplayer.entityDropItem(filled, 0);
}
}
return true;
}
}
}
return true;
}
return false;
}
private void replaceItemInInventory(World world, EntityPlayer player, ItemStack item, ItemStack replacement) {
if (item.stackSize > 1) {
item.stackSize--;
// This method meant to be called both from client and server side, and trying to drop an item
// from the client side would create a doubled ghost item, so we don't allow to do that
if (!player.inventory.addItemStackToInventory(replacement) && !world.isRemote) {
player.entityDropItem(replacement, 0);
}
} else {
player.inventory.setInventorySlotContents(player.inventory.currentItem, replacement);
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlock) {
if (!world.isRemote) {
ChannelLoader.sendPacketToAllPlayers(world.getTileEntity(x, y, z).getDescriptionPacket(), world);
}
}
@@ -243,22 +209,4 @@ public class BlockCertusQuartzTank extends BaseBlockContainer implements IRegist
setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
@Override
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride(World worldIn, int x, int y, int z, int side) {
TileEntity tileEntity = worldIn.getTileEntity(x, y, z);
if (tileEntity instanceof TileCertusQuartzTank tileCertusQuartzTank) {
FluidTankInfo info = tileCertusQuartzTank.getTankInfo(false)[0];
if (info.fluid != null) {
int nonEmptyBump = info.fluid.amount > 0 ? 1 : 0;
return (int) (14.0 * info.fluid.amount / info.capacity) + nonEmptyBump;
}
}
return 0;
}
}
@@ -145,7 +145,7 @@ public abstract class FCBaseItemCell extends AEBaseItem implements IStorageFluid
}
if (handler.isPreformatted()) {
final String list = (handler.getIncludeExcludeMode() == IncludeExclude.WHITELIST ? GuiText.Included
final String list = (handler.getWhitelist() == IncludeExclude.WHITELIST ? GuiText.Included
: GuiText.Excluded).getLocal();
lines.add(GuiText.Partitioned.getLocal() + " - " + list + ' ' + GuiText.Precise.getLocal());
@@ -138,14 +138,19 @@ public class ItemCertusQuartzTank extends BaseItemBlockContainer implements IFlu
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side,
float hitX, float hitY, float hitZ, int metadata) {
if (!super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata)) {
if (!world.setBlock(x, y, z, this.field_150939_a, metadata, 3)) {
return false;
}
if (stack != null) {
((TileCertusQuartzTank) world.getTileEntity(x, y, z)).readFromItemNBT(stack.getTagCompound());
if (world.getBlock(x, y, z) == this.field_150939_a) {
this.field_150939_a.onBlockPlacedBy(world, x, y, z, player, stack);
this.field_150939_a.onPostBlockPlaced(world, x, y, z, metadata);
}
if (stack != null && stack.hasTagCompound()) {
((TileCertusQuartzTank) world.getTileEntity(x, y, z))
.readFromNBTWithoutCoords(stack.getTagCompound().getCompoundTag("tileEntity"));
}
return true;
}
}
@@ -1,7 +1,6 @@
package com.glodblock.github.common.item;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
@@ -23,6 +22,7 @@ import com.glodblock.github.util.NameConst;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.item.AEFluidStack;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
@@ -40,11 +40,34 @@ public class ItemFluidPacket extends FCBaseItem {
if (stack == null || !stack.hasTagCompound()) {
return null;
}
FluidStack fluid = FluidStack
.loadFluidStackFromNBT(Objects.requireNonNull(stack.getTagCompound()).getCompoundTag("FluidStack"));
NBTTagCompound tag = stack.getTagCompound().getCompoundTag("FluidStack");
FluidStack fluid = FluidStack.loadFluidStackFromNBT(tag);
if (fluid != null && tag.getLong("Amount") > Integer.MAX_VALUE) fluid.amount = Integer.MAX_VALUE;
return (fluid != null && fluid.amount > 0) ? fluid : null;
}
@Nullable
public static FluidStack getFluidStack(@Nullable IAEItemStack stack) {
return stack != null ? getFluidStack(stack.getItemStack()) : null;
}
@Nullable
public static IAEFluidStack getFluidAEStack(ItemStack stack) {
if (stack != null && stack.hasTagCompound()) {
NBTTagCompound tag = stack.getTagCompound().getCompoundTag("FluidStack");
IAEFluidStack ifs = AEFluidStack.create(FluidStack.loadFluidStackFromNBT(tag));
if (ifs != null && tag.hasKey("Amount")) ifs.setStackSize(tag.getLong("Amount"));
return ifs;
}
return null;
}
@Nullable
public static IAEFluidStack getFluidAEStack(@Nullable IAEItemStack stack) {
return stack != null ? getFluidAEStack(stack.getItemStack()) : null;
}
@Override
public String getUnlocalizedName(ItemStack stack) {
FluidStack fluid = getFluidStack(stack);
@@ -83,25 +106,20 @@ public class ItemFluidPacket extends FCBaseItem {
}
}
@Nullable
public static FluidStack getFluidStack(@Nullable IAEItemStack stack) {
return stack != null ? getFluidStack(stack.getItemStack()) : null;
}
public static void setFluidAmount(ItemStack stack, int amount) {
public static void setFluidAmount(ItemStack stack, long amount) {
if (stack == null || !stack.hasTagCompound()
|| !stack.getTagCompound().hasKey("FluidStack", Constants.NBT.TAG_COMPOUND)) {
return;
}
stack.getTagCompound().getCompoundTag("FluidStack").setInteger("Amount", amount);
stack.getTagCompound().getCompoundTag("FluidStack").setLong("Amount", amount);
}
public static int getFluidAmount(ItemStack stack) {
public static long getFluidAmount(ItemStack stack) {
if (stack == null || !stack.hasTagCompound()) {
return 0;
}
// Default to 0 if no tag exists
return stack.getTagCompound().getCompoundTag("FluidStack").getInteger("Amount");
return stack.getTagCompound().getCompoundTag("FluidStack").getLong("Amount");
}
@Nullable
@@ -120,10 +138,22 @@ public class ItemFluidPacket extends FCBaseItem {
@Nullable
public static ItemStack newStack(@Nullable IAEFluidStack fluid) {
if (fluid == null || fluid.getStackSize() == 0) {
return null;
if (fluid != null && fluid.getStackSize() > 0) {
ItemStack stack = new ItemStack(ItemAndBlockHolder.PACKET);
NBTTagCompound tag = new NBTTagCompound();
NBTTagCompound fluidTag = new NBTTagCompound();
fluid.getFluidStack().writeToNBT(fluidTag);
fluidTag.setLong("Amount", fluid.getStackSize());
tag.setTag("FluidStack", fluidTag);
stack.setTagCompound(tag);
return stack;
}
return newStack(fluid.getFluidStack());
return null;
}
@Nullable
public static IAEItemStack newAeStack(@Nullable FluidStack fluid) {
return AEItemStack.create(newStack(fluid));
}
@Nullable
@@ -143,11 +173,6 @@ public class ItemFluidPacket extends FCBaseItem {
return stack;
}
@Nullable
public static IAEItemStack newAeStack(@Nullable FluidStack fluid) {
return AEItemStack.create(newStack(fluid));
}
@Override
public int getSpriteNumber() {
return 0;
@@ -1,5 +1,8 @@
package com.glodblock.github.common.parts;
import static appeng.util.Platform.convertStack;
import static appeng.util.Platform.stackConvert;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@@ -11,11 +14,11 @@ import com.glodblock.github.client.textures.FCPartsTexture;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.parts.base.FCSharedFluidBus;
import com.glodblock.github.inventory.FluidConvertingInventoryAdaptor;
import com.google.common.collect.ImmutableSet;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.InsertionMode;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SchedulingMode;
@@ -43,7 +46,6 @@ import appeng.me.GridAccessException;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.item.AEFluidStack;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -269,7 +271,7 @@ public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingReq
}
protected InventoryAdaptor getHandler(TileEntity target) {
return target != null ? FluidConvertingInventoryAdaptor.wrap(target, this.getSide().getOpposite()) : null;
return target != null ? InventoryAdaptor.getAdaptor(target, getSide().getOpposite()) : null;
}
@Override
@@ -282,17 +284,15 @@ public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingReq
final double power = Math.ceil(items.getStackSize() / 1000D);
if (energy.extractAEPower(power, mode, PowerMultiplier.CONFIG) > power - 0.01) {
ItemStack inputStack = items.getItemStack();
ItemStack remaining;
IAEItemStack remaining;
if (mode == Actionable.SIMULATE) {
remaining = d.simulateAdd(inputStack);
remaining = stackConvert(d.simulateAddStack(convertStack(items), InsertionMode.DEFAULT));
} else {
remaining = d.addItems(inputStack);
remaining = stackConvert(d.addStack(convertStack(items), InsertionMode.DEFAULT));
}
return AEItemStack.create(remaining);
return remaining;
}
}
} catch (final GridAccessException e) {
@@ -35,7 +35,6 @@ import com.google.common.collect.ImmutableSet;
import appeng.api.config.Actionable;
import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.tiles.ITileStorageMonitorable;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingLink;
@@ -49,10 +48,12 @@ import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.parts.IPart;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.IConfigManager;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
@@ -173,10 +174,13 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
for (PartFluidP2PInterface p2p : getOutputs()) p2p.duality.addDrops(drops);
} catch (GridAccessException ignored) {}
} else {
if (this.getWaitingToSend() != null) {
for (final ItemStack is : this.getWaitingToSend()) {
if (is != null) {
drops.add(is);
List<IAEStack<?>> waitingList = this.getWaitingToSend();
if (waitingList != null) {
for (final IAEStack<?> as : waitingList) {
if (as instanceof IAEItemStack ais) {
drops.add(ais.getItemStack());
} else if (as instanceof IAEFluidStack afs) {
drops.add(ItemFluidPacket.newStack(afs));
}
}
}
@@ -230,7 +234,6 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
Platform.spawnDrops(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, drops);
}
duality.setStorage(p2p.duality.getStorage());
duality.setSlotInv(p2p.duality.getSlotInv());
duality.sharedInventory = true;
} else {
if (duality.sharedInventory) {
@@ -304,13 +307,9 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
}
@Override
public PartP2PTunnel<?> applyMemoryCard(EntityPlayer player, IMemoryCard memoryCard, ItemStack is) {
PartP2PTunnel<?> newTunnel = super.applyMemoryCard(player, memoryCard, is);
NBTTagCompound data = memoryCard.getData(is);
if (newTunnel instanceof PartFluidP2PInterface p2PInterface) {
p2PInterface.duality.getConfigManager().readFromNBT(data);
}
return newTunnel;
public void pasteMemoryCardData(PartP2PTunnel<?> newTunnel, NBTTagCompound data) throws GridAccessException {
this.duality.getConfigManager().readFromNBT(data);
super.pasteMemoryCardData(newTunnel, data);
}
@Override
@@ -346,7 +345,41 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
@Override
public boolean onPartActivate(final EntityPlayer p, final Vec3 pos) {
AppEngInternalInventory patterns = this.duality.getPatterns();
if (super.onPartActivate(p, pos)) {
ArrayList<ItemStack> drops = new ArrayList<>();
for (int i = 0; i < patterns.getSizeInventory(); i++) {
if (patterns.getStackInSlot(i) == null) continue;
drops.add(patterns.getStackInSlot(i));
}
final IPart tile = this.getHost().getPart(this.getSide());
if (tile instanceof PartFluidP2PInterface dualTile) {
DualityInterface newDuality = dualTile.duality;
// Copy interface storage, upgrades, and settings over
UpgradeInventory upgrades = (UpgradeInventory) duality.getInventoryByName("upgrades");
dualTile.duality.getStorage();
UpgradeInventory newUpgrade = (UpgradeInventory) newDuality.getInventoryByName("upgrades");
for (int i = 0; i < upgrades.getSizeInventory(); ++i) {
newUpgrade.setInventorySlotContents(i, upgrades.getStackInSlot(i));
}
if (!duality.sharedInventory) {
IInventory storage = duality.getStorage();
IInventory newStorage = newDuality.getStorage();
for (int i = 0; i < storage.getSizeInventory(); ++i) {
newStorage.setInventorySlotContents(i, storage.getStackInSlot(i));
}
}
IConfigManager config = duality.getConfigManager();
config.getSettings().forEach(
setting -> newDuality.getConfigManager().putSetting(setting, config.getSetting(setting)));
}
TileEntity te = getTileEntity();
Platform.spawnDrops(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, drops);
return true;
}
@@ -366,64 +399,6 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
return true;
}
private void dropPatterns(final PartFluidP2PInterface p2p) {
final AppEngInternalInventory patterns = p2p.duality.getPatterns();
final List<ItemStack> drops = new ArrayList<>();
for (int i = 0; i < patterns.getSizeInventory(); i++) {
if (patterns.getStackInSlot(i) == null) continue;
drops.add(patterns.getStackInSlot(i));
}
if (!drops.isEmpty()) {
final TileEntity te = p2p.getTileEntity();
Platform.spawnDrops(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, drops);
}
}
@Override
protected void copyContents(final PartP2PTunnel<?> from) {
if (from instanceof PartFluidP2PInterface fromInterface) {
DualityInterface newDuality = this.duality;
// Copy interface storage, upgrades, and settings over
UpgradeInventory upgrades = (UpgradeInventory) fromInterface.duality.getInventoryByName("upgrades");
UpgradeInventory newUpgrade = (UpgradeInventory) newDuality.getInventoryByName("upgrades");
for (int i = 0; i < upgrades.getSizeInventory(); ++i) {
newUpgrade.setInventorySlotContents(i, upgrades.getStackInSlot(i));
}
if (!fromInterface.duality.sharedInventory) {
IInventory storage = fromInterface.duality.getStorage();
IInventory newStorage = newDuality.getStorage();
for (int i = 0; i < storage.getSizeInventory(); ++i) {
newStorage.setInventorySlotContents(i, storage.getStackInSlot(i));
}
}
AppEngInternalInventory patterns = fromInterface.duality.getPatterns();
boolean drop = true;
if (!from.isOutput() && !this.isOutput()) { // input to input
for (int i = 0; i < patterns.getSizeInventory(); i++) {
newDuality.getPatterns().setInventorySlotContents(i, patterns.getStackInSlot(i));
}
drop = false;
}
if (drop) {
this.dropPatterns(fromInterface);
}
}
}
@Override
protected void copySettings(final PartP2PTunnel<?> from) {
if (from instanceof PartFluidP2PInterface fromInterface) {
DualityInterface newDuality = this.duality;
IConfigManager config = fromInterface.duality.getConfigManager();
config.getSettings()
.forEach(setting -> newDuality.getConfigManager().putSetting(setting, config.getSetting(setting)));
}
}
@Override
public IIcon getBreakingTexture() {
return this.getItemStack().getIconIndex();
@@ -84,16 +84,15 @@ public class FluidCellInventory implements IFluidCellInventory {
}
final IInventory upgrades = this.getUpgradesInventory();
Upgrades u;
for (int x = 0; x < upgrades.getSizeInventory(); x++) {
final ItemStack is = upgrades.getStackInSlot(x);
if (is != null && is.getItem() instanceof IUpgradeModule) {
final Upgrades u = ((IUpgradeModule) is.getItem()).getType(is);
if (u != null) {
switch (u) {
case VOID_OVERFLOW -> cardVoidOverflow = true;
case DISTRIBUTION -> cardDistribution = true;
default -> {}
}
if (is == null) continue;
if (is.getItem() instanceof IUpgradeModule upgradeItem && (u = upgradeItem.getType(is)) != null) {
switch (u) {
case VOID_OVERFLOW -> cardVoidOverflow = true;
case DISTRIBUTION -> cardDistribution = true;
default -> {}
}
}
}
@@ -159,7 +158,6 @@ public class FluidCellInventory implements IFluidCellInventory {
final long bytesFree = this.getFreeBytes();
return (bytesFree > this.getBytesPerType()
|| (bytesFree == this.getBytesPerType() && this.getUnusedFluidCount() > 0))
&& (restrictionLong <= 0 || restrictionLong > getStoredFluidCount())
&& this.getRemainingFluidTypes() > 0;
}
@@ -362,12 +360,7 @@ public class FluidCellInventory implements IFluidCellInventory {
if (cardDistribution) {
remainingFluidSlots = this.getRemainingFluidCountDist(l);
} else {
if (restrictionLong > 0) {
remainingFluidSlots = this.getRemainingFluidCount();
} else {
remainingFluidSlots = this.getRemainingFluidCount()
- (long) this.getBytesPerType() * singleByteAmount;
}
remainingFluidSlots = this.getRemainingFluidCount();
}
if (remainingFluidSlots <= 0) {
@@ -7,7 +7,6 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.Util;
import appeng.api.AEApi;
@@ -57,7 +56,6 @@ public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack>
final IInventory upgrades = ci.getUpgradesInventory();
boolean hasSticky = false;
boolean hasInverter = false;
for (int x = 0; x < upgrades.getSizeInventory(); x++) {
final ItemStack is = upgrades.getStackInSlot(x);
@@ -65,14 +63,11 @@ public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack>
final Upgrades u = ((IUpgradeModule) is.getItem()).getType(is);
if (u == Upgrades.STICKY) {
hasSticky = true;
} else if (u == Upgrades.INVERTER) {
hasInverter = true;
break;
}
}
}
this.setWhitelist(hasInverter ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
if (hasSticky) {
setSticky(true);
}
@@ -82,8 +77,8 @@ public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack>
@Override
public IFluidCellInventory getCellInv() {
Object o = this.getInternal();
if (o instanceof MEPassThrough) {
o = Ae2Reflect.getInternal((MEPassThrough<?>) o);
if (o instanceof MEPassThrough<?>pt) {
o = pt.getInternal();
}
return (IFluidCellInventory) (o instanceof IFluidCellInventory ? o : null);
}
@@ -91,16 +86,22 @@ public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack>
@Override
@SuppressWarnings("unchecked")
public Iterable<IAEFluidStack> getPartitionInv() {
return (Iterable<IAEFluidStack>) Ae2Reflect.getPartitionList(this).getItems();
return getPartitionList().getItems();
}
@Override
public boolean isPreformatted() {
return !Ae2Reflect.getPartitionList(this).isEmpty();
return !getPartitionList().isEmpty();
}
@Override
@Deprecated
public IncludeExclude getIncludeExcludeMode() {
return getWhitelist();
}
@Override
public IncludeExclude getWhitelist() {
return IncludeExclude.WHITELIST;
}
@@ -117,11 +118,7 @@ public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack>
@Override
public boolean canGetInv() {
IFluidCellInventory cellInv = this.getCellInv();
if (cellInv instanceof CreativeFluidCellInventory) {
return false;
} else {
return true;
}
return !(cellInv instanceof CreativeFluidCellInventory);
}
@Override
@@ -168,7 +165,6 @@ public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack>
IFluidCellInventory cellInventory = this.getCellInv();
if (cellInventory instanceof FluidCellInventory ci) {
return ci.getRestriction();
}
return null;
}
@@ -11,5 +11,9 @@ public interface IFluidCellInventoryHandler {
boolean isPreformatted();
/** use {@link IFluidCellInventoryHandler#getWhitelist} instead */
@Deprecated
IncludeExclude getIncludeExcludeMode();
IncludeExclude getWhitelist();
}
@@ -1,10 +1,12 @@
package com.glodblock.github.common.tile;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
@@ -12,11 +14,26 @@ import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import com.glodblock.github.loader.ChannelLoader;
import com.glodblock.github.util.BlockPos;
public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
public FluidTank tank = new FluidTank(32000);
private FluidStack lastBeforeUpdate = null;
public FluidTank tank = new FluidTank(32000) {
@Override
public FluidTank readFromNBT(NBTTagCompound nbt) {
if (!nbt.hasKey("Empty")) {
FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt);
setFluid(fluid);
} else {
setFluid(null);
}
return this;
}
};
private boolean hasUpdate;
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
@@ -33,51 +50,80 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
return tankFluid == null || tankFluid.amount == 0 ? 0 : tankFluid.getFluid().getLuminosity(tankFluid);
}
public void compareAndUpdate() {
if (!this.worldObj.isRemote) {
FluidStack current = this.tank.getFluid();
if (current != null) {
if (this.lastBeforeUpdate != null) {
if (Math.abs(current.amount - this.lastBeforeUpdate.amount) >= 500) {
ChannelLoader.sendPacketToAllPlayers(getDescriptionPacket(), this.worldObj);
this.lastBeforeUpdate = current.copy();
} else if (this.lastBeforeUpdate.amount < this.tank.getCapacity()
&& current.amount == this.tank.getCapacity()
|| this.lastBeforeUpdate.amount == this.tank.getCapacity()
&& current.amount < this.tank.getCapacity()) {
ChannelLoader.sendPacketToAllPlayers(getDescriptionPacket(), this.worldObj);
this.lastBeforeUpdate = current.copy();
}
} else {
ChannelLoader.sendPacketToAllPlayers(getDescriptionPacket(), this.worldObj);
this.lastBeforeUpdate = current.copy();
}
} else if (this.lastBeforeUpdate != null) {
ChannelLoader.sendPacketToAllPlayers(getDescriptionPacket(), this.worldObj);
this.lastBeforeUpdate = null;
}
}
}
public FluidStack drain(FluidStack fluid, boolean doDrain, boolean findMainTank) {
if (fluid == null || this.getFluid() == null || this.getFluid() != fluid.getFluid()) {
return null;
}
if (findMainTank) {
// Main tank is the highest tank in the column with desired fluid
int yOff = 0;
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
TileCertusQuartzTank mainTank = this;
TileCertusQuartzTank tankAbove;
while ((tankAbove = mainTank.getTankAbove()) != null) {
// We can't drain tank with different or null fluid
if (fluid.getFluid() != tankAbove.getFluid()) {
break;
while (true) {
if (offTE instanceof TileCertusQuartzTank) {
Fluid offFluid = ((TileCertusQuartzTank) offTE).getFluid();
if (offFluid != null && offFluid == fluid.getFluid()) {
mainTank = (TileCertusQuartzTank) this.worldObj
.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
yOff++;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
continue;
}
}
mainTank = tankAbove;
break;
}
return mainTank.drain(fluid, doDrain, false);
return mainTank != null ? mainTank.drain(fluid, doDrain, false) : null;
}
FluidStack drainedFluid = this.tank.drain(fluid.amount, doDrain);
int drained = drainedFluid != null ? drainedFluid.amount : 0;
FluidStack drained = this.tank.drain(fluid.amount, doDrain);
compareAndUpdate();
if (drained > 0) {
update();
}
if (drained == null || drained.amount < fluid.amount) {
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord);
if (offTE instanceof TileCertusQuartzTank tileCertusQuartzTank) {
FluidStack externallyDrained = tileCertusQuartzTank.drain(
new FluidStack(fluid.getFluid(), fluid.amount - (drained != null ? drained.amount : 0)),
doDrain,
false);
if (drained < fluid.amount) {
TileCertusQuartzTank tankBelow = this.getTankBelow();
if (tankBelow != null) {
FluidStack fluidToDrain = new FluidStack(fluid.getFluid(), fluid.amount - drained);
FluidStack externallyDrained = tankBelow.drain(fluidToDrain, doDrain, false);
if (externallyDrained != null) {
return new FluidStack(fluid.getFluid(), drained + externallyDrained.amount);
}
if (externallyDrained != null) return new FluidStack(
fluid.getFluid(),
(drained != null ? drained.amount : 0) + externallyDrained.amount);
else return drained;
}
}
return drainedFluid;
return drained;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
if (this.tank.getFluid() == null || resource == null || resource.getFluid() != this.tank.getFluid().getFluid())
return null;
return drain(resource, doDrain, true);
}
@@ -89,42 +135,35 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
}
public int fill(FluidStack fluid, boolean doFill, boolean findMainTank) {
if (fluid == null || this.getFluid() != null && this.getFluid() != fluid.getFluid()) {
return 0;
}
if (findMainTank) {
// Main tank is the lowest tank in the column with desired fluid
int yOff = 0;
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
TileCertusQuartzTank mainTank = this;
TileCertusQuartzTank tankBelow;
while ((tankBelow = mainTank.getTankBelow()) != null) {
FluidStack fluidBelow = tankBelow.tank.getFluid();
// We can't fill already full tank
if (fluidBelow != null && fluidBelow.amount == tankBelow.tank.getCapacity()) {
break;
while (true) {
if (offTE instanceof TileCertusQuartzTank) {
Fluid offFluid = ((TileCertusQuartzTank) offTE).getFluid();
if (offFluid == null || offFluid == fluid.getFluid()) {
mainTank = (TileCertusQuartzTank) this.worldObj
.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
yOff++;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
continue;
}
}
// We can't fill tank with different fluid
if (tankBelow.getFluid() != null && fluid.getFluid() != tankBelow.getFluid()) {
break;
}
mainTank = tankBelow;
break;
}
return mainTank.fill(fluid, doFill, false);
return mainTank != null ? mainTank.fill(fluid, doFill, false) : 0;
}
int filled = this.tank.fill(fluid, doFill);
if (filled > 0) {
update();
}
compareAndUpdate();
if (filled < fluid.amount) {
TileCertusQuartzTank tankAbove = this.getTankAbove();
if (tankAbove != null) {
FluidStack fluidToFill = new FluidStack(fluid.getFluid(), fluid.amount - filled);
return filled + tankAbove.fill(fluidToFill, doFill, false);
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord);
if (offTE instanceof TileCertusQuartzTank tileCertusQuartzTank) {
return filled + tileCertusQuartzTank
.fill(new FluidStack(fluid.getFluid(), fluid.amount - filled), doFill, false);
}
}
@@ -136,9 +175,18 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
*/
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
if (resource == null || this.tank.getFluid() != null && resource.getFluid() != this.tank.getFluid().getFluid())
return 0;
return fill(resource, doFill, true);
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}
public Fluid getFluid() {
FluidStack tankFluid = this.tank.getFluid();
return tankFluid != null && tankFluid.amount > 0 ? tankFluid.getFluid() : null;
@@ -152,57 +200,84 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
return (float) this.tank.getFluidAmount() / this.tank.getCapacity();
}
private TileCertusQuartzTank getTankAbove() {
TileEntity tile = new BlockPos(this).getOffSet(0, 1, 0).getTileEntity();
if (tile instanceof TileCertusQuartzTank tankTile) {
return tankTile;
private void onComparatorUpdate(World world, int x, int y, int z, Block block) {
world.func_147453_f(x, y, z, block);
}
@Override
public void updateEntity() {
super.updateEntity();
if (this.tank.getFluid() != null) {
TileCertusQuartzTank below = getTankBelow(this);
if (below != null) {
FluidStack filled = this.tank.getFluid().copy();
filled.amount = below.fill(this.tank.getFluid(), true, true);
if (filled.amount >= 0) {
this.drain(filled, true, true);
this.hasUpdate = true;
below.hasUpdate = true;
}
}
}
if (this.hasUpdate) {
onComparatorUpdate(this.worldObj, this.xCoord, this.yCoord, this.zCoord, this.getBlockType());
this.hasUpdate = false;
}
}
private TileCertusQuartzTank getTankBelow(TileEntity tile) {
TileEntity tank = new BlockPos(tile).getOffSet(0, -1, 0).getTileEntity();
if (tank instanceof TileCertusQuartzTank) {
return (TileCertusQuartzTank) tank;
}
return null;
}
private TileCertusQuartzTank getTankBelow() {
TileEntity tile = new BlockPos(this).getOffSet(0, -1, 0).getTileEntity();
if (tile instanceof TileCertusQuartzTank tankTile) {
return tankTile;
}
return null;
}
public FluidTankInfo[] getTankInfo(boolean goToMainTank) {
if (!goToMainTank) return new FluidTankInfo[] { this.tank.getInfo() };
public FluidTankInfo[] getTankInfo(boolean countAllTanksInColumn) {
if (!countAllTanksInColumn) {
return new FluidTankInfo[] { this.tank.getInfo() };
}
int amount = 0, capacity = 0;
Fluid fluid = null;
final FluidStack tankFluidStack = this.tank.getFluid();
final Fluid mainFluid = tankFluidStack != null ? tankFluidStack.getFluid() : null;
int amount = tankFluidStack == null ? 0 : tankFluidStack.amount;
int capacity = this.tank.getCapacity();
TileCertusQuartzTank tankAbove = this;
while ((tankAbove = tankAbove.getTankAbove()) != null) {
if (tankAbove.getFluid() == null || mainFluid != tankAbove.getFluid()) {
break;
int yOff = 0;
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
TileCertusQuartzTank mainTank;
while (true) {
if (offTE instanceof TileCertusQuartzTank) {
if (((TileCertusQuartzTank) offTE).getFluid() == null
|| ((TileCertusQuartzTank) offTE).getFluid() == getFluid()) {
yOff++;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
continue;
}
}
FluidTankInfo info = tankAbove.tank.getInfo();
amount += info.fluid == null ? 0 : info.fluid.amount;
capacity += info.capacity;
break;
}
TileCertusQuartzTank tankBelow = this;
while ((tankBelow = tankBelow.getTankBelow()) != null) {
if (mainFluid == null || mainFluid != tankBelow.getFluid()) {
break;
yOff -= 1;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
while (true) {
if (offTE instanceof TileCertusQuartzTank) {
mainTank = (TileCertusQuartzTank) offTE;
if (mainTank.getFluid() == null || getFluid() == null || mainTank.getFluid() == getFluid()) {
FluidTankInfo info = mainTank.getTankInfo(false)[0];
if (info != null) {
capacity += info.capacity;
if (info.fluid != null) {
amount += info.fluid.amount;
if (info.fluid.getFluid() != null) fluid = info.fluid.getFluid();
}
}
offTE = new BlockPos(offTE).getOffSet(0, 1, 0).getTileEntity();
continue;
}
}
FluidTankInfo info = tankBelow.tank.getInfo();
amount += info.fluid == null ? 0 : info.fluid.amount;
capacity += info.capacity;
break;
}
return new FluidTankInfo[] {
new FluidTankInfo(mainFluid != null ? new FluidStack(mainFluid, amount) : null, capacity) };
new FluidTankInfo(fluid != null ? new FluidStack(fluid, amount) : null, capacity) };
}
@Override
@@ -210,49 +285,6 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
return getTankInfo(true);
}
public FluidTankInfo[] getInternalFluid() {
return this.getTankInfo(true);
}
private void flowFluidDown(boolean checkTankAbove) {
if (this.getFluid() != null) {
TileCertusQuartzTank below = getTankBelow();
if (below != null) {
FluidStack fluid = this.tank.getFluid().copy();
int amount = below.tank.fill(fluid, true);
if (amount > 0) {
this.tank.drain(amount, true);
this.update();
below.update();
below.flowFluidDown(false);
}
}
}
if (checkTankAbove) {
TileCertusQuartzTank above = getTankAbove();
if (above != null && above.getFluid() != null) {
if (this.getFluid() == null || this.getFluid() == above.getFluid()) {
above.flowFluidDown(true);
}
}
}
}
public void update() {
if (!this.worldObj.isRemote) {
markDirty();
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
this.worldObj.markBlockRangeForRenderUpdate(
@@ -275,15 +307,6 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
this.tank.readFromNBT(tag);
}
// Specifically used when player is placing a tank in world,
// so we can apply the item's NBT and flow down its fluid in lower tanks
public void readFromItemNBT(NBTTagCompound tag) {
if (tag != null) {
this.readFromNBTWithoutCoords(tag.getCompoundTag("tileEntity"));
}
this.flowFluidDown(true);
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
@@ -293,4 +316,8 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
public void writeToNBTWithoutCoords(NBTTagCompound tag) {
this.tank.writeToNBT(tag);
}
public FluidTankInfo[] getInternalFluid() {
return this.getTankInfo(true);
}
}
@@ -1,5 +1,6 @@
package com.glodblock.github.common.tile;
import static appeng.util.Platform.writeStackNBT;
import static com.glodblock.github.loader.RecipeLoader.BUCKET;
import javax.annotation.Nonnull;
@@ -17,7 +18,8 @@ import net.minecraftforge.fluids.FluidStack;
import org.apache.commons.lang3.tuple.MutablePair;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.util.NameConst;
import com.glodblock.github.util.Util;
import appeng.api.AEApi;
@@ -53,6 +55,8 @@ import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkInvTile;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.common.registry.GameRegistry;
public class TileFluidAutoFiller extends AENetworkInvTile
implements ICraftingProvider, IMEMonitorHandlerReceiver<IAEFluidStack>, IGridTickable {
@@ -60,7 +64,7 @@ public class TileFluidAutoFiller extends AENetworkInvTile
private final AppEngInternalInventory inventory = new AppEngInternalInventory(this, 1);
private final BaseActionSource source = new MachineSource(this);
private IItemList<IAEFluidStack> fluids = AEApi.instance().storage().createFluidList();
private final Item encodedPattern = AEApi.instance().definitions().items().encodedPattern().maybeItem().orNull();
private final Item encodedPattern = GameRegistry.findItem(FluidCraft.MODID, NameConst.ITEM_FLUID_ENCODED_PATTERN);
private IAEItemStack returnStack;
private boolean isPowered;
@@ -156,19 +160,21 @@ public class TileFluidAutoFiller extends AENetworkInvTile
MutablePair<Integer, ItemStack> filled = Util.FluidUtil
.fillStack(this.getContainerItem().copy(), new FluidStack(fluid, maxCapacity));
if (filled.right == null) continue;
ItemStack pattern = getPattern(this.getContainerItem(), filled.right);
ItemStack pattern = getPattern(
this.getContainerItem(),
filled.right,
fluidStack.copy().setStackSize(maxCapacity));
ICraftingPatternItem patter = (ICraftingPatternItem) pattern.getItem();
craftingTracker.addCraftingOption(this, patter.getPatternForItem(pattern, getWorldObj()));
}
}
private ItemStack getPattern(ItemStack emptyContainer, ItemStack filledContainer) {
private ItemStack getPattern(ItemStack emptyContainer, ItemStack filledContainer, IAEFluidStack ifs) {
NBTTagList in = new NBTTagList();
NBTTagList out = new NBTTagList();
in.appendTag(emptyContainer.writeToNBT(new NBTTagCompound()));
ItemStack fluidDrop = ItemFluidDrop.newStack(Util.FluidUtil.getFluidFromContainer(filledContainer));
in.appendTag(createItemTag(fluidDrop));
out.appendTag(filledContainer.writeToNBT(new NBTTagCompound()));
in.appendTag(writeStackNBT(AEItemStack.create(emptyContainer), new NBTTagCompound()));
in.appendTag(writeStackNBT(ifs, new NBTTagCompound()));
out.appendTag(writeStackNBT(AEItemStack.create(filledContainer), new NBTTagCompound()));
NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setTag("in", in);
itemTag.setTag("out", out);
@@ -188,8 +194,7 @@ public class TileFluidAutoFiller extends AENetworkInvTile
@Override
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) {
this.returnStack = AEApi.instance().storage()
.createItemStack(patternDetails.getCondensedOutputs()[0].getItemStack());
this.returnStack = (IAEItemStack) patternDetails.getCondensedOutputs()[0];
try {
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
} catch (GridAccessException ignored) {
@@ -224,7 +224,6 @@ public class TileFluidInterface extends TileInterface implements IDualHost {
@Override
public void getDrops(World w, int x, int y, int z, List<ItemStack> drops) {
this.fluidDuality.addDrops(drops);
this.fluidDuality.convertDrops(drops, this.getInterfaceDuality().getWaitingToSend());
super.getDrops(w, x, y, z, drops);
}
}
@@ -59,6 +59,7 @@ import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkTile;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.SettingsFrom;
import appeng.util.item.AEItemStack;
import io.netty.buffer.ByteBuf;
@@ -101,10 +102,7 @@ public class TileLevelMaintainer extends AENetworkTile
@Override
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) {
int idx = this.getRequestIndexByLink(link);
if (idx == -1) {
AELog.warn("Invalid crafting link: " + link);
return items;
}
try {
if (getProxy().isActive()) {
final IEnergyGrid energy = getProxy().getEnergy();
@@ -116,7 +114,9 @@ public class TileLevelMaintainer extends AENetworkTile
.injectItems(ItemFluidDrop.getAeFluidStack(items), mode, source);
if (notInjectedItems != null) {
items.setStackSize(notInjectedItems.getStackSize());
this.updateState(idx, LevelState.Export);
if (idx != -1) {
this.updateState(idx, LevelState.Export);
}
return items;
} else {
@@ -430,7 +430,7 @@ public class TileLevelMaintainer extends AENetworkTile
NBTTagList tagList = new NBTTagList();
for (int i = 0; i < REQ_COUNT; i++) {
if (this.requests[i] != null) {
tagList.appendTag(this.requests[i].writeToNBT());
tagList.appendTag(this.requests[i].writeToNBT(true));
} else {
tagList.appendTag(new NBTTagCompound());
}
@@ -544,6 +544,42 @@ public class TileLevelMaintainer extends AENetworkTile
data.writeBoolean(isActive());
}
@Override
public void uploadSettings(SettingsFrom from, NBTTagCompound compound) {
super.uploadSettings(from, compound);
NBTTagList tagList = compound.getTagList(NBT_REQUESTS, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound tag = tagList.getCompoundTagAt(i);
if (tag == null || !tag.hasKey(NBT_STACK)) {
this.requests[i] = null;
} else {
try {
this.requests[i] = new RequestInfo(tag, this);
this.requests[i].state = LevelState.None;
} catch (Exception ignored) {
this.requests[i] = null;
}
}
}
this.saveChanges();
}
@Override
public NBTTagCompound downloadSettings(SettingsFrom from) {
NBTTagCompound compound = super.downloadSettings(from);
compound = compound == null ? new NBTTagCompound() : compound;
NBTTagList tagList = new NBTTagList();
for (int i = 0; i < REQ_COUNT; i++) {
if (this.requests[i] != null) {
tagList.appendTag(this.requests[i].writeToNBT(false));
} else {
tagList.appendTag(new NBTTagCompound());
}
}
compound.setTag(NBT_REQUESTS, tagList);
return compound;
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkPowerStatusChange p) {
updatePowerState();
@@ -643,7 +679,7 @@ public class TileLevelMaintainer extends AENetworkTile
}
}
public NBTTagCompound writeToNBT() {
public NBTTagCompound writeToNBT(boolean includeLink) {
NBTTagCompound tag = new NBTTagCompound();
NBTTagCompound stackTag = new NBTTagCompound();
itemStack.writeToNBT(stackTag);
@@ -652,7 +688,7 @@ public class TileLevelMaintainer extends AENetworkTile
tag.setLong(NBT_BATCH, batchSize);
tag.setBoolean(NBT_ENABLE, enable);
tag.setInteger(NBT_STATE, state.ordinal());
if (this.link != null) {
if (this.link != null && includeLink) {
NBTTagCompound linkTag = new NBTTagCompound();
this.link.writeToNBT(linkTag);
tag.setTag(NBT_LINK, linkTag);
@@ -8,10 +8,6 @@ import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import com.glodblock.github.coremod.transform.CraftingCpuTransformer;
import com.glodblock.github.coremod.transform.CraftingGridCacheTransformer;
import com.glodblock.github.coremod.transform.CraftingTreeNodeTransformer;
import com.glodblock.github.coremod.transform.DualityInterfaceTransformer;
import com.glodblock.github.coremod.transform.ExternalStorageRegistryTransformer;
import com.glodblock.github.coremod.transform.GuiCraftingTransformer;
import com.glodblock.github.coremod.transform.NEITransformer;
@@ -25,10 +21,6 @@ public class FCClassTransformer implements IClassTransformer {
public byte[] transform(String name, String transformedName, byte[] basicClass) {
ClassMapper tform;
switch (transformedName) {
case "appeng.crafting.CraftingTreeNode" -> tform = CraftingTreeNodeTransformer.INSTANCE;
case "appeng.me.cache.CraftingGridCache" -> tform = CraftingGridCacheTransformer.INSTANCE;
case "appeng.me.cluster.implementations.CraftingCPUCluster" -> tform = CraftingCpuTransformer.INSTANCE;
case "appeng.helpers.DualityInterface" -> tform = DualityInterfaceTransformer.INSTANCE;
case "appeng.client.gui.implementations.GuiCraftingCPU", "appeng.client.gui.implementations.GuiCraftConfirm", "net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm", "appeng.client.gui.widgets.GuiCraftingTree" -> tform = GuiCraftingTransformer.INSTANCE;
case "appeng.integration.modules.NEI" -> tform = NEITransformer.INSTANCE;
case "appeng.core.features.registries.ExternalStorageRegistry" -> tform = ExternalStorageRegistryTransformer.INSTANCE;
@@ -1,86 +1,18 @@
package com.glodblock.github.coremod.hooker;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import com.glodblock.github.client.gui.GuiFluidCraftConfirm;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.CraftingGridCacheFluidInventoryProxyCell;
import com.glodblock.github.inventory.FluidConvertingInventoryAdaptor;
import com.glodblock.github.inventory.FluidConvertingInventoryCrafting;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.Ae2Reflect;
import appeng.api.config.Actionable;
import appeng.api.networking.IGrid;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.IGuiTooltipHandler;
import appeng.crafting.MECraftingInventory;
import appeng.me.cache.CraftingGridCache;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.util.InventoryAdaptor;
public class CoreModHooks {
public static InventoryCrafting wrapCraftingBuffer(InventoryCrafting inv) {
return new FluidConvertingInventoryCrafting(
inv.eventHandler,
inv.inventoryWidth,
inv.getSizeInventory() / inv.inventoryWidth);
}
public static IAEItemStack wrapFluidPacketStack(IAEItemStack stack) {
if (stack.getItem() == ItemAndBlockHolder.PACKET) {
IAEItemStack dropStack = ItemFluidDrop.newAeStack(ItemFluidPacket.getFluidStack(stack.getItemStack()));
if (dropStack != null) {
return dropStack;
}
}
return stack;
}
public static ItemStack removeFluidPackets(InventoryCrafting inv, int index) {
ItemStack stack = inv.getStackInSlot(index);
if (stack != null && stack.getItem() instanceof ItemFluidPacket) {
FluidStack fluid = ItemFluidPacket.getFluidStack(stack);
return ItemFluidDrop.newStack(fluid);
} else {
return stack;
}
}
@Nullable
public static InventoryAdaptor wrapInventory(@Nullable TileEntity tile, ForgeDirection face) {
return tile != null ? FluidConvertingInventoryAdaptor.wrap(tile, face) : null;
}
public static long getCraftingByteCost(IAEItemStack stack) {
return stack.getItem() instanceof ItemFluidDrop ? (long) Math.ceil(stack.getStackSize() / 1000D)
: stack.getStackSize();
}
public static long getFluidDropsByteCost(long totalBytes, long originByte, IAEItemStack stack) {
if (stack != null && stack.getItem() instanceof ItemFluidDrop) {
return (long) Math.ceil(originByte / 1000D) + totalBytes;
}
return originByte + totalBytes;
}
public static ItemStack displayFluid(IAEItemStack aeStack) {
if (aeStack.getItemStack() != null && aeStack.getItemStack().getItem() instanceof ItemFluidDrop) {
FluidStack fluid = ItemFluidDrop.getFluidStack(aeStack.getItemStack());
@@ -88,61 +20,6 @@ public class CoreModHooks {
} else return aeStack.getItemStack();
}
public static long getFluidSize(IAEItemStack aeStack) {
if (aeStack.getItemStack() != null && aeStack.getItemStack().getItem() instanceof ItemFluidDrop) {
return (long) Math.max(aeStack.getStackSize() / 1000D, 1);
} else return aeStack.getStackSize();
}
public static List<IMEInventoryHandler<?>> craftingGridCacheGetCellArray(final CraftingGridCache instance,
final StorageChannel channel) {
// Equivalent to original function, but using the proxy for fluid channel
return channel == StorageChannel.ITEMS ? Arrays.asList(instance)
: Arrays.asList(new CraftingGridCacheFluidInventoryProxyCell(instance));
}
public static void storeFluidItem(CraftingCPUCluster instance) {
final IGrid g = Ae2Reflect.getGrid(instance);
if (g == null) {
return;
}
final IStorageGrid sg = g.getCache(IStorageGrid.class);
final IMEInventory<IAEItemStack> ii = sg.getItemInventory();
final IMEInventory<IAEFluidStack> jj = sg.getFluidInventory();
final MECraftingInventory inventory = Ae2Reflect.getCPUInventory(instance);
for (IAEItemStack is : inventory.getItemList()) {
is = inventory.extractItems(is.copy(), Actionable.MODULATE, Ae2Reflect.getCPUSource(instance));
if (is != null) {
Ae2Reflect.postCPUChange(instance, is, Ae2Reflect.getCPUSource(instance));
if (is.getItem() instanceof ItemFluidDrop) {
IAEFluidStack fluidDrop = ItemFluidDrop.getAeFluidStack(is);
fluidDrop = jj.injectItems(fluidDrop, Actionable.MODULATE, Ae2Reflect.getCPUSource(instance));
if (fluidDrop == null) {
is = null;
} else {
is.setStackSize(fluidDrop.getStackSize());
}
} else {
is = ii.injectItems(is, Actionable.MODULATE, Ae2Reflect.getCPUSource(instance));
}
}
if (is != null) {
inventory.injectItems(is, Actionable.MODULATE, Ae2Reflect.getCPUSource(instance));
}
}
if (inventory.getItemList().isEmpty()) {
Ae2Reflect.setCPUInventory(instance, new MECraftingInventory());
}
Ae2Reflect.markCPUDirty(instance);
}
public static ItemStack getStackUnderMouse(GuiContainer gui, int mousex, int mousey) {
if (gui instanceof IGuiTooltipHandler guiTooltipHandler) {
return guiTooltipHandler.getHoveredStack();
@@ -1,142 +0,0 @@
package com.glodblock.github.coremod.transform;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import com.glodblock.github.coremod.FCClassTransformer;
public class CraftingCpuTransformer extends FCClassTransformer.ClassMapper {
public static final CraftingCpuTransformer INSTANCE = new CraftingCpuTransformer();
private CraftingCpuTransformer() {
// NO-OP
}
@Override
protected ClassVisitor getClassMapper(ClassVisitor downstream) {
return new TransformCraftingCPUCluster(Opcodes.ASM5, downstream);
}
private static class TransformCraftingCPUCluster extends ClassVisitor {
TransformCraftingCPUCluster(int api, ClassVisitor cv) {
super(api, cv);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (name.equals("executeCrafting")) {
return new TransformExecuteCrafting(api, super.visitMethod(access, name, desc, signature, exceptions));
} else if (name.equals("cancel")) {
return new TransformStoreItems(api, super.visitMethod(access, name, desc, signature, exceptions));
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
}
private static class TransformExecuteCrafting extends MethodVisitor {
private boolean gotInventory = false;
private int reach_stack = 0;
TransformExecuteCrafting(int api, MethodVisitor mv) {
super(api, mv);
}
@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
if (opcode == Opcodes.GETFIELD && owner.equals("appeng/me/cluster/implementations/CraftingCPUCluster")
&& name.equals("inventory")) {
gotInventory = true;
}
super.visitFieldInsn(opcode, owner, name, desc);
}
@Override
public void visitLineNumber(int line, Label start) {
gotInventory = false;
super.visitLineNumber(line, start);
}
@Override
public void visitJumpInsn(int opcode, Label label) {
if (opcode == Opcodes.IFNULL && reach_stack == 0) {
reach_stack = 1;
}
super.visitJumpInsn(opcode, label);
}
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (reach_stack == 1) {
if (opcode == Opcodes.INVOKEINTERFACE && owner.equals("appeng/api/storage/data/IAEItemStack")
&& name.equals("getStackSize")) {
reach_stack = 2;
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"getFluidSize",
"(Lappeng/api/storage/data/IAEItemStack;)J",
false);
return;
}
}
if (opcode == Opcodes.INVOKEVIRTUAL && owner.equals("net/minecraft/inventory/InventoryCrafting")
&& (name.equals("getStackInSlot") || name.equals("func_70301_a"))) {
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"removeFluidPackets",
"(Lnet/minecraft/inventory/InventoryCrafting;I)Lnet/minecraft/item/ItemStack;",
false);
return;
}
super.visitMethodInsn(opcode, owner, name, desc, itf);
if (gotInventory) {
if (opcode == Opcodes.INVOKESTATIC && owner.equals("appeng/util/item/AEItemStack")
&& name.equals("create")) {
gotInventory = false;
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"wrapFluidPacketStack",
"(Lappeng/api/storage/data/IAEItemStack;)Lappeng/api/storage/data/IAEItemStack;",
false);
}
} else if (opcode == Opcodes.INVOKESPECIAL && owner.equals("net/minecraft/inventory/InventoryCrafting")
&& name.equals("<init>")) {
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"wrapCraftingBuffer",
"(Lnet/minecraft/inventory/InventoryCrafting;)Lnet/minecraft/inventory/InventoryCrafting;",
false);
}
}
}
private static class TransformStoreItems extends MethodVisitor {
TransformStoreItems(int api, MethodVisitor mv) {
super(api, mv);
}
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (opcode == Opcodes.INVOKESPECIAL && owner.equals("appeng/me/cluster/implementations/CraftingCPUCluster")
&& name.equals("storeItems")) {
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"storeFluidItem",
"(Lappeng/me/cluster/implementations/CraftingCPUCluster;)V",
false);
} else {
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
}
}
}
@@ -1,67 +0,0 @@
package com.glodblock.github.coremod.transform;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import com.glodblock.github.coremod.FCClassTransformer;
public class CraftingGridCacheTransformer extends FCClassTransformer.ClassMapper {
public static final CraftingGridCacheTransformer INSTANCE = new CraftingGridCacheTransformer();
private CraftingGridCacheTransformer() {
// NO-OP
}
@Override
protected ClassVisitor getClassMapper(ClassVisitor downstream) {
return new CraftingGridCacheTransformer.TransformCraftingGridCache(Opcodes.ASM5, downstream);
}
private static class TransformCraftingGridCache extends ClassVisitor {
TransformCraftingGridCache(int api, ClassVisitor cv) {
super(api, cv);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (name.equals("getCellArray")) {
return new CraftingGridCacheTransformer.ReplaceGetCellArray(
api,
super.visitMethod(access, name, desc, signature, exceptions));
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
}
private static class ReplaceGetCellArray extends MethodVisitor {
private final MethodVisitor target;
ReplaceGetCellArray(int api, MethodVisitor mv) {
// Original method is replaced
super(api, null);
target = mv;
}
@Override
public void visitCode() {
target.visitCode();
// Equivalent to
// return CoreModHooks::craftingGridCacheGetCellArray(this, channel);
target.visitVarInsn(Opcodes.ALOAD, 0);
target.visitVarInsn(Opcodes.ALOAD, 1);
target.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"craftingGridCacheGetCellArray",
"(Lappeng/me/cache/CraftingGridCache;Lappeng/api/storage/StorageChannel;)Ljava/util/List;",
false);
target.visitInsn(Opcodes.ARETURN);
target.visitMaxs(2, 3);
target.visitEnd();
}
}
}
@@ -1,102 +0,0 @@
package com.glodblock.github.coremod.transform;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import com.glodblock.github.coremod.FCClassTransformer;
public class CraftingTreeNodeTransformer extends FCClassTransformer.ClassMapper {
public static final CraftingTreeNodeTransformer INSTANCE = new CraftingTreeNodeTransformer();
private CraftingTreeNodeTransformer() {
// NO-OP
}
@Override
protected ClassVisitor getClassMapper(ClassVisitor downstream) {
return new TransformCraftingTreeNode(Opcodes.ASM5, downstream);
}
private static class TransformCraftingTreeNode extends ClassVisitor {
TransformCraftingTreeNode(int api, ClassVisitor cv) {
super(api, cv);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (name.equals("request")) {
return new TransformRequest(api, super.visitMethod(access, name, desc, signature, exceptions));
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
}
private static class TransformRequest extends MethodVisitor {
private boolean writingBytes = false;
private int cnt = 0;
TransformRequest(int api, MethodVisitor mv) {
super(api, mv);
}
@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
if (opcode == Opcodes.GETFIELD && owner.equals("appeng/crafting/CraftingTreeNode")
&& name.equals("bytes")) {
writingBytes = true;
}
super.visitFieldInsn(opcode, owner, name, desc);
}
@Override
public void visitLineNumber(int line, Label start) {
writingBytes = false; // no write here
super.visitLineNumber(line, start);
}
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (writingBytes && opcode == Opcodes.INVOKEINTERFACE
&& owner.equals("appeng/api/storage/data/IAEItemStack")
&& name.equals("getStackSize")) {
writingBytes = false;
cnt++;
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"getCraftingByteCost",
"(Lappeng/api/storage/data/IAEItemStack;)J",
false);
} else {
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
}
@Override
public void visitInsn(int opcode) {
if (writingBytes && cnt == 5 && opcode == Opcodes.LADD) {
super.visitVarInsn(Opcodes.ALOAD, 0);
super.visitFieldInsn(
Opcodes.GETFIELD,
"appeng/crafting/CraftingTreeNode",
"what",
"Lappeng/api/storage/data/IAEItemStack;");
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"getFluidDropsByteCost",
"(JJLappeng/api/storage/data/IAEItemStack;)J",
false);
writingBytes = false;
cnt++;
return;
}
super.visitInsn(opcode);
}
}
}
@@ -1,60 +0,0 @@
package com.glodblock.github.coremod.transform;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import com.glodblock.github.coremod.FCClassTransformer;
public class DualityInterfaceTransformer extends FCClassTransformer.ClassMapper {
public static final DualityInterfaceTransformer INSTANCE = new DualityInterfaceTransformer();
private DualityInterfaceTransformer() {
// NO-OP
}
@Override
protected ClassVisitor getClassMapper(ClassVisitor downstream) {
return new TransformDualityInterface(Opcodes.ASM5, downstream);
}
private static class TransformDualityInterface extends ClassVisitor {
TransformDualityInterface(int api, ClassVisitor cv) {
super(api, cv);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
return switch (name) {
case "pushItemsOut", "pushPattern", "isBusy" -> new TransformInvAdaptorCalls(
api,
super.visitMethod(access, name, desc, signature, exceptions));
default -> super.visitMethod(access, name, desc, signature, exceptions);
};
}
}
private static class TransformInvAdaptorCalls extends MethodVisitor {
private TransformInvAdaptorCalls(int api, MethodVisitor mv) {
super(api, mv);
}
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (opcode == Opcodes.INVOKESTATIC && owner.equals("appeng/util/InventoryAdaptor")
&& name.equals("getAdaptor")) {
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"wrapInventory",
"(Lnet/minecraft/tileentity/TileEntity;Lnet/minecraftforge/common/util/ForgeDirection;)Lappeng/util/InventoryAdaptor;",
false);
} else {
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
}
}
}
@@ -1,30 +0,0 @@
package com.glodblock.github.crossmod.waila;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidTankInfo;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
public class CertusQuartzTankWailaDataProvider extends BaseWailaDataProvider {
@Override
public List<String> getWailaBody(final ItemStack itemStack, final List<String> currentToolTip,
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
TileEntity tileEntity = accessor.getTileEntity();
if (tileEntity instanceof TileCertusQuartzTank quartzTank) {
FluidTankInfo info = quartzTank.getTankInfo(true)[0];
if (info.fluid != null) {
currentToolTip
.add(Tooltip.fluidFormat(info.fluid.getLocalizedName(), info.fluid.amount, info.capacity));
}
}
return currentToolTip;
}
}
@@ -0,0 +1,71 @@
package com.glodblock.github.crossmod.waila;
import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import com.glodblock.github.crossmod.waila.vanilla.FluidInvWailaDataProvider;
import com.google.common.collect.Lists;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
public class VanillaTileWailaDataProvider implements IWailaDataProvider {
private final List<IWailaDataProvider> providers;
public VanillaTileWailaDataProvider() {
final IWailaDataProvider fluidInv = new FluidInvWailaDataProvider();
this.providers = Lists.newArrayList(fluidInv);
}
@Override
public ItemStack getWailaStack(final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaHead(final ItemStack itemStack, final List<String> currentToolTip,
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
for (final IWailaDataProvider provider : this.providers) {
provider.getWailaHead(itemStack, currentToolTip, accessor, config);
}
return currentToolTip;
}
@Override
public List<String> getWailaBody(final ItemStack itemStack, final List<String> currentToolTip,
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
for (final IWailaDataProvider provider : this.providers) {
provider.getWailaBody(itemStack, currentToolTip, accessor, config);
}
return currentToolTip;
}
@Override
public List<String> getWailaTail(final ItemStack itemStack, final List<String> currentToolTip,
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
for (final IWailaDataProvider provider : this.providers) {
provider.getWailaTail(itemStack, currentToolTip, accessor, config);
}
return currentToolTip;
}
@Override
public NBTTagCompound getNBTData(final EntityPlayerMP player, final TileEntity te, final NBTTagCompound tag,
final World world, final int x, final int y, final int z) {
for (final IWailaDataProvider provider : this.providers) {
provider.getNBTData(player, te, tag, world, x, y, z);
}
return tag;
}
}
@@ -1,7 +1,6 @@
package com.glodblock.github.crossmod.waila;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import com.glodblock.github.util.ModAndClassUtil;
import net.minecraft.tileentity.TileEntity;
import appeng.api.parts.IPartHost;
import appeng.tile.AEBaseTile;
@@ -27,9 +26,9 @@ public class WailaInit {
registrar.registerBodyProvider(tile, AEBaseTile.class);
registrar.registerNBTProvider(tile, AEBaseTile.class);
if (!ModAndClassUtil.WAILA_PLUGINS) {
final IWailaDataProvider certusQuartzTank = new CertusQuartzTankWailaDataProvider();
registrar.registerBodyProvider(certusQuartzTank, TileCertusQuartzTank.class);
}
final IWailaDataProvider vanillaTile = new VanillaTileWailaDataProvider();
registrar.registerBodyProvider(vanillaTile, TileEntity.class);
registrar.registerNBTProvider(vanillaTile, TileEntity.class);
}
}
@@ -0,0 +1,50 @@
package com.glodblock.github.crossmod.waila.vanilla;
import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidTankInfo;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import com.glodblock.github.crossmod.waila.Tooltip;
import com.glodblock.github.util.Util;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
public class FluidInvWailaDataProvider extends BaseWailaDataProvider {
@Override
public List<String> getWailaBody(final ItemStack itemStack, final List<String> currentToolTip,
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
final TileEntity te = accessor.getTileEntity();
if (te instanceof TileCertusQuartzTank) {
if (accessor.getNBTData().hasKey("fluidInv")) {
NBTTagCompound data = (NBTTagCompound) accessor.getNBTData().getTag("fluidInv");
for (FluidTankInfo info : Util.FluidUtil.fluidTankInfoReadFromNBT(data)) {
if (info.fluid == null) continue;
currentToolTip
.add(Tooltip.fluidFormat(info.fluid.getLocalizedName(), info.fluid.amount, info.capacity));
}
}
}
return currentToolTip;
}
@Override
public NBTTagCompound getNBTData(final EntityPlayerMP player, final TileEntity te, final NBTTagCompound tag,
final World world, final int x, final int y, final int z) {
if (te instanceof TileCertusQuartzTank) {
NBTTagCompound data = new NBTTagCompound();
Util.FluidUtil.fluidTankInfoWriteToNBT(((TileCertusQuartzTank) te).getInternalFluid(), data);
tag.setTag("fluidInv", data);
te.writeToNBT(tag);
}
return tag;
}
}
@@ -1,85 +0,0 @@
package com.glodblock.github.inventory;
import org.jetbrains.annotations.NotNull;
import com.glodblock.github.common.item.ItemFluidDrop;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.me.cache.CraftingGridCache;
public class CraftingGridCacheFluidInventoryProxyCell implements IMEInventoryHandler<IAEFluidStack> {
private final CraftingGridCache inner;
public CraftingGridCacheFluidInventoryProxyCell(final CraftingGridCache craftingGridCache) {
inner = craftingGridCache;
}
@Override
public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, BaseActionSource src) {
return ItemFluidDrop
.getAeFluidStack((IAEItemStack) inner.injectItems(ItemFluidDrop.newAeStack(input), type, src));
}
@Override
public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, BaseActionSource src) {
return null;
}
@Override
public IItemList<IAEFluidStack> getAvailableItems(IItemList<IAEFluidStack> out, int iteration) {
return out;
}
@Override
public IAEFluidStack getAvailableItem(@NotNull IAEFluidStack request, int iteration) {
return null;
}
@Override
public StorageChannel getChannel() {
return StorageChannel.FLUIDS;
}
@Override
public AccessRestriction getAccess() {
return inner.getAccess();
}
@Override
public boolean isPrioritized(IAEFluidStack input) {
return inner.isPrioritized(input);
}
@Override
public boolean canAccept(IAEFluidStack input) {
return inner.canAccept(ItemFluidDrop.newAeStack(input));
}
@Override
public int getPriority() {
return inner.getPriority();
}
@Override
public int getSlot() {
return inner.getSlot();
}
@Override
public boolean validForPass(int i) {
return inner.validForPass(i);
}
@Override
public boolean isAutoCraftingInventory() {
return inner.isAutoCraftingInventory();
}
}
@@ -1,540 +0,0 @@
package com.glodblock.github.inventory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import com.glodblock.github.common.Config;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.parts.PartFluidExportBus;
import com.glodblock.github.common.parts.PartFluidInterface;
import com.glodblock.github.common.parts.PartFluidP2PInterface;
import com.glodblock.github.common.tile.TileFluidInterface;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.BlockPos;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.Util;
import appeng.api.config.FuzzyMode;
import appeng.api.config.InsertionMode;
import appeng.api.config.Upgrades;
import appeng.api.parts.IPart;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.me.GridAccessException;
import appeng.me.helpers.AENetworkProxy;
import appeng.parts.p2p.PartP2PLiquids;
import appeng.tile.misc.TileInterface;
import appeng.tile.networking.TileCableBus;
import appeng.util.InventoryAdaptor;
import appeng.util.inv.IInventoryDestination;
import appeng.util.inv.ItemSlot;
import cofh.api.transport.IItemDuct;
import crazypants.enderio.conduit.ConnectionMode;
import crazypants.enderio.conduit.item.IItemConduit;
import crazypants.enderio.conduit.liquid.ILiquidConduit;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaPipeEntity;
public class FluidConvertingInventoryAdaptor extends InventoryAdaptor {
// facing is the target TE direction
// |T|-facing->|I|
public FluidConvertingInventoryAdaptor(TileEntity te, @Nullable InventoryAdaptor invItems,
@Nullable IFluidHandler invFluids, ForgeDirection facing, BlockPos pos, boolean isOnmi) {
this.invItems = invItems;
this.invFluids = invFluids;
this.side = facing;
this.posInterface = pos;
this.onmi = isOnmi;
this.selfInterface = getInterfaceTE(pos.getTileEntity(), facing.getOpposite());
this.targetInterface = getInterfaceTE(te, facing);
}
private final InventoryAdaptor invItems;
private final IFluidHandler invFluids;
private final ForgeDirection side;
private final BlockPos posInterface;
@Nullable
private final IInterfaceHost targetInterface;
@Nullable
private final IInterfaceHost selfInterface;
private final boolean onmi;
private static Method eioTypeCheck;
private static Class<?> conduitClazz;
static {
if (ModAndClassUtil.EIO) {
try {
conduitClazz = Class.forName("crazypants.enderio.conduit.TileConduitBundle");
eioTypeCheck = conduitClazz.getDeclaredMethod("getConduit", Class.class);
} catch (ClassNotFoundException | NoSuchMethodException e) {
eioTypeCheck = null;
}
} else {
eioTypeCheck = null;
}
}
public static InventoryAdaptor wrap(TileEntity capProvider, ForgeDirection face) {
TileEntity inter = capProvider.getWorldObj().getTileEntity(
capProvider.xCoord + face.offsetX,
capProvider.yCoord + face.offsetY,
capProvider.zCoord + face.offsetZ);
if (!Config.noFluidPacket && !(inter instanceof TileFluidInterface
|| Util.getPart(inter, face.getOpposite()) instanceof PartFluidInterface
|| Util.getPart(inter, face.getOpposite()) instanceof PartFluidExportBus
|| Util.getPart(inter, face.getOpposite()) instanceof PartFluidP2PInterface))
return InventoryAdaptor.getAdaptor(capProvider, face);
if (InventoryAdaptor.getAdaptor(capProvider, face) == null
&& !(ModAndClassUtil.EIO && capProvider instanceof IItemDuct)) {
if (capProvider instanceof IFluidHandler tank) {
if (tank.getTankInfo(face) == null || !(tank.getTankInfo(face).length > 0)) return null;
} else {
return null;
}
}
InventoryAdaptor item = InventoryAdaptor.getAdaptor(capProvider, face);
IFluidHandler fluid = capProvider instanceof IFluidHandler ? (IFluidHandler) capProvider : null;
boolean onmi = false;
if (inter instanceof TileInterface in) {
onmi = in.getTargets().size() > 1;
}
return new FluidConvertingInventoryAdaptor(capProvider, item, fluid, face, new BlockPos(inter), onmi);
}
public ItemStack addItems(ItemStack toBeAdded, InsertionMode insertionMode) {
FluidStack fluid = Util.getFluidFromVirtual(toBeAdded);
if (!this.onmi) {
if (!checkValidSide(
this.posInterface.getOffSet(this.side.getOpposite()).getTileEntity(),
this.side.getOpposite())) {
return toBeAdded;
}
if (fluid != null) {
int filled = fillSideFluid(fluid, this.invFluids, this.side, true);
fluid.amount -= filled;
return ItemFluidDrop.newStack(fluid);
} else {
ItemStack notFilled = fillSideItem(toBeAdded, this.invItems, insertionMode, true);
if (notFilled != null) {
// Fill EIO Conduit at last.
return fillEIOConduit(
notFilled,
this.posInterface.getOffSet(this.side.getOpposite()).getTileEntity(),
this.side);
}
return null;
}
} else {
if (fluid != null) {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (fluid.amount <= 0) {
return null;
}
if (!checkValidSide(this.posInterface.getOffSet(dir).getTileEntity(), dir)) {
continue;
}
int filled = fillSideFluid(fluid, getSideFluid(dir), dir.getOpposite(), true);
fluid.amount -= filled;
}
return ItemFluidPacket.newStack(fluid);
} else {
ItemStack item = toBeAdded.copy();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (item == null || item.stackSize <= 0) {
return null;
}
if (!checkValidSide(this.posInterface.getOffSet(dir).getTileEntity(), dir)) {
continue;
}
item = fillSideItem(item, getSideItem(dir), insertionMode, true);
}
// Fill EIO Conduit at last.
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (item == null || item.stackSize <= 0) {
return null;
}
if (!checkValidSide(this.posInterface.getOffSet(dir).getTileEntity(), dir)) {
continue;
}
item = fillEIOConduit(item, this.posInterface.getOffSet(dir).getTileEntity(), dir.getOpposite());
}
return item;
}
}
}
@Override
public ItemStack addItems(ItemStack toBeAdded) {
return addItems(toBeAdded, InsertionMode.DEFAULT);
}
@Override
public ItemStack simulateAdd(ItemStack toBeSimulated) {
return simulateAdd(toBeSimulated, InsertionMode.DEFAULT);
}
@Override
public ItemStack simulateAdd(ItemStack toBeSimulated, InsertionMode insertionMode) {
FluidStack fluid = Util.getFluidFromVirtual(toBeSimulated);
if (!this.onmi) {
if (!checkValidSide(
this.posInterface.getOffSet(this.side.getOpposite()).getTileEntity(),
this.side.getOpposite())) {
return toBeSimulated;
}
if (fluid != null) {
int filled = fillSideFluid(fluid, this.invFluids, this.side, false);
fluid.amount -= filled;
return ItemFluidPacket.newStack(fluid);
} else {
// Assert EIO conduit can hold all item, as it is the origin practice in AE2
if (isConduit(this.posInterface.getOffSet(this.side.getOpposite()).getTileEntity())) {
return null;
} else {
return fillSideItem(toBeSimulated, this.invItems, insertionMode, false);
}
}
} else {
// In onmi mode, fluid/item only need to be partly inserted.
boolean sus = false;
if (fluid != null) {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (!checkValidSide(this.posInterface.getOffSet(dir).getTileEntity(), dir)) {
continue;
}
int filled = fillSideFluid(fluid, getSideFluid(dir), dir.getOpposite(), false);
if (filled > 0) {
sus = true;
break;
}
}
} else {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (!checkValidSide(this.posInterface.getOffSet(dir).getTileEntity(), dir)) {
continue;
}
// Assert EIO conduit can hold all item, as it is the origin practice in AE2
if (isConduit(this.posInterface.getOffSet(dir).getTileEntity())) {
return null;
}
ItemStack notFilled = fillSideItem(toBeSimulated, getSideItem(dir), insertionMode, false);
if (notFilled == null || notFilled.stackSize < toBeSimulated.stackSize) {
sus = true;
break;
}
}
}
return sus ? null : toBeSimulated;
}
}
@Override
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination) {
return invItems != null ? invItems.removeItems(amount, filter, destination) : null;
}
@Override
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination) {
return invItems != null ? invItems.simulateRemove(amount, filter, destination) : null;
}
@Override
public ItemStack removeSimilarItems(int amount, ItemStack filter, FuzzyMode fuzzyMode,
IInventoryDestination destination) {
return invItems != null ? invItems.removeSimilarItems(amount, filter, fuzzyMode, destination) : null;
}
@Override
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode,
IInventoryDestination destination) {
return invItems != null ? invItems.simulateSimilarRemove(amount, filter, fuzzyMode, destination) : null;
}
@Override
public boolean containsItems() {
if (!this.onmi) {
// If there is no fluid tank or item inventory, it shouldn't send stuff here.
return checkItemFluids(this.invFluids, this.invItems, this.side) > 0;
}
boolean anyValid = false;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
// Avoid sending stuff into itself me network
TileEntity te = this.posInterface.getOffSet(dir).getTileEntity();
if (te != null && checkValidSide(te, dir)) {
if (!isConduit(te) || (!isItemConduit(te) && isFluidConduitConnected(te, dir))) {
final int result = checkItemFluids(
this.getSideFluid(dir),
this.getSideItem(dir),
dir.getOpposite());
if (result == 1) {
return true;
}
if (result != 2) {
anyValid = true;
}
}
}
}
// Same here. if there is no fluid tank or item inventory existed, it shouldn't send stuff here.
return !anyValid;
}
public boolean hasSlots() {
return (invFluids != null && invFluids.getTankInfo(side).length > 0) || (invItems != null);
}
@Override
public Iterator<ItemSlot> iterator() {
FluidTankInfo[] info = null;
if (invFluids != null) {
info = invFluids.getTankInfo(side);
}
// Null check is needed because some tank infos return null (EIO conduits...)
if (info == null) {
info = new FluidTankInfo[0];
}
return new SlotIterator(info, invItems != null ? invItems.iterator() : Collections.emptyIterator());
}
private IFluidHandler getSideFluid(ForgeDirection direction) {
TileEntity te = this.posInterface.getOffSet(direction).getTileEntity();
if (te instanceof IFluidHandler) {
return (IFluidHandler) te;
}
return null;
}
private int fillSideFluid(FluidStack fluid, IFluidHandler tank, ForgeDirection direction, boolean doFill) {
if (tank != null) {
return tank.fill(direction, fluid, doFill);
}
return 0;
}
// EIO conduit isn't considered here
private ItemStack fillSideItem(ItemStack item, InventoryAdaptor inv, InsertionMode mode, boolean doFill) {
if (inv != null) {
if (doFill) {
return inv.addItems(item, mode);
} else {
return inv.simulateAdd(item, mode);
}
}
return item;
}
private int gtMachineCircuitCheck(InventoryAdaptor ad) {
if (ad == null) {
return 0;
}
for (ItemSlot i : ad) {
ItemStack is = i.getItemStack();
if (is == null || Objects.requireNonNull(is.getItem()).getUnlocalizedName().equals("gt.integrated_circuit"))
continue;
return 1;
}
return 0;
}
private boolean isGTMachine(Object o) {
if (!(ModAndClassUtil.GT5 || ModAndClassUtil.GT5NH)) return false;
if (o instanceof TileEntity te) {
return te.getBlockType().getUnlocalizedName().equals("gt.blockmachines");
}
return false;
}
private boolean isFluidConduitConnected(TileEntity te, ForgeDirection dir) {
try {
ILiquidConduit liquidConduit = (ILiquidConduit) eioTypeCheck.invoke(te, ILiquidConduit.class);
return liquidConduit != null
&& liquidConduit.getConnectionMode(dir.getOpposite()) != ConnectionMode.DISABLED;
} catch (IllegalAccessException | InvocationTargetException e) {
return false;
}
}
private boolean isItemConduit(TileEntity te) {
if (isConduit(te)) {
try {
return eioTypeCheck.invoke(te, IItemConduit.class) != null;
} catch (InvocationTargetException | IllegalAccessException e) {
return false;
}
}
return false;
}
private boolean isConduit(TileEntity te) {
return ModAndClassUtil.EIO && conduitClazz.isInstance(te);
}
private ItemStack fillEIOConduit(ItemStack item, TileEntity te, ForgeDirection direction) {
if (isConduit(te)) {
return ((IItemDuct) te).insertItem(direction, item);
}
return item;
}
private InventoryAdaptor getSideItem(ForgeDirection direction) {
TileEntity te = this.posInterface.getOffSet(direction).getTileEntity();
return InventoryAdaptor.getAdaptor(te, direction.getOpposite());
}
// 0 - It is empty
// 1 - It contains item/fluid
// 2 - It doesn't exist
private int checkItemFluids(IFluidHandler tank, InventoryAdaptor inv, ForgeDirection direction) {
if (tank == null && inv == null) {
return 2;
}
if (targetInterface != null && targetInterface.getInstalledUpgrades(Upgrades.ADVANCED_BLOCKING) > 0
&& targetInterface instanceof IDualHost
&& !((IDualHost) targetInterface).getDualityFluid().getFluidInventory().getStorageList().isEmpty()) {
return 1;
}
if (tank != null && tank.getTankInfo(direction) != null) {
List<FluidTankInfo[]> tankInfos = new LinkedList<>();
if (Util.getPart(tank, direction) instanceof PartP2PLiquids invFluidsP2P) {
// read other ends of p2p for blocking mode
try {
Iterator<PartP2PLiquids> it = invFluidsP2P.getOutputs().iterator();
boolean checkedInput = false;
while (it.hasNext() || !checkedInput) {
PartP2PLiquids p2p;
if (it.hasNext()) {
p2p = it.next();
} else {
p2p = invFluidsP2P.getInput();
checkedInput = true;
}
if (p2p == invFluidsP2P || p2p == null) continue;
IFluidHandler target = Ae2Reflect.getP2PLiquidTarget(p2p);
if (target == null) continue;
FluidTankInfo[] info = target.getTankInfo(p2p.getSide().getOpposite());
if (info != null) {
tankInfos.add(info);
}
}
} catch (GridAccessException ignore) {}
} else {
tankInfos.add(tank.getTankInfo(direction));
}
boolean hasTank = false;
for (FluidTankInfo[] tankInfoArray : tankInfos) {
for (FluidTankInfo tankInfo : tankInfoArray) {
hasTank = true;
FluidStack fluid = tankInfo.fluid;
if (fluid != null && fluid.amount > 0) {
return 1;
}
}
}
if (!hasTank && inv == null) {
return 2;
}
}
if (isGTMachine(tank)) {
return gtMachineCircuitCheck(inv);
}
return inv != null && inv.containsItems() ? 1 : 0;
}
private boolean checkValidSide(TileEntity te, ForgeDirection direction) {
if (isGTMachine(te)) {
return checkGTPipeConnection(te, direction.getOpposite());
}
return isDifferentGrid(getInterfaceTE(te, direction.getOpposite()));
}
private boolean checkGTPipeConnection(TileEntity te, ForgeDirection direction) {
if (te instanceof IGregTechTileEntity) {
IMetaTileEntity mte = ((IGregTechTileEntity) te).getMetaTileEntity();
if (mte instanceof MetaPipeEntity) {
return ((MetaPipeEntity) mte).isConnectedAtSide(direction);
}
}
return true;
}
private static IInterfaceHost getInterfaceTE(TileEntity te, ForgeDirection face) {
if (te instanceof IInterfaceHost) {
return (IInterfaceHost) te;
} else if (te instanceof TileCableBus) {
IPart part = ((TileCableBus) te).getPart(face);
if (part instanceof IInterfaceHost) {
return (IInterfaceHost) part;
}
}
return null;
}
private boolean isDifferentGrid(IInterfaceHost target) {
if (this.selfInterface != null && target != null) {
DualityInterface other = target.getInterfaceDuality();
DualityInterface self = this.selfInterface.getInterfaceDuality();
try {
AENetworkProxy proxy1 = Ae2Reflect.getInterfaceProxy(other);
AENetworkProxy proxy2 = Ae2Reflect.getInterfaceProxy(self);
if (proxy1.getGrid() == proxy2.getGrid()) {
return false;
}
} catch (GridAccessException e) {
return true;
}
}
return true;
}
private static class SlotIterator implements Iterator<ItemSlot> {
private final FluidTankInfo[] tanks;
private final Iterator<ItemSlot> itemSlots;
private int nextSlotIndex = 0;
SlotIterator(FluidTankInfo[] tanks, Iterator<ItemSlot> itemSlots) {
this.tanks = tanks;
this.itemSlots = itemSlots;
}
@Override
public boolean hasNext() {
return itemSlots.hasNext() || nextSlotIndex < tanks.length;
}
@Override
public ItemSlot next() {
if (nextSlotIndex < tanks.length) {
FluidStack fluid = tanks[nextSlotIndex].fluid;
ItemSlot slot = new ItemSlot();
slot.setSlot(nextSlotIndex++);
slot.setItemStack(fluid != null ? ItemFluidPacket.newStack(fluid) : null);
Ae2Reflect.setItemSlotExtractable(slot, false);
return slot;
} else {
ItemSlot slot = itemSlots.next();
slot.setSlot(nextSlotIndex++);
return slot;
}
}
}
}
@@ -1,33 +0,0 @@
package com.glodblock.github.inventory;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
public class FluidConvertingInventoryCrafting extends InventoryCrafting {
public FluidConvertingInventoryCrafting(Container container, int width, int height) {
super(container, width, height);
}
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
if (stack != null && stack.getItem() instanceof ItemFluidDrop) {
FluidStack fluid = ItemFluidDrop.getFluidStack(stack);
if (fluid != null) {
super.setInventorySlotContents(index, ItemFluidPacket.newStack(new FluidStack(fluid, stack.stackSize)));
} else {
super.setInventorySlotContents(
index,
ItemFluidPacket.newStack(new FluidStack(FluidRegistry.WATER, 1000)));
}
} else {
super.setInventorySlotContents(index, stack);
}
}
}
@@ -42,7 +42,6 @@ public class MEMonitorIFluidHandler implements IMEMonitor<IAEFluidStack> {
private final HashMap<IMEMonitorHandlerReceiver<IAEFluidStack>, Object> listeners = new HashMap<>();
private BaseActionSource mySource;
private StorageFilter mode;
private boolean init = false;
public MEMonitorIFluidHandler(IFluidHandler handler, ForgeDirection side) {
this.mode = StorageFilter.EXTRACTABLE_ONLY;
@@ -224,10 +223,7 @@ public class MEMonitorIFluidHandler implements IMEMonitor<IAEFluidStack> {
}
public IItemList<IAEFluidStack> getAvailableItems(IItemList<IAEFluidStack> out, int iteration) {
if (!init) {
this.onTick();
init = true;
}
for (IAEFluidStack fs : this.cache) {
out.addStorage(fs);
}
@@ -237,10 +233,6 @@ public class MEMonitorIFluidHandler implements IMEMonitor<IAEFluidStack> {
@Override
public IAEFluidStack getAvailableItem(@Nonnull IAEFluidStack request, int iteration) {
if (!init) {
this.onTick();
init = true;
}
return this.cache.findPrecise(request);
}
@@ -31,6 +31,7 @@ import com.glodblock.github.client.gui.GuiFluidTerminal;
import com.glodblock.github.client.gui.GuiIngredientBuffer;
import com.glodblock.github.client.gui.GuiInterfaceWireless;
import com.glodblock.github.client.gui.GuiLargeIngredientBuffer;
import com.glodblock.github.client.gui.GuiLevelEmitterProxy;
import com.glodblock.github.client.gui.GuiLevelMaintainer;
import com.glodblock.github.client.gui.GuiLevelTerminal;
import com.glodblock.github.client.gui.GuiLevelWireless;
@@ -91,10 +92,12 @@ import com.google.common.collect.ImmutableList;
import appeng.api.storage.ITerminalHost;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.container.implementations.ContainerCraftingStatus;
import appeng.container.implementations.ContainerLevelEmitter;
import appeng.container.implementations.ContainerPatternItemRenamer;
import appeng.container.implementations.ContainerPriority;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.IPriorityHost;
import appeng.parts.automation.PartLevelEmitter;
public enum GuiType {
@@ -123,6 +126,19 @@ public enum GuiType {
}
}),
LEVEL_EMITTER_PROXY(new PartGuiFactory<>(PartLevelEmitter.class) {
@Override
protected Object createServerGui(EntityPlayer player, PartLevelEmitter inv) {
return new ContainerLevelEmitter(player.inventory, inv);
}
@Override
protected Object createClientGui(EntityPlayer player, PartLevelEmitter inv) {
return new GuiLevelEmitterProxy(player.inventory, inv);
}
}),
FLUID_LEVEL_EMITTER(new PartGuiFactory<>(PartFluidLevelEmitter.class) {
@Override
@@ -1,5 +1,9 @@
package com.glodblock.github.loader;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.Packet;
import net.minecraft.world.World;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.network.CPacketCraftRequest;
import com.glodblock.github.network.CPacketDumpTank;
@@ -96,4 +100,12 @@ public class ChannelLoader implements Runnable {
id++,
Side.CLIENT);
}
public static void sendPacketToAllPlayers(Packet packet, World world) {
for (Object player : world.playerEntities) {
if (player instanceof EntityPlayerMP) {
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(packet);
}
}
}
}
@@ -5,10 +5,14 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.util.ForgeDirection;
import com.glodblock.github.common.parts.PartFluidLevelEmitter;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.util.BlockPos;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.parts.automation.PartLevelEmitter;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
@@ -110,12 +114,33 @@ public class CPacketLevelTerminalCommands implements IMessage {
case EDIT -> {
TileEntity tile = DimensionManager.getWorld(message.dim)
.getTileEntity(message.x, message.y, message.z);
InventoryHandler.openGui(
player,
player.worldObj,
new BlockPos(tile),
message.side,
GuiType.LEVEL_MAINTAINER);
if (tile instanceof IPartHost host) {
IPart part = host.getPart(message.side);
if (part instanceof PartLevelEmitter) {
InventoryHandler.openGui(
player,
tile.getWorldObj(),
new BlockPos(tile),
message.side,
GuiType.LEVEL_EMITTER_PROXY);
} else if (part instanceof PartFluidLevelEmitter) {
InventoryHandler.openGui(
player,
tile.getWorldObj(),
new BlockPos(tile),
message.side,
GuiType.FLUID_LEVEL_EMITTER);
}
} else {
InventoryHandler.openGui(
player,
tile.getWorldObj(),
new BlockPos(tile),
message.side,
GuiType.LEVEL_MAINTAINER);
}
}
case BACK -> {
GuiType originalGui = GuiType.getByOrdinal(message.originalGui);
@@ -136,18 +136,6 @@ public class CommonProxy {
Upgrades.STICKY.registerItem(new ItemStack(ItemAndBlockHolder.QUANTUM_CELL), 1);
Upgrades.STICKY.registerItem(new ItemStack(ItemAndBlockHolder.SINGULARITY_CELL), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.FLUID_VOID_CELL), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL1K), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL4K), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL16K), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL64K), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL256K), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL1024K), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL4096K), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL16384K), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.QUANTUM_CELL), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.SINGULARITY_CELL), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL1K), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL4K), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL16K), 1);
@@ -168,16 +156,6 @@ public class CommonProxy {
Upgrades.STICKY.registerItem(new ItemStack(ItemAndBlockHolder.CELL16384KM), 1);
Upgrades.STICKY.registerItem(new ItemStack(ItemAndBlockHolder.ARTIFICIAL_UNIVERSE_CELL), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL1KM), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL4KM), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL16KM), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL64KM), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL256KM), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL1024KM), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL4096KM), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.CELL16384KM), 1);
Upgrades.INVERTER.registerItem(new ItemStack(ItemAndBlockHolder.ARTIFICIAL_UNIVERSE_CELL), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL1KM), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL4KM), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL16KM), 1);
@@ -8,16 +8,11 @@ import net.minecraftforge.fluids.IFluidHandler;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.MachineSource;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.container.implementations.ContainerUpgradeable;
import appeng.container.implementations.CraftingCPURecord;
import appeng.crafting.MECraftingInventory;
import appeng.helpers.DualityInterface;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.me.helpers.AENetworkProxy;
@@ -32,19 +27,12 @@ public class Ae2Reflect {
private static final Field fInventory_containerUpgrade;
private static final Field fAEPass_internal;
private static final Field fAEInv_partitionList;
private static final Field fCPU_cpu;
private static final Field fCPU_myName;
private static final Field fCPU_processors;
private static final Field fCPU_size;
private static final Field fCPU_inventory;
private static final Field fCPU_machineSrc;
private static final Field fContainerUpgradeable_upgradeable;
private static final Field fDualInterface_gridProxy;
private static final Field fCraftConfirm_result;
private static final Method mItemSlot_setExtractable;
private static final Method mCPU_getGrid;
private static final Method mCPU_postChange;
private static final Method mCPU_markDirty;
private static final Method mP2PLiquids_getTarget;
private static final Method mCraftConfirm_getGrid;
@@ -53,22 +41,11 @@ public class Ae2Reflect {
fInventory_containerUpgrade = reflectField(ContainerUpgradeable.class, "upgradeable");
fAEPass_internal = reflectField(MEPassThrough.class, "internal");
fAEInv_partitionList = reflectField(MEInventoryHandler.class, "myPartitionList");
fCPU_cpu = Ae2Reflect.reflectField(CraftingCPURecord.class, "cpu");
fCPU_myName = Ae2Reflect.reflectField(CraftingCPURecord.class, "myName");
fCPU_processors = Ae2Reflect.reflectField(CraftingCPURecord.class, "processors");
fCPU_size = Ae2Reflect.reflectField(CraftingCPURecord.class, "size");
fCPU_inventory = Ae2Reflect.reflectField(CraftingCPUCluster.class, "inventory");
fCPU_machineSrc = Ae2Reflect.reflectField(CraftingCPUCluster.class, "machineSrc");
fContainerUpgradeable_upgradeable = Ae2Reflect.reflectField(ContainerUpgradeable.class, "upgradeable");
mItemSlot_setExtractable = reflectMethod(ItemSlot.class, "setExtractable", boolean.class);
fDualInterface_gridProxy = reflectField(DualityInterface.class, "gridProxy");
mCPU_getGrid = reflectMethod(CraftingCPUCluster.class, "getGrid");
mCPU_postChange = reflectMethod(
CraftingCPUCluster.class,
"postChange",
IAEItemStack.class,
BaseActionSource.class);
mCPU_markDirty = reflectMethod(CraftingCPUCluster.class, "markDirty");
mP2PLiquids_getTarget = reflectMethod(PartP2PLiquids.class, "getTarget");
fCraftConfirm_result = reflectField(ContainerCraftConfirm.class, "result");
mCraftConfirm_getGrid = reflectMethod(ContainerCraftConfirm.class, "getGrid");
@@ -116,14 +93,17 @@ public class Ae2Reflect {
}
}
@Deprecated
public static IPartitionList<?> getPartitionList(MEInventoryHandler<?> me) {
return Ae2Reflect.readField(me, fAEInv_partitionList);
}
@Deprecated
public static IMEInventory<?> getInternal(MEPassThrough<?> me) {
return Ae2Reflect.readField(me, fAEPass_internal);
}
@Deprecated
public static void setItemSlotExtractable(ItemSlot slot, boolean extractable) {
try {
mItemSlot_setExtractable.invoke(slot, extractable);
@@ -132,26 +112,17 @@ public class Ae2Reflect {
}
}
public static ICraftingCPU getCPU(CraftingCPURecord cpu) {
return Ae2Reflect.readField(cpu, fCPU_cpu);
}
@Deprecated
public static String getName(CraftingCPURecord cpu) {
return Ae2Reflect.readField(cpu, fCPU_myName);
}
public static int getProcessors(CraftingCPURecord cpu) {
return Ae2Reflect.readField(cpu, fCPU_processors);
}
public static long getSize(CraftingCPURecord cpu) {
return Ae2Reflect.readField(cpu, fCPU_size);
}
@Deprecated
public static IUpgradeableHost getUpgradeList(ContainerUpgradeable container) {
return Ae2Reflect.readField(container, fInventory_containerUpgrade);
}
@Deprecated
public static IGrid getGrid(CraftingCPUCluster cpu) {
try {
return (IGrid) mCPU_getGrid.invoke(cpu);
@@ -160,6 +131,7 @@ public class Ae2Reflect {
}
}
@Deprecated
public static IGrid getGrid(ContainerCraftConfirm ccc) {
try {
return (IGrid) mCraftConfirm_getGrid.invoke(ccc);
@@ -168,46 +140,22 @@ public class Ae2Reflect {
}
}
@Deprecated
public static ICraftingJob getResult(ContainerCraftConfirm ccc) {
return Ae2Reflect.readField(ccc, fCraftConfirm_result);
}
public static MECraftingInventory getCPUInventory(CraftingCPUCluster cpu) {
return Ae2Reflect.readField(cpu, fCPU_inventory);
}
public static void setCPUInventory(CraftingCPUCluster cpu, MECraftingInventory value) {
Ae2Reflect.writeField(cpu, fCPU_inventory, value);
}
public static MachineSource getCPUSource(CraftingCPUCluster cpu) {
return Ae2Reflect.readField(cpu, fCPU_machineSrc);
}
@Deprecated
public static IUpgradeableHost getUpgradeableHost(ContainerUpgradeable owner) {
return Ae2Reflect.readField(owner, fContainerUpgradeable_upgradeable);
}
@Deprecated
public static AENetworkProxy getInterfaceProxy(DualityInterface owner) {
return Ae2Reflect.readField(owner, fDualInterface_gridProxy);
}
public static void postCPUChange(CraftingCPUCluster cpu, IAEItemStack stack, MachineSource src) {
try {
mCPU_postChange.invoke(cpu, stack, src);
} catch (Exception e) {
throw new IllegalStateException("Failed to invoke method: " + mCPU_postChange, e);
}
}
public static void markCPUDirty(CraftingCPUCluster cpu) {
try {
mCPU_markDirty.invoke(cpu);
} catch (Exception e) {
throw new IllegalStateException("Failed to invoke method: " + mCPU_markDirty, e);
}
}
@Deprecated
public static IFluidHandler getP2PLiquidTarget(PartP2PLiquids p2p) {
try {
return (IFluidHandler) mP2PLiquids_getTarget.invoke(p2p);
@@ -45,18 +45,22 @@ public class Ae2ReflectClient {
}
}
@Deprecated
public static void rewriteIcon(GuiCraftingStatus gui, ItemStack icon) {
Ae2Reflect.writeField(gui, fGuiCPUStatus_icon, icon);
}
@Deprecated
public static Set<Slot> getDragClick(AEBaseGui gui) {
return Ae2Reflect.readField(gui, fGui_drag);
}
@Deprecated
public static AppEngRenderItem getStackSizeRenderer(AEBaseGui gui) {
return Ae2Reflect.readField(gui, fAEBaseGui_stackSizeRenderer);
}
@Deprecated
public static GuiTabButton getOriginalGuiButton(GuiCraftingStatus gui) {
return Ae2Reflect.readField(gui, fGuiCraftingStatus_originalGuiBtn);
}
@@ -1,5 +1,8 @@
package com.glodblock.github.util;
import static appeng.util.Platform.readStackNBT;
import static appeng.util.Platform.stackConvert;
import java.util.Arrays;
import java.util.Objects;
@@ -14,7 +17,9 @@ import net.minecraftforge.common.util.Constants;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.helpers.PatternHelper;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<FluidPatternDetails> {
@@ -22,6 +27,7 @@ public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<
private final ItemStack patternStack;
private IAEItemStack patternStackAe;
private IAEItemStack[] inputs = null, inputsCond = null, outputs = null, outputsCond = null;
private IAEStack<?>[] aeInputs = null, aeInputsCond = null, aeOutputs = null, aeOutputsCond = null;
private int priority = 0;
private int combine = 0;
private int beSubstitute = 0;
@@ -83,18 +89,42 @@ public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<
return checkInitialized(inputs);
}
@Override
public IAEStack<?>[] getAEInputs() {
return checkInitialized(aeInputs);
}
@Override
public IAEItemStack[] getCondensedInputs() {
return checkInitialized(inputsCond);
}
public boolean setInputs(IAEItemStack[] inputs) {
IAEItemStack[] condensed = condenseStacks(inputs);
@Override
public IAEStack<?>[] getCondensedAEInputs() {
return checkInitialized(aeInputsCond);
}
public boolean setInputs(IAEStack<?>[] inputs) {
IAEStack<?>[] condensed = condenseAEStacks(inputs);
if (condensed.length == 0) {
return false;
}
this.inputs = inputs;
this.inputsCond = condensed;
this.aeInputs = inputs;
this.aeInputsCond = condensed;
IAEItemStack[] legacy = new IAEItemStack[inputs.length];
for (int i = 0; i < inputs.length; i++) {
if (inputs[i] != null) {
if (inputs[i].isItem()) {
legacy[i] = (IAEItemStack) inputs[i];
} else {
legacy[i] = stackConvert(inputs[i]);
}
}
}
this.inputs = legacy;
this.inputsCond = condenseStacks(legacy);
return true;
}
@@ -103,18 +133,42 @@ public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<
return checkInitialized(outputs);
}
@Override
public IAEStack<?>[] getAEOutputs() {
return checkInitialized(aeOutputs);
}
@Override
public IAEItemStack[] getCondensedOutputs() {
return checkInitialized(outputsCond);
}
public boolean setOutputs(IAEItemStack[] outputs) {
IAEItemStack[] condensed = condenseStacks(outputs);
@Override
public IAEStack<?>[] getCondensedAEOutputs() {
return checkInitialized(aeOutputsCond);
}
public boolean setOutputs(IAEStack<?>[] outputs) {
IAEStack<?>[] condensed = condenseAEStacks(outputs);
if (condensed.length == 0) {
return false;
}
this.outputs = Arrays.stream(outputs).filter(Objects::nonNull).toArray(IAEItemStack[]::new);
this.outputsCond = condensed;
this.aeOutputs = Arrays.stream(outputs).filter(Objects::nonNull).toArray(IAEStack<?>[]::new);
this.aeOutputsCond = condensed;
IAEItemStack[] legacy = new IAEItemStack[outputs.length];
for (int i = 0; i < outputs.length; i++) {
if (outputs[i] != null) {
if (outputs[i].isItem()) {
legacy[i] = (IAEItemStack) outputs[i];
} else {
legacy[i] = stackConvert(outputs[i]);
}
}
}
this.outputs = legacy;
this.outputsCond = condenseStacks(legacy);
return true;
}
@@ -122,11 +176,20 @@ public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<
return PatternHelper.convertToCondensedList(stacks);
}
private static IAEStack<?>[] condenseAEStacks(IAEStack<?>[] stacks) {
return PatternHelper.convertToCondensedAEList(stacks);
}
@Override
public ItemStack getOutput(InventoryCrafting craftingInv, World world) {
throw new IllegalStateException("Not a crafting recipe!");
}
@Override
public boolean isValidItemForSlot(int slotIndex, IAEStack<?> stack, World world) {
throw new IllegalStateException("Not a crafting recipe!");
}
@Override
public boolean isValidItemForSlot(int slotIndex, ItemStack itemStack, World world) {
throw new IllegalStateException("Not a crafting recipe!");
@@ -171,12 +234,12 @@ public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<
return patternStack;
}
public static NBTTagList writeStackArray(IAEItemStack[] stacks) {
public static NBTTagList writeStackArray(IAEStack<?>[] stacks) {
NBTTagList listTag = new NBTTagList();
for (IAEItemStack stack : stacks) {
for (IAEStack<?> stack : stacks) {
// see note at top of class
NBTTagCompound stackTag = new NBTTagCompound();
if (stack != null) stack.writeToNBT(stackTag);
Platform.writeStackNBT(stack, stackTag);
listTag.appendTag(stackTag);
}
return listTag;
@@ -196,11 +259,11 @@ public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<
&& setOutputs(readStackArray(tag.getTagList("out", Constants.NBT.TAG_COMPOUND)));
}
public static IAEItemStack[] readStackArray(NBTTagList listTag) {
public static IAEStack<?>[] readStackArray(NBTTagList listTag) {
// see note at top of class
IAEItemStack[] stacks = new IAEItemStack[listTag.tagCount()];
IAEStack<?>[] stacks = new IAEStack<?>[listTag.tagCount()];
for (int i = 0; i < stacks.length; i++) {
stacks[i] = AEItemStack.loadItemStackFromNBT(listTag.getCompoundTagAt(i));
stacks[i] = readStackNBT(listTag.getCompoundTagAt(i), true);
}
return stacks;
}
@@ -32,7 +32,6 @@ public final class ModAndClassUtil {
public static boolean COFH = false;
public static boolean GTPP = false;
public static boolean WAILA = false;
public static boolean WAILA_PLUGINS = false;
public static boolean AVARITIA = false;
public static boolean HODGEPODGE = false;
public static boolean NEW_HORIZONS_CORE_MOD = false;
@@ -148,7 +147,6 @@ public final class ModAndClassUtil {
if (Loader.isModLoaded("CoFHCore")) COFH = true;
if (Loader.isModLoaded("miscutils")) GTPP = true;
if (Loader.isModLoaded("Waila")) WAILA = true;
if (Loader.isModLoaded("wailaplugins")) WAILA_PLUGINS = true;
if (Loader.isModLoaded("Avaritia")) AVARITIA = true;
if (Loader.isModLoaded("hodgepodge")) HODGEPODGE = true;
if (Loader.isModLoaded("dreamcraft")) NEW_HORIZONS_CORE_MOD = true;
@@ -7,6 +7,8 @@ import static com.glodblock.github.util.Util.DimensionalCoordSide.hasEnergyCard;
import static net.minecraft.init.Items.glass_bottle;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
@@ -22,6 +24,7 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidContainerItem;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -278,28 +281,28 @@ public final class Util {
}
public static FluidStack getFluidFromItem(ItemStack stack) {
if (stack != null) {
FluidStack fluid = null;
if (stack == null) return null;
if (stack.getItem() instanceof IFluidContainerItem) {
fluid = ((IFluidContainerItem) stack.getItem()).getFluid(stack);
} else if (FluidContainerRegistry.isContainer(stack)) {
fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
} else if (stack.getItem() instanceof ItemFluidPacket) {
fluid = ItemFluidPacket.getFluidStack(stack);
} else if (stack.getItem() instanceof ItemFluidDrop) {
fluid = ItemFluidDrop.getFluidStack(Util.copyStackWithSize(stack, 1));
}
FluidStack fluid = null;
if (fluid == null) {
fluid = StackInfo.getFluid(Util.copyStackWithSize(stack, 1));
}
if (stack.getItem() instanceof IFluidContainerItem) {
fluid = ((IFluidContainerItem) stack.getItem()).getFluid(stack);
} else if (FluidContainerRegistry.isContainer(stack)) {
fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
} else if (stack.getItem() instanceof ItemFluidPacket) {
fluid = ItemFluidPacket.getFluidStack(stack);
} else if (stack.getItem() instanceof ItemFluidDrop) {
fluid = ItemFluidDrop.getFluidStack(Util.copyStackWithSize(stack, 1));
}
if (fluid != null) {
FluidStack fluid0 = fluid.copy();
fluid0.amount *= stack.stackSize;
return fluid0;
}
if (fluid == null) {
fluid = StackInfo.getFluid(Util.copyStackWithSize(stack, 1));
}
if (fluid != null) {
FluidStack fluid0 = fluid.copy();
fluid0.amount *= stack.stackSize;
return fluid0;
}
return null;
}
@@ -507,6 +510,36 @@ public final class Util {
public static final ItemStack water_bucket = new ItemStack(Items.water_bucket, 1);
public static void fluidTankInfoWriteToNBT(FluidTankInfo[] infos, NBTTagCompound data) {
int i = 0;
for (FluidTankInfo info : infos) {
if (info.fluid != null && info.fluid.amount > 0) {
NBTTagCompound fs = new NBTTagCompound();
info.fluid.writeToNBT(fs);
fs.setInteger("capacity", info.capacity);
data.setTag("#" + i, fs);
}
i++;
}
data.setInteger("fluidInvSize", i);
}
public static FluidTankInfo[] fluidTankInfoReadFromNBT(NBTTagCompound data) {
int i = 0;
List<FluidTankInfo> infos = new ArrayList<>();
while (data.hasKey("fluidInvSize") && i < data.getInteger("fluidInvSize")) {
if (data.hasKey("#" + i)) {
NBTTagCompound tag = (NBTTagCompound) data.getTag("#" + i);
FluidStack fs = FluidStack.loadFluidStackFromNBT(tag);
infos.add(new FluidTankInfo(fs, tag.getInteger("capacity")));
} else {
infos.add(new FluidTankInfo(null, 0));
}
i++;
}
return infos.toArray(new FluidTankInfo[0]);
}
public static IAEFluidStack createAEFluidStack(Fluid fluid) {
return createAEFluidStack(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME));
}