Compare commits

..
Author SHA1 Message Date
Maya 70a55239eb Merge branch 'master' into dev 2025-05-12 09:23:49 -05:00
Martin Robertz 00529ca1b3 Merge branch 'master' into dev
# Conflicts:
#	dependencies.gradle
2025-05-12 09:33:13 +02:00
Martin Robertz 5b1607a817 Merge remote-tracking branch 'lordIcocain/fix-cell-math' into dev 2025-05-12 09:32:41 +02:00
lordIcocain 1163beabdf correct singleByteAmount 2025-05-12 01:23:48 +03:00
lordIcocain f31956ecc5 simplify 2025-05-12 00:54:55 +03:00
lordIcocain 0c0a6655a5 fix math 2025-05-12 00:40:39 +03:00
Maya ca0618c5ab Merge branch 'master' into dev 2025-05-11 12:17:37 -05:00
Martin Robertz 28ddd23ffb fix 2025-05-10 14:04:19 +02:00
Martin Robertz d1e6bfcb47 update 2025-05-10 13:39:25 +02:00
Martin Robertz 76313d947a sa+deps 2025-05-10 13:38:54 +02:00
Martin Robertz b4ea48a827 Merge remote-tracking branch 'lordIcocain/magnet-and-restock' into dev
# Conflicts:
#	src/main/java/com/glodblock/github/inventory/gui/GuiType.java
2025-05-10 13:38:30 +02:00
Maya eece3f73cb Merge branch 'master' into magnet-and-restock 2025-05-06 17:51:00 -05:00
Maya ec86685d7d Merge branch 'master' into magnet-and-restock 2025-04-19 10:41:41 -05:00
lordIcocain b9cd36f3cc restock cleanup 2025-04-11 19:16:32 +03:00
lordIcocain 7190bf39f5 fix restock crash on out of range 2025-04-11 17:49:33 +03:00
lordIcocain f388bdaf78 caching by UUID instead of EntityPlayer 2025-04-11 02:11:14 +03:00
lordIcocain bb912ec8a1 Fix filters
Add oredictionary filter
Fix inconsistent with WCT
Gui improvements
Filter caching
GuiFCImgButton 3/4 size support
2025-04-11 02:00:31 +03:00
lordIcocain 083c135874 Merge remote-tracking branch 'origin/magnet-and-restock' into magnet-and-restock 2025-04-09 22:44:30 +03:00
lordIcocain 765033762a fix filters 2025-04-09 22:44:22 +03:00
Maya a82b9b2931 Merge branch 'master' into magnet-and-restock 2025-04-08 23:49:41 -05:00
lordIcocain 95d4b0a14b fix crash when terminal out of range 2025-04-09 00:18:53 +03:00
lordIcocain e37a24a861 1st commit 2025-03-29 04:37:30 +02:00
81 changed files with 3824 additions and 1427 deletions

No files matched your search

+9 -9
View File
@@ -34,28 +34,28 @@
* 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.7.45-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-616-GTNH-pre:dev')
api('com.github.GTNewHorizons:NotEnoughItems:2.7.40-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-603-GTNH-pre:dev')
api('curse.maven:cofh-core-69162:2388751')
api('com.github.GTNewHorizons:waila:1.8.4:dev')
api("com.github.GTNewHorizons:GTNHLib:0.6.22:dev")
api("com.github.GTNewHorizons:GTNHLib:0.6.21:dev")
implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.12.2:dev") {
implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.12.0:dev") {
exclude group: 'com.github.GTNewHorizons', module: 'Applied-Energistics-2-Unofficial'
}
compileOnly('com.github.GTNewHorizons:Baubles-Expanded:2.1.8-GTNH:dev')
compileOnly('com.github.GTNewHorizons:Baubles-Expanded:2.1.7-GTNH:dev')
compileOnly('com.github.GTNewHorizons:ExtraCells2:2.5.35:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:ForestryMC:4.10.8:dev')
compileOnly('com.github.GTNewHorizons:EnderIO:2.9.14:dev')
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.51.299:dev') {
compileOnly('com.github.GTNewHorizons:ForestryMC:4.10.7:dev')
compileOnly('com.github.GTNewHorizons:EnderIO:2.9.12:dev')
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.51.282: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.11.15-GTNH:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:OpenComputers:1.11.13-GTNH:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:ThaumicEnergistics:1.7.7-GTNH:dev') { transitive = false }
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.6.53:dev") { transitive = false }
@@ -33,7 +33,7 @@ import cpw.mods.fml.common.network.NetworkRegistry;
modid = FluidCraft.MODID,
version = FluidCraft.VERSION,
name = FluidCraft.MODNAME,
dependencies = "required-after:appliedenergistics2@[rv3-beta-238,);required-after:CoFHCore;after:waila;after:thaumicenergistics;after:ae2wct")
dependencies = "required-after:appliedenergistics2@[rv3-beta-238,);required-after:CoFHCore;required-after:Baubles;after:waila;after:thaumicenergistics;after:ae2wct")
public class FluidCraft {
public static final String MODID = "ae2fc";
@@ -16,13 +16,11 @@ public interface ILevelViewable extends IGridHost, ISide, ISegmentedInventory, I
TileEntity getTile();
@Deprecated
default long getSortValue() {
TileEntity te = getTile();
return ((long) te.zCoord << 24) ^ ((long) te.xCoord << 8) ^ te.yCoord;
}
@Deprecated
default boolean shouldDisplay() {
return true;
}
@@ -41,7 +39,6 @@ public interface ILevelViewable extends IGridHost, ISide, ISegmentedInventory, I
return 1;
};
@Deprecated
default ItemStack getSelfItemStack() {
return null;
}
@@ -49,11 +46,8 @@ public interface ILevelViewable extends IGridHost, ISide, ISegmentedInventory, I
/**
* "Target" Display representation
*/
@Deprecated
default ItemStack getDisplayItemStack() {
return null;
}
LevelItemInfo[] getLevelItemInfoList();
}
@@ -1,20 +0,0 @@
package com.glodblock.github.api.registries;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.NotNull;
public class LevelItemInfo {
public ItemStack stack;
public long quantity;
public long batchSize;
public LevelState state;
public LevelItemInfo(@NotNull ItemStack stack, long quantity, long batchSize, LevelState state) {
this.stack = stack;
this.quantity = quantity;
this.batchSize = batchSize;
this.state = state;
}
}
@@ -1,9 +0,0 @@
package com.glodblock.github.api.registries;
public enum LevelState {
None,
Idle,
Craft,
Export,
Error
}
@@ -0,0 +1,86 @@
package com.glodblock.github.client.gui.widget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
public class FCGuiBaseButton extends GuiButton {
// copy from wct button
protected static final ResourceLocation buttonTextures = new ResourceLocation(
"minecraft",
"textures/gui/widgets.png");
public FCGuiBaseButton(int id, int xPosition, int yPosition, int width, int height, String displayString) {
super(id, xPosition, yPosition, width, height, displayString);
this.enabled = true;
this.visible = true;
this.id = id;
this.xPosition = xPosition;
this.yPosition = yPosition;
this.width = width;
this.height = height;
this.displayString = displayString;
}
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
if (this.visible) {
FontRenderer fontrenderer = mc.fontRenderer;
mc.getTextureManager().bindTexture(buttonTextures);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition
&& mouseX < this.xPosition + this.width
&& mouseY < this.yPosition + this.height;
int k = this.getHoverState(this.field_146123_n);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
this.drawTexturedModalRect(
this.xPosition + this.width / 2,
this.yPosition,
200 - this.width / 2,
46 + k * 20,
this.width / 2,
this.height - 2);
this.drawTexturedModalRect(
this.xPosition + 2,
this.yPosition + (this.height - 2),
200 - (this.width - 2),
64 + k * 20,
this.width - 2,
2);
this.drawTexturedModalRect(
this.xPosition,
this.yPosition + (this.height - 1),
200 - this.width,
65 + k * 20,
this.width,
1);
this.mouseDragged(mc, mouseX, mouseY);
int l = 14737632;
if (packedFGColour != 0) {
l = packedFGColour;
} else if (!this.enabled) {
l = 10526880;
} else if (this.field_146123_n) {
l = 16777120;
}
this.drawCenteredString(
fontrenderer,
this.displayString,
this.xPosition + this.width / 2,
this.yPosition + (this.height - 8) / 2,
l);
}
}
}
@@ -22,6 +22,7 @@ public class GuiFCImgButton extends GuiButton implements ITooltip {
private static Map<EnumPair, ButtonAppearance> appearances;
private final String buttonSetting;
private boolean halfSize = false;
private boolean threeFourths = false;
private String fillVar;
private String currentValue;
private final boolean background;
@@ -66,6 +67,16 @@ public class GuiFCImgButton extends GuiButton implements ITooltip {
this.registerApp(22, "SWITCH", "DISABLE", "disable");
this.registerApp(23, "CONFIG", "YES", "open_configuration");
this.registerApp(24, "HIGHLIGHT", "YES", "block_highlight");
this.registerApp(30, "MAGNET_CARD", "INV", "magnet_card.inv");
this.registerApp(30, "MAGNET_CARD", "ME", "magnet_card.me");
this.registerApp(30, "MAGNET_CARD", "FILTER", "magnet_card.filter");
this.registerApp(31, "MAGNET_CARD", "OFF", "magnet_card.off");
this.registerApp(32, "DATA_SYNC", "ENABLE", "data_sync.enable");
this.registerApp(33, "ENABLE_12x", "ENABLE", "enable");
this.registerApp(34, "DISABLE_12x", "DISABLE", "disable");
this.registerApp(35, "DATA_SYNC", "DISABLE", "data_sync.disable");
this.registerApp(36, "RESTOCK", "ENABLE", "restock.on");
this.registerApp(37, "RESTOCK", "DISABLE", "restock.off");
}
}
@@ -135,6 +146,14 @@ public class GuiFCImgButton extends GuiButton implements ITooltip {
this.halfSize = halfSize;
}
public boolean isThreeFourths() {
return threeFourths;
}
public void setThreeFourths(boolean threeFourths) {
this.threeFourths = threeFourths;
}
public String getFillVar() {
return this.fillVar;
}
@@ -155,12 +174,12 @@ public class GuiFCImgButton extends GuiButton implements ITooltip {
@Override
public int getWidth() {
return this.halfSize ? 8 : 16;
return this.halfSize ? 8 : threeFourths ? 12 : 16;
}
@Override
public int getHeight() {
return this.halfSize ? 8 : 16;
return this.halfSize ? 8 : threeFourths ? 12 : 16;
}
@Override
@@ -217,79 +236,44 @@ public class GuiFCImgButton extends GuiButton implements ITooltip {
if (this.visible) {
final int iconIndex = this.getIconIndex();
final int iconPage = this.getIconPage();
this.width = getWidth();
this.height = getHeight();
float scaleFactor = halfSize ? 3 : threeFourths ? 4.5f : 6;
if (this.halfSize) {
this.width = 8;
this.height = 8;
GL11.glPushMatrix();
GL11.glTranslatef(this.xPosition, this.yPosition, 0.0F);
GL11.glScalef(0.5f / 16 * 3, 0.5f / 16 * 3, 0.5f / 16 * 3);
if (this.enabled) {
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
} else {
GL11.glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
}
par1Minecraft.renderEngine.bindTexture(FluidCraft.resource("textures/gui/states" + iconPage + ".png"));
this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition
&& par2 < this.xPosition + this.width
&& par3 < this.yPosition + this.height;
final int uv_y = (int) Math.floor(iconIndex / 3.0);
final int uv_x = iconIndex - uv_y * 3;
if (this.background) {
this.drawTexturedModalRect(
0,
0,
Math.round(32F * 16F / 3F),
Math.round(32F * 16F / 3F),
Math.round(16F * 16F / 3F),
Math.round(16F * 16F / 3F));
}
this.drawTexturedModalRect(
0,
0,
Math.round(uv_x * 16F * 16F / 3F),
Math.round(uv_y * 16F * 16F / 3F),
Math.round(16F * 16F / 3F),
Math.round(16F * 16F / 3F));
GL11.glPushMatrix();
GL11.glTranslatef(this.xPosition, this.yPosition, 0.0F);
GL11.glScalef(0.5f / 16 * scaleFactor, 0.5f / 16 * scaleFactor, 0.5f / 16 * scaleFactor);
if (this.enabled) {
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
} else {
GL11.glPushMatrix();
GL11.glTranslatef(this.xPosition, this.yPosition, 0.0F);
GL11.glScalef(0.5f / 16 * 6, 0.5f / 16 * 6, 0.5f / 16 * 6);
if (this.enabled) {
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
} else {
GL11.glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
}
GL11.glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
}
par1Minecraft.renderEngine.bindTexture(FluidCraft.resource("textures/gui/states" + iconPage + ".png"));
this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition
&& par2 < this.xPosition + this.width
&& par3 < this.yPosition + this.height;
par1Minecraft.renderEngine.bindTexture(FluidCraft.resource("textures/gui/states" + iconPage + ".png"));
this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition
&& par2 < this.xPosition + this.width
&& par3 < this.yPosition + this.height;
final int uv_y = (int) Math.floor(iconIndex / 3.0);
final int uv_x = iconIndex - uv_y * 3;
if (this.background) {
this.drawTexturedModalRect(
0,
0,
Math.round(32F * 16F / 3F),
Math.round(32F * 16F / 3F),
Math.round(16F * 16F / 3F),
Math.round(16F * 16F / 3F));
}
final int uv_y = (int) Math.floor(iconIndex / 3.0);
final int uv_x = iconIndex - uv_y * 3;
if (this.background) {
this.drawTexturedModalRect(
0,
0,
Math.round(uv_x * 16F * 16F / 3F),
Math.round(uv_y * 16F * 16F / 3F),
Math.round(32F * 16F / 3F),
Math.round(32F * 16F / 3F),
Math.round(16F * 16F / 3F),
Math.round(16F * 16F / 3F));
}
this.drawTexturedModalRect(
0,
0,
Math.round(uv_x * 16F * 16F / 3F),
Math.round(uv_y * 16F * 16F / 3F),
Math.round(16F * 16F / 3F),
Math.round(16F * 16F / 3F));
this.mouseDragged(par1Minecraft, par2, par3);
GL11.glPopMatrix();
}
@@ -44,6 +44,7 @@ public class GuiFluidMonitor extends FCGuiMonitor<IAEFluidStack> {
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.fontRendererObj.drawString(this.getGuiDisplayName(GuiText.Terminal.getLocal()), 8, 6, 4210752);
this.fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
super.drawFG(offsetX, offsetY, mouseX, mouseY);
}
@Override
@@ -27,4 +27,9 @@ public class GuiFluidPortableCell extends GuiFluidTerminal {
return 3;
}
}
@Override
protected boolean isPortableCell() {
return true;
}
}
@@ -37,6 +37,7 @@ public class GuiItemMonitor extends FCGuiMonitor<IAEItemStack> {
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.fontRendererObj.drawString(this.getGuiDisplayName(GuiText.Terminal.getLocal()), 8, 6, 4210752);
this.fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
super.drawFG(offsetX, offsetY, mouseX, mouseY);
}
@Override
@@ -1,5 +1,7 @@
package com.glodblock.github.client.gui;
import static com.glodblock.github.client.gui.container.ContainerLevelMaintainer.createLevelValues;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
@@ -11,6 +13,7 @@ import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
@@ -20,11 +23,12 @@ import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.api.registries.LevelState;
import com.glodblock.github.client.gui.container.ContainerLevelMaintainer;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import com.glodblock.github.common.parts.PartLevelTerminal;
import com.glodblock.github.common.tile.TileLevelMaintainer;
import com.glodblock.github.common.tile.TileLevelMaintainer.State;
import com.glodblock.github.common.tile.TileLevelMaintainer.TLMTags;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.gui.MouseRegionManager;
import com.glodblock.github.inventory.item.IWirelessTerminal;
@@ -45,6 +49,9 @@ import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotFake;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.features.AEFeature;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketNEIDragClick;
import appeng.util.calculators.ArithHelper;
@@ -63,6 +70,8 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
private final Component[] component = new Component[TileLevelMaintainer.REQ_COUNT];
private final MouseRegionManager mouseRegions = new MouseRegionManager(this);
private Widget focusedWidget;
private int lastWorkingTick;
private int refreshTick;
private final CoFHFontRenderer render;
protected ItemStack icon = null;
@@ -80,7 +89,7 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
TEX_BG,
Minecraft.getMinecraft().getTextureManager(),
true);
this.refreshTick = 0;
if (ipl.player.openContainer instanceof AEBaseContainer container) {
var target = container.getTarget();
if (target instanceof PartLevelTerminal terminal) {
@@ -117,11 +126,40 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
}
}
}
public void postUpdate(List<IAEItemStack> list) {
for (Slot slot : this.cont.getRequestSlots()) {
if (!slot.getHasStack()) {
component[slot.getSlotIndex()].setState(State.None);
}
}
for (IAEItemStack is : list) {
NBTTagCompound data = is.getItemStack().getTagCompound();
if (data == null) {
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
AELog.info("Received empty configuration: ", is);
}
continue;
}
long batch = data.getLong(TLMTags.Batch.tagName);
long quantity = data.getLong(TLMTags.Quantity.tagName);
int idx = data.getInteger(TLMTags.Index.tagName);
boolean isEnable = data.getBoolean(TLMTags.Enable.tagName);
State state = State.values()[data.getInteger(TLMTags.State.tagName)];
component[idx].getQty().textField.setText(String.valueOf(quantity));
component[idx].getBatch().textField.setText(String.valueOf(batch));
component[idx].getQty().validate();
component[idx].getBatch().validate();
component[idx].setEnable(isEnable);
component[idx].setState(state);
}
}
@Override
public void initGui() {
super.initGui();
this.lastWorkingTick = this.refreshTick;
for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) {
component[i] = new Component(
new Widget(
@@ -138,8 +176,7 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
new GuiFCImgButton(guiLeft + 9, guiTop + 20 + 19 * i, "ENABLE", "ENABLE", false),
new GuiFCImgButton(guiLeft + 9, guiTop + 20 + 19 * i, "DISABLE", "DISABLE", false),
new FCGuiLineField(fontRendererObj, guiLeft + 47, guiTop + 33 + 19 * i, 125),
this.buttonList,
this.cont);
this.buttonList);
}
if (this.icon != null) {
this.originalGuiBtn = new GuiTabButton(
@@ -151,10 +188,11 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
this.originalGuiBtn.setHideEdge(13);
this.buttonList.add(originalGuiBtn);
}
FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer(Action.Refresh));
}
@Override
public void drawScreen(final int mouseX, final int mouseY, final float btn) {
this.refreshTick++;
super.drawScreen(mouseX, mouseY, btn);
for (Component com : this.component) {
com.getQty().textField.handleTooltip(mouseX, mouseY, this);
@@ -167,7 +205,12 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
mc.getTextureManager().bindTexture(TEX_BG);
drawTexturedModalRect(offsetX, offsetY, 0, 0, 176, ySize);
int tick = this.refreshTick;
int interval = 20;
if (tick > lastWorkingTick + interval && this.focusedWidget == null) {
FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer(Action.Refresh));
lastWorkingTick = this.refreshTick;
}
for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) {
this.component[i].draw();
}
@@ -251,6 +294,20 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
}
}
@Override
protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) {
if (slot instanceof SlotFluidConvertingFake && this.cont.getPlayerInv().getItemStack() != null) {
this.component[slot.getSlotIndex()].getQty().textField
.setText(String.valueOf(this.cont.getPlayerInv().getItemStack().stackSize));
return;
}
super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton);
}
public void updateAmount(int idx, int stackSize) {
this.component[idx].getQty().textField.setText(String.valueOf(stackSize));
}
@Override
protected void actionPerformed(final GuiButton btn) {
if (btn == originalGuiBtn) {
@@ -294,15 +351,6 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
return null;
}
@Override
protected void handleMouseClick(Slot slot, int slotIdx, int ctrlDown, int mouseButton) {
if (slot instanceof SlotFluidConvertingFake && this.cont.getPlayerInv().getItemStack() == null) {
slot.putStack(null);
this.component[slot.getSlotIndex()].reset();
}
super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton);
}
@Override
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
if (draggedStack == null) {
@@ -318,9 +366,11 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
for (int i = 0; i < this.cont.getRequestSlots().length; i++) {
SlotFluidConvertingFake slot = this.cont.getRequestSlots()[i];
if (slotAtPosition.equals(slot)) {
slot.putStack(draggedStack);
component[i].reset();
NetworkHandler.instance.sendToServer(new PacketNEIDragClick(draggedStack, slot.getSlotIndex()));
ItemStack itemStack = createLevelValues(draggedStack.copy());
itemStack.getTagCompound().setInteger(TLMTags.Index.tagName, i);
slot.putStack(itemStack);
NetworkHandler.instance.sendToServer(new PacketNEIDragClick(itemStack, slot.getSlotIndex()));
this.updateAmount(slot.getSlotIndex(), itemStack.stackSize);
return true;
}
}
@@ -332,44 +382,26 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
return false;
}
public void updateComponent(int index, long quantity, long batchSize, boolean isEnabled, LevelState state) {
if (index < 0 || index >= TileLevelMaintainer.REQ_COUNT) return;
component[index].setEnable(isEnabled);
component[index].setState(state);
component[index].getQty().textField.setText(String.valueOf(quantity));
component[index].getBatch().textField.setText(String.valueOf(batchSize));
component[index].getQty().validate();
component[index].getBatch().validate();
}
public void updateComponent(int index, LevelState state) {
if (index < 0 || index >= TileLevelMaintainer.REQ_COUNT) return;
component[index].setState(state);
}
private class Component {
public boolean isEnable = false;
public boolean isEnable = true;
private final Widget qty;
private final Widget batch;
private final GuiFCImgButton disable;
private final GuiFCImgButton enable;
private final GuiFCImgButton submit;
private final FCGuiLineField line;
private LevelState state;
private final ContainerLevelMaintainer container;
private State state;
public Component(Widget qtyInput, Widget batchInput, GuiFCImgButton submitBtn, GuiFCImgButton enableBtn,
GuiFCImgButton disableBtn, FCGuiLineField line, List<GuiButton> buttonList,
ContainerLevelMaintainer container) {
GuiFCImgButton disableBtn, FCGuiLineField line, List<GuiButton> buttonList) {
this.qty = qtyInput;
this.batch = batchInput;
this.enable = enableBtn;
this.disable = disableBtn;
this.submit = submitBtn;
this.line = line;
this.state = LevelState.None;
this.container = container;
this.state = State.None;
buttonList.add(this.submit);
buttonList.add(this.enable);
buttonList.add(this.disable);
@@ -403,25 +435,18 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
batch.validate();
if (qty.getAmount() != null) {
this.send(qty);
qty.textField.setText(String.valueOf(qty.getAmount()));
}
if (batch.getAmount() != null) {
this.send(batch);
batch.textField.setText(String.valueOf(batch.getAmount()));
}
didSomething = true;
} else if (this.enable == btn) {
this.setEnable(false);
FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer(Action.Enable, this.getIndex()));
didSomething = true;
} else if (this.disable == btn) {
if (this.container.getInventory().get(this.getIndex()) != null) {
this.setEnable(true);
FluidCraft.proxy.netHandler
.sendToServer(new CPacketLevelMaintainer(Action.Disable, this.getIndex()));
didSomething = true;
}
FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer(Action.Disable, this.getIndex()));
didSomething = true;
}
return didSomething;
}
@@ -506,18 +531,9 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
}
}
public void setState(LevelState state) {
public void setState(State state) {
this.state = state;
}
public void reset() {
this.qty.textField.setText("0");
this.batch.textField.setText("0");
this.qty.validate();
this.batch.validate();
this.setEnable(false);
this.setState(LevelState.None);
}
}
private class Widget {
@@ -569,7 +585,7 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
public void validate() {
final double result = Calculator.conversion(this.textField.getText());
if (Double.isNaN(result) || result < 0) {
if (Double.isNaN(result)) {
this.amount = null;
this.textField.setTextColor(0xFF0000);
} else {
@@ -1,6 +1,13 @@
package com.glodblock.github.client.gui;
import static com.glodblock.github.common.item.ItemWirelessUltraTerminal.hasInfinityBoosterCard;
import static com.glodblock.github.network.SPacketLevelTerminalUpdate.CLEAR_ALL_BIT;
import static com.glodblock.github.network.SPacketLevelTerminalUpdate.DISCONNECT_BIT;
import static com.glodblock.github.network.SPacketLevelTerminalUpdate.PacketAdd;
import static com.glodblock.github.network.SPacketLevelTerminalUpdate.PacketEntry;
import static com.glodblock.github.network.SPacketLevelTerminalUpdate.PacketOverwrite;
import static com.glodblock.github.network.SPacketLevelTerminalUpdate.PacketRemove;
import static com.glodblock.github.network.SPacketLevelTerminalUpdate.PacketRename;
import java.text.NumberFormat;
import java.util.ArrayList;
@@ -10,6 +17,7 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
@@ -26,6 +34,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
@@ -35,17 +45,16 @@ import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.api.registries.LevelItemInfo;
import com.glodblock.github.api.registries.LevelState;
import com.glodblock.github.client.gui.base.FCBaseMEGui;
import com.glodblock.github.client.gui.container.ContainerLevelTerminal;
import com.glodblock.github.common.tile.TileLevelMaintainer.State;
import com.glodblock.github.common.tile.TileLevelMaintainer.TLMTags;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.network.CPacketInventoryAction;
import com.glodblock.github.network.CPacketLevelTerminalCommands;
import com.glodblock.github.network.CPacketLevelTerminalCommands.Action;
import com.glodblock.github.network.CPacketRenamer;
import com.glodblock.github.network.SPacketLevelTerminalUpdate;
import com.glodblock.github.util.FCGuiColors;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.NameConst;
@@ -56,6 +65,7 @@ import appeng.api.config.TerminalFontSize;
import appeng.api.config.TerminalStyle;
import appeng.api.config.YesNo;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.IGuiTooltipHandler;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiScrollbar;
@@ -73,6 +83,7 @@ import appeng.core.localization.PlayerMessages;
import appeng.helpers.InventoryAction;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.Platform;
import appeng.util.ReadableNumberConverter;
import appeng.util.item.AEItemStack;
@@ -140,7 +151,6 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
};
searchFieldNames.setFocused(true);
extraOptionsText.add(ButtonToolTips.HighlightInterface.getLocal());
online = true;
}
public GuiLevelTerminal(final InventoryPlayer inventoryPlayer, final ITerminalHost te) {
@@ -174,6 +184,8 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
final int unusedSpace = height - ySize;
guiTop = (int) Math.floor(unusedSpace / (unusedSpace < 0 ? 3.8f : 2.0f));
// modeSwitchView = new GuiFCImgButton(guiLeft + xSize - 40, guiTop + 1, "SWITCH", "OFF", false);
// modeSwitchEdit = new GuiFCImgButton(guiLeft + xSize - 40, guiTop + 1, "SWITCH", "ON", false);
offsetY = guiTop + 8;
terminalStyleBox = new GuiImgButton(
guiLeft - 18,
@@ -278,6 +290,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
buttonList.add(terminalStyleBox);
buttonList.add(searchStringSave);
buttonList.add(craftingStatusBtn);
// buttonList.add(Objects.equals(currentMode, "OFF") ? modeSwitchView : modeSwitchEdit);
addSwitchGuiBtns();
super.drawScreen(mouseX, mouseY, btn);
@@ -309,6 +322,11 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
@Override
protected void actionPerformed(final GuiButton btn) {
// if (btn == modeSwitchView) {
// currentMode = "ON";
// } else if (btn == modeSwitchEdit) {
// currentMode = "OFF";
// } else
if (ModAndClassUtil.isSaveText && btn == searchStringSave) {
final boolean backwards = Mouse.isButtonDown(1);
@@ -548,21 +566,26 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
if (viewY + rowYBot <= titleBottom) {
continue;
}
AppEngInternalInventory inv = entry.getInventory();
for (int col = 0; col < entry.rowSize; ++col) {
final int colLeft = col * 18 + slotLeftMargin + 1;
final int colRight = colLeft + 18 + 1;
final int slotIdx = row * entry.rowSize + col;
LevelItemInfo info = entry.infoList[slotIdx];
ItemStack stack = inv.getStackInSlot(slotIdx);
boolean tooltip = relMouseX > colLeft - 1 && relMouseX < colRight - 1
&& relMouseY >= Math.max(viewY + rowYTop, LevelTerminalSection.TITLE_HEIGHT)
&& relMouseY < Math.min(viewY + rowYBot, viewHeight);
if (info != null) {
ItemStack itemStack = info.stack;
long quantity = info.quantity;
long batch = info.batchSize;
LevelState state = info.state;
if (stack != null) {
NBTTagCompound data = stack.getTagCompound();
ItemStack itemStack = data.hasKey(TLMTags.Stack.tagName)
? ItemStack.loadItemStackFromNBT(data.getCompoundTag(TLMTags.Stack.tagName))
: stack.copy();
long quantity = data.getLong(TLMTags.Quantity.tagName);
long batch = data.getLong(TLMTags.Batch.tagName);
State state = State.values()[data.getInteger(TLMTags.State.tagName)];
GL11.glPushMatrix();
GL11.glTranslatef(colLeft, viewY + rowYTop + 1, ITEM_STACK_Z);
@@ -585,7 +608,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
drawRect(offset, offset, offset + size, offset + size, color);
GL11.glTranslatef(0.0f, 0.0f, ITEM_STACK_OVERLAY_Z - ITEM_STACK_Z);
this.drawReadableAmount(fontRendererObj, quantity, true, 16777215);
if (batch >= 0) {
if (batch > 0) {
this.drawReadableAmount(fontRendererObj, batch, false, 16777215);
}
RenderHelper.disableStandardItemLighting();
@@ -599,7 +622,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
drawRect(0, 0, 16, 16, GuiColors.ItemSlotOverlayUnpowered.getColor());
}
} else {
tooltipStack = itemStack;
tooltipStack = stack;
}
GL11.glPopMatrix();
} else if (entry.filteredRecipes[slotIdx]) {
@@ -823,50 +846,58 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
&& mouseY < guiTop + HEADER_HEIGHT + viewHeight;
}
public void receivePackets(List<SPacketLevelTerminalUpdate.PacketEntry> packets) {
for (SPacketLevelTerminalUpdate.PacketEntry packet : packets) {
parsePacket(packet);
public void postUpdate(List<PacketEntry> updates, int statusFlags) {
if ((statusFlags & CLEAR_ALL_BIT) == CLEAR_ALL_BIT) {
/* Should clear all client entries. */
masterList.list.clear();
}
/* Should indicate disconnected, so the terminal turns dark. */
online = (statusFlags & DISCONNECT_BIT) != DISCONNECT_BIT;
for (PacketEntry cmd : updates) {
parsePacketCmd(cmd);
}
masterList.markDirty();
}
private void parsePacket(SPacketLevelTerminalUpdate.PacketEntry packet) {
if (packet instanceof SPacketLevelTerminalUpdate.PacketAdd packetAdd) {
private void parsePacketCmd(PacketEntry cmd) {
long id = cmd.entryId;
if (cmd instanceof PacketAdd addCmd) {
LevelTerminalEntry entry = new LevelTerminalEntry(
packetAdd.entryId,
packetAdd.name,
packetAdd.rows,
packetAdd.rowSize,
true).setLocation(packetAdd.x, packetAdd.y, packetAdd.z, packetAdd.dim, packetAdd.side)
.setInfoList(packetAdd.infolist);
this.masterList.addEntry(entry);
} else if (packet instanceof SPacketLevelTerminalUpdate.PacketRemove packetRemove) {
this.masterList.removeEntry(packetRemove.entryId);
} else if (packet instanceof SPacketLevelTerminalUpdate.PacketRename packetRename) {
LevelTerminalEntry entry = masterList.list.get(packetRename.entryId);
if (entry == null) return;
id,
addCmd.name,
addCmd.rows,
addCmd.rowSize,
addCmd.online).setLocation(addCmd.x, addCmd.y, addCmd.z, addCmd.dim, addCmd.side)
.setIcons(addCmd.selfItemStack, addCmd.displayItemStack).setItems(addCmd.items);
masterList.addEntry(entry);
} else if (cmd instanceof PacketRemove) {
masterList.removeEntry(id);
} else if (cmd instanceof PacketOverwrite owCmd) {
LevelTerminalEntry entry = masterList.list.get(id);
if (StatCollector.canTranslate(packetRename.newName)) {
entry.customName = StatCollector.translateToLocal(packetRename.newName);
} else {
entry.customName = StatCollector.translateToFallback(packetRename.newName);
if (entry == null) {
return;
}
if (owCmd.itemsValid) {
if (owCmd.allItemUpdate) {
entry.fullItemUpdate(owCmd.items, owCmd.validIndices.length);
} else {
entry.partialItemUpdate(owCmd.items, owCmd.validIndices);
}
}
masterList.isDirty = true;
} else if (packet instanceof SPacketLevelTerminalUpdate.PacketDisconnect) {
online = false;
}
} else if (cmd instanceof PacketRename renameCmd) {
LevelTerminalEntry entry = masterList.list.get(id);
else if (packet instanceof SPacketLevelTerminalUpdate.PacketOverwriteSlot packetOverwirteSlot) {
LevelTerminalEntry entry = masterList.list.get(packetOverwirteSlot.entryId);
if (entry == null) return;
entry.infoList[packetOverwirteSlot.index] = packetOverwirteSlot.info;
masterList.isDirty = true;
} else if (packet instanceof SPacketLevelTerminalUpdate.PacketOverwirteAllSlot packetOverwirteAllSlot) {
LevelTerminalEntry entry = masterList.list.get(packetOverwirteAllSlot.entryId);
if (entry == null) return;
entry.infoList = packetOverwirteAllSlot.infoList;
if (entry != null) {
if (StatCollector.canTranslate(renameCmd.newName)) {
entry.customName = StatCollector.translateToLocal(renameCmd.newName);
} else {
entry.customName = StatCollector.translateToFallback(renameCmd.newName);
}
}
masterList.isDirty = true;
}
}
@@ -901,23 +932,22 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
@Override
public List<String> handleItemTooltip(ItemStack stack, int mouseX, int mouseY, List<String> currentToolTip) {
if (stack == null || !isShiftKeyDown()) return currentToolTip;
for (LevelTerminalSection section : this.masterList.getVisibleSections()) {
for (LevelTerminalEntry entry : section.visibleEntries) {
for (LevelItemInfo info : entry.infoList) {
if (info != null && info.stack.equals(stack)) {
currentToolTip.add(
I18n.format(NameConst.TT_LEVEL_MAINTAINER_REQUEST_SIZE, "\n", false) + ": "
+ NumberFormat.getInstance().format(info.quantity));
if (stack != null && isShiftKeyDown() && stack.hasTagCompound()) {
NBTTagCompound data = stack.getTagCompound();
if (info.batchSize >= 0) {
currentToolTip.add(
I18n.format(NameConst.TT_LEVEL_MAINTAINER_BATCH_SIZE, "\n", false) + ": "
+ NumberFormat.getInstance().format(info.batchSize));
}
break;
}
if (data.hasKey(TLMTags.Quantity.tagName)) {
long quantity = data.getLong(TLMTags.Quantity.tagName);
long batch = data.getLong(TLMTags.Batch.tagName);
currentToolTip.add(
I18n.format(NameConst.TT_LEVEL_MAINTAINER_REQUEST_SIZE, "\n", false) + ": "
+ NumberFormat.getNumberInstance(Locale.US).format(quantity));
if (batch > 0) {
currentToolTip.add(
I18n.format(NameConst.TT_LEVEL_MAINTAINER_BATCH_SIZE, "\n", false) + ": "
+ NumberFormat.getNumberInstance(Locale.US).format(batch));
}
}
}
@@ -1072,7 +1102,13 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
String name;
List<LevelTerminalEntry> entries = new ArrayList<>();
Set<LevelTerminalEntry> visibleEntries = new TreeSet<>(Comparator.comparing(e -> e.customName + e.id));
Set<LevelTerminalEntry> visibleEntries = new TreeSet<>(Comparator.comparing(e -> {
if (e.displayItemStack != null) {
return e.displayItemStack.getDisplayName() + e.id;
} else {
return String.valueOf(e.id);
}
}));
int height;
private boolean isDirty = true;
boolean visible = false;
@@ -1112,22 +1148,18 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
entry.dispY = -9999;
// Find search terms
if (!output.isEmpty()) {
AppEngInternalInventory inv = entry.inv;
boolean shouldAdd = false;
for (int i = 0; i < entry.infoList.length; ++i) {
if (entry.infoList[i] == null) {
entry.filteredRecipes[i] = true;
continue;
}
if (itemStackMatchesSearchTerm(entry.infoList[i].stack, output)) {
for (int i = 0; i < inv.getSizeInventory(); ++i) {
ItemStack stack = inv.getStackInSlot(i);
if (itemStackMatchesSearchTerm(stack, output)) {
shouldAdd = true;
entry.filteredRecipes[i] = false;
} else {
entry.filteredRecipes[i] = true;
}
}
if (!shouldAdd) {
continue;
}
@@ -1175,9 +1207,12 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
private class LevelTerminalEntry {
String customName;
AppEngInternalInventory inv;
GuiFCImgButton highlightButton;
GuiFCImgButton renameButton;
GuiFCImgButton configButton;
/** Nullable - icon that represents the interface's "target" */
ItemStack displayItemStack;
LevelTerminalSection section;
long id;
int x, y, z, dim, side;
@@ -1185,8 +1220,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
int guiHeight;
int dispY = -9999;
boolean[] filteredRecipes;
LevelItemInfo[] infoList;
int numItems = 0;
LevelTerminalEntry(long id, String name, int rows, int rowSize, boolean online) {
this.id = id;
@@ -1202,6 +1236,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
customName = StatCollector.translateToFallback(name);
}
}
inv = new AppEngInternalInventory(null, rows * rowSize, 1);
highlightButton = new GuiFCImgButton(1, 0, "HIGHLIGHT", "YES");
renameButton = new GuiFCImgButton(1, 0, "EDIT", "YES");
configButton = new GuiFCImgButton(1, 0, "CONFIG", "YES");
@@ -1219,11 +1254,53 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
return this;
}
LevelTerminalEntry setInfoList(LevelItemInfo[] infoList) {
this.infoList = infoList;
LevelTerminalEntry setIcons(ItemStack selfItemStack, ItemStack displayItemStack) {
this.displayItemStack = displayItemStack;
return this;
}
public void fullItemUpdate(NBTTagList items, int newSize) {
inv = new AppEngInternalInventory(null, newSize);
rows = newSize / rowSize;
numItems = 0;
for (int i = 0; i < inv.getSizeInventory(); ++i) {
setItemInSlot(ItemStack.loadItemStackFromNBT(items.getCompoundTagAt(i)), i);
}
guiHeight = 18 * rows + 4;
}
LevelTerminalEntry setItems(NBTTagList items) {
assert items.tagCount() == inv.getSizeInventory();
for (int i = 0; i < items.tagCount(); ++i) {
setItemInSlot(ItemStack.loadItemStackFromNBT(items.getCompoundTagAt(i)), i);
}
return this;
}
public void partialItemUpdate(NBTTagList items, int[] validIndices) {
for (int i = 0; i < validIndices.length; ++i) {
setItemInSlot(ItemStack.loadItemStackFromNBT(items.getCompoundTagAt(i)), validIndices[i]);
}
}
private void setItemInSlot(ItemStack stack, int idx) {
final int oldHasItem = inv.getStackInSlot(idx) != null ? 1 : 0;
final int newHasItem = stack != null ? 1 : 0;
inv.setInventorySlotContents(idx, stack);
// Update item count
numItems += newHasItem - oldHasItem;
assert numItems >= 0;
}
public AppEngInternalInventory getInventory() {
return inv;
}
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (!section.visible || mouseButton < 0 || mouseButton > 2) {
return false;
@@ -1291,10 +1368,20 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
default -> null;// drop item:
};
if (action != null && this.infoList[slotIdx] != null) {
AEItemStack aeStack = AEItemStack.create(this.infoList[slotIdx].stack);
((AEBaseContainer) inventorySlots).setTargetStack(aeStack);
FluidCraft.proxy.netHandler.sendToServer(new CPacketInventoryAction(action, slotIdx, 0, aeStack));
if (action != null) {
ItemStack itemStack = getInventory().getStackInSlot(slotIdx);
if (itemStack != null && itemStack.hasTagCompound()
&& itemStack.getTagCompound().hasKey(TLMTags.Stack.tagName)) {
long batch = itemStack.getTagCompound().getLong(TLMTags.Batch.tagName);
NBTTagCompound stackData = itemStack.getTagCompound().getCompoundTag(TLMTags.Stack.tagName);
ItemStack is = ItemStack.loadItemStackFromNBT(stackData);
IAEItemStack stack = AEItemStack.create(is);
if (stack == null) return true;
stack.setStackSize(batch);
((AEBaseContainer) inventorySlots).setTargetStack(stack);
FluidCraft.proxy.netHandler.sendToServer(new CPacketInventoryAction(action, slotIdx, 0, stack));
}
}
return true;
@@ -0,0 +1,214 @@
/* Author: asdflj */
package com.glodblock.github.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerMagnetFilter;
import com.glodblock.github.client.gui.widget.FCGuiBaseButton;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.item.WirelessMagnet;
import com.glodblock.github.network.CPacketFluidPatternTermBtns;
import com.glodblock.github.util.NameConst;
import appeng.api.config.ActionItems;
import appeng.api.config.Settings;
import appeng.api.storage.ITerminalHost;
import appeng.client.gui.AEBaseMEGui;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.MEGuiTextField;
public class GuiMagnetFilter extends AEBaseMEGui {
protected FCGuiBaseButton listModeBtn;
protected ContainerMagnetFilter cont;
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/magnet_filter.png");
protected Component[] components = new Component[4];
protected MEGuiTextField oreDict;
protected GuiTabButton originalGuiBtn;
protected GuiImgButton clearBtn;
public GuiMagnetFilter(InventoryPlayer ip, ITerminalHost container) {
super(new ContainerMagnetFilter(ip, container));
this.xSize = 195;
this.ySize = 214;
this.cont = (ContainerMagnetFilter) this.inventorySlots;
oreDict = new MEGuiTextField(149, 12, NameConst.i18n(NameConst.TT_MAGNET_CARD_OREDICT));
}
private class Component {
private final GuiFCImgButton enable;
private final GuiFCImgButton disable;
private final String action;
private boolean var;
public Component(int x, int y, boolean var, String action) {
this.enable = new GuiFCImgButton(x, y, "ENABLE_12x", "ENABLE", false);
this.disable = new GuiFCImgButton(x, y, "DISABLE_12x", "DISABLE", false);
this.var = var;
this.action = action;
enable.setThreeFourths(true);
disable.setThreeFourths(true);
buttonList.add(this.enable);
buttonList.add(this.disable);
}
public boolean sameBtn(GuiButton btn) {
return btn == this.enable || btn == this.disable;
}
public boolean getVar() {
return this.var;
}
public void setVar(boolean var) {
this.var = var;
}
public void send() {
FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidPatternTermBtns(this.action, !this.getVar()));
}
public void draw() {
if (var) {
this.enable.visible = true;
this.disable.visible = false;
} else {
this.enable.visible = false;
this.disable.visible = true;
}
}
}
@Override
public void initGui() {
super.initGui();
this.buttonList.clear();
this.buttonList.add(
this.listModeBtn = new FCGuiBaseButton(
0,
this.guiLeft + 86,
this.guiTop + 4,
64,
14,
NameConst.i18n(
this.cont.listMode == WirelessMagnet.ListMode.WhiteList
? NameConst.GUI_MAGNET_CARD_WhiteList
: NameConst.GUI_MAGNET_CARD_BlackList)));
this.components[0] = new Component(
this.guiLeft + 157,
this.guiTop + 18,
this.cont.nbt,
"WirelessTerminal.magnet.NBT");
this.components[1] = new Component(
this.guiLeft + 157,
this.guiTop + 31,
this.cont.meta,
"WirelessTerminal.magnet.Meta");
this.components[2] = new Component(
this.guiLeft + 157,
this.guiTop + 44,
this.cont.ore,
"WirelessTerminal.magnet.Ore");
this.components[3] = new Component(
this.guiLeft + 157,
this.guiTop + 112,
this.cont.oreDict,
"WirelessTerminal.magnet.OreDictState");
oreDict.x = this.guiLeft + 7;
oreDict.y = this.guiTop + 112;
oreDict.setText(this.cont.oreDictFilter);
this.buttonList.add(
this.originalGuiBtn = new GuiTabButton(
this.guiLeft + this.xSize - 44,
this.guiTop - 4,
this.cont.getPortableCell().getItemStack(),
this.cont.getPortableCell().getItemStack().getDisplayName(),
itemRender));
this.originalGuiBtn.setHideEdge(13); // GuiTabButton implementation //
this.clearBtn = new GuiImgButton(this.guiLeft + 7, this.guiTop + 48, Settings.ACTIONS, ActionItems.CLOSE);
this.clearBtn.setHalfSize(true);
this.buttonList.add(this.clearBtn);
}
@Override
public void drawScreen(int mouseX, int mouseY, float btn) {
handleTooltip(mouseX, mouseY, oreDict);
super.drawScreen(mouseX, mouseY, btn);
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.fontRendererObj.drawString(NameConst.i18n(NameConst.GUI_MAGNET_CARD), 8, 6, 0x404040);
this.fontRendererObj.drawString(NameConst.i18n(NameConst.GUI_MAGNET_CARD_NBT), 61, 22, 0x404040);
this.fontRendererObj.drawString(NameConst.i18n(NameConst.GUI_MAGNET_CARD_META), 61, 34, 0x404040);
this.fontRendererObj.drawString(NameConst.i18n(NameConst.GUI_MAGNET_CARD_ORE), 61, 46, 0x404040);
this.components[0].setVar(this.cont.nbt);
this.components[1].setVar(this.cont.meta);
this.components[2].setVar(this.cont.ore);
this.components[3].setVar(this.cont.oreDict);
for (Component c : components) {
c.draw();
}
this.listModeBtn.displayString = NameConst.i18n(
this.cont.listMode == WirelessMagnet.ListMode.WhiteList ? NameConst.GUI_MAGNET_CARD_WhiteList
: NameConst.GUI_MAGNET_CARD_BlackList);
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
bindTexture(TEX_BG);
drawTexturedModalRect(offsetX, offsetY, 0, 0, xSize, ySize);
oreDict.drawTextBox();
}
@Override
protected void keyTyped(char typedChar, int keyCode) {
if (oreDict.isFocused() && (Keyboard.KEY_NUMPADENTER == keyCode || Keyboard.KEY_RETURN == keyCode)) {
FluidCraft.proxy.netHandler.sendToServer(
new CPacketFluidPatternTermBtns("WirelessTerminal.magnet.OreDictFilter", oreDict.getText()));
}
if (!oreDict.textboxKeyTyped(typedChar, keyCode)) super.keyTyped(typedChar, keyCode);
}
@Override
protected void mouseClicked(int xCoord, int yCoord, int btn) {
oreDict.mouseClicked(xCoord, yCoord, btn);
super.mouseClicked(xCoord, yCoord, btn);
}
@Override
protected void actionPerformed(GuiButton btn) {
for (Component c : components) {
if (c.sameBtn(btn)) {
c.send();
break;
}
}
if (btn == this.listModeBtn) {
FluidCraft.proxy.netHandler.sendToServer(
new CPacketFluidPatternTermBtns(
"WirelessTerminal.magnet.FilterMode",
this.cont.listMode != WirelessMagnet.ListMode.WhiteList));
} else if (btn == this.originalGuiBtn) {
InventoryHandler.switchGui(ItemWirelessUltraTerminal.readMode(this.cont.getPortableCell().getItemStack()));
} else if (btn == this.clearBtn) {
FluidCraft.proxy.netHandler
.sendToServer(new CPacketFluidPatternTermBtns("WirelessTerminal.magnet.clear", 1));
}
super.actionPerformed(btn);
}
}
@@ -9,7 +9,7 @@ import com.glodblock.github.client.gui.container.ContainerPatternValueAmount;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import com.glodblock.github.common.parts.PartFluidPatternTerminal;
import com.glodblock.github.common.parts.PartFluidPatternTerminalEx;
import com.glodblock.github.common.tile.TileSuperStockReplenisher;
import com.glodblock.github.common.tile.TileSuperStoker;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory;
@@ -77,9 +77,9 @@ public class GuiPatternValueAmount extends FCGuiAmount {
} else if (target instanceof WirelessPatternTerminalInventory) {
this.myIcon = ItemAndBlockHolder.WIRELESS_PATTERN_TERM.stack();
this.originalGui = GuiType.WIRELESS_FLUID_PATTERN_TERMINAL;
} else if (target instanceof TileSuperStockReplenisher) {
this.myIcon = ItemAndBlockHolder.SUPER_STOCK_RERPLENISHER.stack();
this.originalGui = GuiType.GUI_SUPER_STOCK_REPLENISHER;
} else if (target instanceof TileSuperStoker) {
this.myIcon = ItemAndBlockHolder.SUPER_STOKER.stack();
this.originalGui = GuiType.GUI_SUPER_STOKER;
}
}
@@ -11,9 +11,9 @@ import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerSuperStockReplenisher;
import com.glodblock.github.client.gui.container.ContainerSuperStoker;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.tile.TileSuperStockReplenisher;
import com.glodblock.github.common.tile.TileSuperStoker;
import com.glodblock.github.network.CPacketInventoryAction;
import appeng.api.storage.data.IAEItemStack;
@@ -25,17 +25,17 @@ import appeng.core.localization.GuiText;
import appeng.helpers.InventoryAction;
import appeng.util.item.AEItemStack;
public class GuiSuperStockReplenisher extends AEBaseGui {
public class GuiSuperStoker extends AEBaseGui {
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/superStockReplenisher.png");
private final ContainerSuperStockReplenisher cont;
private final TileSuperStockReplenisher tile;
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/superStoker.png");
private final ContainerSuperStoker cont;
private final TileSuperStoker tile;
private Map<Integer, IAEStack<?>> list = new HashMap<>();
public GuiSuperStockReplenisher(InventoryPlayer ipl, TileSuperStockReplenisher tile) {
super(new ContainerSuperStockReplenisher(ipl, tile));
public GuiSuperStoker(InventoryPlayer ipl, TileSuperStoker tile) {
super(new ContainerSuperStoker(ipl, tile));
this.tile = tile;
this.cont = (ContainerSuperStockReplenisher) inventorySlots;
this.cont = (ContainerSuperStoker) inventorySlots;
this.ySize = 251;
this.xSize = 216;
}
@@ -7,6 +7,7 @@ import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.GuiEssentiaTerminal;
import com.glodblock.github.client.gui.GuiFCImgButton;
import com.glodblock.github.client.gui.GuiFluidCraftingWireless;
@@ -18,8 +19,11 @@ import com.glodblock.github.client.gui.container.base.FCBaseContainer;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.inventory.item.WirelessMagnet;
import com.glodblock.github.network.CPacketFluidPatternTermBtns;
import com.glodblock.github.util.ModAndClassUtil;
import appeng.api.storage.StorageChannel;
import appeng.client.gui.AEBaseMEGui;
public abstract class FCBaseMEGui extends AEBaseMEGui {
@@ -31,8 +35,15 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
protected GuiFCImgButton InterfaceTerminal;
protected GuiFCImgButton LevelTerminal;
protected GuiFCImgButton PatternTerminalEx;
protected GuiFCImgButton magnetOff;
protected GuiFCImgButton magnetInv;
protected GuiFCImgButton magnetME;
protected GuiFCImgButton magnetFilter;
protected GuiFCImgButton restockEnableBtn;
protected GuiFCImgButton restockDisableBtn;
protected List<GuiFCImgButton> termBtns = new ArrayList<>();
protected boolean drawSwitchGuiBtn;
private StorageChannel channel = null;
public FCBaseMEGui(final InventoryPlayer inventoryPlayer, Container container) {
super(container);
@@ -41,10 +52,19 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
if (target instanceof IWirelessTerminal
&& ((IWirelessTerminal) target).getItemStack().getItem() instanceof ItemWirelessUltraTerminal) {
this.drawSwitchGuiBtn = true;
channel = ((IWirelessTerminal) target).getChannel();
}
}
}
protected WirelessMagnet.Mode getMagnetMode() {
return ((FCBaseContainer) this.inventorySlots).mode;
}
protected boolean isRestock() {
return ((FCBaseContainer) this.inventorySlots).restock;
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
@@ -65,6 +85,46 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
if (!termBtns.isEmpty()) {
this.termBtns.clear();
}
if (this.getMagnetMode() != null && this.channel == StorageChannel.ITEMS) {
this.buttonList.add(
this.magnetOff = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiTop + this.ySize - 124,
"MAGNET_CARD",
"OFF"));
this.buttonList.add(
this.magnetInv = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiTop + this.ySize - 124,
"MAGNET_CARD",
"INV"));
this.buttonList.add(
this.magnetME = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiTop + this.ySize - 124,
"MAGNET_CARD",
"ME"));
this.buttonList.add(
this.magnetFilter = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiTop + this.ySize - 104,
"MAGNET_CARD",
"FILTER"));
}
if (this.channel == StorageChannel.ITEMS) {
this.buttonList.add(
this.restockEnableBtn = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiTop + this.ySize - 84,
"RESTOCK",
"ENABLE"));
this.buttonList.add(
this.restockDisableBtn = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiTop + this.ySize - 84,
"RESTOCK",
"DISABLE"));
}
if (!(this instanceof GuiFluidCraftingWireless)) {
this.buttonList.add(
this.CraftingTerminal = new GuiFCImgButton(
@@ -154,6 +214,21 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
scheduleGuiResize = true;
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
if (isPortableCell()) return;
if (getMagnetMode() != null && this.channel == StorageChannel.ITEMS) {
GuiFCImgButton[] magnetButtons = { this.magnetOff, this.magnetInv, this.magnetME };
for (int i = 0; i < magnetButtons.length; i++) {
magnetButtons[i].visible = getMagnetMode().ordinal() == i;
}
}
if (this.drawSwitchGuiBtn && this.channel == StorageChannel.ITEMS) { // Only ultra terminal
this.restockDisableBtn.visible = !this.isRestock();
this.restockEnableBtn.visible = this.isRestock();
}
}
@Override
protected void actionPerformed(final GuiButton btn) {
if (btn instanceof GuiFCImgButton) {
@@ -171,8 +246,20 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_LEVEL_TERMINAL);
} else if (btn == this.PatternTerminalEx) {
ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_FLUID_PATTERN_TERMINAL_EX);
} else if (btn == this.magnetOff || btn == this.magnetME || btn == this.magnetInv) {
FluidCraft.proxy.netHandler.sendToServer(
new CPacketFluidPatternTermBtns("WirelessTerminal.MagnetMode", this.getMagnetMode().ordinal()));
} else if (btn == this.magnetFilter) {
FluidCraft.proxy.netHandler
.sendToServer(new CPacketFluidPatternTermBtns("WirelessTerminal.OpenMagnet", 0));
} else if (btn == this.restockDisableBtn || btn == this.restockEnableBtn) {
FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidPatternTermBtns("WirelessTerminal.Stock", 1));
}
}
super.actionPerformed(btn);
}
protected boolean isPortableCell() {
return false;
}
}
@@ -1,15 +1,20 @@
package com.glodblock.github.client.gui.container;
import java.util.Objects;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.tile.TileLevelMaintainer;
import com.glodblock.github.common.tile.TileLevelMaintainer.State;
import com.glodblock.github.common.tile.TileLevelMaintainer.TLMTags;
import com.glodblock.github.inventory.AeItemStackHandler;
import com.glodblock.github.inventory.slot.SlotFluidConvertingFake;
import com.glodblock.github.network.SPacketLevelMaintainerGuiUpdate;
import com.glodblock.github.util.Util;
import appeng.api.config.SecurityPermissions;
import appeng.container.AEBaseContainer;
@@ -21,10 +26,6 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
private final TileLevelMaintainer tile;
private final SlotFluidConvertingFake[] requestSlots = new SlotFluidConvertingFake[TileLevelMaintainer.REQ_COUNT];
private static final int UPDATE_INTERVAL = 20;
private boolean isFirstUpdate = true;
private int updateCount = UPDATE_INTERVAL;
public ContainerLevelMaintainer(InventoryPlayer ipl, TileLevelMaintainer tile) {
super(ipl, tile);
this.tile = tile;
@@ -47,14 +48,49 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
@Override
public void doAction(EntityPlayerMP player, InventoryAction action, int slotId, long id) {
if (getSlot(slotId) instanceof SlotFluidConvertingFake slot) {
Slot slot = getSlot(slotId);
if (slot instanceof SlotFluidConvertingFake) {
final ItemStack stack = player.inventory.getItemStack();
switch (action) {
case PICKUP_OR_SET_DOWN, PLACE_SINGLE, SPLIT_OR_PLACE_SINGLE -> {
case PICKUP_OR_SET_DOWN -> {
if (stack == null) {
slot.putStack(null);
} else {
slot.putConvertedStack(stack);
((SlotFluidConvertingFake) slot).putConvertedStack(createLevelValues(stack.copy()));
}
}
case PLACE_SINGLE -> {
if (stack != null) {
((SlotFluidConvertingFake) slot).putConvertedStack(
createLevelValues(Objects.requireNonNull(Util.copyStackWithSize(stack, 1))));
}
}
case SPLIT_OR_PLACE_SINGLE -> {
ItemStack inSlot = slot.getStack();
if (inSlot != null) {
if (stack == null) {
slot.putStack(
createLevelValues(
Objects.requireNonNull(
Util.copyStackWithSize(
inSlot,
Math.max(1, inSlot.stackSize - 1)))));
} else if (stack.isItemEqual(inSlot)) {
slot.putStack(
createLevelValues(
Objects.requireNonNull(
Util.copyStackWithSize(
inSlot,
Math.min(
inSlot.getMaxStackSize(),
inSlot.stackSize + 1)))));
} else {
((SlotFluidConvertingFake) slot).putConvertedStack(
createLevelValues(Objects.requireNonNull(Util.copyStackWithSize(stack, 1))));
}
} else if (stack != null) {
((SlotFluidConvertingFake) slot).putConvertedStack(
createLevelValues(Objects.requireNonNull(Util.copyStackWithSize(stack, 1))));
}
}
default -> {}
@@ -73,8 +109,10 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
for (int i = 0; i < this.getRequestSlots().length; i++) {
SlotFluidConvertingFake slot = this.getRequestSlots()[i];
if (!slot.getHasStack()) {
ItemStack itemStack = this.inventorySlots.get(idx).getStack();
tile.updateStack(i, itemStack.copy());
ItemStack itemStack = ((Slot) this.inventorySlots.get(idx)).getStack();
ItemStack configuration = createLevelValues(itemStack.copy());
configuration.getTagCompound().setInteger(TLMTags.Index.tagName, i);
slot.putConvertedStack(configuration);
break;
}
}
@@ -85,23 +123,35 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (Platform.isClient()) {
return;
}
this.verifyPermissions(SecurityPermissions.BUILD, false);
if (this.updateCount++ >= UPDATE_INTERVAL) {
this.updateGui();
}
super.detectAndSendChanges();
}
public void updateGui() {
FluidCraft.proxy.netHandler.sendTo(
new SPacketLevelMaintainerGuiUpdate(this.tile.requests, !this.isFirstUpdate),
(EntityPlayerMP) this.getInventoryPlayer().player);
this.isFirstUpdate = false;
this.updateCount = 0;
public static ItemStack createLevelValues(ItemStack itemStack) {
var data = itemStack.hasTagCompound() ? itemStack.getTagCompound() : new NBTTagCompound();
if (!data.hasKey(TLMTags.Stack.tagName)) {
var itemStackTag = new NBTTagCompound();
itemStack.copy().writeToNBT(itemStackTag);
data.setTag(TLMTags.Stack.tagName, itemStackTag);
}
if (!data.hasKey(TLMTags.Quantity.tagName)) {
data.setLong(TLMTags.Quantity.tagName, itemStack.stackSize > 0 ? itemStack.stackSize : 1);
}
if (!data.hasKey(TLMTags.Batch.tagName)) {
data.setLong(TLMTags.Batch.tagName, 1);
}
if (!data.hasKey(TLMTags.Enable.tagName)) {
data.setBoolean(TLMTags.Enable.tagName, false);
}
if (data.hasKey(TLMTags.Index.tagName)) {
data.removeTag(TLMTags.Index.tagName);
}
data.setInteger(TLMTags.State.tagName, State.None.ordinal());
itemStack.setTagCompound(data);
return itemStack;
}
}
@@ -1,27 +1,30 @@
package com.glodblock.github.client.gui.container;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.ForgeDirection;
import org.jetbrains.annotations.Nullable;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.api.registries.ILevelViewable;
import com.glodblock.github.api.registries.LevelItemInfo;
import com.glodblock.github.client.gui.container.base.FCBaseContainer;
import com.glodblock.github.common.parts.PartLevelTerminal;
import com.glodblock.github.coremod.registries.LevelTerminalRegistry;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.network.SPacketLevelTerminalUpdate;
import com.google.common.primitives.Ints;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
@@ -29,7 +32,12 @@ import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionHost;
import appeng.api.storage.ITerminalHost;
import appeng.api.util.DimensionalCoord;
import appeng.helpers.InventoryAction;
import appeng.items.misc.ItemEncodedPattern;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorPlayerHand;
import appeng.util.inv.ItemSlot;
public class ContainerLevelTerminal extends FCBaseContainer {
@@ -42,8 +50,8 @@ public class ContainerLevelTerminal extends FCBaseContainer {
private final Map<Long, ContainerLevelTerminal.InvTracker> trackedById = new HashMap<>();
private IGrid grid;
private SPacketLevelTerminalUpdate updatePacket;
private boolean isPacketDirty;
private SPacketLevelTerminalUpdate dirty;
private boolean isDirty;
private boolean wasOff;
private int ticks = 0;
@@ -55,13 +63,11 @@ public class ContainerLevelTerminal extends FCBaseContainer {
} else if (monitorable instanceof IWirelessTerminal wirelessTerminal) {
grid = wirelessTerminal.getActionableNode().getGrid();
}
updatePacket = this.updateList();
if (updatePacket != null) {
this.isPacketDirty = true;
dirty = this.updateList();
if (dirty != null) {
this.isDirty = true;
} else {
updatePacket = new SPacketLevelTerminalUpdate();
this.isPacketDirty = false;
dirty = new SPacketLevelTerminalUpdate();
}
}
@@ -86,7 +92,7 @@ public class ContainerLevelTerminal extends FCBaseContainer {
if (!wasOff) {
SPacketLevelTerminalUpdate update = new SPacketLevelTerminalUpdate();
update.addDisconnectEntry();
update.setDisconnect();
wasOff = true;
FluidCraft.proxy.netHandler.sendTo(update, (EntityPlayerMP) this.getPlayerInv().player);
}
@@ -94,20 +100,149 @@ public class ContainerLevelTerminal extends FCBaseContainer {
}
wasOff = false;
if (isPacketDirty) {
FluidCraft.proxy.netHandler.sendTo(updatePacket, (EntityPlayerMP) this.getPlayerInv().player);
updatePacket = new SPacketLevelTerminalUpdate();
isPacketDirty = false;
if (isDirty) {
FluidCraft.proxy.netHandler.sendTo(dirty, (EntityPlayerMP) this.getPlayerInv().player);
dirty = new SPacketLevelTerminalUpdate();
isDirty = false;
} else if (++ticks % 20 == 0) {
ticks = 0;
SPacketLevelTerminalUpdate updateNew = this.updateList();
if (updateNew != null) {
FluidCraft.proxy.netHandler.sendTo(updateNew, (EntityPlayerMP) this.getPlayerInv().player);
SPacketLevelTerminalUpdate update = this.updateList();
if (update != null) {
FluidCraft.proxy.netHandler.sendTo(update, (EntityPlayerMP) this.getPlayerInv().player);
}
}
}
@Nullable
/**
* Merge from slot -> player inv. Returns the items not added.
*/
private ItemStack mergeToPlayerInventory(InventoryAdaptor playerInv, ItemStack stack) {
if (stack == null) return null;
for (ItemSlot slot : playerInv) {
if (Platform.isSameItemPrecise(slot.getItemStack(), stack)) {
if (slot.getItemStack().stackSize < slot.getItemStack().getMaxStackSize()) {
++slot.getItemStack().stackSize;
return null;
}
}
}
return playerInv.addItems(stack);
}
@Override
public void doAction(final EntityPlayerMP player, final InventoryAction action, final int slotIdx, final long id) {
final ContainerLevelTerminal.InvTracker invTracker = this.trackedById.get(id);
if (invTracker != null) {
final ItemStack handStack = player.inventory.getItemStack();
if (handStack != null && !(handStack.getItem() instanceof ItemEncodedPattern)) {
// Why even bother if we're not dealing with an encoded pattern in hand
return;
}
final ItemStack slotStack = invTracker.requests.getStackInSlot(slotIdx);
final InventoryAdaptor playerHand = new AdaptorPlayerHand(player);
switch (action) {
/* Set down/pickup. This is the same as SPLIT_OR_PLACE_SINGLE as our max stack sizes are 1 in slots. */
case PICKUP_OR_SET_DOWN -> {
if (handStack != null) {
for (int s = 0; s < invTracker.requests.getSizeInventory(); s++) {
/* Is there a duplicate pattern here? */
if (Platform.isSameItemPrecise(invTracker.requests.getStackInSlot(s), handStack)) {
/* We're done here - dupe found. */
return;
}
}
}
if (slotStack == null) {
/* Insert to container, if valid */
if (handStack == null) {
/* Nothing happens */
return;
}
invTracker.requests.setInventorySlotContents(slotIdx, playerHand.removeItems(1, null, null));
} else {
/* Exchange? */
if (handStack != null && handStack.stackSize > 1) {
/* Exchange is impossible, abort */
return;
}
invTracker.requests.setInventorySlotContents(slotIdx, playerHand.removeItems(1, null, null));
playerHand.addItems(slotStack.copy());
}
syncLevelTerminalSlot(invTracker, id, slotIdx, invTracker.requests.getStackInSlot(slotIdx));
}
/* Shift click from slotIdx -> player. Player -> slotIdx is not supported. */
case SHIFT_CLICK -> {
InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor(player.inventory, ForgeDirection.UNKNOWN);
ItemStack leftOver = mergeToPlayerInventory(playerInv, slotStack);
if (leftOver == null) {
invTracker.requests.setInventorySlotContents(slotIdx, null);
syncLevelTerminalSlot(invTracker, id, slotIdx, null);
}
}
/* Move all blank patterns -> player */
case MOVE_REGION -> {
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN);
List<Integer> valid = new ArrayList<>();
for (int i = 0; i < invTracker.requests.getSizeInventory(); i++) {
ItemStack toExtract = invTracker.requests.getStackInSlot(i);
if (toExtract == null) {
continue;
}
ItemStack leftOver = mergeToPlayerInventory(playerInv, toExtract);
if (leftOver != null) {
break;
} else {
invTracker.requests.setInventorySlotContents(i, null);
}
valid.add(i);
}
if (!valid.isEmpty()) {
int[] validIndices = Ints.toArray(valid);
NBTTagList tag = new NBTTagList();
for (int i = 0; i < valid.size(); ++i) {
tag.appendTag(new NBTTagCompound());
}
dirty.addOverwriteEntry(id).setItems(validIndices, tag);
isDirty = true;
}
}
case CREATIVE_DUPLICATE -> {
if (player.capabilities.isCreativeMode) {
playerHand.addItems(handStack);
}
}
default -> {
return;
}
}
this.updateHeld(player);
}
}
private void syncLevelTerminalSlot(ContainerLevelTerminal.InvTracker inv, long id, int slot, ItemStack stack) {
int[] validIndices = { slot };
NBTTagList list = new NBTTagList();
NBTTagCompound item = new NBTTagCompound();
if (stack != null) {
stack.writeToNBT(item);
}
list.appendTag(item);
inv.updateNBT();
this.dirty.addOverwriteEntry(id).setItems(validIndices, list);
this.isDirty = true;
}
private SPacketLevelTerminalUpdate updateList() {
SPacketLevelTerminalUpdate update = null;
var supported = LevelTerminalRegistry.instance().getSupportedClasses();
@@ -122,67 +257,64 @@ public class ContainerLevelTerminal extends FCBaseContainer {
final ILevelViewable machine = isAdopted
? LevelTerminalRegistry.instance().getAdapter(clz).adapt(gridHost)
: (ILevelViewable) gridHost;
visited.add(gridHost);
/* First check if we are already tracking this node */
if (tracked.containsKey(gridHost)) {
/* Check for updates */
ContainerLevelTerminal.InvTracker knownTracker = tracked.get(gridHost);
/* Name changed? */
String name = machine.getCustomName();
if (!Objects.equals(knownTracker.name, name)) {
knownTracker.name = name;
if (update == null) update = new SPacketLevelTerminalUpdate();
update.addRenameEntry(knownTracker.id, name);
update.addRenamedEntry(knownTracker.id, name);
knownTracker.name = name;
}
LevelItemInfo[] prev = knownTracker.infoList;
LevelItemInfo[] curr = machine.getLevelItemInfoList();
if (prev.length == curr.length) {
for (int i = 0; i < prev.length; i++) {
if (prev[i] == null && curr[i] == null) continue;
/* Status changed? */
boolean isActive = gridNode.isActive() || machine.shouldDisplay();
if (prev[i] == null) {
knownTracker.infoList[i] = curr[i];
if (update == null) update = new SPacketLevelTerminalUpdate();
update.addOverwriteSlotEntry(knownTracker.id, i, curr[i]);
} else if (curr[i] == null) {
knownTracker.infoList[i] = null;
if (update == null) update = new SPacketLevelTerminalUpdate();
update.addOverwriteSlotEntry(knownTracker.id, i, null);
} else if (!ItemStack.areItemStacksEqual(prev[i].stack, curr[i].stack)
|| prev[i].quantity == curr[i].quantity
|| prev[i].batchSize == curr[i].batchSize
|| prev[i].state == curr[i].state) {
knownTracker.infoList[i] = curr[i];
if (update == null) update = new SPacketLevelTerminalUpdate();
update.addOverwriteSlotEntry(knownTracker.id, i, curr[i]);
}
}
} else {
knownTracker.infoList = curr;
if (!knownTracker.online && isActive) {
/* Node offline -> online */
knownTracker.online = true;
if (update == null) update = new SPacketLevelTerminalUpdate();
update.addOverwriteAllSlotEntry(knownTracker.id, curr);
knownTracker.updateNBT();
update.addOverwriteEntry(knownTracker.id).setOnline(true)
.setItems(knownTracker.requests.getSizeInventory(), knownTracker.inventoryNbt);
} else if (knownTracker.online && !isActive) {
/* Node online -> offline */
knownTracker.online = false;
if (update == null) update = new SPacketLevelTerminalUpdate();
update.addOverwriteEntry(knownTracker.id).setOnline(false);
}
for (int i = 0; i < knownTracker.requests.getSizeInventory(); i++) {
ItemStack knowmItemStack = ItemStack
.loadItemStackFromNBT(knownTracker.inventoryNbt.getCompoundTagAt(i));
ItemStack machineItemStack = machine.getInventoryByName("config").getStackInSlot(i);
if (isDifferent(knowmItemStack, machineItemStack)) {
if (update == null) update = new SPacketLevelTerminalUpdate();
knownTracker.updateNBT();
update.addOverwriteEntry(knownTracker.id)
.setItems(knownTracker.requests.getSizeInventory(), knownTracker.inventoryNbt);
}
}
} else {
/* Add a new entry */
if (update == null) update = new SPacketLevelTerminalUpdate();
ContainerLevelTerminal.InvTracker entry = new ContainerLevelTerminal.InvTracker(nextId++, machine);
update.addNewEntry(
entry.id,
entry.x,
entry.y,
entry.z,
entry.dim,
entry.side.ordinal(),
entry.rows,
entry.rowSize,
entry.name,
entry.infoList);
ContainerLevelTerminal.InvTracker entry = new ContainerLevelTerminal.InvTracker(
nextId++,
machine,
gridNode.isActive());
update.addNewEntry(entry.id, entry.name, entry.online)
.setLocation(entry.x, entry.y, entry.z, entry.dim, entry.side.ordinal())
.setItems(entry.rows, entry.rowSize, entry.inventoryNbt)
.setViewItemStack(machine.getSelfItemStack(), machine.getDisplayItemStack());
tracked.put(gridHost, entry);
trackedById.put(entry.id, entry);
}
visited.add(gridHost);
}
}
@@ -195,9 +327,10 @@ public class ContainerLevelTerminal extends FCBaseContainer {
}
if (update == null) update = new SPacketLevelTerminalUpdate();
update.addRemoveEntry(entry.getValue().id);
trackedById.remove(entry.getValue().id);
it.remove();
update.addRemovalEntry(entry.getValue().id);
}
return update;
}
@@ -207,10 +340,23 @@ public class ContainerLevelTerminal extends FCBaseContainer {
return false;
}
private boolean isDifferent(final ItemStack a, final ItemStack b) {
if (a == null && b == null) {
return false;
}
if (a == null || b == null) {
return true;
}
return !ItemStack.areItemStacksEqual(a, b);
}
private static class InvTracker {
private final long id;
private String name;
private final IInventory requests;
private final int rowSize;
private final int rows;
private final int x;
@@ -218,15 +364,16 @@ public class ContainerLevelTerminal extends FCBaseContainer {
private final int z;
private final int dim;
private final ForgeDirection side;
private boolean online;
private NBTTagList inventoryNbt;
private LevelItemInfo[] infoList;
public InvTracker(long id, ILevelViewable machine) {
public InvTracker(long id, ILevelViewable machine, boolean online) {
DimensionalCoord location = machine.getLocation();
this.id = id;
this.name = machine.getCustomName();
this.requests = machine.getInventoryByName("config");
this.rowSize = machine.rowSize();
this.rows = machine.rows();
this.x = location.x;
@@ -234,8 +381,26 @@ public class ContainerLevelTerminal extends FCBaseContainer {
this.z = location.z;
this.dim = location.getDimension();
this.side = machine.getSide();
this.infoList = machine.getLevelItemInfoList();
this.online = online;
this.inventoryNbt = new NBTTagList();
updateNBT();
}
private void updateNBT() {
this.inventoryNbt = new NBTTagList();
for (int i = 0; i < this.rows; ++i) {
for (int j = 0; j < this.rowSize; ++j) {
final int offset = this.rowSize * i;
ItemStack stack = this.requests.getStackInSlot(offset + j);
if (stack != null) {
this.inventoryNbt.appendTag(stack.writeToNBT(new NBTTagCompound()));
} else {
this.inventoryNbt.appendTag(new NBTTagCompound());
}
}
}
}
}
}
@@ -0,0 +1,107 @@
/* Author: asdflj */
package com.glodblock.github.client.gui.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import com.glodblock.github.client.gui.container.base.FCBaseContainer;
import com.glodblock.github.inventory.item.IItemTerminal;
import com.glodblock.github.inventory.item.IWirelessMagnetFilter;
import com.glodblock.github.inventory.item.WirelessMagnet;
import appeng.api.storage.ITerminalHost;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.AppEngSlot;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.SlotFake;
import appeng.container.slot.SlotPatternOutputs;
import appeng.util.Platform;
public class ContainerMagnetFilter extends FCBaseContainer implements IOptionalSlotHost {
@GuiSync(101)
public WirelessMagnet.ListMode listMode;
@GuiSync(102)
public boolean nbt;
@GuiSync(103)
public boolean meta;
@GuiSync(104)
public boolean ore;
@GuiSync(105)
public boolean oreDict;
@GuiSync(106)
public String oreDictFilter;
protected OptionalSlotFake[] filterSlots;
protected final IInventory filter;
public ContainerMagnetFilter(InventoryPlayer ip, ITerminalHost monitorable) {
super(ip, monitorable);
this.filter = ((IItemTerminal) monitorable).getInventoryByName("config");
this.filterSlots = new OptionalSlotFake[27];
oreDictFilter = ((IWirelessMagnetFilter) getHost()).getOreDictFilter();
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 9; x++) {
this.addSlotToContainer(
this.filterSlots[x + y * 9] = new SlotPatternOutputs(
this.filter,
this,
x + y * 9,
8 + x * 18,
58 + y * 18,
0,
0,
1));
this.filterSlots[x + y * 9].setRenderDisabled(false);
}
}
bindPlayerInventory(ip, 0, 126);
}
@Override
protected boolean isWirelessTerminal() {
return true;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer p, int idx) {
AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx);
if (clickSlot == null || !clickSlot.getHasStack()) return null;
ItemStack tis = clickSlot.getStack();
for (SlotFake slot : this.filterSlots) {
if (!slot.getHasStack()) {
slot.putStack(tis);
detectAndSendChanges();
break;
}
}
return super.transferStackInSlot(p, idx);
}
@Override
public void detectAndSendChanges() {
if (Platform.isServer() && this.getPortableCell() instanceof IWirelessMagnetFilter) {
IWirelessMagnetFilter host = (IWirelessMagnetFilter) this.getHost();
this.listMode = host.getListMode();
this.meta = host.getMetaMode();
this.nbt = host.getNBTMode();
this.ore = host.getOreMode();
this.oreDict = host.getOreDictMode();
this.oreDictFilter = host.getOreDictFilter();
}
super.detectAndSendChanges();
}
@Override
public boolean isSlotEnabled(int idx) {
return true;
}
}
@@ -13,9 +13,9 @@ import net.minecraft.item.ItemStack;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.FCBaseItemCell;
import com.glodblock.github.common.tile.TileSuperStockReplenisher;
import com.glodblock.github.common.tile.TileSuperStoker;
import com.glodblock.github.inventory.slot.OptionalFluidSlotFake;
import com.glodblock.github.network.SPacketSuperStockReplenisherUpdate;
import com.glodblock.github.network.SPacketSuperStokerUpdate;
import appeng.api.storage.data.IAEStack;
import appeng.container.AEBaseContainer;
@@ -24,14 +24,14 @@ import appeng.container.slot.SlotPatternOutputs;
import appeng.container.slot.SlotRestrictedInput;
import appeng.items.storage.ItemBasicStorageCell;
public class ContainerSuperStockReplenisher extends AEBaseContainer implements IOptionalSlotHost {
public class ContainerSuperStoker extends AEBaseContainer implements IOptionalSlotHost {
private final TileSuperStockReplenisher tile;
private final TileSuperStoker tile;
private final IInventory configFluids;
private final IInventory configItems;
private int lastUpdated = 0;
public ContainerSuperStockReplenisher(InventoryPlayer ipl, TileSuperStockReplenisher tile) {
public ContainerSuperStoker(InventoryPlayer ipl, TileSuperStoker tile) {
super(ipl, tile);
this.tile = tile;
configFluids = tile.getConfigFluid();
@@ -101,7 +101,7 @@ public class ContainerSuperStockReplenisher extends AEBaseContainer implements I
for (final Object g : this.crafters) {
if (g instanceof EntityPlayer) {
FluidCraft.proxy.netHandler.sendTo(new SPacketSuperStockReplenisherUpdate(tmp), (EntityPlayerMP) g);
FluidCraft.proxy.netHandler.sendTo(new SPacketSuperStokerUpdate(tmp), (EntityPlayerMP) g);
}
}
}
@@ -147,7 +147,7 @@ public class ContainerSuperStockReplenisher extends AEBaseContainer implements I
return super.isValidForSlot(s, is);
}
public TileSuperStockReplenisher getTile() {
public TileSuperStoker getTile() {
return tile;
}
}
@@ -3,32 +3,42 @@ package com.glodblock.github.client.gui.container.base;
import net.minecraft.entity.player.InventoryPlayer;
import com.glodblock.github.inventory.item.IFluidPortableCell;
import com.glodblock.github.inventory.item.IWirelessExtendCard;
import com.glodblock.github.inventory.item.WirelessMagnet;
import com.glodblock.github.util.Util;
import appeng.api.storage.ITerminalHost;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.util.Platform;
public abstract class FCBaseContainer extends AEBaseContainer {
private int ticks;
private final double powerMultiplier = 0.5;
private IFluidPortableCell host;
private ITerminalHost host;
private int slot = -1;
private final InventoryPlayer ip;
@GuiSync(105)
public boolean restock = false;
@GuiSync(106)
public WirelessMagnet.Mode mode = WirelessMagnet.Mode.Off;
public FCBaseContainer(InventoryPlayer ip, ITerminalHost monitorable) {
super(ip, monitorable);
this.ip = ip;
this.host = monitorable;
if (isWirelessTerminal()) {
host = (IFluidPortableCell) monitorable;
this.slot = lockSlot();
}
}
private int lockSlot() {
if (isWirelessTerminal()) {
if (this.host != null) {
final int slotIndex = this.host.getInventorySlot();
if (this.host instanceof IFluidPortableCell) {
final int slotIndex = ((IFluidPortableCell) this.host).getInventorySlot();
if (Util.GuiHelper.decodeInvType(slotIndex).getLeft() == Util.GuiHelper.InvType.PLAYER_INV) {
this.lockPlayerInventorySlot(slotIndex);
}
@@ -50,7 +60,14 @@ public abstract class FCBaseContainer extends AEBaseContainer {
this.slot,
this.ticks,
this.getPowerMultiplier(),
this.host);
((IFluidPortableCell) this.host));
}
if (Platform.isServer()) {
if (this.host instanceof IWirelessExtendCard wec) {
this.mode = wec.getMagnetCardMode();
this.restock = wec.isRestock();
}
}
super.detectAndSendChanges();
}
@@ -59,4 +76,14 @@ public abstract class FCBaseContainer extends AEBaseContainer {
return this.powerMultiplier;
}
public ITerminalHost getHost() {
return this.host;
}
public IFluidPortableCell getPortableCell() {
if (this.host instanceof IFluidPortableCell fpc) {
return fpc;
}
return null;
}
}
@@ -230,8 +230,4 @@ public abstract class FCContainerMonitor<T extends IAEStack<T>> extends FCBaseCo
this.getGui().updateSetting(manager, settingName, newValue);
}
}
public ITerminalHost getHost() {
return this.host;
}
}
@@ -22,6 +22,8 @@ public class Config {
public static boolean replaceEC2;
public static int levelMaintainerMinTicks;
public static int levelMaintainerMaxTicks;
public static int reStockTime;
public static int magnetRange;
public static void run() {
loadCategory();
@@ -74,6 +76,9 @@ public class Config {
levelMaintainerMaxTicks = Config.get("LevelMaintainer", "maxTick", 120, "Number on ticks for maximal request")
.getInt();
reStockTime = Config.get("UltraWireless", "reStockTime", 1000, "Time between restocks").getInt();
magnetRange = Config.get("UltraWireless", "magnetRange", 16, "Magnet pick up radius").getInt();
if (Config.hasChanged()) Config.save();
}
@@ -7,7 +7,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.common.tile.TileSuperStockReplenisher;
import com.glodblock.github.common.tile.TileSuperStoker;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.util.BlockPos;
@@ -16,11 +16,11 @@ import com.glodblock.github.util.NameConst;
import appeng.block.AEBaseItemBlock;
import cpw.mods.fml.common.registry.GameRegistry;
public class BlockSuperStockReplenisher extends FCBaseBlock {
public class BlockSuperStoker extends FCBaseBlock {
public BlockSuperStockReplenisher() {
super(Material.web, NameConst.BLOCK_SUPER_STOCK_REPLENISHER);
setTileEntity(TileSuperStockReplenisher.class);
public BlockSuperStoker() {
super(Material.web, NameConst.BLOCK_SUPER_STOKER);
setTileEntity(TileSuperStoker.class);
setOpaque(false);
setFullBlock(false);
this.lightOpacity = 4;
@@ -32,7 +32,7 @@ public class BlockSuperStockReplenisher extends FCBaseBlock {
if (player.isSneaking()) {
return false;
}
TileSuperStockReplenisher tile = getTileEntity(world, x, y, z);
TileSuperStoker tile = getTileEntity(world, x, y, z);
if (tile != null) {
if (!world.isRemote) {
InventoryHandler.openGui(
@@ -40,7 +40,7 @@ public class BlockSuperStockReplenisher extends FCBaseBlock {
world,
new BlockPos(x, y, z),
ForgeDirection.getOrientation(facing),
GuiType.GUI_SUPER_STOCK_REPLENISHER);
GuiType.GUI_SUPER_STOKER);
}
return true;
}
@@ -49,7 +49,7 @@ public class BlockSuperStockReplenisher extends FCBaseBlock {
@Override
public void breakBlock(World w, int x, int y, int z, Block a, int b) {
final TileSuperStockReplenisher tss = this.getTileEntity(w, x, y, z);
final TileSuperStoker tss = this.getTileEntity(w, x, y, z);
if (tss != null) {
tss.fullRefund();
}
@@ -57,9 +57,9 @@ public class BlockSuperStockReplenisher extends FCBaseBlock {
}
@Override
public BlockSuperStockReplenisher register() {
GameRegistry.registerBlock(this, AEBaseItemBlock.class, NameConst.BLOCK_SUPER_STOCK_REPLENISHER);
GameRegistry.registerTileEntity(TileSuperStockReplenisher.class, NameConst.BLOCK_SUPER_STOCK_REPLENISHER);
public BlockSuperStoker register() {
GameRegistry.registerBlock(this, AEBaseItemBlock.class, NameConst.BLOCK_SUPER_STOKER);
GameRegistry.registerTileEntity(TileSuperStoker.class, NameConst.BLOCK_SUPER_STOKER);
setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
@@ -10,6 +10,7 @@ import java.util.List;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@@ -36,6 +37,8 @@ public class ItemBaseWirelessTerminal extends ToolWirelessTerminal implements II
protected GuiType type;
public static String infinityBoosterCard = "infinityBoosterCard";
public static String infinityEnergyCard = "InfinityEnergyCard";
public static String restockItems = "restock";
private static boolean effect = false;
public ItemBaseWirelessTerminal(GuiType t) {
super();
@@ -48,6 +51,7 @@ public class ItemBaseWirelessTerminal extends ToolWirelessTerminal implements II
// terminal
if (ForgeEventFactory.onItemUseStart(player, item, 1) > 0) {
if (Platform.isClient()) {
setEffect(false);
return item;
}
IWirelessTermRegistry term = AEApi.instance().registries().wireless();
@@ -131,4 +135,24 @@ public class ItemBaseWirelessTerminal extends ToolWirelessTerminal implements II
return this.type;
}
public static void setEffect(boolean e) {
effect = e;
}
public static boolean getEffect() {
return effect;
}
@Override
public boolean hasEffect(ItemStack par1ItemStack, int pass) {
if (Platform.isClient()) {
return getEffect();
}
return super.hasEffect(par1ItemStack, pass);
}
public static void toggleRestockItemsMode(ItemStack is, boolean state) {
NBTTagCompound data = Platform.openNbtData(is);
data.setBoolean(restockItems, state);
}
}
@@ -25,6 +25,7 @@ import com.glodblock.github.inventory.item.WirelessCraftingTerminalInventory;
import com.glodblock.github.inventory.item.WirelessFluidTerminalInventory;
import com.glodblock.github.inventory.item.WirelessInterfaceTerminalInventory;
import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory;
import com.glodblock.github.inventory.item.WirelessMagnetCardFilterInventory;
import com.glodblock.github.inventory.item.WirelessPatternTerminalExInventory;
import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory;
import com.glodblock.github.loader.IRegister;
@@ -102,7 +103,9 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal
try {
IGridNode gridNode = Util.getWirelessGrid(stack);
final GuiType gui;
if (Util.GuiHelper.decodeType(y).getLeft() == Util.GuiHelper.GuiType.ITEM && z > 0) {
if (Util.GuiHelper.decodeType(y).getLeft() == Util.GuiHelper.GuiType.ITEM && z == -1) {
gui = GuiType.WIRELESS_MAGNET_FILTER;
} else if (Util.GuiHelper.decodeType(y).getLeft() == Util.GuiHelper.GuiType.ITEM && z > 0) {
gui = getGuis().get(Util.GuiHelper.decodeType(y).getRight());
} else {
gui = readMode(stack);
@@ -121,6 +124,8 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal
return new WirelessLevelTerminalInventory(stack, x, gridNode, player);
} else if (gui == GuiType.WIRELESS_FLUID_PATTERN_TERMINAL_EX) {
return new WirelessPatternTerminalExInventory(stack, x, gridNode, player);
} else if (gui == GuiType.WIRELESS_MAGNET_FILTER) {
return new WirelessMagnetCardFilterInventory(stack, x, gridNode, player);
} else {
this.setMode(GuiType.WIRELESS_FLUID_TERMINAL, stack); // set as default mode
return new WirelessFluidTerminalInventory(stack, x, gridNode, player);
@@ -18,8 +18,6 @@ import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import com.glodblock.github.api.registries.ILevelViewable;
import com.glodblock.github.api.registries.LevelItemInfo;
import com.glodblock.github.api.registries.LevelState;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
@@ -588,15 +586,4 @@ public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatc
return super.getInventoryByName(name);
}
@Override
public LevelItemInfo[] getLevelItemInfoList() {
ItemStack stack = this.config.getStackInSlot(0);
if (stack == null) return new LevelItemInfo[] { null };
return new LevelItemInfo[] { new LevelItemInfo(
stack,
this.getReportingValue(),
-1,
this.isProvidingStrongPower() > 0 ? LevelState.Craft : LevelState.Idle) };
}
}
@@ -13,8 +13,6 @@ import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import org.jetbrains.annotations.NotNull;
import com.glodblock.github.common.item.ItemBaseInfinityStorageCell;
import com.glodblock.github.common.item.ItemFluidVoidStorageCell;
import com.glodblock.github.crossmod.extracells.storage.ProxyFluidCellInventory;
@@ -478,7 +476,7 @@ public class FluidCellInventory implements IFluidCellInventory {
}
@Override
public @NotNull List<IAEFluidStack> getContents() {
public List<IAEFluidStack> getContents() {
List<IAEFluidStack> ret = new ArrayList<>();
for (IAEFluidStack fluid : this.getCellFluids()) {
ret.add(fluid);
@@ -1,14 +1,11 @@
package com.glodblock.github.common.storage;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import appeng.api.config.Actionable;
import appeng.api.exceptions.AppEngException;
import appeng.api.networking.security.BaseActionSource;
@@ -112,7 +109,7 @@ public class FluidVoidStorageCellInventory extends FluidCellInventory {
}
@Override
public @NotNull List<IAEFluidStack> getContents() {
return Collections.emptyList();
public List<IAEFluidStack> getContents() {
return null;
}
}
@@ -5,8 +5,6 @@ import java.util.List;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.data.IAEFluidStack;
@@ -92,7 +90,6 @@ public interface IFluidCellInventory extends IMEInventory<IAEFluidStack> {
*/
long getTotalFluidTypes();
@NotNull
List<IAEFluidStack> getContents();
/**
@@ -1,6 +1,5 @@
package com.glodblock.github.common.tile;
import static appeng.util.Platform.writeStackNBT;
import static com.glodblock.github.loader.RecipeLoader.BUCKET;
import javax.annotation.Nonnull;
@@ -18,8 +17,7 @@ import net.minecraftforge.fluids.FluidStack;
import org.apache.commons.lang3.tuple.MutablePair;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.util.NameConst;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.util.Util;
import appeng.api.AEApi;
@@ -55,8 +53,6 @@ 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 {
@@ -64,7 +60,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 = GameRegistry.findItem(FluidCraft.MODID, NameConst.ITEM_FLUID_ENCODED_PATTERN);
private final Item encodedPattern = AEApi.instance().definitions().items().encodedPattern().maybeItem().orNull();
private IAEItemStack returnStack;
private boolean isPowered;
@@ -160,21 +156,19 @@ 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,
fluidStack.copy().setStackSize(maxCapacity));
ItemStack pattern = getPattern(this.getContainerItem(), filled.right);
ICraftingPatternItem patter = (ICraftingPatternItem) pattern.getItem();
craftingTracker.addCraftingOption(this, patter.getPatternForItem(pattern, getWorldObj()));
}
}
private ItemStack getPattern(ItemStack emptyContainer, ItemStack filledContainer, IAEFluidStack ifs) {
private ItemStack getPattern(ItemStack emptyContainer, ItemStack filledContainer) {
NBTTagList in = new NBTTagList();
NBTTagList out = new NBTTagList();
in.appendTag(writeStackNBT(AEItemStack.create(emptyContainer), new NBTTagCompound()));
in.appendTag(writeStackNBT(ifs, new NBTTagCompound()));
out.appendTag(writeStackNBT(AEItemStack.create(filledContainer), new NBTTagCompound()));
in.appendTag(emptyContainer.writeToNBT(new NBTTagCompound()));
ItemStack fluidDrop = ItemFluidDrop.newStack(Util.FluidUtil.getFluidFromContainer(filledContainer));
in.appendTag(createItemTag(fluidDrop));
out.appendTag(filledContainer.writeToNBT(new NBTTagCompound()));
NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setTag("in", in);
itemTag.setTag("out", out);
@@ -194,7 +188,8 @@ public class TileFluidAutoFiller extends AENetworkInvTile
@Override
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) {
this.returnStack = (IAEItemStack) patternDetails.getCondensedOutputs()[0];
this.returnStack = AEApi.instance().storage()
.createItemStack(patternDetails.getCondensedOutputs()[0].getItemStack());
try {
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
} catch (GridAccessException ignored) {
@@ -1,30 +1,23 @@
package com.glodblock.github.common.tile;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.Future;
import java.util.stream.Stream;
import java.util.function.UnaryOperator;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.glodblock.github.api.registries.ILevelViewable;
import com.glodblock.github.api.registries.LevelItemInfo;
import com.glodblock.github.api.registries.LevelState;
import com.glodblock.github.common.Config;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.crossmod.thaumcraft.ThaumicEnergisticsCrafting;
import com.glodblock.github.inventory.AeItemStackHandler;
import com.glodblock.github.inventory.AeStackInventory;
import com.glodblock.github.inventory.AeStackInventoryImpl;
import com.glodblock.github.util.ModAndClassUtil;
import com.google.common.collect.ImmutableSet;
@@ -49,16 +42,19 @@ import appeng.api.networking.security.MachineSource;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
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.core.AELog;
import appeng.helpers.NonNullArrayIterator;
import appeng.me.GridAccessException;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkTile;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import io.netty.buffer.ByteBuf;
@@ -66,19 +62,10 @@ public class TileLevelMaintainer extends AENetworkTile
implements IAEAppEngInventory, IGridTickable, ICraftingRequester, IPowerChannelState, ILevelViewable {
public static final int REQ_COUNT = 5;
public static final String NBT_REQUESTS = "Requests";
public static final String NBT_STACK = "stack";
public static final String NBT_QUANTITY = "quantity";
public static final String NBT_BATCH = "batch";
public static final String NBT_ENABLE = "enable";
public static final String NBT_STATE = "state";
public static final String NBT_LINK = "link";
public final RequestInfo[] requests = new RequestInfo[REQ_COUNT];
private final LevelMaintainerInventory inventory = new LevelMaintainerInventory(requests, this);
public final InventoryRequest requests = new InventoryRequest(this);
private int firstRequest = 0;
private final BaseActionSource source;
private final IInventory inv = new AeItemStackHandler(inventory);
private final IInventory inv = new AeItemStackHandler(requests.requestStacks);
private boolean isPowered = false;
public TileLevelMaintainer() {
@@ -88,23 +75,17 @@ public class TileLevelMaintainer extends AENetworkTile
}
public AeStackInventory<IAEItemStack> getRequestSlots() {
return inventory;
return requests.requestStacks;
}
@Override
public ImmutableSet<ICraftingLink> getRequestedJobs() {
return ImmutableSet.copyOf(
Arrays.stream(this.requests).filter(Objects::nonNull).map(info -> info.link).filter(Objects::nonNull)
.iterator());
return ImmutableSet.copyOf(new NonNullArrayIterator<>(requests.links));
}
@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;
} ;
int idx = requests.getIdxByLink(link);
try {
if (getProxy().isActive()) {
final IEnergyGrid energy = getProxy().getEnergy();
@@ -116,7 +97,7 @@ public class TileLevelMaintainer extends AENetworkTile
.injectItems(ItemFluidDrop.getAeFluidStack(items), mode, source);
if (notInjectedItems != null) {
items.setStackSize(notInjectedItems.getStackSize());
this.updateState(idx, LevelState.Export);
requests.updateState(idx, State.Export);
return items;
} else {
@@ -136,9 +117,10 @@ public class TileLevelMaintainer extends AENetworkTile
@Override
public void jobStateChange(ICraftingLink link) {
for (int i = 0; i < REQ_COUNT; i++) {
if (requests[i] != null && requests[i].link == link) {
this.updateLink(i, null);
for (int x = 0; x < REQ_COUNT; x++) {
if (requests.getLink(x) == link) {
requests.updateLink(x, link);
return;
}
}
}
@@ -182,107 +164,92 @@ public class TileLevelMaintainer extends AENetworkTile
for (int j = 0; j < REQ_COUNT; ++j) {
int i = (firstRequest + j) % REQ_COUNT;
if (requests[i] == null) continue;
final long quantity = requests[i].quantity;
final long batchSize = requests[i].batchSize;
final boolean isEnable = requests[i].enable;
long quantity = requests.getQuantity(i);
long batchSize = requests.getBatchSize(i);
boolean isEnable = requests.isEnable(i);
if (!isEnable || batchSize == 0) requests.updateState(i, State.None);
if (batchSize > 0) {
IAEItemStack craftItem = requests.getCraftItem(i);
if (!isEnable || quantity == 0 || batchSize == 0) {
this.updateState(i, LevelState.None);
continue;
}
IAEItemStack craftItem = requests[i].itemStack.copy();
craftItem.setStackSize(batchSize);
if (ModAndClassUtil.ThE) {
if (ThaumicEnergisticsCrafting.isAspectStack(craftItem.getItemStack())) {
craftItem = ThaumicEnergisticsCrafting.convertAspectStack(craftItem);
}
}
IAEItemStack aeItem = inv.findPrecise(craftItem);
long stackSize = aeItem == null ? 0 : aeItem.getStackSize();
if (ModAndClassUtil.ThE) {
if (aeItem != null && ThaumicEnergisticsCrafting.isAspectStack(aeItem.getItemStack())) {
stackSize = ThaumicEnergisticsCrafting.getEssentiaAmount(aeItem, grid);
}
}
boolean isDone = this.isDone(i);
boolean isCraftable = aeItem != null && aeItem.isCraftable();
boolean shouldCraft = isCraftable && stackSize < quantity;
if (isDone) {
if (this.requests[i].state != LevelState.Idle) {
this.updateState(i, LevelState.Idle);
}
if (this.requests[i].link != null) {
this.updateLink(i, null);
}
if (!isCraftable) {
updateState(i, LevelState.Error);
}
}
if (allBusy || !isDone || !shouldCraft) {
continue;
}
if (craftingGrid.canEmitFor(craftItem)) {
continue;
}
if (craftingGrid.isRequesting(craftItem)) {
continue;
}
// do crafting
Future<ICraftingJob> jobTask = requests[i].job;
if (jobTask == null) {
if (itemToBegin == null) {
itemToBegin = craftItem;
itemToBeginIdx = i;
}
} else if (jobTask.isDone()) {
this.updateState(i, LevelState.Craft);
try {
ICraftingJob job = jobTask.get();
if (job != null) {
if (jobToSubmit == null) {
jobToSubmit = job;
jobToSubmitIdx = i;
}
} else {
this.updateState(i, LevelState.Error);
if (ModAndClassUtil.ThE) {
if (craftItem != null && ThaumicEnergisticsCrafting.isAspectStack(craftItem.getItemStack())) {
craftItem = ThaumicEnergisticsCrafting.convertAspectStack(craftItem);
}
}
IAEItemStack aeItem = inv.findPrecise(craftItem);
long stackSize = aeItem == null ? 0 : aeItem.getStackSize();
if (ModAndClassUtil.ThE) {
if (aeItem != null && ThaumicEnergisticsCrafting.isAspectStack(aeItem.getItemStack())) {
stackSize = ThaumicEnergisticsCrafting.getEssentiaAmount(aeItem, grid);
}
}
boolean isDone = requests.isDone(i);
boolean isCraftable = aeItem != null && aeItem.isCraftable();
boolean shouldCraft = isCraftable && stackSize < quantity;
if (isDone) requests.updateState(i, State.Idle);
if (!isCraftable) requests.updateState(i, State.Error);
if (allBusy || !isDone || !shouldCraft) {
continue;
}
if (craftingGrid.canEmitFor(craftItem)) {
continue;
}
if (craftingGrid.isRequesting(craftItem)) {
continue;
}
// do crafting
Future<ICraftingJob> jobTask = requests.getJob(i);
if (jobTask == null) {
if (itemToBegin == null) {
itemToBegin = craftItem;
itemToBeginIdx = i;
}
} else if (jobTask.isDone()) {
requests.updateState(i, State.Craft);
try {
ICraftingJob job = jobTask.get();
if (job != null) {
if (jobToSubmit == null) {
jobToSubmit = job;
jobToSubmitIdx = i;
}
} else {
requests.updateState(i, State.Error);
}
} catch (Exception ignored) {
requests.updateState(i, State.Error);
}
} catch (Exception ignored) {
this.updateState(i, LevelState.Error);
}
}
}
if (jobToSubmit != null) {
// Finished calculating a request, try to submit it.
ICraftingLink link = craftingGrid.submitJob(jobToSubmit, this, null, false, source);
requests[jobToSubmitIdx].job = null;
requests.updateJob(jobToSubmitIdx, null);
if (link != null) {
this.updateState(jobToSubmitIdx, LevelState.Craft);
this.updateLink(jobToSubmitIdx, link);
requests.updateState(jobToSubmitIdx, State.Craft);
requests.updateLink(jobToSubmitIdx, link);
} else {
this.updateState(jobToSubmitIdx, LevelState.Error);
requests.updateState(jobToSubmitIdx, State.Error);
}
} else if (itemToBegin != null) {
// No jobs to submit, start calculating some item.
requests[itemToBeginIdx].job = craftingGrid
.beginCraftingJob(getWorldObj(), grid, source, itemToBegin, null);
this.updateState(itemToBeginIdx, LevelState.Craft);
requests.updateJob(
itemToBeginIdx,
craftingGrid.beginCraftingJob(getWorldObj(), grid, source, itemToBegin, null));
requests.updateState(itemToBeginIdx, State.Craft);
// Try the next item next time.
firstRequest = (firstRequest + 1) % REQ_COUNT;
@@ -317,6 +284,9 @@ public class TileLevelMaintainer extends AENetworkTile
return getProxy().isActive();
}
@Override
public void gridChanged() {}
@Override
public boolean isPowered() {
return isPowered;
@@ -327,205 +297,120 @@ public class TileLevelMaintainer extends AENetworkTile
return isPowered;
}
public InventoryRequest getRequestInventory() {
return requests;
}
public IInventory getInventory() {
return inv;
}
public IInventory getInventoryByName(String name) {
if (Objects.equals(name, "config")) return new AeItemStackHandler(this.inventory);
if (name == "config") return new AeItemStackHandler(requests.requestStacks);
return null;
}
@Override
public LevelItemInfo[] getLevelItemInfoList() {
return Arrays.stream(this.requests).map(request -> {
if (request == null) return null;
return new LevelItemInfo(
request.itemStack.getItemStack(),
request.getQuantity(),
request.getBatchSize(),
request.getState());
}).toArray(LevelItemInfo[]::new);
}
public void updateQuantity(int idx, long size) {
if (requests[idx] == null) return;
requests[idx].quantity = size > 0 ? size : 0;
this.checkState(idx);
this.saveChanges();
requests.updateQuantity(idx, size);
}
public void updateBatchSize(int idx, long size) {
if (requests[idx] == null) return;
requests[idx].batchSize = size > 0 ? size : 0;
this.checkState(idx);
this.saveChanges();
requests.updateBatchSize(idx, size);
}
public void updateStatus(int idx, boolean enable) {
if (requests[idx] == null) return;
requests[idx].enable = enable;
this.checkState(idx);
this.saveChanges();
requests.updateStatus(idx, enable);
}
private void updateState(int idx, @NotNull LevelState state) {
if (requests[idx] == null) return;
requests[idx].state = state;
this.saveChanges();
}
public void updateStack(int idx, @Nullable ItemStack stack) {
if (stack == null) {
requests[idx] = null;
} else {
stack = this.removeRecursion(stack);
requests[idx] = new RequestInfo(stack, this);
}
this.saveChanges();
}
private void updateLink(int idx, @Nullable ICraftingLink link) {
if (requests[idx] == null) return;
requests[idx].link = link;
this.saveChanges();
}
private void checkState(int idx) {
if (!requests[idx].enable || requests[idx].quantity == 0 || requests[idx].batchSize == 0) {
this.updateState(idx, LevelState.None);
} else if (!this.isDone(idx)) {
this.updateState(idx, LevelState.Craft);
} else {
this.updateState(idx, LevelState.Idle);
}
}
public boolean isDone(int i) {
if (requests[i] == null) {
return true;
}
ICraftingLink link = requests[i].link;
return link == null || link.isDone() || link.isCanceled();
}
private int getRequestIndexByLink(ICraftingLink link) {
for (int i = 0; i < REQ_COUNT; i++) {
if (requests[i] != null && requests[i].link == link) {
return i;
/**
* @deprecated
*/
@Deprecated
private void readLinkFromNBT__old(NBTTagCompound data) {
try {
for (int i = 0; i < REQ_COUNT; i++) {
final NBTTagCompound link = data.getCompoundTag("links-" + i);
if (link != null && link.hasNoTags()) {
requests.updateLink(i, null);
} else {
requests.updateLink(i, AEApi.instance().storage().loadCraftingLink(link, this));
if (!requests.isDone(i)) requests.updateState(i, State.Craft);
}
}
}
return -1;
} catch (Exception ignore) {}
}
@TileEvent(TileEventType.WORLD_NBT_WRITE)
public void writeToNBTEvent(NBTTagCompound data) {
NBTTagList tagList = new NBTTagList();
for (int i = 0; i < REQ_COUNT; i++) {
if (this.requests[i] != null) {
tagList.appendTag(this.requests[i].writeToNBT());
} else {
tagList.appendTag(new NBTTagCompound());
}
}
data.setTag(NBT_REQUESTS, tagList);
requests.requestStacks.writeToNbt(data, TLMTags.RequestStacks.tagName);
}
@TileEvent(TileEventType.WORLD_NBT_READ)
public void readFromNBTEvent(NBTTagCompound data) {
if (data.hasKey(NBT_REQUESTS)) {
NBTTagList tagList = data.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 if (this.requests[i] == null) {
try {
this.requests[i] = new RequestInfo(tag, this);
} catch (Exception ignored) {
this.requests[i] = null;
if (data.hasKey(TLMTags.RequestStacks.tagName)) {
requests.requestStacks.readFromNbt(data, TLMTags.RequestStacks.tagName);
if (Platform.isServer()) {
for (int i = 0; i < REQ_COUNT; i++) {
if (requests.requestStacks.getStack(i) != null) {
ItemStack storageStack = requests.requestStacks.getStack(i).getItemStack();
ItemStack itemStack = loadItemStackFromTag(storageStack);
ItemStack craftStack = removeRecursion(storageStack);
if (!ItemStack.areItemStacksEqual(itemStack, craftStack)) {
requests.updateStack(i, craftStack);
AELog.info(
"[TileLevelMaintainer] Replace craft stack from: " + itemStack.toString()
+ ":"
+ (itemStack.hasTagCompound() ? itemStack.getTagCompound() : "{no tags}")
+ "; with: "
+ craftStack
+ ":"
+ (craftStack.hasTagCompound() ? craftStack.getTagCompound()
: "{no tags}"));
}
}
} else {
this.requests[i].loadFromNBT(tag);
}
}
} else if (data.hasKey("RequestStacks")) {
// Migration from old NBT
NBTTagList stacksTag = data.getCompoundTag("RequestStacks")
.getTagList("Contents", Constants.NBT.TAG_COMPOUND);
IAEItemStack[] stacks = new IAEItemStack[REQ_COUNT];
for (int i = 0; i < REQ_COUNT; i++) {
NBTTagCompound stackTag = stacksTag.getCompoundTagAt(i);
if (stackTag == null) continue;
stacks[i] = AEItemStack.loadItemStackFromNBT(stackTag);
if (stacks[i] == null) continue;
ItemStack itemstack = stacks[i].getItemStack();
if (!itemstack.hasTagCompound()) continue;
NBTTagCompound itemTag = itemstack.getTagCompound();
ItemStack craftStack = ItemStack.loadItemStackFromNBT(itemTag.getCompoundTag("Stack"));
craftStack = removeRecursion(craftStack);
if (craftStack == null) continue;
requests[i] = new RequestInfo(craftStack, this);
if (itemTag.hasKey("Enable")) {
requests[i].enable = itemTag.getBoolean("Enable");
}
if (itemTag.hasKey("Quantity")) {
requests[i].quantity = itemTag.getLong("Quantity");
}
if (itemTag.hasKey("Batch")) {
requests[i].batchSize = itemTag.getLong("Batch");
}
}
} else {
// Migration from old old data storage
// Migration from old data storage
long[] batches = new long[REQ_COUNT];
long[] quantyties = new long[REQ_COUNT];
ItemStack[] stacks = new ItemStack[REQ_COUNT];
NBTTagList batchTag = data.getCompoundTag("Batch").getTagList("Contents", Constants.NBT.TAG_COMPOUND);
requests.requestStacks.readFromNbt(data, "Batch");
for (int i = 0; i < REQ_COUNT; i++) {
NBTTagCompound stackTag = batchTag.getCompoundTagAt(i);
IAEItemStack stack = AEItemStack.loadItemStackFromNBT(stackTag);
batches[i] = stack != null ? stack.getStackSize() : 0;
IAEItemStack batchStack = requests.requestStacks.getStack(i);
batches[i] = batchStack != null ? batchStack.getStackSize() : 0;
}
NBTTagList quantityTag = data.getCompoundTag("Count").getTagList("Contents", Constants.NBT.TAG_COMPOUND);
requests.requestStacks.readFromNbt(data, "Count");
for (int i = 0; i < REQ_COUNT; i++) {
NBTTagCompound stackTag = quantityTag.getCompoundTagAt(i);
IAEItemStack stack = AEItemStack.loadItemStackFromNBT(stackTag);
quantyties[i] = stack != null ? stack.getStackSize() : 0;
IAEItemStack quantityStack = requests.requestStacks.getStack(i);
quantyties[i] = quantityStack != null ? quantityStack.getStackSize() : 0;
}
NBTTagList inventoryTag = data.getCompoundTag("Count").getTagList("Contents", Constants.NBT.TAG_COMPOUND);
requests.requestStacks.readFromNbt(data, "Inventory");
for (int i = 0; i < REQ_COUNT; i++) {
NBTTagCompound stackTag = inventoryTag.getCompoundTagAt(i);
IAEItemStack stack = AEItemStack.loadItemStackFromNBT(stackTag);
stacks[i] = stack != null ? stack.getItemStack() : null;
}
for (int i = 0; i < REQ_COUNT; i++) {
if (stacks[i] == null) continue;
this.requests[i] = new RequestInfo(stacks[i], this);
this.requests[i].batchSize = batches[i];
this.requests[i].quantity = quantyties[i];
IAEItemStack requestsStack = requests.requestStacks.getStack(i);
if (requestsStack != null) {
requests.updateStack(i, requestsStack.getItemStack());
requests.updateBatchSize(i, batches[i]);
requests.updateQuantity(i, quantyties[i]);
}
}
readLinkFromNBT__old(data);
}
}
// Remove old format NBT data from ItemStack
private ItemStack removeRecursion(ItemStack itemStack) {
if (itemStack == null || !itemStack.hasTagCompound()) return itemStack;
NBTTagCompound tag = itemStack.getTagCompound();
if (tag.hasKey("Stack") && tag.hasKey("Quantity")) {
return removeRecursion(ItemStack.loadItemStackFromNBT(itemStack.getTagCompound().getCompoundTag("Stack")));
if (itemStack != null && itemStack.hasTagCompound()
&& itemStack.getTagCompound().hasKey(TLMTags.Stack.tagName)) {
return removeRecursion(loadItemStackFromTag(itemStack));
}
return itemStack;
}
@Nullable
private static ItemStack loadItemStackFromTag(ItemStack itemStack) {
return ItemStack.loadItemStackFromNBT(itemStack.getTagCompound().getCompoundTag(TLMTags.Stack.tagName));
}
@TileEvent(TileEventType.NETWORK_READ)
public boolean readFromStream(final ByteBuf data) {
final boolean oldPower = isPowered;
@@ -564,7 +449,7 @@ public class TileLevelMaintainer extends AENetworkTile
}
@Override
public @NotNull TileEntity getTile() {
public TileEntity getTile() {
return this;
}
@@ -578,140 +463,209 @@ public class TileLevelMaintainer extends AENetworkTile
return REQ_COUNT;
}
public static class RequestInfo {
@Override
public ItemStack getSelfItemStack() {
return getItemFromTile(this);
}
private final TileLevelMaintainer tile;
private @NotNull IAEItemStack itemStack;
private long quantity;
private long batchSize;
private boolean enable;
private LevelState state;
@Nullable
private Future<ICraftingJob> job;
@Nullable
private ICraftingLink link;
public enum State {
None,
Idle,
Craft,
Export,
Error
}
public RequestInfo(@NotNull ItemStack stack, TileLevelMaintainer tile) {
this.tile = tile;
itemStack = AEItemStack.create(stack);
quantity = 0;
batchSize = 0;
enable = false;
state = LevelState.None;
link = null;
job = null;
}
public enum TLMTags {
public RequestInfo(NBTTagCompound tag, TileLevelMaintainer tile) throws IllegalArgumentException {
this.tile = tile;
itemStack = AEItemStack.loadItemStackFromNBT(tag.getCompoundTag(NBT_STACK));
if (itemStack == null) {
throw new IllegalArgumentException("ItemStack cannot be null!");
}
quantity = tag.getLong(NBT_QUANTITY);
batchSize = tag.getLong(NBT_BATCH);
enable = tag.getBoolean(NBT_ENABLE);
state = LevelState.values()[tag.getInteger(NBT_STATE)];
if (tag.hasKey(NBT_LINK)) {
try {
this.link = AEApi.instance().storage().loadCraftingLink(tag.getCompoundTag(NBT_LINK), this.tile);
} catch (Exception ignored) {
this.link = null;
}
}
job = null;
}
RequestStacks("RequestStacks"),
Enable("Enable"),
Quantity("Quantity"),
Batch("Batch"),
Link("Link"),
State("State"),
Index("Index"),
Stack("Stack");
public void loadFromNBT(NBTTagCompound tag) {
itemStack = AEItemStack.loadItemStackFromNBT(tag.getCompoundTag(NBT_STACK));
quantity = tag.getLong(NBT_QUANTITY);
batchSize = tag.getLong(NBT_BATCH);
enable = tag.getBoolean(NBT_ENABLE);
state = LevelState.values()[tag.getInteger(NBT_STATE)];
if (tag.hasKey(NBT_LINK)) {
try {
this.link = AEApi.instance().storage().loadCraftingLink(tag.getCompoundTag(NBT_LINK), this.tile);
} catch (Exception ignored) {
this.link = null;
}
}
}
public final String tagName;
public NBTTagCompound writeToNBT() {
NBTTagCompound tag = new NBTTagCompound();
NBTTagCompound stackTag = new NBTTagCompound();
itemStack.writeToNBT(stackTag);
tag.setTag(NBT_STACK, stackTag);
tag.setLong(NBT_QUANTITY, quantity);
tag.setLong(NBT_BATCH, batchSize);
tag.setBoolean(NBT_ENABLE, enable);
tag.setInteger(NBT_STATE, state.ordinal());
if (this.link != null) {
NBTTagCompound linkTag = new NBTTagCompound();
this.link.writeToNBT(linkTag);
tag.setTag(NBT_LINK, linkTag);
}
return tag;
}
public IAEItemStack getAEItemStack() {
return this.itemStack;
}
public long getQuantity() {
return quantity;
}
public long getBatchSize() {
return batchSize;
}
public boolean isEnable() {
return enable;
}
public LevelState getState() {
return state;
TLMTags(String tagName) {
this.tagName = tagName;
}
}
private static class LevelMaintainerInventory implements AeStackInventory<IAEItemStack> {
public static final class InventoryRequest {
private final RequestInfo[] requests;
private final TileLevelMaintainer tile;
private final AeStackInventoryImpl<IAEItemStack> requestStacks;
private final Future<ICraftingJob>[] jobs;
private final ICraftingLink[] links;
private final State[] state = new State[REQ_COUNT];
private LevelMaintainerInventory(RequestInfo[] requests, TileLevelMaintainer tile) {
this.requests = requests;
this.tile = tile;
@SuppressWarnings("unchecked")
public InventoryRequest(TileLevelMaintainer tile) {
requestStacks = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
jobs = new Future[REQ_COUNT];
links = new ICraftingLink[REQ_COUNT];
}
@Override
public @NotNull Iterator<IAEItemStack> iterator() {
return Arrays.stream(requests).map(info -> info != null ? info.itemStack : null).iterator();
}
@Override
public int getSlotCount() {
return requests.length;
}
@Override
public @Nullable IAEItemStack getStack(int slot) {
return requests[slot] != null ? requests[slot].itemStack : null;
}
@Override
public void setStack(int slot, @Nullable IAEItemStack stack) {
if (stack == null) {
this.tile.updateStack(slot, null);
public State getState(int idx) {
IAEItemStack ias = requestStacks.getStack(idx);
if (ias == null) {
return State.None;
} else {
this.tile.updateStack(slot, stack.getItemStack());
return state[idx] == null ? State.Idle : state[idx];
}
}
@Override
public Stream<IAEItemStack> stream() {
return Arrays.stream(requests).map(info -> info != null ? info.itemStack : null);
public int getIdxByLink(ICraftingLink link) {
for (int i = 0; i < REQ_COUNT; i++) {
if (links[i] == link) {
return i;
}
}
return 0;
}
public boolean isEnable(int idx) {
IAEItemStack ias = requestStacks.getStack(idx);
if (ias == null) {
return true;
}
ItemStack is = ias.getItemStack();
return is.hasTagCompound() ? is.getTagCompound().getBoolean(TLMTags.Enable.tagName) : true;
}
public boolean isDone(int index) {
if (links[index] == null) {
return true;
}
return links[index].isDone() || links[index].isCanceled();
}
public Future<ICraftingJob> getJob(int idx) {
return jobs[idx];
}
public ICraftingLink getLink(int idx) {
return links[idx];
}
public void updateJob(int idx, Future<ICraftingJob> job) {
jobs[idx] = job;
}
private void updateField(int idx, UnaryOperator<NBTTagCompound> updater) {
IAEItemStack ias = requestStacks.getStack(idx);
if (ias == null) return;
ItemStack itemStack = ias.getItemStack();
NBTTagCompound data = itemStack.hasTagCompound() ? itemStack.getTagCompound() : new NBTTagCompound();
data.setInteger(TLMTags.Index.tagName, idx);
itemStack.setTagCompound(updater.apply(data));
IAEItemStack newRequestStack = AEItemStack.create(itemStack);
newRequestStack.setStackSize(ias.getStackSize());
requestStacks.setStack(idx, newRequestStack);
}
public void updateLink(int idx, ICraftingLink link) {
links[idx] = link;
updateField(idx, data -> {
NBTTagCompound linkData = new NBTTagCompound();
if (link != null) link.writeToNBT(linkData);
data.setTag(TLMTags.Link.tagName, linkData);
return data;
});
}
public void updateState(int idx, State nextState) {
state[idx] = nextState;
updateField(idx, data -> {
data.setInteger(TLMTags.State.tagName, nextState.ordinal());
return data;
});
}
public void updateStatus(int idx, boolean enable) {
updateField(idx, data -> {
State nextState = enable ? State.Idle : State.None;
data.setBoolean(TLMTags.Enable.tagName, enable);
data.setInteger(TLMTags.State.tagName, nextState.ordinal());
return data;
});
}
public void updateQuantity(int idx, long quantity) {
updateField(idx, data -> {
data.setLong(TLMTags.Quantity.tagName, quantity);
return data;
});
}
public void updateBatchSize(int idx, long batch) {
updateField(idx, data -> {
data.setLong(TLMTags.Batch.tagName, batch);
data.setBoolean(TLMTags.Enable.tagName, true);
return data;
});
}
public void updateStack(int idx, ItemStack itemStack) {
updateField(idx, data -> {
NBTTagCompound stackData = new NBTTagCompound();
if (itemStack != null) itemStack.writeToNBT(stackData);
data.setTag(TLMTags.Stack.tagName, stackData);
return data;
});
}
public IAEItemStack getAEItemStack(int idx) {
return requestStacks.getStack(idx);
}
public ItemStack getItemStack(int idx) {
return requestStacks.getStack(idx).getItemStack();
}
public long getQuantity(int idx) {
if (!isEnable(idx)) return 0;
IAEItemStack ias = requestStacks.getStack(idx);
if (ias == null) return 0;
ItemStack itemStack = ias.getItemStack();
if (!itemStack.hasTagCompound()) return 0;
return itemStack.getTagCompound().getLong(TLMTags.Quantity.tagName);
}
public long getBatchSize(int idx) {
if (!isEnable(idx)) return 0;
IAEItemStack ias = requestStacks.getStack(idx);
if (ias == null) return 0;
ItemStack itemStack = ias.getItemStack();
if (!itemStack.hasTagCompound()) return 0;
return itemStack.getTagCompound().getLong(TLMTags.Batch.tagName);
}
public IAEItemStack getCraftItem(int idx) {
IAEItemStack is = requestStacks.getStack(idx);
if (is == null) return null;
if (is.getItemStack() == null) return null;
ItemStack qis = loadItemStackFromTag(is.getItemStack());
if (qis == null) return null;
IAEItemStack qais = AEItemStack.create(qis);
qais.setStackSize(getBatchSize(idx));
return qais;
}
}
}
@@ -50,7 +50,7 @@ import appeng.tile.inventory.InvOperation;
import appeng.util.item.AEFluidStack;
import io.netty.buffer.ByteBuf;
public class TileSuperStockReplenisher extends AENetworkInvTile
public class TileSuperStoker extends AENetworkInvTile
implements IAEFluidInventory, IFluidHandler, IPowerChannelState, IGridTickable {
private final AppEngInternalInventory cell = new AppEngInternalInventory(this, 1);
@@ -64,7 +64,7 @@ public class TileSuperStockReplenisher extends AENetworkInvTile
private long storedFluidCount;
private long storedItemCount;
public TileSuperStockReplenisher() {
public TileSuperStoker() {
getProxy().setIdlePowerUsage(4D);
getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
this.source = new MachineSource(this);
@@ -356,14 +356,14 @@ public class TileSuperStockReplenisher extends AENetworkInvTile
}
@TileEvent(TileEventType.NETWORK_READ)
public boolean readFromStream_TileSuperStockReplenisher(final ByteBuf data) {
public boolean readFromStream_TileSuperStoker(final ByteBuf data) {
final boolean oldPower = isPowered;
isPowered = data.readBoolean();
return isPowered != oldPower;
}
@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStream_TileSuperStockReplenisher(final ByteBuf data) {
public void writeToStream_TileSuperStoker(final ByteBuf data) {
data.writeBoolean(isActive());
}
@@ -8,6 +8,9 @@ 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;
@@ -22,6 +25,9 @@ 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;
@@ -1,8 +1,12 @@
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;
@@ -11,19 +15,72 @@ 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());
@@ -31,6 +88,61 @@ 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,5 +1,7 @@
package com.glodblock.github.coremod.registries.adapters;
import static com.glodblock.github.coremod.registries.adapters.PartLevelEmitterAdapter.getPatchedInventory;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -7,9 +9,8 @@ import net.minecraftforge.common.util.ForgeDirection;
import com.glodblock.github.api.registries.ILevelViewable;
import com.glodblock.github.api.registries.ILevelViewableAdapter;
import com.glodblock.github.api.registries.LevelItemInfo;
import com.glodblock.github.api.registries.LevelState;
import com.glodblock.github.common.parts.PartFluidLevelEmitter;
import com.glodblock.github.common.tile.TileLevelMaintainer.State;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
@@ -44,7 +45,10 @@ public class PartFluidLevelEmitterAdapter implements ILevelViewable, ILevelViewa
@Override
public IInventory getInventoryByName(String name) {
return delegate.getInventoryByName(name);
long value = delegate.getReportingValue();
State state = delegate.isProvidingStrongPower() > 0 ? State.Craft : State.Idle;
return getPatchedInventory(delegate.getInventoryByName(name), value, state);
}
@Override
@@ -78,13 +82,7 @@ public class PartFluidLevelEmitterAdapter implements ILevelViewable, ILevelViewa
}
@Override
public LevelItemInfo[] getLevelItemInfoList() {
ItemStack stack = delegate.getInventoryByName("config").getStackInSlot(0);
if (stack == null) return new LevelItemInfo[] { null };
return new LevelItemInfo[] { new LevelItemInfo(
stack,
delegate.getReportingValue(),
-1,
delegate.isProvidingStrongPower() > 0 ? LevelState.Craft : LevelState.Idle) };
public ItemStack getSelfItemStack() {
return delegate.getItemStack();
}
}
@@ -2,24 +2,34 @@ package com.glodblock.github.coremod.registries.adapters;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import org.jetbrains.annotations.NotNull;
import com.glodblock.github.api.registries.ILevelViewable;
import com.glodblock.github.api.registries.ILevelViewableAdapter;
import com.glodblock.github.api.registries.LevelItemInfo;
import com.glodblock.github.api.registries.LevelState;
import com.glodblock.github.common.tile.TileLevelMaintainer.State;
import com.glodblock.github.common.tile.TileLevelMaintainer.TLMTags;
import com.glodblock.github.inventory.AeItemStackHandler;
import com.glodblock.github.inventory.AeStackInventoryImpl;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AECableType;
import appeng.api.util.DimensionalCoord;
import appeng.parts.automation.PartLevelEmitter;
import appeng.util.item.AEItemStack;
public class PartLevelEmitterAdapter implements ILevelViewable, ILevelViewableAdapter {
private PartLevelEmitter delegate;
private static final int SLOT_IN = 0;
public PartLevelEmitterAdapter() {}
public ILevelViewable adapt(IGridHost gridHost) {
@@ -27,6 +37,21 @@ public class PartLevelEmitterAdapter implements ILevelViewable, ILevelViewableAd
return this;
}
@NotNull
static public IInventory getPatchedInventory(IInventory inventory, long quantity, State state) {
ItemStack itemStack = inventory.getStackInSlot(SLOT_IN);
if (itemStack == null) return inventory;
NBTTagCompound data = !itemStack.hasTagCompound() ? new NBTTagCompound() : itemStack.getTagCompound();
data.setLong(TLMTags.Quantity.tagName, quantity);
data.setInteger(TLMTags.State.tagName, state.ordinal());
itemStack.setTagCompound(data);
AeStackInventoryImpl<IAEItemStack> inv = new AeStackInventoryImpl<>(StorageChannel.ITEMS, 1);
inv.setStack(SLOT_IN, AEItemStack.create(itemStack));
return new AeItemStackHandler(inv);
}
@Override
public DimensionalCoord getLocation() {
return delegate.getLocation();
@@ -39,7 +64,10 @@ public class PartLevelEmitterAdapter implements ILevelViewable, ILevelViewableAd
@Override
public IInventory getInventoryByName(String name) {
return delegate.getInventoryByName(name);
long value = delegate.getReportingValue();
State state = delegate.isProvidingStrongPower() > 0 ? State.Craft : State.Idle;
return getPatchedInventory(delegate.getInventoryByName(name), value, state);
}
@Override
@@ -78,13 +106,12 @@ public class PartLevelEmitterAdapter implements ILevelViewable, ILevelViewableAd
}
@Override
public LevelItemInfo[] getLevelItemInfoList() {
ItemStack stack = delegate.getInventoryByName("config").getStackInSlot(0);
if (stack == null) return new LevelItemInfo[] { null };
return new LevelItemInfo[] { new LevelItemInfo(
stack,
delegate.getReportingValue(),
-1,
delegate.isProvidingStrongPower() > 0 ? LevelState.Craft : LevelState.Idle) };
public ItemStack getSelfItemStack() {
return delegate.getItemStack();
}
@Override
public ItemStack getDisplayItemStack() {
return delegate.getCrafterIcon();
}
}
@@ -0,0 +1,142 @@
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);
}
}
}
}
@@ -0,0 +1,67 @@
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();
}
}
}
@@ -0,0 +1,102 @@
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);
}
}
}
@@ -61,7 +61,7 @@ public class DriverLevelMaintainer extends DriverSidedTileEntity {
if (slot < 0 || slot >= TileLevelMaintainer.REQ_COUNT) {
throw new IllegalArgumentException("Invalid slot");
}
return tileEntity.isDone(slot);
return tileEntity.requests.isDone(slot);
}
private boolean isEnable(Arguments args) {
@@ -69,7 +69,7 @@ public class DriverLevelMaintainer extends DriverSidedTileEntity {
if (slot < 0 || slot >= TileLevelMaintainer.REQ_COUNT) {
throw new IllegalArgumentException("Invalid slot");
}
return tileEntity.requests[slot].isEnable();
return tileEntity.requests.isEnable(slot);
}
private boolean setEnable(Arguments args) {
@@ -81,7 +81,7 @@ public class DriverLevelMaintainer extends DriverSidedTileEntity {
throw new IllegalArgumentException("Invalid slot");
}
boolean enable = args.checkBoolean(1);
tileEntity.updateStatus(slot, enable);
tileEntity.requests.updateStatus(slot, enable);
return true;
}
}
@@ -103,12 +103,12 @@ public class DriverLevelMaintainer extends DriverSidedTileEntity {
result.put("label", stack.getDisplayName());
result.put("maxDamage", stack.getMaxDamage());
result.put("name", GameRegistry.findUniqueIdentifierFor(stack.getItem()).toString());
result.put("quantity", tileEntity.requests[slot].getQuantity());
result.put("batch", tileEntity.requests[slot].getBatchSize());
result.put("quantity", tileEntity.requests.getQuantity(slot));
result.put("batch", tileEntity.requests.getBatchSize(slot));
result.put("isFluid", ItemFluidDrop.isFluidStack(stack));
if (ItemFluidDrop.isFluidStack(stack)) result.put("fluid", ItemFluidDrop.getFluidStack(stack));
result.put("isEnable", tileEntity.requests[slot].isEnable());
result.put("isDone", tileEntity.isDone(slot));
result.put("isEnable", tileEntity.requests.isEnable(slot));
result.put("isDone", tileEntity.requests.isDone(slot));
return new Object[] { result };
}
return new Object[] { null };
@@ -122,7 +122,7 @@ public class DriverLevelMaintainer extends DriverSidedTileEntity {
if (dbStack == null) {
throw new IllegalArgumentException("Invalid slot");
}
tileEntity.updateStack(slot, dbStack);
tileEntity.requests.updateStack(slot, dbStack);
} else {
throw new IllegalArgumentException("Not a database");
}
@@ -1,14 +1,17 @@
package com.glodblock.github.crossmod.waila;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.fluids.FluidStack;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.Util;
import mcp.mobius.waila.handlers.nei.TooltipHandlerWaila;
@@ -36,6 +39,15 @@ public class FCTooltipHandlerWaila extends TooltipHandlerWaila {
}
String modName = Util.getFluidModName(fs.getFluid());
if (modName != null && !modName.equals("")) currenttip.set(currenttip.size() - 1, "§9§o" + modName);
if (ModAndClassUtil.GT5NH || ModAndClassUtil.GT5) {
ItemStack potion = Util.FluidUtil.getPotion(fs);
if (potion != null && potion.getItem() instanceof ItemPotion) {
List<String> potionEffects = new ArrayList<>();
potion.getItem().addInformation(potion, Minecraft.getMinecraft().thePlayer, potionEffects, false);
currenttip.addAll(currenttip.size() - 1, potionEffects);
}
}
}
return currenttip;
}
@@ -20,8 +20,9 @@ public class SpeedWailaDataProvider extends BasePartWailaDataProvider {
@Override
public List<String> getWailaBody(final IPart part, final List<String> currentToolTip,
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
if (accessor.getNBTData().hasKey("BusSpeed")) {
currentToolTip.add(Tooltip.partFluidBusFormat(accessor.getNBTData().getInteger("BusSpeed")));
if (part instanceof FCSharedFluidBus) {
part.readFromNBT(accessor.getNBTData());
currentToolTip.add(Tooltip.partFluidBusFormat(((FCSharedFluidBus) part).calculateAmountToSend() / 5));
}
return currentToolTip;
}
@@ -29,8 +30,8 @@ public class SpeedWailaDataProvider extends BasePartWailaDataProvider {
@Override
public NBTTagCompound getNBTData(final EntityPlayerMP player, final IPart part, final TileEntity te,
final NBTTagCompound tag, final World world, final int x, final int y, final int z) {
if (part instanceof FCSharedFluidBus bus) {
tag.setInteger("BusSpeed", bus.calculateAmountToSend() / 5);
if (part instanceof FCSharedFluidBus) {
part.writeToNBT(tag);
}
return tag;
}
@@ -5,14 +5,13 @@ import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import com.glodblock.github.common.tile.TileLevelMaintainer;
import com.glodblock.github.crossmod.waila.Tooltip;
import appeng.api.storage.data.IAEItemStack;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
@@ -24,24 +23,16 @@ public class LevelMaintainerWailaDataProvider extends BaseWailaDataProvider {
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
final TileEntity te = accessor.getTileEntity();
if (te instanceof TileLevelMaintainer tileLevelMaintainer) {
NBTTagCompound data = accessor.getNBTData();
if (data.hasKey(TileLevelMaintainer.NBT_REQUESTS)) {
NBTTagList tagList = data.getTagList(TileLevelMaintainer.NBT_REQUESTS, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound tag = tagList.getCompoundTagAt(i);
if (tag == null || !tag.hasKey(TileLevelMaintainer.NBT_STACK)) continue;
try {
TileLevelMaintainer.RequestInfo request = new TileLevelMaintainer.RequestInfo(
tag,
tileLevelMaintainer);
currentToolTip.add(
Tooltip.tileLevelMaintainerFormat(
request.getAEItemStack().getItemStack().getDisplayName(),
request.getQuantity(),
request.getBatchSize(),
request.isEnable()));
} catch (Exception ignored) {}
te.readFromNBT(accessor.getNBTData());
for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) {
IAEItemStack ias = tileLevelMaintainer.requests.getAEItemStack(i);
if (ias != null) {
currentToolTip.add(
Tooltip.tileLevelMaintainerFormat(
ias.getItemStack().getDisplayName(),
tileLevelMaintainer.requests.getQuantity(i),
tileLevelMaintainer.requests.getBatchSize(i),
tileLevelMaintainer.requests.isEnable(i)));
}
}
}
@@ -0,0 +1,85 @@
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();
}
}
@@ -34,12 +34,13 @@ import com.glodblock.github.client.gui.GuiLargeIngredientBuffer;
import com.glodblock.github.client.gui.GuiLevelMaintainer;
import com.glodblock.github.client.gui.GuiLevelTerminal;
import com.glodblock.github.client.gui.GuiLevelWireless;
import com.glodblock.github.client.gui.GuiMagnetFilter;
import com.glodblock.github.client.gui.GuiOCPatternEditor;
import com.glodblock.github.client.gui.GuiPatternItemRenamer;
import com.glodblock.github.client.gui.GuiPatternMulti;
import com.glodblock.github.client.gui.GuiPatternValueAmount;
import com.glodblock.github.client.gui.GuiRenamer;
import com.glodblock.github.client.gui.GuiSuperStockReplenisher;
import com.glodblock.github.client.gui.GuiSuperStoker;
import com.glodblock.github.client.gui.container.ContainerCraftingWireless;
import com.glodblock.github.client.gui.container.ContainerDualInterface;
import com.glodblock.github.client.gui.container.ContainerEssentiaMonitor;
@@ -64,11 +65,12 @@ import com.glodblock.github.client.gui.container.ContainerLargeIngredientBuffer;
import com.glodblock.github.client.gui.container.ContainerLevelMaintainer;
import com.glodblock.github.client.gui.container.ContainerLevelTerminal;
import com.glodblock.github.client.gui.container.ContainerLevelWireless;
import com.glodblock.github.client.gui.container.ContainerMagnetFilter;
import com.glodblock.github.client.gui.container.ContainerOCPatternEditor;
import com.glodblock.github.client.gui.container.ContainerPatternMulti;
import com.glodblock.github.client.gui.container.ContainerPatternValueAmount;
import com.glodblock.github.client.gui.container.ContainerRenamer;
import com.glodblock.github.client.gui.container.ContainerSuperStockReplenisher;
import com.glodblock.github.client.gui.container.ContainerSuperStoker;
import com.glodblock.github.common.parts.PartFluidLevelEmitter;
import com.glodblock.github.common.parts.PartFluidStorageBus;
import com.glodblock.github.common.parts.base.FCPart;
@@ -80,7 +82,7 @@ import com.glodblock.github.common.tile.TileIngredientBuffer;
import com.glodblock.github.common.tile.TileLargeIngredientBuffer;
import com.glodblock.github.common.tile.TileLevelMaintainer;
import com.glodblock.github.common.tile.TileOCPatternEditor;
import com.glodblock.github.common.tile.TileSuperStockReplenisher;
import com.glodblock.github.common.tile.TileSuperStoker;
import com.glodblock.github.inventory.IDualHost;
import com.glodblock.github.inventory.item.IFluidPortableCell;
import com.glodblock.github.inventory.item.IWirelessTerminal;
@@ -547,6 +549,18 @@ public enum GuiType {
}
}),
WIRELESS_MAGNET_FILTER(new ItemGuiFactory<>(ITerminalHost.class) {
@Override
protected Object createServerGui(EntityPlayer player, ITerminalHost inv) {
return new ContainerMagnetFilter(player.inventory, inv);
}
@Override
protected Object createClientGui(EntityPlayer player, ITerminalHost inv) {
return new GuiMagnetFilter(player.inventory, inv);
}
}),
GUI_PATTERN_ITEM_RENAMER(new PartOrItemGuiFactory<>(ITerminalHost.class) {
@Override
@@ -560,16 +574,16 @@ public enum GuiType {
}
}),
GUI_SUPER_STOCK_REPLENISHER(new TileGuiFactory<>(TileSuperStockReplenisher.class) {
GUI_SUPER_STOKER(new TileGuiFactory<>(TileSuperStoker.class) {
@Override
protected Object createServerGui(EntityPlayer player, TileSuperStockReplenisher inv) {
return new ContainerSuperStockReplenisher(player.inventory, inv);
protected Object createServerGui(EntityPlayer player, TileSuperStoker inv) {
return new ContainerSuperStoker(player.inventory, inv);
}
@Override
protected Object createClientGui(EntityPlayer player, TileSuperStockReplenisher inv) {
return new GuiSuperStockReplenisher(player.inventory, inv);
protected Object createClientGui(EntityPlayer player, TileSuperStoker inv) {
return new GuiSuperStoker(player.inventory, inv);
}
});
@@ -0,0 +1,186 @@
package com.glodblock.github.inventory.item;
import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.restockItems;
import static com.glodblock.github.inventory.item.WirelessMagnet.modeKey;
import java.util.Objects;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import com.glodblock.github.common.item.ItemBaseWirelessTerminal;
import com.glodblock.github.util.Util;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.PlayerSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.MEMonitorHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.AECableType;
import appeng.items.tools.powered.ToolWirelessTerminal;
import appeng.me.storage.NullInventory;
import appeng.util.Platform;
public abstract class BaseWirelessInventory extends MEMonitorHandler implements IWirelessTerminal, IWirelessExtendCard {
protected final ItemStack target;
protected final IAEItemPowerStorage ips;
protected final int inventorySlot;
protected final IGridNode grid;
protected final PlayerSource source;
protected final StorageChannel channel;
protected WirelessMagnet.Mode magnetMode = WirelessMagnet.Mode.Off;
protected EntityPlayer player;
protected boolean restock;
@SuppressWarnings("unchecked")
public BaseWirelessInventory(final ItemStack is, final int slot, IGridNode gridNode, EntityPlayer player,
StorageChannel channel) {
super(Objects.requireNonNull(Util.getWirelessInv(is, player, channel)));
this.ips = (ToolWirelessTerminal) is.getItem();
this.grid = gridNode;
this.target = is;
this.inventorySlot = slot;
this.channel = channel;
this.source = new PlayerSource(player, this);
this.readFromNBT();
}
@SuppressWarnings("unchecked")
public BaseWirelessInventory(final ItemStack is, final int slot, IGridNode gridNode, EntityPlayer player,
StorageChannel channel, boolean nullInventory) {
super(new NullInventory<>());
this.ips = (ToolWirelessTerminal) is.getItem();
this.grid = gridNode;
this.target = is;
this.inventorySlot = slot;
this.channel = channel;
this.source = new PlayerSource(player, this);
this.readFromNBT();
}
private void readFromNBT() {
NBTTagCompound data = Platform.openNbtData(this.target);
this.setMagnetCardMode(WirelessMagnet.Mode.values()[data.getInteger(modeKey)]);
this.setRestock(data.getBoolean(ItemBaseWirelessTerminal.restockItems));
}
public StorageChannel getChannel() {
return this.channel;
}
@Override
public ItemStack getItemStack() {
return this.target;
}
@Override
public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier) {
amt = usePowerMultiplier.multiply(amt);
if (mode == Actionable.SIMULATE) {
return usePowerMultiplier.divide(Math.min(amt, this.ips.getAECurrentPower(this.target)));
}
return usePowerMultiplier.divide(this.ips.extractAEPower(this.target, amt));
}
@Override
public int getInventorySlot() {
return this.inventorySlot;
}
@Override
public IGridNode getGridNode(ForgeDirection dir) {
return this.grid;
}
@Override
public AECableType getCableConnectionType(ForgeDirection dir) {
return AECableType.NONE;
}
@Override
public void securityBreak() {
this.getGridNode(ForgeDirection.UNKNOWN).getMachine().securityBreak();
}
@Override
public void saveChanges() {}
@Override
public IGridNode getActionableNode() {
return this.grid;
}
@Override
public PlayerSource getActionSource() {
return this.source;
}
@Override
public void setMagnetCardMode(WirelessMagnet.Mode mode) {
this.magnetMode = mode;
}
@Override
public WirelessMagnet.Mode getMagnetCardMode() {
return this.magnetMode;
}
public void setMagnetCardNextMode() {
setMagnetCardMode(
WirelessMagnet.Mode.values()[(getMagnetCardMode().ordinal() + 1)
% WirelessMagnet.Mode.values().length]);
}
public void setRestock(boolean val) {
this.restock = val;
}
public boolean isRestock() {
return this.restock;
}
public IAEStack injectItems(IAEStack aeStack) {
try {
if (aeStack.isItem()) {
return ((IStorageGrid) getActionableNode().getGrid().getCache(IStorageGrid.class)).getItemInventory()
.injectItems((IAEItemStack) aeStack, Actionable.MODULATE, getActionSource());
} else {
return ((IStorageGrid) getActionableNode().getGrid().getCache(IStorageGrid.class)).getFluidInventory()
.injectItems((IAEFluidStack) aeStack, Actionable.MODULATE, getActionSource());
}
} catch (Exception e) {
return aeStack;
}
}
public IAEStack extractItems(IAEStack aeStack) {
try {
if (aeStack.isItem()) {
return ((IStorageGrid) getActionableNode().getGrid().getCache(IStorageGrid.class)).getItemInventory()
.extractItems((IAEItemStack) aeStack, Actionable.MODULATE, getActionSource());
} else {
return ((IStorageGrid) getActionableNode().getGrid().getCache(IStorageGrid.class)).getFluidInventory()
.extractItems((IAEFluidStack) aeStack, Actionable.MODULATE, getActionSource());
}
} catch (Exception e) {
return null;
}
}
public void saveSettings() {
NBTTagCompound data = Platform.openNbtData(this.target);
data.setBoolean(restockItems, this.restock);
data.setInteger(modeKey, this.getMagnetCardMode().ordinal());
}
}
@@ -0,0 +1,26 @@
package com.glodblock.github.inventory.item;
import appeng.api.networking.security.PlayerSource;
import appeng.api.storage.data.IAEStack;
public interface IWirelessExtendCard {
default void setMagnetCardMode(WirelessMagnet.Mode mode) {}
WirelessMagnet.Mode getMagnetCardMode();
PlayerSource getActionSource();
IAEStack injectItems(IAEStack aeStack);
IAEStack extractItems(IAEStack aeStack);
default void setMagnetCardNextMode() {};
void setRestock(boolean val);
default boolean isRestock() {
return false;
}
}
@@ -0,0 +1,31 @@
package com.glodblock.github.inventory.item;
public interface IWirelessMagnetFilter extends IWirelessTerminal, IItemTerminal {
WirelessMagnet.ListMode getListMode();
boolean getNBTMode();
boolean getMetaMode();
boolean getOreMode();
boolean getOreDictMode();
String getOreDictFilter();
void setListMode(WirelessMagnet.ListMode mode);
void setNBTMode(boolean ignoreNBT);
void setMetaMode(boolean ignoreMeta);
void setOreMode(boolean useOre);
void setOreDictMode(boolean useOreDict);
void setOreDictFilter(String str);
default void clearConfig() {};
}
@@ -8,6 +8,7 @@ import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.networking.IGridHost;
import appeng.api.networking.security.IActionHost;
import appeng.api.storage.StorageChannel;
import appeng.tile.inventory.IAEAppEngInventory;
public interface IWirelessTerminal
@@ -21,4 +22,7 @@ public interface IWirelessTerminal
return false;
}
default StorageChannel getChannel() {
return null;
}
}
@@ -1,7 +1,5 @@
package com.glodblock.github.inventory.item;
import java.util.Objects;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@@ -9,7 +7,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import com.glodblock.github.inventory.ItemBiggerAppEngInventory;
import com.glodblock.github.util.Util;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
@@ -20,9 +17,7 @@ import appeng.api.config.TypeFilter;
import appeng.api.config.ViewItems;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.IGridNode;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.MEMonitorHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
@@ -35,8 +30,7 @@ import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.Platform;
public class WirelessCraftingTerminalInventory extends MEMonitorHandler<IAEItemStack>
implements IWirelessCraftTerminal {
public class WirelessCraftingTerminalInventory extends BaseWirelessInventory implements IWirelessCraftTerminal {
private final ItemStack target;
private final IAEItemPowerStorage ips;
@@ -51,9 +45,7 @@ public class WirelessCraftingTerminalInventory extends MEMonitorHandler<IAEItemS
@SuppressWarnings("unchecked")
public WirelessCraftingTerminalInventory(final ItemStack is, final int slot, IGridNode gridNode,
EntityPlayer player) {
super(
(IMEInventoryHandler<IAEItemStack>) Objects
.requireNonNull(Util.getWirelessInv(is, player, StorageChannel.ITEMS)));
super(is, slot, gridNode, player, StorageChannel.ITEMS);
this.ips = (ToolWirelessTerminal) is.getItem();
this.grid = gridNode;
this.target = is;
@@ -1,15 +1,11 @@
package com.glodblock.github.inventory.item;
import java.util.Objects;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import com.glodblock.github.util.Util;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.Settings;
@@ -18,9 +14,7 @@ import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.IGridNode;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.MEMonitorHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
@@ -33,7 +27,7 @@ import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.Platform;
public class WirelessFluidTerminalInventory extends MEMonitorHandler<IAEFluidStack> implements IWirelessTerminal {
public class WirelessFluidTerminalInventory extends BaseWirelessInventory implements IWirelessTerminal, IItemTerminal {
private final ItemStack target;
private final IAEItemPowerStorage ips;
@@ -44,9 +38,7 @@ public class WirelessFluidTerminalInventory extends MEMonitorHandler<IAEFluidSta
@SuppressWarnings("unchecked")
public WirelessFluidTerminalInventory(final ItemStack is, final int slot, IGridNode gridNode, EntityPlayer player) {
super(
(IMEInventoryHandler<IAEFluidStack>) Objects
.requireNonNull(Util.getWirelessInv(is, player, StorageChannel.FLUIDS)));
super(is, slot, gridNode, player, StorageChannel.FLUIDS);
this.ips = (ToolWirelessTerminal) is.getItem();
this.grid = gridNode;
this.target = is;
@@ -135,4 +127,9 @@ public class WirelessFluidTerminalInventory extends MEMonitorHandler<IAEFluidSta
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack,
ItemStack newStack) {}
@Override
public IInventory getInventoryByName(String name) {
return null;
}
}
@@ -0,0 +1,140 @@
/* Author: asdflj */
package com.glodblock.github.inventory.item;
import static com.glodblock.github.common.Config.magnetRange;
import java.util.Iterator;
import java.util.List;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import appeng.util.Platform;
public class WirelessMagnet {
public static String modeKey = "MagnetMode";
public static String filterKey = "MagnetFilter";
public static String filterConfigKey = "MagnetConfig";
public enum Mode {
Off,
Inv,
ME
}
public enum ListMode {
WhiteList,
BlackList
}
public static List<?> getEntitiesInRange(Class<?> entityType, World world, int x, int y, int z, int distance) {
return world.getEntitiesWithinAABB(
entityType,
AxisAlignedBB.getBoundingBox(
x - distance,
y - distance,
z - distance,
x + distance,
y + distance,
z + distance));
}
@SuppressWarnings("unchecked")
public static boolean isConfigured(ItemStack wirelessTerm) {
NBTTagCompound data = Platform.openNbtData(wirelessTerm);
return data.hasKey(modeKey);
}
public static void doMagnet(ItemStack wirelessTerm, World world, EntityPlayer player) {
if (Platform.isClient() || wirelessTerm == null
|| getMode(wirelessTerm) == Mode.Off
|| player == null
|| player.isSneaking()
|| !isConfigured(wirelessTerm))
return;
Iterator<?> iterator = getEntitiesInRange(
EntityItem.class,
world,
(int) player.posX,
(int) player.posY,
(int) player.posZ,
magnetRange).iterator();
while (iterator.hasNext()) {
EntityItem itemToGet = (EntityItem) iterator.next();
if (itemToGet.func_145800_j() != null && itemToGet.func_145800_j()
.equals(player.getCommandSenderName())) { /* don`t pick up items dropped by yourself */
continue;
}
EntityPlayer closestPlayer = world.getClosestPlayerToEntity(itemToGet, magnetRange);
if (closestPlayer != null && closestPlayer != player) {
continue;
}
if (itemToGet.delayBeforeCanPickup > 0) {
itemToGet.delayBeforeCanPickup = 0;
}
itemToGet.motionX = itemToGet.motionY = itemToGet.motionZ = 0;
itemToGet.setPosition(
player.posX - 0.2 + (world.rand.nextDouble() * 0.4),
player.posY - 0.6,
player.posZ - 0.2 + (world.rand.nextDouble() * 0.4));
}
// xp
iterator = getEntitiesInRange(
EntityXPOrb.class,
world,
(int) player.posX,
(int) player.posY,
(int) player.posZ,
magnetRange).iterator();
while (iterator.hasNext()) {
EntityXPOrb xpToGet = (EntityXPOrb) iterator.next();
if (xpToGet.isDead || xpToGet.isInvisible()) {
continue;
}
int xpAmount = xpToGet.xpValue;
xpToGet.xpValue = 0;
player.xpCooldown = 0;
player.addExperience(xpAmount);
xpToGet.setDead();
xpToGet.setInvisible(true);
world.playSoundAtEntity(
player,
"random.orb",
0.08F,
0.5F * ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.8F));
}
}
public static Mode getMode(ItemStack is) {
if (is != null && is.getItem() instanceof ItemWirelessUltraTerminal) {
NBTTagCompound data = Platform.openNbtData(is);
if (data.hasKey(modeKey)) {
return Mode.values()[data.getInteger(modeKey)];
}
setMode(is, Mode.Off);
}
return Mode.Off;
}
public static void setMode(ItemStack is, Mode mode) {
if (is != null && is.getItem() instanceof ItemWirelessUltraTerminal) {
NBTTagCompound data = Platform.openNbtData(is);
data.setInteger(modeKey, mode.ordinal());
}
}
}
@@ -0,0 +1,284 @@
/* Author: asdflj */
package com.glodblock.github.inventory.item;
import static com.glodblock.github.inventory.item.WirelessMagnet.filterConfigKey;
import static com.glodblock.github.inventory.item.WirelessMagnet.filterKey;
import java.util.HashMap;
import java.util.UUID;
import java.util.function.Predicate;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import com.glodblock.github.inventory.ItemBiggerAppEngInventory;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.networking.IGridNode;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.IConfigManager;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import appeng.util.item.OreHelper;
import appeng.util.prioitylist.OreFilteredList;
public class WirelessMagnetCardFilterInventory extends BaseWirelessInventory implements IWirelessMagnetFilter {
private boolean ignoreNbt;
private boolean ignoreMeta;
private boolean useOre;
private boolean useOreDict;
private String oreDictFilter = "";
protected Predicate<IAEItemStack> filterPredicate = null;
private WirelessMagnet.ListMode listMode = WirelessMagnet.ListMode.WhiteList;
private final AppEngInternalInventory filterInventory;
private final NBTTagCompound settingCache;
private final NBTTagCompound filterCache;
@SuppressWarnings("unchecked")
public WirelessMagnetCardFilterInventory(ItemStack is, int slot, IGridNode gridNode, EntityPlayer player) {
super(is, slot, gridNode, player, StorageChannel.ITEMS, true);
filterInventory = new ItemBiggerAppEngInventory(is, filterKey, 27);
settingCache = getSettingTag(is);
filterCache = getFilterTag(is);
readFromNBT();
}
public void readFromNBT() {
NBTTagCompound data = Platform.openNbtData(this.target);
if (!data.hasKey(filterConfigKey)) this.writeToNBT();
NBTTagCompound tag = (NBTTagCompound) data.getTag(filterConfigKey);
ignoreNbt = tag.getBoolean("nbt");
ignoreMeta = tag.getBoolean("meta");
useOre = tag.getBoolean("ore");
useOreDict = tag.getBoolean("oreDict");
oreDictFilter = tag.getString("oreDictFilter");
this.listMode = WirelessMagnet.ListMode.values()[tag.getInteger("list")];
}
public void writeToNBT() {
NBTTagCompound data = Platform.openNbtData(this.target);
NBTTagCompound tmp = new NBTTagCompound();
tmp.setBoolean("nbt", ignoreNbt);
tmp.setBoolean("meta", ignoreMeta);
tmp.setBoolean("ore", useOre);
tmp.setBoolean("oreDict", useOreDict);
tmp.setString("oreDictFilter", oreDictFilter);
tmp.setInteger("list", this.listMode.ordinal());
data.setTag(filterConfigKey, tmp);
}
private NBTTagCompound getSettingTag(ItemStack is) {
return (NBTTagCompound) is.getTagCompound().getCompoundTag(filterConfigKey).copy();
}
private NBTTagCompound getFilterTag(ItemStack is) {
return (NBTTagCompound) is.getTagCompound().getCompoundTag(filterKey).copy();
}
@Override
public WirelessMagnet.ListMode getListMode() {
return this.listMode;
}
@Override
public boolean getNBTMode() {
return ignoreNbt;
}
@Override
public boolean getMetaMode() {
return ignoreMeta;
}
@Override
public boolean getOreMode() {
return useOre;
}
@Override
public boolean getOreDictMode() {
return useOreDict;
}
@Override
public String getOreDictFilter() {
return oreDictFilter;
}
@Override
public void setListMode(WirelessMagnet.ListMode mode) {
this.listMode = mode;
}
@Override
public void setNBTMode(boolean ignoreNBT) {
ignoreNbt = ignoreNBT;
}
@Override
public void setMetaMode(boolean ignoreMeta) {
this.ignoreMeta = ignoreMeta;
}
@Override
public void setOreMode(boolean useOre) {
this.useOre = useOre;
}
@Override
public void setOreDictMode(boolean useOreDict) {
this.useOreDict = useOreDict;
}
@Override
public void setOreDictFilter(String str) {
oreDictFilter = str;
filterPredicate = null;
}
@Override
public void clearConfig() {
IInventory inv = this.getInventoryByName("config");
for (int i = 0; i < inv.getSizeInventory(); i++) {
inv.setInventorySlotContents(i, null);
}
}
@Override
public StorageChannel getChannel() {
return null;
}
@Override
public IInventory getViewCellStorage() {
return null;
}
@Override
public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier) {
return 0;
}
@Override
public IMEMonitor<IAEItemStack> getItemInventory() {
return null;
}
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory() {
return null;
}
@Override
public IConfigManager getConfigManager() {
return null;
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack,
ItemStack newStack) {}
@Override
public void saveSettings() {
super.saveSettings();
writeToNBT();
}
@Override
public IInventory getInventoryByName(String name) {
if (name.equals("config")) {
return filterInventory;
}
return null;
}
public boolean doInject(IAEItemStack is, EntityItem itemToGet, World world) {
IAEItemStack ais = (IAEItemStack) injectItems(is);
if (ais != null) {
player.onItemPickup(itemToGet, ais.getItemStack().stackSize);
player.inventory.addItemStackToInventory(ais.getItemStack());
world.playSoundAtEntity(
player,
"random.pop",
0.15F,
((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
return false;
}
return true;
}
public boolean isItemFiltered(ItemStack inputItemStack) {
if (useOreDict && !oreDictFilter.isEmpty()) {
if (filterPredicate == null) filterPredicate = OreFilteredList.makeFilter(oreDictFilter);
if (filterPredicate.test(AEItemStack.create(inputItemStack))) return true;
}
for (int i = 0; i < filterInventory.getSizeInventory(); i++) {
ItemStack is = filterInventory.getStackInSlot(i);
if (is != null) {
if (useOre) {
// use oredict
if (OreHelper.INSTANCE
.sameOre(OreHelper.INSTANCE.isOre(is), OreHelper.INSTANCE.isOre(inputItemStack)))
return true;
}
if (ignoreMeta && ignoreNbt) {
// ignore meta & nbt
return is.getItem().equals(inputItemStack.getItem());
} else if (ignoreMeta) {
// ignore meta only
return ItemStack.areItemStackTagsEqual(is, inputItemStack)
&& is.getItem() == inputItemStack.getItem();
} else if (ignoreNbt) {
// ignore nbt only
return is.getItem() == inputItemStack.getItem()
&& is.getItemDamage() == inputItemStack.getItemDamage();
} else {
// ignore nothing/don't use oredict--must be exact match
return is.isItemEqual(inputItemStack) && ItemStack.areItemStackTagsEqual(is, inputItemStack);
}
}
}
return false;
}
public boolean isPassFilter(ItemStack is) {
return is != null && (listMode == WirelessMagnet.ListMode.WhiteList) == isItemFiltered(is);
}
public boolean checkCache(ItemStack is) {
return settingCache.equals(getSettingTag(is)) && filterCache.equals(getFilterTag(is));
}
public static class FilterCache {
private static final HashMap<UUID, WirelessMagnetCardFilterInventory> cache = new HashMap<>();
public static WirelessMagnetCardFilterInventory getFilter(ItemStack is, int slot, IGridNode gridNode,
EntityPlayer player) {
WirelessMagnetCardFilterInventory cachedInv = cache.get(player.getUniqueID());
if (cachedInv != null && cachedInv.checkCache(is)) {
return cachedInv;
} else {
WirelessMagnetCardFilterInventory newInv = new WirelessMagnetCardFilterInventory(
is,
slot,
gridNode,
player);
cache.put(player.getUniqueID(), newInv);
return newInv;
}
}
}
}
@@ -2,7 +2,6 @@ package com.glodblock.github.inventory.item;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
@@ -14,7 +13,6 @@ import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.ItemBiggerAppEngInventory;
import com.glodblock.github.inventory.WirelessFluidPatternTerminalPatterns;
import com.glodblock.github.util.Util;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
@@ -27,9 +25,7 @@ import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.MEMonitorHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
@@ -42,8 +38,7 @@ import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.Platform;
public class WirelessPatternTerminalExInventory extends MEMonitorHandler<IAEItemStack>
implements IWirelessPatternTerminal {
public class WirelessPatternTerminalExInventory extends BaseWirelessInventory implements IWirelessPatternTerminal {
private final ItemStack target;
private final IAEItemPowerStorage ips;
@@ -68,9 +63,7 @@ public class WirelessPatternTerminalExInventory extends MEMonitorHandler<IAEItem
@SuppressWarnings("unchecked")
public WirelessPatternTerminalExInventory(final ItemStack is, final int slot, IGridNode gridNode,
EntityPlayer player) {
super(
(IMEInventoryHandler<IAEItemStack>) Objects
.requireNonNull(Util.getWirelessInv(is, player, StorageChannel.ITEMS)));
super(is, slot, gridNode, player, StorageChannel.ITEMS);
this.ips = (ToolWirelessTerminal) is.getItem();
this.grid = gridNode;
this.target = is;
@@ -419,6 +412,7 @@ public class WirelessPatternTerminalExInventory extends MEMonitorHandler<IAEItem
@Override
public void saveSettings() {
super.saveSettings();
this.writeToNBT();
}
@@ -2,7 +2,6 @@ package com.glodblock.github.inventory.item;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
@@ -14,7 +13,6 @@ import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.ItemBiggerAppEngInventory;
import com.glodblock.github.inventory.WirelessFluidPatternTerminalPatterns;
import com.glodblock.github.util.Util;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
@@ -27,9 +25,7 @@ import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.MEMonitorHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
@@ -42,8 +38,7 @@ import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.Platform;
public class WirelessPatternTerminalInventory extends MEMonitorHandler<IAEItemStack>
implements IWirelessPatternTerminal {
public class WirelessPatternTerminalInventory extends BaseWirelessInventory implements IWirelessPatternTerminal {
private final ItemStack target;
private final IAEItemPowerStorage ips;
@@ -68,9 +63,7 @@ public class WirelessPatternTerminalInventory extends MEMonitorHandler<IAEItemSt
@SuppressWarnings("unchecked")
public WirelessPatternTerminalInventory(final ItemStack is, final int slot, IGridNode gridNode,
EntityPlayer player) {
super(
(IMEInventoryHandler<IAEItemStack>) Objects
.requireNonNull(Util.getWirelessInv(is, player, StorageChannel.ITEMS)));
super(is, slot, gridNode, player, StorageChannel.ITEMS);
this.ips = (ToolWirelessTerminal) is.getItem();
this.grid = gridNode;
this.target = is;
@@ -391,6 +384,7 @@ public class WirelessPatternTerminalInventory extends MEMonitorHandler<IAEItemSt
@Override
public void saveSettings() {
super.saveSettings();
this.writeToNBT();
}
@@ -20,14 +20,13 @@ import com.glodblock.github.network.CPacketSwitchGuis;
import com.glodblock.github.network.CPacketTransferRecipe;
import com.glodblock.github.network.CPacketValueConfig;
import com.glodblock.github.network.SPacketFluidUpdate;
import com.glodblock.github.network.SPacketLevelMaintainerGuiUpdate;
import com.glodblock.github.network.SPacketLevelTerminalUpdate;
import com.glodblock.github.network.SPacketMEFluidInvUpdate;
import com.glodblock.github.network.SPacketMEItemInvUpdate;
import com.glodblock.github.network.SPacketPatternItemRenamer;
import com.glodblock.github.network.SPacketSetItemAmount;
import com.glodblock.github.network.SPacketStringUpdate;
import com.glodblock.github.network.SPacketSuperStockReplenisherUpdate;
import com.glodblock.github.network.SPacketSuperStokerUpdate;
import com.glodblock.github.network.SPacketSwitchBack;
import com.glodblock.github.network.wrapper.FCNetworkWrapper;
@@ -63,8 +62,8 @@ public class ChannelLoader implements Runnable {
netHandler.registerMessage(new CPacketDumpTank.Handler(), CPacketDumpTank.class, id++, Side.SERVER);
netHandler.registerMessage(new SPacketFluidUpdate.Handler(), SPacketFluidUpdate.class, id++, Side.CLIENT);
netHandler.registerMessage(
new SPacketSuperStockReplenisherUpdate.Handler(),
SPacketSuperStockReplenisherUpdate.class,
new SPacketSuperStokerUpdate.Handler(),
SPacketSuperStokerUpdate.class,
id++,
Side.CLIENT);
netHandler
@@ -94,11 +93,6 @@ public class ChannelLoader implements Runnable {
SPacketPatternItemRenamer.class,
id++,
Side.SERVER);
netHandler.registerMessage(
new SPacketLevelMaintainerGuiUpdate.Handler(),
SPacketLevelMaintainerGuiUpdate.class,
id++,
Side.CLIENT);
}
public static void sendPacketToAllPlayers(Packet packet, World world) {
@@ -14,7 +14,7 @@ import com.glodblock.github.common.block.BlockIngredientBuffer;
import com.glodblock.github.common.block.BlockLargeIngredientBuffer;
import com.glodblock.github.common.block.BlockLevelMaintainer;
import com.glodblock.github.common.block.BlockOCPatternEditor;
import com.glodblock.github.common.block.BlockSuperStockReplenisher;
import com.glodblock.github.common.block.BlockSuperStoker;
import com.glodblock.github.common.block.BlockWalrus;
import com.glodblock.github.common.item.ItemBasicFluidStorageCell;
import com.glodblock.github.common.item.ItemBasicFluidStoragePart;
@@ -66,7 +66,7 @@ public class ItemAndBlockHolder {
public static BlockLargeIngredientBuffer LARGE_BUFFER = new BlockLargeIngredientBuffer().register();
public static BlockOCPatternEditor OC_EDITOR = new BlockOCPatternEditor().register();
public static BlockWalrus WALRUS = new BlockWalrus().register();
public static BlockSuperStockReplenisher SUPER_STOCK_RERPLENISHER = new BlockSuperStockReplenisher().register();
public static BlockSuperStoker SUPER_STOKER = new BlockSuperStoker().register();
public static ItemFluidDrop DROP = new ItemFluidDrop().register();
public static ItemFluidEncodedPattern PATTERN = new ItemFluidEncodedPattern().register();
public static ItemPartFluidTerminal FLUID_TERM = new ItemPartFluidTerminal().register();
@@ -8,7 +8,9 @@ import net.minecraft.item.ItemStack;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.lwjgl.input.Keyboard;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import com.glodblock.github.network.CPacketValueConfig;
import com.glodblock.github.util.Util;
import cpw.mods.fml.client.registry.ClientRegistry;
@@ -22,11 +24,14 @@ import cpw.mods.fml.relauncher.SideOnly;
public class KeybindLoader implements Runnable {
public static KeyBinding openTerminal;
public static KeyBinding restock;
@Override
public void run() {
openTerminal = new KeyBinding("key.OpenTerminal", Keyboard.CHAR_NONE, "itemGroup.ae2fc");
openTerminal = new KeyBinding(FluidCraft.MODID + ".key.OpenTerminal", Keyboard.CHAR_NONE, "itemGroup.ae2fc");
restock = new KeyBinding(FluidCraft.MODID + ".key.Restock", Keyboard.CHAR_NONE, "itemGroup.ae2fc");
ClientRegistry.registerKeyBinding(openTerminal);
ClientRegistry.registerKeyBinding(restock);
FMLCommonHandler.instance().bus().register(this);
}
@@ -35,6 +40,8 @@ public class KeybindLoader implements Runnable {
public void onKeyInput(InputEvent.KeyInputEvent event) {
if (openTerminal.isPressed()) {
handleOpenTerminalKey();
} else if (restock.isPressed()) {
handleRestockKey();
}
}
@@ -43,6 +50,8 @@ public class KeybindLoader implements Runnable {
public void onMouseInput(InputEvent.MouseInputEvent event) {
if (openTerminal.isPressed()) {
handleOpenTerminalKey();
} else if (restock.isPressed()) {
handleRestockKey();
}
}
@@ -60,4 +69,17 @@ public class KeybindLoader implements Runnable {
((ItemWirelessUltraTerminal) term.getRight().getItem()).guiGuiType(term.getRight()));
}
}
private void handleRestockKey() {
if (Minecraft.getMinecraft().currentScreen != null) return;
EntityClientPlayerMP p = Minecraft.getMinecraft().thePlayer;
if (p.openContainer == null) {
return;
}
ImmutablePair<Integer, ItemStack> term = Util.getUltraWirelessTerm(p);
if (term != null) {
FluidCraft.proxy.netHandler.sendToServer(new CPacketValueConfig(0, 1));
}
}
}
@@ -85,6 +85,7 @@ public class NEICellViewHandler implements IUsageHandler {
int count = 0;
for (IAEFluidStack aeFluid : sortedStacks) {
FluidStack fluid = aeFluid.getFluidStack();
long amount = fluid.amount;
ItemStack fluidItemStack = ItemFluidDrop.newStack(fluid);
if (fluidItemStack != null) {
fluidItemStack.stackSize = 1;
@@ -92,7 +93,7 @@ public class NEICellViewHandler implements IUsageHandler {
fluidItemStack,
OFFSET_X + count % ROW_ITEM_NUM * 18 + 1,
ITEMS_OFFSET_Y + count / ROW_ITEM_NUM * 18 + 1);
stacks.add(new ViewItemStack(positionedStack, aeFluid.getStackSize(), fluid.getFluid().getIcon(), fluid.getFluid().getColor()));
stacks.add(new ViewItemStack(positionedStack, amount, fluid.getFluid().getIcon(), fluid.getFluid().getColor()));
count++;
}
}
@@ -3,7 +3,6 @@ package com.glodblock.github.nei;
import java.util.regex.Pattern;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import com.glodblock.github.common.storage.IFluidCellInventory;
import com.glodblock.github.common.storage.IFluidCellInventoryHandler;
@@ -14,10 +13,9 @@ import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import codechicken.nei.SearchField;
import codechicken.nei.SearchTokenParser;
import codechicken.nei.api.ItemFilter;
public class NEISearchFilter implements SearchTokenParser.ISearchParserProvider {
public class NEIItemFilter implements SearchField.ISearchProvider {
@Override
public ItemFilter getFilter(String searchText) {
@@ -26,18 +24,8 @@ public class NEISearchFilter implements SearchTokenParser.ISearchParserProvider
}
@Override
public char getPrefix() {
return 0;
}
@Override
public EnumChatFormatting getHighlightedColor() {
return null;
}
@Override
public SearchTokenParser.SearchMode getSearchMode() {
return SearchTokenParser.SearchMode.ALWAYS;
public boolean isPrimary() {
return false;
}
public static class Filter implements ItemFilter {
@@ -52,13 +40,13 @@ public class NEISearchFilter implements SearchTokenParser.ISearchParserProvider
public boolean matches(ItemStack itemStack) {
if (itemStack.getItem() instanceof IStorageFluidCell) {
final IMEInventoryHandler<?> inventory = AEApi.instance().registries().cell()
.getCellInventory(itemStack, null, StorageChannel.FLUIDS);
.getCellInventory(itemStack, null, StorageChannel.FLUIDS);
if (inventory instanceof final IFluidCellInventoryHandler handler) {
final IFluidCellInventory cellInventory = handler.getCellInv();
if (cellInventory != null) {
for (IAEFluidStack fluid : cellInventory.getContents()) {
boolean result = pattern.matcher(fluid.getFluidStack().getLocalizedName().toLowerCase())
.find();
.find();
if (result) return true;
}
@@ -69,4 +57,5 @@ public class NEISearchFilter implements SearchTokenParser.ISearchParserProvider
}
}
}
@@ -18,7 +18,7 @@ public class NEI_FC_Config implements IConfigureNEI {
@Override
public void loadConfig() {
API.registerNEIGuiHandler(new AE2FC_NEIGuiHandler());
API.addSearchProvider(new NEISearchFilter());
API.addSearchProvider(new NEIItemFilter());
API.registerStackStringifyHandler(new FCStackStringifyHandler());
API.registerUsageHandler(new NEICellViewHandler());
@@ -1,9 +1,20 @@
package com.glodblock.github.network;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraftforge.common.util.ForgeDirection;
import com.glodblock.github.client.gui.container.ContainerFluidStorageBus;
import com.glodblock.github.client.gui.container.base.FCBaseContainer;
import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IItemTerminal;
import com.glodblock.github.inventory.item.IWirelessExtendCard;
import com.glodblock.github.inventory.item.IWirelessMagnetFilter;
import com.glodblock.github.inventory.item.WirelessMagnet;
import com.glodblock.github.util.BlockPos;
import com.glodblock.github.util.Util;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
@@ -25,6 +36,10 @@ public class CPacketFluidPatternTermBtns implements IMessage {
Value = value.toString();
}
public CPacketFluidPatternTermBtns(final String name, final boolean value) {
this(name, value ? 1 : 0);
}
public CPacketFluidPatternTermBtns() {
// NO-OP
}
@@ -64,7 +79,55 @@ public class CPacketFluidPatternTermBtns implements IMessage {
String Name = message.Name;
String Value = message.Value;
final Container c = ctx.getServerHandler().playerEntity.openContainer;
if (Name.startsWith("PatternTerminal.") && (c instanceof final FCContainerEncodeTerminal cpt)) {
final EntityPlayer player = ctx.getServerHandler().playerEntity;
if (Name.startsWith("WirelessTerminal.") && (c instanceof FCBaseContainer)) {
final FCBaseContainer cpt = (FCBaseContainer) c;
final IItemTerminal itemTerminal = (IItemTerminal) cpt.getHost();
final IWirelessExtendCard iwt = (IWirelessExtendCard) itemTerminal;
switch (Name) {
case "WirelessTerminal.Stock":
iwt.setRestock(!iwt.isRestock());
break;
case "WirelessTerminal.MagnetMode":
iwt.setMagnetCardNextMode();
break;
case "WirelessTerminal.OpenMagnet":
InventoryHandler.openGui(
player,
player.worldObj,
new BlockPos(
cpt.getPortableCell().getInventorySlot(),
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
-1),
ForgeDirection.UNKNOWN,
GuiType.WIRELESS_MAGNET_FILTER);
break;
case "WirelessTerminal.magnet.NBT":
((IWirelessMagnetFilter) itemTerminal).setNBTMode(Value.equals("1"));
break;
case "WirelessTerminal.magnet.Meta":
((IWirelessMagnetFilter) itemTerminal).setMetaMode(Value.equals("1"));
break;
case "WirelessTerminal.magnet.Ore":
((IWirelessMagnetFilter) itemTerminal).setOreMode(Value.equals("1"));
break;
case "WirelessTerminal.magnet.OreDictState":
((IWirelessMagnetFilter) itemTerminal).setOreDictMode(Value.equals("1"));
break;
case "WirelessTerminal.magnet.OreDictFilter":
((IWirelessMagnetFilter) itemTerminal).setOreDictFilter(Value);
break;
case "WirelessTerminal.magnet.FilterMode":
((IWirelessMagnetFilter) itemTerminal).setListMode(
Value.equals("1") ? WirelessMagnet.ListMode.WhiteList
: WirelessMagnet.ListMode.BlackList);
break;
case "WirelessTerminal.magnet.clear":
((IWirelessMagnetFilter) itemTerminal).clearConfig();
break;
}
itemTerminal.saveSettings();
} else if (Name.startsWith("PatternTerminal.") && (c instanceof final FCContainerEncodeTerminal cpt)) {
switch (Name) {
case "PatternTerminal.CraftMode" -> cpt.getPatternTerminal().setCraftingRecipe(Value.equals("1"));
case "PatternTerminal.Encode" -> {
@@ -1,9 +1,16 @@
package com.glodblock.github.network;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import com.glodblock.github.client.gui.container.ContainerLevelMaintainer;
import net.minecraft.entity.player.EntityPlayerMP;
import com.glodblock.github.client.gui.container.ContainerLevelMaintainer;
import com.glodblock.github.common.tile.TileLevelMaintainer;
import appeng.api.storage.data.IAEItemStack;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
@@ -12,18 +19,28 @@ import io.netty.buffer.ByteBuf;
public class CPacketLevelMaintainer implements IMessage {
public enum Action {
Refresh,
Quantity,
Batch,
Enable,
Disable,
Disable
}
private Action action;
private long size;
private int slotIndex;
@SuppressWarnings("unused")
public CPacketLevelMaintainer() {}
public CPacketLevelMaintainer() {
this.action = Action.Refresh;
this.slotIndex = 0;
this.size = 0;
}
public CPacketLevelMaintainer(Action action) {
this.action = action;
this.slotIndex = 0;
this.size = 0;
}
public CPacketLevelMaintainer(Action action, int slotIndex) {
this.action = action;
@@ -53,17 +70,43 @@ public class CPacketLevelMaintainer implements IMessage {
public static class Handler implements IMessageHandler<CPacketLevelMaintainer, IMessage> {
private List<IAEItemStack> refresh(ContainerLevelMaintainer cca) {
List<IAEItemStack> toSend = new ArrayList<>(TileLevelMaintainer.REQ_COUNT);
for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) {
IAEItemStack ias = cca.getTile().requests.getAEItemStack(i);
if (ias != null) {
toSend.add(ias);
}
}
return toSend;
}
@Nullable
@Override
public IMessage onMessage(CPacketLevelMaintainer message, MessageContext ctx) {
if (ctx.getServerHandler().playerEntity.openContainer instanceof final ContainerLevelMaintainer clm) {
switch (message.action) {
case Quantity -> clm.getTile().updateQuantity(message.slotIndex, message.size);
case Batch -> clm.getTile().updateBatchSize(message.slotIndex, message.size);
case Enable -> clm.getTile().updateStatus(message.slotIndex, false);
case Disable -> clm.getTile().updateStatus(message.slotIndex, true);
}
clm.updateGui();
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
List<IAEItemStack> toSend = switch (message.action) {
case Quantity -> {
clm.getTile().updateQuantity(message.slotIndex, message.size);
yield this.refresh(clm);
}
case Batch -> {
clm.getTile().updateBatchSize(message.slotIndex, message.size);
yield this.refresh(clm);
}
case Enable -> {
clm.getTile().updateStatus(message.slotIndex, false);
yield this.refresh(clm);
}
case Disable -> {
clm.getTile().updateStatus(message.slotIndex, true);
yield this.refresh(clm);
}
case Refresh -> this.refresh(clm);
};
SPacketMEUpdateBuffer.scheduleItemUpdate(player, toSend);
}
return null;
}
@@ -9,7 +9,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import com.glodblock.github.client.gui.container.ContainerPatternValueAmount;
import com.glodblock.github.client.gui.container.ContainerSuperStockReplenisher;
import com.glodblock.github.client.gui.container.ContainerSuperStoker;
import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.InventoryHandler;
@@ -94,7 +94,7 @@ public class CPacketPatternValueSet implements IMessage {
message.originGui);
}
if (player.openContainer instanceof FCContainerEncodeTerminal
|| player.openContainer instanceof ContainerSuperStockReplenisher) {
|| player.openContainer instanceof ContainerSuperStoker) {
Slot slot = player.openContainer.getSlot(message.valueIndex);
if (slot instanceof SlotFake) {
ItemStack stack = slot.getStack().copy();
@@ -2,9 +2,23 @@ package com.glodblock.github.network;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.StatCollector;
import org.apache.commons.lang3.tuple.ImmutablePair;
import com.glodblock.github.client.gui.container.ContainerFluidLevelEmitter;
import com.glodblock.github.common.item.ItemBaseWirelessTerminal;
import com.glodblock.github.inventory.item.WirelessCraftingTerminalInventory;
import com.glodblock.github.util.NameConst;
import com.glodblock.github.util.Util;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.IGridNode;
import appeng.api.storage.data.IAEItemStack;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
@@ -39,13 +53,61 @@ public class CPacketValueConfig implements IMessage {
@Override
public IMessage onMessage(CPacketValueConfig message, MessageContext ctx) {
EntityPlayer player = ctx.getServerHandler().playerEntity;
if (player.openContainer != null) {
Container container = player.openContainer;
Container container = player.openContainer;
if (container != null) {
if (container instanceof ContainerFluidLevelEmitter) {
((ContainerFluidLevelEmitter) container).setLevel(message.amount, player);
} else if (container instanceof ContainerPlayer) {
ImmutablePair<Integer, ItemStack> result = Util.getUltraWirelessTerm(player);
if (result != null) {
final ItemStack wirelessTerm = result.getRight();
if (message.valueIndex == 1) {
ItemBaseWirelessTerminal
.toggleRestockItemsMode(wirelessTerm, !Util.isRestock(wirelessTerm));
player.addChatMessage(
new ChatComponentText(
StatCollector.translateToLocal(
!Util.isRestock(wirelessTerm)
? NameConst.TT_ULTRA_TERMINAL_RESTOCK_ON
: NameConst.TT_ULTRA_TERMINAL_RESTOCK_OFF)));
} else {
IGridNode gridNode = Util.getWirelessGrid(wirelessTerm);
if (gridNode != null && Util.isRestock(wirelessTerm)
&& Util.rangeCheck(wirelessTerm, player, gridNode)) {
restockItems(wirelessTerm, gridNode, result.getLeft(), player);
}
}
}
}
}
return null;
}
@SuppressWarnings("unchecked")
private void restockItems(ItemStack terminal, IGridNode gridNode, int slot, EntityPlayer player) {
WirelessCraftingTerminalInventory inv = new WirelessCraftingTerminalInventory(
terminal,
slot,
gridNode,
player);
for (int i = 0; i < 9; i++) {
ItemStack is = player.inventory.mainInventory[i];
if (is != null) {
int maxSize = is.getMaxStackSize();
if (is.stackSize < maxSize) {
int fillSize = maxSize - is.stackSize;
IAEItemStack ias = AEApi.instance().storage().createItemStack(is);
ias.setStackSize(fillSize);
IAEItemStack extractedItem = (IAEItemStack) inv
.extractItems(ias, Actionable.MODULATE, inv.getActionSource());
if (extractedItem != null) {
player.inventory.addItemStackToInventory(extractedItem.getItemStack());
}
}
}
}
}
}
}
@@ -1,122 +0,0 @@
package com.glodblock.github.network;
import static com.glodblock.github.common.tile.TileLevelMaintainer.REQ_COUNT;
import static com.glodblock.github.common.tile.TileLevelMaintainer.RequestInfo;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import com.glodblock.github.api.registries.LevelState;
import com.glodblock.github.client.gui.GuiLevelMaintainer;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
public class SPacketLevelMaintainerGuiUpdate implements IMessage {
private Info[] infoList;
private boolean onlyState;
@SuppressWarnings("unused")
public SPacketLevelMaintainerGuiUpdate() {}
public SPacketLevelMaintainerGuiUpdate(RequestInfo[] requests, boolean onlyState) {
this.infoList = new Info[REQ_COUNT];
this.onlyState = onlyState;
for (int i = 0; i < REQ_COUNT; i++) {
if (requests[i] == null) {
this.infoList[i] = null;
} else {
this.infoList[i] = new Info(
requests[i].getQuantity(),
requests[i].getBatchSize(),
requests[i].isEnable(),
requests[i].getState());
}
}
}
@Override
public void fromBytes(ByteBuf buf) {
this.infoList = new Info[REQ_COUNT];
this.onlyState = buf.readBoolean();
for (int i = 0; i < REQ_COUNT; i++) {
if (buf.readBoolean()) {
if (this.onlyState) {
this.infoList[i] = new Info(LevelState.values()[buf.readInt()]);
} else {
this.infoList[i] = new Info(
buf.readLong(),
buf.readLong(),
buf.readBoolean(),
LevelState.values()[buf.readInt()]);
}
} else {
this.infoList[i] = null;
}
}
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeBoolean(this.onlyState);
for (Info info : this.infoList) {
buf.writeBoolean(info != null);
if (info == null) continue;
if (!this.onlyState) {
buf.writeLong(info.quantity);
buf.writeLong(info.batchSize);
buf.writeBoolean(info.enable);
}
buf.writeInt(info.state.ordinal());
}
}
private static class Info {
long quantity;
long batchSize;
boolean enable;
LevelState state;
Info(long quantity, long batchSize, boolean enable, LevelState state) {
this.quantity = quantity;
this.batchSize = batchSize;
this.enable = enable;
this.state = state;
}
Info(LevelState state) {
this.quantity = 0;
this.batchSize = 0;
this.enable = false;
this.state = state;
}
}
public static class Handler implements IMessageHandler<SPacketLevelMaintainerGuiUpdate, IMessage> {
@Override
public IMessage onMessage(SPacketLevelMaintainerGuiUpdate message, MessageContext ctx) {
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if (gs instanceof GuiLevelMaintainer gui) {
for (int i = 0; i < REQ_COUNT; i++) {
Info info = message.infoList[i];
if (info == null) continue;
if (message.onlyState) {
gui.updateComponent(i, info.state);
} else {
gui.updateComponent(i, info.quantity, info.batchSize, info.enable, info.state);
}
}
}
return null;
}
}
}
@@ -1,17 +1,22 @@
package com.glodblock.github.network;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.common.util.ForgeDirection;
import org.jetbrains.annotations.Nullable;
import com.glodblock.github.api.registries.LevelItemInfo;
import com.glodblock.github.api.registries.LevelState;
import com.glodblock.github.client.gui.GuiLevelTerminal;
import appeng.core.AEConfig;
@@ -22,28 +27,58 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
/**
* Packet used for level terminal updates. Packet allows the server to send an array of command packets, which are then
* processed in order. This allows for chaining commands to produce the desired update.
*/
public class SPacketLevelTerminalUpdate implements IMessage {
public static final int CLEAR_ALL_BIT = 1;
public static final int DISCONNECT_BIT = 2;
private final List<PacketEntry> commands = new ArrayList<>();
private int statusFlags;
public SPacketLevelTerminalUpdate() {}
@Override
public void fromBytes(ByteBuf buf) {
int entryNum = buf.readInt();
this.statusFlags = buf.readByte();
int numEntries = buf.readInt();
for (int i = 0; i < entryNum; i++) {
PacketType type = PacketType.values()[buf.readByte()];
for (int i = 0; i < numEntries; ++i) {
try {
PacketType type = PacketType.values()[buf.readByte()];
switch (type) {
case ADD -> this.commands.add(new PacketAdd(buf));
case REMOVE -> this.commands.add(new PacketRemove(buf));
case RENAME -> this.commands.add(new PacketRename(buf));
case DISCONNECT -> this.commands.add(new PacketDisconnect(buf));
case OVERWRITE_SLOT -> this.commands.add(new PacketOverwriteSlot(buf));
case OVERWITE_ALL_SLOT -> this.commands.add(new PacketOverwirteAllSlot(buf));
switch (type) {
case ADD -> this.commands.add(new PacketAdd(buf));
case REMOVE -> this.commands.add(new PacketRemove(buf));
case OVERWRITE -> this.commands.add(new PacketOverwrite(buf));
case RENAME -> this.commands.add(new PacketRename(buf));
default -> throw new IOException("Unknown packet type received of index " + type);
}
} catch (Exception e) {
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
AELog.info(
"Corrupted packet commands: (" + i
+ ") of ("
+ numEntries
+ ") -> "
+ this.commands.size()
+ " : "
+ this.commands.stream().map(packetEntry -> packetEntry.getClass().getSimpleName())
.collect(Collectors.groupingBy(String::new, Collectors.counting())));
if (AEConfig.instance.isFeatureEnabled(AEFeature.DebugLogging)) {
AELog.info(" <- Parsed content: " + this.commands);
}
}
AELog.debug(e);
return;
}
}
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
AELog.info(
" <- Received commands " + this.commands.size()
@@ -53,49 +88,80 @@ public class SPacketLevelTerminalUpdate implements IMessage {
}
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(commands.size());
for (PacketEntry entry : this.commands) {
buf.writeByte(entry.getType().ordinal());
entry.write(buf);
}
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
AELog.info(
" <- Sent commands " + this.commands.size()
+ " : "
+ this.commands.stream().map(packetEntry -> packetEntry.getClass().getSimpleName())
.collect(Collectors.groupingBy(String::new, Collectors.counting())));
if (AEConfig.instance.isFeatureEnabled(AEFeature.DebugLogging)) {
AELog.info(" -> Sent commands: " + this.commands);
try {
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
AELog.info(
" <- Sent commands " + this.commands.size()
+ " : "
+ this.commands.stream().map(packetEntry -> packetEntry.getClass().getSimpleName())
.collect(Collectors.groupingBy(String::new, Collectors.counting())));
if (AEConfig.instance.isFeatureEnabled(AEFeature.DebugLogging)) {
AELog.info(" -> Sent commands: " + this.commands);
}
}
buf.writeByte(statusFlags);
buf.writeInt(commands.size());
for (PacketEntry entry : commands) {
entry.write(buf);
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
public void addNewEntry(long id, int x, int y, int z, int dim, int side, int rows, int rowSize, String name,
LevelItemInfo[] infolist) {
this.commands.add(new PacketAdd(id, x, y, z, dim, side, rows, rowSize, name, infolist));
/**
* Remove all entries on the terminal. This is done BEFORE any entries are processed, so you can set this to clear
* old entries, and add new ones after in one packet.
*/
public void setClear() {
statusFlags |= CLEAR_ALL_BIT;
}
public void addRemoveEntry(long id) {
this.commands.add(new PacketRemove(id));
/**
* The terminal disconnected. Entries are still processed, but indicates for the GUI to darken/turn off the
* terminal. No further updates will arrive until the terminal reconnects.
*/
public void setDisconnect() {
this.statusFlags |= DISCONNECT_BIT;
}
public void addRenameEntry(long id, String newName) {
this.commands.add(new PacketRename(id, newName));
/**
* Adds a new entry. Fill out the rest of the command using the {@link PacketAdd#setItems(int, int, NBTTagList)} and
* {@link PacketAdd#setLocation(int, int, int, int, int)}.
*
* @return the packet, which needs to have information filled out.
*/
public PacketAdd addNewEntry(long id, String name, boolean online) {
PacketAdd packet = new PacketAdd(id, name, online);
commands.add(packet);
return packet;
}
public void addDisconnectEntry() {
this.commands.add(new PacketDisconnect());
/**
* Remove the entry with the id from the terminal.
*/
public void addRemovalEntry(long id) {
commands.add(new PacketRemove(id));
}
public void addOverwriteSlotEntry(long id, int index, LevelItemInfo info) {
this.commands.add(new PacketOverwriteSlot(id, index, info));
/**
* Rename the entry
*/
public void addRenamedEntry(long id, String newName) {
commands.add(new PacketRename(id, newName));
}
public void addOverwriteAllSlotEntry(long id, LevelItemInfo[] info) {
this.commands.add(new PacketOverwirteAllSlot(id, info));
/**
* Overwrite the entry with new items or new status
*/
public PacketOverwrite addOverwriteEntry(long id) {
PacketOverwrite packet = new PacketOverwrite(id);
commands.add(packet);
return packet;
}
public static class Handler implements IMessageHandler<SPacketLevelTerminalUpdate, IMessage> {
@@ -106,22 +172,23 @@ public class SPacketLevelTerminalUpdate implements IMessage {
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if (gs instanceof GuiLevelTerminal levelTerminal) {
levelTerminal.receivePackets(message.commands);
levelTerminal.postUpdate(message.commands, message.statusFlags);
}
return null;
}
}
protected enum PacketType {
enum PacketType {
ADD,
REMOVE,
OVERWRITE,
RENAME,
DISCONNECT,
OVERWRITE_SLOT,
OVERWITE_ALL_SLOT,
}
/**
* A packet for updating an entry.
*/
public abstract static class PacketEntry {
public final long entryId;
@@ -130,87 +197,181 @@ public class SPacketLevelTerminalUpdate implements IMessage {
this.entryId = entryId;
}
public PacketEntry(ByteBuf buf) {
protected PacketEntry(ByteBuf buf) throws IOException {
this.entryId = buf.readLong();
read(buf);
}
protected abstract PacketType getType();
/**
* Needs to write the packet id.
*/
protected abstract void write(ByteBuf buf) throws IOException;
protected void write(ByteBuf buf) {
buf.writeLong(this.entryId);
}
/**
* Reading the entry id is not needed.
*/
protected abstract void read(ByteBuf buf) throws IOException;
}
/**
* A command for sending a new entry.
*/
public static class PacketAdd extends PacketEntry {
public String name;
public int x, y, z, dim, side;
public int rows, rowSize;
public String name;
public LevelItemInfo[] infolist;
public boolean online;
public ItemStack selfItemStack;
public ItemStack displayItemStack;
public NBTTagList items;
PacketAdd(long id, int x, int y, int z, int dim, int side, int rows, int rowSize, String name,
LevelItemInfo[] infolist) {
PacketAdd(long id, String name, boolean online) {
super(id);
this.name = name;
this.online = online;
}
PacketAdd(ByteBuf buf) throws IOException {
super(buf);
}
public PacketAdd setLocation(int x, int y, int z, int dim, int side) {
this.x = x;
this.y = y;
this.z = z;
this.dim = dim;
this.side = side;
this.rows = rows;
this.rowSize = rowSize;
this.name = name;
this.infolist = infolist;
return this;
}
public PacketAdd(ByteBuf buf) {
super(buf);
public PacketAdd setItems(int rows, int rowSize, NBTTagList items) {
this.rows = rows;
this.rowSize = rowSize;
this.items = items;
return this;
}
public PacketAdd setViewItemStack(ItemStack selfItemStack, ItemStack displayItemStack) {
this.selfItemStack = selfItemStack;
this.displayItemStack = displayItemStack;
return this;
}
@Override
protected void write(ByteBuf buf) throws IOException {
buf.writeByte(PacketType.ADD.ordinal());
buf.writeLong(entryId);
ByteBufUtils.writeUTF8String(buf, this.name);
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
buf.writeInt(dim);
buf.writeByte(side);
buf.writeInt(rows);
buf.writeInt(rowSize);
ByteBuf tempBuf = Unpooled.directBuffer(256);
try {
try (ByteBufOutputStream stream = new ByteBufOutputStream(tempBuf)) {
NBTTagCompound wrapper = new NBTTagCompound();
if (selfItemStack != null) {
wrapper.setTag("self", selfItemStack.writeToNBT(new NBTTagCompound()));
}
if (displayItemStack != null) {
wrapper.setTag("display", displayItemStack.writeToNBT(new NBTTagCompound()));
}
wrapper.setTag("data", items);
CompressedStreamTools.writeCompressed(wrapper, stream);
}
buf.writeInt(tempBuf.readableBytes());
buf.writeBytes(tempBuf);
} finally {
tempBuf.release();
}
}
@Override
protected void read(ByteBuf buf) throws IOException {
this.name = ByteBufUtils.readUTF8String(buf);
this.x = buf.readInt();
this.y = buf.readInt();
this.z = buf.readInt();
this.dim = buf.readInt();
this.side = buf.readInt();
this.side = buf.readByte();
this.rows = buf.readInt();
this.rowSize = buf.readInt();
this.name = ByteBufUtils.readUTF8String(buf);
int infoSize = buf.readInt();
infolist = new LevelItemInfo[infoSize];
for (int i = 0; i < infoSize; i++) {
if (!buf.readBoolean()) continue;
ItemStack stack = ByteBufUtils.readItemStack(buf);
long quantity = buf.readLong();
long batchSize = buf.readLong();
LevelState state = LevelState.values()[buf.readInt()];
infolist[i] = new LevelItemInfo(stack, quantity, batchSize, state);
int payloadSize = buf.readInt();
try (ByteBufInputStream stream = new ByteBufInputStream(buf, payloadSize)) {
NBTTagCompound payload = CompressedStreamTools.readCompressed(stream);
int available = stream.available();
if (available > 0) {
byte[] left = new byte[available];
int read = stream.read(left);
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
AELog.info(
"Unread bytes detected (" + read
+ "): "
+ Arrays.toString(left)
+ " at "
+ dim
+ "#("
+ x
+ ":"
+ y
+ ":"
+ z
+ ")@"
+ ForgeDirection.getOrientation(side));
}
}
if (payload.hasKey("self", NBT.TAG_COMPOUND)) {
this.selfItemStack = ItemStack.loadItemStackFromNBT(payload.getCompoundTag("self"));
}
if (payload.hasKey("display", NBT.TAG_COMPOUND)) {
this.displayItemStack = ItemStack.loadItemStackFromNBT(payload.getCompoundTag("display"));
}
this.items = payload.getTagList("data", NBT.TAG_COMPOUND);
}
}
@Override
protected PacketType getType() {
return PacketType.ADD;
}
@Override
protected void write(ByteBuf buf) {
super.write(buf);
buf.writeInt(this.x);
buf.writeInt(this.y);
buf.writeInt(this.z);
buf.writeInt(this.dim);
buf.writeInt(this.side);
buf.writeInt(this.rows);
buf.writeInt(this.rowSize);
ByteBufUtils.writeUTF8String(buf, this.name);
buf.writeInt(this.infolist.length);
for (int i = 0; i < this.infolist.length; i++) {
LevelItemInfo info = this.infolist[i];
buf.writeBoolean(info != null);
if (info == null) continue;
// System.out.println("Writing info: " + info.stack != null);
ByteBufUtils.writeItemStack(buf, info.stack);
buf.writeLong(info.quantity);
buf.writeLong(info.batchSize);
buf.writeInt(info.state.ordinal());
}
public String toString() {
return "PacketAdd{" + "name='"
+ name
+ '\''
+ ", x="
+ x
+ ", y="
+ y
+ ", z="
+ z
+ ", dim="
+ dim
+ ", side="
+ side
+ ", rows="
+ rows
+ ", rowSize="
+ rowSize
+ ", online="
+ online
+ ", selfItemStack="
+ selfItemStack
+ ", displayItemStack="
+ displayItemStack
+ ", items="
+ items
+ ", entryId="
+ entryId
+ '}';
}
}
@@ -220,147 +381,205 @@ public class SPacketLevelTerminalUpdate implements IMessage {
super(id);
}
PacketRemove(ByteBuf buf) {
PacketRemove(ByteBuf buf) throws IOException {
super(buf);
}
@Override
protected PacketType getType() {
return PacketType.REMOVE;
protected void write(ByteBuf buf) {
buf.writeByte(PacketType.REMOVE.ordinal());
buf.writeLong(entryId);
}
@Override
protected void write(ByteBuf buf) {
super.write(buf);
protected void read(ByteBuf buf) {}
@Override
public String toString() {
return "PacketRemove{" + "entryId=" + entryId + '}';
}
}
/**
* Overwrite online status or inventory of the entry.
*/
public static class PacketOverwrite extends PacketEntry {
public static final int ONLINE_BIT = 1;
public static final int ONLINE_VALID = 1 << 1;
public static final int ITEMS_VALID = 1 << 2;
public static final int ALL_ITEM_UPDATE_BIT = 1 << 3;
public boolean onlineValid;
public boolean online;
public boolean itemsValid;
public boolean allItemUpdate;
public int[] validIndices;
public NBTTagList items;
protected PacketOverwrite(long id) {
super(id);
}
protected PacketOverwrite(ByteBuf buf) throws IOException {
super(buf);
}
public PacketOverwrite setOnline(boolean online) {
this.onlineValid = true;
this.online = online;
return this;
}
public PacketOverwrite setItems(int[] validIndices, NBTTagList items) {
this.itemsValid = true;
this.allItemUpdate = validIndices == null || validIndices.length == 0;
this.validIndices = validIndices;
this.items = items;
return this;
}
public PacketOverwrite setItems(int newSize, NBTTagList items) {
this.itemsValid = true;
this.allItemUpdate = true;
this.validIndices = new int[newSize];
this.items = items;
return this;
}
@Override
protected void write(ByteBuf buf) throws IOException {
buf.writeByte(PacketType.OVERWRITE.ordinal());
buf.writeLong(entryId);
int flags = 0;
if (onlineValid) {
flags |= ONLINE_VALID;
flags |= online ? ONLINE_BIT : 0;
}
if (itemsValid) {
flags |= ITEMS_VALID;
if (allItemUpdate) {
flags |= ALL_ITEM_UPDATE_BIT;
buf.writeByte(flags);
buf.writeInt(validIndices.length);
} else {
buf.writeByte(flags);
buf.writeInt(validIndices.length);
for (int validIndex : validIndices) {
buf.writeInt(validIndex);
}
}
ByteBuf tempBuf = Unpooled.directBuffer(256);
try {
try (ByteBufOutputStream stream = new ByteBufOutputStream(tempBuf)) {
NBTTagCompound wrapper = new NBTTagCompound();
wrapper.setTag("data", items);
CompressedStreamTools.writeCompressed(wrapper, stream);
}
buf.writeInt(tempBuf.readableBytes());
buf.writeBytes(tempBuf);
} finally {
tempBuf.release();
}
} else {
buf.writeByte(flags);
}
}
@Override
protected void read(ByteBuf buf) throws IOException {
int flags = buf.readByte();
/* Decide whether to use online flag or not */
if ((flags & ONLINE_VALID) == ONLINE_VALID) {
this.onlineValid = true;
this.online = (flags & ONLINE_BIT) == ONLINE_BIT;
}
/* Decide whether to read item list or not */
if ((flags & ITEMS_VALID) == ITEMS_VALID) {
this.itemsValid = true;
if ((flags & ALL_ITEM_UPDATE_BIT) == ALL_ITEM_UPDATE_BIT) {
this.allItemUpdate = true;
int numItems = buf.readInt();
this.validIndices = new int[numItems];
} else {
int numItems = buf.readInt();
this.validIndices = new int[numItems];
for (int i = 0; i < numItems; ++i) {
this.validIndices[i] = buf.readInt();
}
}
int payloadSize = buf.readInt();
try (ByteBufInputStream stream = new ByteBufInputStream(buf, payloadSize)) {
this.items = CompressedStreamTools.readCompressed(stream).getTagList("data", NBT.TAG_COMPOUND);
int available = stream.available();
if (available > 0) {
byte[] left = new byte[available];
int read = stream.read(left);
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
AELog.info("Unread bytes detected (" + read + "): " + Arrays.toString(left));
}
}
}
}
}
@Override
public String toString() {
return "PacketOverwrite{" + "onlineValid="
+ onlineValid
+ ", online="
+ online
+ ", itemsValid="
+ itemsValid
+ ", allItemUpdate="
+ allItemUpdate
+ ", validIndices="
+ Arrays.toString(validIndices)
+ ", items="
+ items
+ ", entryId="
+ entryId
+ '}';
}
}
/**
* Rename the entry.
*/
public static class PacketRename extends PacketEntry {
public String newName;
PacketRename(long id, String newName) {
protected PacketRename(long id, String newName) {
super(id);
this.newName = newName;
}
PacketRename(ByteBuf buf) {
protected PacketRename(ByteBuf buf) throws IOException {
super(buf);
this.newName = ByteBufUtils.readUTF8String(buf);
}
@Override
protected PacketType getType() {
return PacketType.RENAME;
}
@Override
protected void write(ByteBuf buf) {
super.write(buf);
ByteBufUtils.writeUTF8String(buf, this.newName);
}
}
public static class PacketDisconnect extends PacketEntry {
PacketDisconnect() {
super(0); // Ignored id
}
PacketDisconnect(ByteBuf buf) {
super(buf);
buf.writeByte(PacketType.RENAME.ordinal());
buf.writeLong(entryId);
ByteBufUtils.writeUTF8String(buf, newName);
}
@Override
protected PacketType getType() {
return PacketType.DISCONNECT;
}
}
public static class PacketOverwriteSlot extends PacketEntry {
public int index;
public LevelItemInfo info;
PacketOverwriteSlot(long id, int index, LevelItemInfo info) {
super(id);
this.index = index;
this.info = info;
}
PacketOverwriteSlot(ByteBuf buf) {
super(buf);
this.index = buf.readInt();
if (buf.readBoolean()) {
this.info = new LevelItemInfo(
ByteBufUtils.readItemStack(buf),
buf.readLong(),
buf.readLong(),
LevelState.values()[buf.readInt()]);
} else {
this.info = null;
}
protected void read(ByteBuf buf) {
newName = ByteBufUtils.readUTF8String(buf);
}
@Override
protected PacketType getType() {
return PacketType.OVERWRITE_SLOT;
}
@Override
protected void write(ByteBuf buf) {
super.write(buf);
buf.writeInt(index);
buf.writeBoolean(info != null);
ByteBufUtils.writeItemStack(buf, info.stack);
buf.writeLong(info.quantity);
buf.writeLong(info.batchSize);
buf.writeInt(info.state.ordinal());
}
}
public static class PacketOverwirteAllSlot extends PacketEntry {
public LevelItemInfo[] infoList;
PacketOverwirteAllSlot(long id, LevelItemInfo[] info) {
super(id);
this.infoList = info;
}
PacketOverwirteAllSlot(ByteBuf buf) {
super(buf);
int infoSize = buf.readInt();
this.infoList = new LevelItemInfo[infoSize];
for (int i = 0; i < infoSize; i++) {
if (!buf.readBoolean()) continue;
ItemStack stack = ByteBufUtils.readItemStack(buf);
long quantity = buf.readLong();
long batchSize = buf.readLong();
LevelState state = LevelState.values()[buf.readInt()];
this.infoList[i] = new LevelItemInfo(stack, quantity, batchSize, state);
}
}
@Override
protected PacketType getType() {
return PacketType.OVERWITE_ALL_SLOT;
}
@Override
protected void write(ByteBuf buf) {
super.write(buf);
buf.writeInt(this.infoList.length);
for (int i = 0; i < this.infoList.length; i++) {
LevelItemInfo info = this.infoList[i];
buf.writeBoolean(info != null);
if (info == null) continue;
buf.writeInt(i);
ByteBufUtils.writeItemStack(buf, info.stack);
buf.writeLong(info.quantity);
buf.writeLong(info.batchSize);
buf.writeInt(info.state.ordinal());
}
public String toString() {
return "PacketRename{" + "newName='" + newName + '\'' + ", entryId=" + entryId + '}';
}
}
}
@@ -9,6 +9,7 @@ import net.minecraft.client.gui.GuiScreen;
import com.glodblock.github.client.gui.GuiFluidCraftConfirm;
import com.glodblock.github.client.gui.GuiItemMonitor;
import com.glodblock.github.client.gui.GuiLevelMaintainer;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.item.AEItemStack;
@@ -96,6 +97,8 @@ public class SPacketMEItemInvUpdate implements IMessage {
((GuiItemMonitor) gs).postUpdate(message.list, message.resort);
} else if (gs instanceof GuiFluidCraftConfirm) {
((GuiFluidCraftConfirm) gs).postUpdate(message.list, message.ref);
} else if (gs instanceof GuiLevelMaintainer) {
((GuiLevelMaintainer) gs).postUpdate(message.list);
}
return null;
}
@@ -7,7 +7,7 @@ import java.util.Map;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import com.glodblock.github.client.gui.GuiSuperStockReplenisher;
import com.glodblock.github.client.gui.GuiSuperStoker;
import com.glodblock.github.util.Util;
import appeng.api.storage.data.IAEStack;
@@ -16,13 +16,13 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
public class SPacketSuperStockReplenisherUpdate implements IMessage {
public class SPacketSuperStokerUpdate implements IMessage {
private Map<Integer, IAEStack<?>> list;
public SPacketSuperStockReplenisherUpdate() {}
public SPacketSuperStokerUpdate() {}
public SPacketSuperStockReplenisherUpdate(Map<Integer, IAEStack<?>> data) {
public SPacketSuperStokerUpdate(Map<Integer, IAEStack<?>> data) {
this.list = data;
}
@@ -45,12 +45,12 @@ public class SPacketSuperStockReplenisherUpdate implements IMessage {
}
}
public static class Handler implements IMessageHandler<SPacketSuperStockReplenisherUpdate, IMessage> {
public static class Handler implements IMessageHandler<SPacketSuperStokerUpdate, IMessage> {
@Override
public IMessage onMessage(SPacketSuperStockReplenisherUpdate message, MessageContext ctx) {
public IMessage onMessage(SPacketSuperStokerUpdate message, MessageContext ctx) {
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if (gs instanceof GuiSuperStockReplenisher gss) {
if (gs instanceof GuiSuperStoker gss) {
gss.update(message.list);
}
return null;
@@ -1,18 +1,33 @@
package com.glodblock.github.proxy;
import static com.glodblock.github.common.Config.reStockTime;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import org.apache.commons.lang3.tuple.ImmutablePair;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.loader.KeybindLoader;
import com.glodblock.github.loader.ListenerLoader;
import com.glodblock.github.loader.RenderLoader;
import com.glodblock.github.nei.recipes.DefaultExtractorLoader;
import com.glodblock.github.network.CPacketValueConfig;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.Util;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
public class ClientProxy extends CommonProxy {
private static final Minecraft mc = Minecraft.getMinecraft();
private static long refreshTick = System.currentTimeMillis();
@Override
public void preInit(FMLPreInitializationEvent event) {
super.preInit(event);
@@ -38,4 +53,17 @@ public class ClientProxy extends CommonProxy {
new DefaultExtractorLoader().run();
}
}
@SubscribeEvent
public void tickEvent(TickEvent.PlayerTickEvent e) {
super.tickEvent(e);
if (refreshTick + reStockTime < System.currentTimeMillis()) {
// try to stock items
ImmutablePair<Integer, ItemStack> result = Util.getUltraWirelessTerm(mc.thePlayer);
if (result != null && mc.currentScreen == null && Util.isRestock(result.getRight())) {
FluidCraft.proxy.netHandler.sendToServer(new CPacketValueConfig(1, 0));
}
refreshTick = System.currentTimeMillis();
}
}
}
@@ -1,6 +1,13 @@
package com.glodblock.github.proxy;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import org.apache.commons.lang3.tuple.ImmutablePair;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.Config;
@@ -12,24 +19,87 @@ import com.glodblock.github.crossmod.extracells.EC2Replacer;
import com.glodblock.github.crossmod.thaumcraft.AspectUtil;
import com.glodblock.github.crossmod.thaumcraft.ThaumicEnergisticsCrafting;
import com.glodblock.github.inventory.external.AEFluidInterfaceHandler;
import com.glodblock.github.inventory.item.WirelessMagnet;
import com.glodblock.github.inventory.item.WirelessMagnetCardFilterInventory;
import com.glodblock.github.inventory.item.WirelessMagnetCardFilterInventory.FilterCache;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.network.SPacketMEUpdateBuffer;
import com.glodblock.github.network.wrapper.FCNetworkWrapper;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.Util;
import appeng.api.AEApi;
import appeng.api.IAppEngApi;
import appeng.api.config.Upgrades;
import appeng.api.networking.IGridNode;
import appeng.util.Platform;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
public class CommonProxy {
public final FCNetworkWrapper netHandler = new FCNetworkWrapper(FluidCraft.MODID);
public CommonProxy() {
MinecraftForge.EVENT_BUS.register(this);
FMLCommonHandler.instance().bus().register(this);
}
@SuppressWarnings("unchecked")
@SubscribeEvent
public void pickupEvent(EntityItemPickupEvent e) {
if (Platform.isServer() && e.entityPlayer != null) {
try {
EntityPlayer player = e.entityPlayer;
EntityItem itemEntity = e.item;
ItemStack stack = itemEntity.getEntityItem();
World world = player.getEntityWorld();
ImmutablePair<Integer, ItemStack> result = Util.getUltraWirelessTerm(player);
if (result != null) {
final ItemStack wirelessTerm = result.getRight();
WirelessMagnet.Mode mode = WirelessMagnet.getMode(wirelessTerm);
if (mode == WirelessMagnet.Mode.ME) {
IGridNode gridNode = Util.getWirelessGrid(wirelessTerm);
if (gridNode != null && Util.rangeCheck(wirelessTerm, player, gridNode)) {
WirelessMagnetCardFilterInventory inv = FilterCache
.getFilter(wirelessTerm, result.getLeft(), gridNode, player);
if (inv.isPassFilter(stack)) {
if (inv.doInject(
AEApi.instance().storage().createItemStack(stack),
itemEntity,
world)) {
itemEntity.setDead();
e.setCanceled(true);
}
}
}
}
}
} catch (NullPointerException ex) {
ex.printStackTrace();
}
}
}
@SubscribeEvent
public void tickEvent(TickEvent.PlayerTickEvent e) {
EntityPlayer player = e.player;
ImmutablePair<Integer, ItemStack> result = Util.getUltraWirelessTerm(player);
if (result != null) {
final ItemStack wirelessTerm = result.getRight();
if (WirelessMagnet.getMode(wirelessTerm) != WirelessMagnet.Mode.Off) {
WirelessMagnet.doMagnet(wirelessTerm, e.player.worldObj, e.player);
}
}
}
public void preInit(FMLPreInitializationEvent event) {
ModAndClassUtil.init();
ItemAndBlockHolder.init();
@@ -8,11 +8,16 @@ 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;
@@ -27,12 +32,19 @@ 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;
@@ -41,11 +53,22 @@ 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");
@@ -109,10 +132,22 @@ public class Ae2Reflect {
}
}
public static ICraftingCPU getCPU(CraftingCPURecord cpu) {
return Ae2Reflect.readField(cpu, fCPU_cpu);
}
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);
}
public static IUpgradeableHost getUpgradeList(ContainerUpgradeable container) {
return Ae2Reflect.readField(container, fInventory_containerUpgrade);
}
@@ -137,6 +172,18 @@ public class Ae2Reflect {
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);
}
public static IUpgradeableHost getUpgradeableHost(ContainerUpgradeable owner) {
return Ae2Reflect.readField(owner, fContainerUpgradeable_upgradeable);
}
@@ -145,6 +192,22 @@ public class Ae2Reflect {
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);
}
}
public static IFluidHandler getP2PLiquidTarget(PartP2PLiquids p2p) {
try {
return (IFluidHandler) mP2PLiquids_getTarget.invoke(p2p);
@@ -1,8 +1,5 @@
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;
@@ -17,9 +14,7 @@ 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> {
@@ -27,7 +22,6 @@ 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;
@@ -89,42 +83,18 @@ public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<
return checkInitialized(inputs);
}
@Override
public IAEStack<?>[] getAEInputs() {
return checkInitialized(aeInputs);
}
@Override
public IAEItemStack[] getCondensedInputs() {
return checkInitialized(inputsCond);
}
@Override
public IAEStack<?>[] getCondensedAEInputs() {
return checkInitialized(aeInputsCond);
}
public boolean setInputs(IAEStack<?>[] inputs) {
IAEStack<?>[] condensed = condenseAEStacks(inputs);
public boolean setInputs(IAEItemStack[] inputs) {
IAEItemStack[] condensed = condenseStacks(inputs);
if (condensed.length == 0) {
return false;
}
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);
this.inputs = inputs;
this.inputsCond = condensed;
return true;
}
@@ -133,42 +103,18 @@ public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<
return checkInitialized(outputs);
}
@Override
public IAEStack<?>[] getAEOutputs() {
return checkInitialized(aeOutputs);
}
@Override
public IAEItemStack[] getCondensedOutputs() {
return checkInitialized(outputsCond);
}
@Override
public IAEStack<?>[] getCondensedAEOutputs() {
return checkInitialized(aeOutputsCond);
}
public boolean setOutputs(IAEStack<?>[] outputs) {
IAEStack<?>[] condensed = condenseAEStacks(outputs);
public boolean setOutputs(IAEItemStack[] outputs) {
IAEItemStack[] condensed = condenseStacks(outputs);
if (condensed.length == 0) {
return false;
}
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);
this.outputs = Arrays.stream(outputs).filter(Objects::nonNull).toArray(IAEItemStack[]::new);
this.outputsCond = condensed;
return true;
}
@@ -176,20 +122,11 @@ 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!");
@@ -234,12 +171,12 @@ public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<
return patternStack;
}
public static NBTTagList writeStackArray(IAEStack<?>[] stacks) {
public static NBTTagList writeStackArray(IAEItemStack[] stacks) {
NBTTagList listTag = new NBTTagList();
for (IAEStack<?> stack : stacks) {
for (IAEItemStack stack : stacks) {
// see note at top of class
NBTTagCompound stackTag = new NBTTagCompound();
Platform.writeStackNBT(stack, stackTag);
if (stack != null) stack.writeToNBT(stackTag);
listTag.appendTag(stackTag);
}
return listTag;
@@ -259,11 +196,11 @@ public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<
&& setOutputs(readStackArray(tag.getTagList("out", Constants.NBT.TAG_COMPOUND)));
}
public static IAEStack<?>[] readStackArray(NBTTagList listTag) {
public static IAEItemStack[] readStackArray(NBTTagList listTag) {
// see note at top of class
IAEStack<?>[] stacks = new IAEStack<?>[listTag.tagCount()];
IAEItemStack[] stacks = new IAEItemStack[listTag.tagCount()];
for (int i = 0; i < stacks.length; i++) {
stacks[i] = readStackNBT(listTag.getCompoundTagAt(i), true);
stacks[i] = AEItemStack.loadItemStackFromNBT(listTag.getCompoundTagAt(i));
}
return stacks;
}
@@ -21,7 +21,7 @@ public class NameConst {
public static final String BLOCK_OC_PATTERN_EDITOR = "oc_pattern_editor";
public static final String BLOCK_LEVEL_MAINTAINER = "level_maintainer";
public static final String BLOCK_WALRUS = "walrus";
public static final String BLOCK_SUPER_STOCK_REPLENISHER = "super_stock_replenisher";
public static final String BLOCK_SUPER_STOKER = "super_stoker";
public static final String ITEM_FLUID_DROP = "fluid_drop";
public static final String ITEM_FLUID_ENCODED_PATTERN = "fluid_encoded_pattern";
public static final String ITEM_PART_FLUID_STORAGE_MONITOR = "part_fluid_storage_monitor";
@@ -58,7 +58,9 @@ public class NameConst {
public static final String ITEM_ENERGY_CARD = "energy_card";
public static final String TT_KEY = FluidCraft.MODID + ".tooltip.";
public static final String TT_CRAFTING_COMPLETE = TT_KEY + "crafting_complete";
public static final String TT_FLUID_TERMINAL = TT_KEY + "fluid_terminal";
public static final String TT_FLUID_TERMINAL_AMOUNT = TT_FLUID_TERMINAL + ".amount";
public static final String TT_LEVEL_TERMINAL = TT_KEY + "level_terminal";
public static final String TT_INVALID_FLUID = TT_KEY + "invalid_fluid";
public static final String TT_FLUID_PACKET = TT_KEY + "fluid_packet";
@@ -107,6 +109,12 @@ public class NameConst {
public static final String TT_QUANTUM_BRIDGE_CARD_DESC = TT_QUANTUM_BRIDGE_CARD + ".desc";
public static final String TT_ITEM_FLUID_VOID_CELL = TT_KEY + ITEM_FLUID_VOID_CELL;
public static final String TT_ULTRA_TERMINAL_RESTOCK = TT_ULTRA_TERMINAL + ".restock";
public static final String TT_ULTRA_TERMINAL_RESTOCK_ON = TT_ULTRA_TERMINAL_RESTOCK + ".on";
public static final String TT_ULTRA_TERMINAL_RESTOCK_OFF = TT_ULTRA_TERMINAL_RESTOCK + ".off";
public static final String TT_MAGNET_CARD_OREDICT = TT_KEY + "magnet_card.oreDictFilter";
public static final String WAILA_KEY = FluidCraft.MODID + ".waila.";
public static final String WAILA_ENABLE = WAILA_KEY + "enable";
public static final String WAILA_DISABLE = WAILA_KEY + "disable";
@@ -131,6 +139,13 @@ public class NameConst {
public static final String GUI_FLUID_EXPORT = GUI_KEY + ITEM_PART_FLUID_EXPORT;
public static final String GUI_FLUID_STORAGE_BUS = GUI_KEY + ITEM_PART_FLUID_STORAGE_BUS;
public static final String GUI_MAGNET_CARD = GUI_KEY + "magnet";
public static final String GUI_MAGNET_CARD_NBT = GUI_MAGNET_CARD + ".nbt";
public static final String GUI_MAGNET_CARD_META = GUI_MAGNET_CARD + ".meta";
public static final String GUI_MAGNET_CARD_ORE = GUI_MAGNET_CARD + ".ore";
public static final String GUI_MAGNET_CARD_WhiteList = GUI_MAGNET_CARD + ".whitelist";
public static final String GUI_MAGNET_CARD_BlackList = GUI_MAGNET_CARD + ".blacklist";
public static String i18n(String t, String delimiter, boolean hint) {
if (!hint) {
return I18n.format(t);
@@ -2,7 +2,9 @@ package com.glodblock.github.util;
import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.infinityBoosterCard;
import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.infinityEnergyCard;
import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.restockItems;
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;
@@ -14,6 +16,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
@@ -61,15 +64,12 @@ import appeng.util.item.AEFluidStack;
import appeng.util.item.AEItemStack;
import baubles.api.BaublesApi;
import codechicken.nei.recipe.StackInfo;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.registry.GameData;
import io.netty.buffer.ByteBuf;
public final class Util {
public static boolean isBaublesLoaded = Loader.isModLoaded("Baubles");
public static int drainItemPower(AEBaseContainer c, InventoryPlayer ip, int slot, int ticks, double pm,
IFluidPortableCell wt) {
if (slot != -1) {
@@ -110,6 +110,40 @@ public final class Util {
return ticks;
}
public static boolean rangeCheck(ItemStack is, EntityPlayer player, IGridNode grid) {
if (grid.getGrid() == null) return false;
return rangeCheck(is, player, grid.getGrid());
}
public static boolean rangeCheck(ItemStack is, EntityPlayer player, IGrid grid) {
boolean canConnect = false;
if (hasInfinityBoosterCard(is)) {
canConnect = true;
} else {
for (IGridNode node : grid.getMachines(TileWireless.class)) {
IWirelessAccessPoint accessPoint = (IWirelessAccessPoint) node.getMachine();
if (accessPoint.isActive() && accessPoint.getLocation().getDimension() == player.dimension) {
WorldCoord distance = accessPoint.getLocation()
.subtract((int) player.posX, (int) player.posY, (int) player.posZ);
int squaredDistance = distance.x * distance.x + distance.y * distance.y + distance.z * distance.z;
if (squaredDistance <= accessPoint.getRange() * accessPoint.getRange()) {
canConnect = true;
break;
}
}
}
}
return canConnect;
}
public static boolean isRestock(ItemStack is) {
if (is.getItem() instanceof ItemBaseWirelessTerminal) {
NBTTagCompound data = Platform.openNbtData(is);
return data.hasKey(restockItems) && data.getBoolean(restockItems);
}
return false;
}
public static boolean hasInfinityBoosterCard(ItemStack is) {
if (is.getItem() instanceof ItemBaseWirelessTerminal) {
NBTTagCompound data = Platform.openNbtData(is);
@@ -130,39 +164,26 @@ public final class Util {
}
public static IMEInventoryHandler<?> getWirelessInv(ItemStack is, EntityPlayer player, StorageChannel channel) {
if (Platform.isClient()) return new NullInventory<>();
IGridNode gridNode = getWirelessGrid(is);
if (gridNode == null) return null;
IGrid grid = gridNode.getGrid();
if (grid == null) return null;
boolean canConnect = false;
if (hasInfinityBoosterCard(is)) {
canConnect = true;
} else {
for (IGridNode node : grid.getMachines(TileWireless.class)) {
IWirelessAccessPoint accessPoint = (IWirelessAccessPoint) node.getMachine();
if (accessPoint.isActive() && accessPoint.getLocation().getDimension() == player.dimension) {
WorldCoord distance = accessPoint.getLocation()
.subtract((int) player.posX, (int) player.posY, (int) player.posZ);
int squaredDistance = distance.x * distance.x + distance.y * distance.y + distance.z * distance.z;
if (squaredDistance <= accessPoint.getRange() * accessPoint.getRange()) {
canConnect = true;
break;
if (Platform.isServer()) {
IGridNode gridNode = getWirelessGrid(is);
if (gridNode != null) {
IGrid grid = gridNode.getGrid();
if (grid != null) {
if (rangeCheck(is, player, grid)) {
IStorageGrid gridCache = grid.getCache(IStorageGrid.class);
if (gridCache != null) {
if (channel == StorageChannel.FLUIDS) {
return gridCache.getFluidInventory();
} else {
return gridCache.getItemInventory();
}
}
}
}
}
return null;
}
if (canConnect) {
IStorageGrid gridCache = grid.getCache(IStorageGrid.class);
if (gridCache != null) {
if (channel == StorageChannel.FLUIDS) {
return gridCache.getFluidInventory();
} else {
return gridCache.getItemInventory();
}
}
}
return null;
return new NullInventory<>();
}
public static ItemStack getWirelessTerminal(EntityPlayer player, int x) {
@@ -186,20 +207,16 @@ public final class Util {
return new ImmutablePair<>(i, is);
}
}
if (isBaublesLoaded) {
IInventory handler = BaublesApi.getBaubles(player);
if (handler != null) {
invSize = handler.getSizeInventory();
for (int i = 0; i < invSize; ++i) {
ItemStack is = handler.getStackInSlot(i);
if (is != null && is.getItem() instanceof ItemWirelessUltraTerminal) {
return new ImmutablePair<>(GuiHelper.encodeType(i, GuiHelper.InvType.PLAYER_BAUBLES), is);
}
IInventory handler = BaublesApi.getBaubles(player);
if (handler != null) {
invSize = handler.getSizeInventory();
for (int i = 0; i < invSize; ++i) {
ItemStack is = handler.getStackInSlot(i);
if (is != null && is.getItem() instanceof ItemWirelessUltraTerminal) {
return new ImmutablePair<>(GuiHelper.encodeType(i, GuiHelper.InvType.PLAYER_BAUBLES), is);
}
}
}
return null;
}
@@ -472,6 +489,18 @@ public final class Util {
public static class FluidUtil {
private static final ItemStack glassBottle = new ItemStack(glass_bottle, 1);
public static ItemStack getPotion(FluidStack fs) {
if (fs == null) return null;
MutablePair<Integer, ItemStack> fillStack = Util.FluidUtil.fillStack(glassBottle, fs);
if (fillStack != null && fillStack.getRight() != null
&& fillStack.getRight().getItem() instanceof ItemPotion) {
return fillStack.right;
}
return null;
}
public static final ItemStack water_bucket = new ItemStack(Items.water_bucket, 1);
public static void fluidTankInfoWriteToNBT(FluidTankInfo[] infos, NBTTagCompound data) {
@@ -75,7 +75,7 @@ tile.oc_pattern_editor.name=OC Pattern Editor
tile.level_maintainer.name=ME Level Maintainer
tile.fluid_buffer.name=ME Fluid Buffer
tile.walrus.name=Walrus
tile.super_stock_replenisher.name=Super Stock Replenisher
tile.super_stoker.name=Super Stoker
tile.fluid_auto_filler.name=ME Fluid Auto Filler
tile.certus_quartz_tank.name=Certus Quartz Tank - %s
tile.certus_quartz_tank_empty.name=Certus Quartz Tank
@@ -118,6 +118,8 @@ ae2fc.tooltip.ultra_terminal.WIRELESS_FLUID_PATTERN_TERMINAL_EX=Mode: Processing
ae2fc.tooltip.ultra_terminal=Right click + sneaking to switch mode.
ae2fc.tooltip.ultra_terminal.tips=ToolTips:
ae2fc.tooltip.ultra_terminal.tips.desc=1.You can put it to baubles slot and use hotkey to open.\n2.Interface mode hold §3Shift§7 toggle interface renamer button.\n3.When you are in the crafting plan screen.\nHold §3Shift§7 click cancel button will automatically add missing items to NEI bookmark.
ae2fc.tooltip.ultra_terminal.restock.on=Restock activate
ae2fc.tooltip.ultra_terminal.restock.off=Restock deactivated
ae2fc.tooltip.infinity_fluid=§aInfinity§r
ae2fc.tooltip.fluid_storage.void=Where nothing is everything, and everything is nothing
@@ -164,6 +166,19 @@ ae2fc.tooltip.not_fill_pattern.hint=Disabled
ae2fc.tooltip.open_configuration=Open configuration
ae2fc.tooltip.block_highlight=Highlight Block
ae2fc.tooltip.magnet_card.off=Magnet Card
ae2fc.tooltip.magnet_card.off.hint=Off
ae2fc.tooltip.magnet_card.inv=Magnet Card
ae2fc.tooltip.magnet_card.inv.hint=Pickup to Inventory
ae2fc.tooltip.magnet_card.me=Magnet Card
ae2fc.tooltip.magnet_card.me.hint=Pickup to ME
ae2fc.tooltip.magnet_card.filter=Magnet Filter
ae2fc.tooltip.magnet_card.oreDictFilter=Oredictionary filter
ae2fc.tooltip.restock.on=Toggle Restock
ae2fc.tooltip.restock.on.hint=Enable
ae2fc.tooltip.restock.off=Toggle Restock
ae2fc.tooltip.restock.off.hint=Disable
ae2fc.gui.part_fluid_pattern_terminal=Fluid Pattern Terminal
ae2fc.gui.part_fluid_pattern_terminal_ex=Fluid Processing Pattern Terminal
ae2fc.gui.part_level_terminal=Level Terminal
@@ -188,6 +203,13 @@ ae2fc.gui.part_fluid_terminal=ME Fluid Terminal
ae2fc.gui.part_fluid_storage_bus=ME Fluid Storage Bus
ae2fc.gui.fluid_auto_filler=ME Fluid Auto Filler
ae2fc.gui.magnet=Magnet Filter
ae2fc.gui.magnet.nbt=Ignore NBT Data
ae2fc.gui.magnet.meta=Ignore Meta Data
ae2fc.gui.magnet.ore=Use Ore Dictionary
ae2fc.gui.magnet.whitelist=Whitelisting
ae2fc.gui.magnet.blacklist=BlackListing
ae2fc.gui.color.StateNone=00000000
ae2fc.gui.color.StateIdle=FF55FF55
ae2fc.gui.color.StateCraft=FFFFFF55
@@ -196,7 +218,8 @@ ae2fc.gui.color.StateError=FFFF5555
error.unknown=Unknown
key.OpenTerminal=Open Wireless Universal Terminal
ae2fc.key.OpenTerminal=Open Wireless Universal Terminal
ae2fc.key.Restock=Toggle Restock
itemGroup.ae2fc=Fluid Craft For AE2
File renamed without changes.

Before

Width:  |  Height:  |  Size: 494 B

After

Width:  |  Height:  |  Size: 494 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB