Compare commits

...
88 Commits
Author SHA1 Message Date
danyadev b95dc4df18 support comparators for Certus Quartz Tank (#349) 2025-11-15 21:15:38 +01:00
danyadevandMartin Robertz d650636479 Support for GT large cell interactions with certus quartz tanks (#358)
Co-authored-by: Martin Robertz <[email protected]>
2025-11-15 10:42:44 +01:00
danyadevandMartin Robertz 2e6bfe6aac Fix Certus Quartz fluid flickering and sometimes rendering an incorrect amount of fluid, optimize packet sending and ticking (#348)
Co-authored-by: Martin Robertz <[email protected]>
2025-11-14 23:20:19 +01:00
Litten 219f8c313a Resolves Multi-Fluid Distribution Limit Check Only Evaluating First 5 Partition Slots (#362) 2025-11-13 18:44:17 +01:00
danyadev 0d5f682d3a don't integrate certus quartz tank with waila if WailaPlugins is present (#361) 2025-11-11 20:57:27 +01:00
danyadev adee911b77 remove IPatchedTextureAtlasSprite.markNeedsAnimationUpdate() calls (#357) 2025-11-10 10:19:42 +01:00
danyadev 8909e28ea3 certus quartz tank item rendering improvements (#355) 2025-11-09 12:15:52 +01:00
Martin Robertz 0207ffe430 update 2025-11-07 21:48:43 +01:00
hiroscho 3bb08974ce Fix/p2p bind doesn't copy stocking settings (#354) 2025-11-07 20:44:54 +00:00
Martin Robertz 2a2f22ce44 update 2025-11-07 21:35:46 +01:00
hiroscho 4a2b662dee Fix/p2p desync when saving an input to memory card again (#353) 2025-11-07 21:33:01 +01:00
Martin Robertz d9ccbe4bb1 update 2025-11-07 18:53:47 +01:00
hiroscho 488b08f1fa Fix dupe bug for dual p2p interface (#352) 2025-11-07 18:52:19 +01:00
danyadev 6490451dc8 fix waila body flickering when looking at a certus quartz tank (#350) 2025-11-03 15:13:46 +01:00
Dream Master b0f0c22eae update 2025-10-31 13:59:53 +01:00
danyadev 32af02239d refactor TileCertusQuartzTank (#346) 2025-10-30 16:30:10 +00:00
Martin Robertz f9c5b9bc41 update 2025-10-22 21:35:35 +02:00
hiroscho 3621f4ac62 Fix advanced blocking card doesn't work on load (#342) 2025-10-22 21:25:06 +02:00
Martin Robertz 8d9150bad9 update 2025-10-22 20:37:51 +02:00
lc-1337 7aaa651632 quick copy paste (#341) 2025-10-19 23:36:21 +02:00
Martin Robertz 03140c9d9a update 2025-10-07 11:52:49 +02:00
Kogepan229andMartin Robertz 826f966a46 Allows open the Level Emitter GUI from Level Terminal (#332)
Co-authored-by: Martin Robertz <[email protected]>
2025-10-06 16:39:30 +00:00
Kogepan229andMartin Robertz f755ba66d5 Add Memory Card support to Level Maintainer (#327)
Co-authored-by: Martin Robertz <[email protected]>
2025-10-06 16:23:17 +00:00
Martin Robertz 98f40ca0fa update 2025-10-06 17:28:39 +02:00
lc-1337 ef7a5d4d86 make maintainer read fluid level (#339) 2025-10-06 15:38:01 +02:00
0d91a7dd43 Compatibility with ae native fluid (#293)
Co-authored-by: lordIcocain <[email protected]>
Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: Kogepan229 <[email protected]>
2025-10-04 15:57:41 +00:00
Martin Robertz d49b319954 update 2025-10-04 17:51:22 +02:00
a955757cd7 Refactor: Replace Ae2Reflect usages with direct method calls (#326)
Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: Kogepan229 <[email protected]>
Co-authored-by: Kogepan229 <[email protected]>
2025-10-01 19:02:48 +02:00
Martin Robertz 855fe03f75 fix 2025-10-01 18:43:50 +02:00
Martin Robertz 9a7630bdfa update 2025-10-01 18:29:07 +02:00
Kogepan229andboubou19 8c2bd3ceef Adapted to AE2 GuiAmount changes (#338)
Co-authored-by: boubou19 <[email protected]>
2025-09-27 17:59:42 +02:00
lc-1337 0d58fe01b2 make nbt match item after forming press rename (#337) 2025-09-27 17:37:41 +02:00
Martin Robertz 550e3b2bab update 2025-09-15 21:00:18 +02:00
Martin Robertz d6ae1cf144 update 2025-09-09 07:59:47 +02:00
SKProCH de2f625577 Disable hotbar keys handling in terminals (#331) 2025-09-08 17:05:59 +02:00
Martin Robertz 029b479297 merge conflic fix 2025-09-07 13:24:35 +02:00
lc-1337andUltraProdigy 446920485a fix item duplication when cant inject (#334)
Co-authored-by: UltraProdigy <[email protected]>
2025-09-07 12:35:10 +02:00
Dream Master a48914c55c update 2025-09-05 16:18:39 +02:00
lc-1337 f5bdb35783 Fix Auto Filler crash (#335) 2025-09-03 18:29:53 +02:00
Martin Robertz 99822efb6d update 2025-08-31 11:07:13 +02:00
JakubandMartin Robertz 4c19501f38 Fix duping and voiding bug on network changes in p2p interface (#333)
Co-authored-by: Martin Robertz <[email protected]>
2025-08-31 09:03:14 +00:00
Martin Robertz ec26b6a372 update 2025-08-25 18:36:39 +02:00
SKProCHandKogepan229 697217c5cd Middle click craft ordering inserts a proper count (#329)
Co-authored-by: Kogepan229 <[email protected]>
2025-08-25 16:35:20 +00:00
SKProCH 80bcb3bdf3 Force save search text in the wireless terminal on any button press (#330) 2025-08-18 07:45:31 +07:00
Dream Master 8fe16e87bc update 2025-08-08 23:11:48 +07:00
NeOzay e471c1b38c shows Items|Fluids storage disks with NEI search inventories mode of Search Field (#324) 2025-08-08 16:10:04 +00:00
Niclas Klugmann 81c975ce12 German translation (#325) 2025-08-08 12:15:08 +00:00
Kogepan229 17d9ae47c0 Fix dreamcraft mod ID specification (#328) 2025-08-06 14:49:14 +07:00
Dream Master bbcea46300 update 2025-08-04 10:23:06 +07:00
01b08897d2 fix autofiller wont work after boot (#323)
Co-authored-by: NeOzay <[email protected]>
Co-authored-by: NeOzay <[email protected]>
2025-08-01 22:03:34 +07:00
lc-1337andNeOzay 64ecb14e96 reduce p2p interface lags on bind and on pattern change (#322)
Co-authored-by: NeOzay <[email protected]>
2025-07-27 11:57:21 +02:00
Eldrinn-Elantey 12bdd5ebfc Update ru_RU.lang (#318) 2025-07-27 08:59:08 +07:00
Alexdoru 10ee6f40ca fix event handler SPacketMEUpdateBuffer not being registered (#320) 2025-07-20 08:30:21 +00:00
Alexdoru 1e66772abc Cache Tessellator#instance in local var (#321) 2025-07-18 11:51:16 -07:00
NeOzay ae7af4e712 Use new localization message system from AE2 (#319) 2025-07-14 20:28:34 +00:00
Maya f9566ce891 update 2025-07-05 09:54:43 -06:00
8267150fa6 extend level maintainer feedback (#316)
Co-authored-by: Nikolay S. <[email protected]>
Co-authored-by: Maya <[email protected]>
2025-07-05 15:53:35 +00:00
Kogepan229 22b73f9fbf Use CraftingID to check CraftingLink equivalence in Level Maintainer (#317) 2025-07-05 09:49:50 -06:00
Martin Robertz 4669a1e4ed update 2025-07-02 18:21:47 +02:00
c86370caf9 implement pins (#315)
Co-authored-by: Maya <[email protected]>
Co-authored-by: Martin Robertz <[email protected]>
2025-07-01 20:40:42 +02:00
Martin Robertz 10fefc7996 update 2025-07-01 13:19:41 +02:00
8a086d714a Make P2P Tunnel - ME Dual Interface share storage slot contents between input and outputs (#302)
Co-authored-by: Ruling-0 <[email protected]>
Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: lordIcocain <[email protected]>
2025-06-29 17:51:17 +02:00
zyf051520 25abc806df Fix FluidExportBus NPE (#314) 2025-06-24 07:31:59 +00:00
Martin Robertz 04558b6913 update 2025-06-22 18:22:29 +02:00
0499adcc6f Add Super Stock Replenisher (#278)
Co-authored-by: Maya <[email protected]>
Co-authored-by: boubou19 <[email protected]>
Co-authored-by: lordIcocain <[email protected]>
2025-06-22 17:49:44 +02:00
Martin Robertz 35136c31ee update 2025-06-20 21:56:28 +02:00
lc-1337andboubou19 dffd8e07e0 always use fluid packet for partition (#310)
Co-authored-by: boubou19 <[email protected]>
2025-06-19 08:45:08 +00:00
Ethryanandgithub-actions[bot] 88c5b6be72 Hide EC stuff if EC is not loaded. (#312)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-06-17 16:24:33 +02:00
lc-1337 0095f69da2 fix player null crash magnet (#309) 2025-06-15 00:24:25 -05:00
Alexdoru bfba45e796 Account for client /server desync when teleporting items with magnet (#305) 2025-06-11 06:26:00 +02:00
Michael Doyle dee1277753 Fix Universal Terminal restock hotkey chat message saying the opposite of the current state (#308) 2025-06-10 20:36:14 -05:00
Kogepan229andboubou19 6ac5ea30f0 Rewrite Level Maintainer/Terminal Logic (#294)
Co-authored-by: boubou19 <[email protected]>
2025-06-09 20:12:08 +00:00
Martin Robertz 1ffcea9dd9 update 2025-06-09 15:35:46 +02:00
RecursivePineapple 3428c86f64 Fix div by zero (#306) 2025-06-09 12:25:06 +02:00
Alexdoru c504dbb28a Magnet improvements (#303) 2025-06-08 19:42:19 +02:00
Martin Robertz fe3168ed6e update 2025-05-31 14:55:00 +02:00
c5cea9eb19 Add magnet and restock to Universal terminal (#275)
Co-authored-by: Maya <[email protected]>
Co-authored-by: Caedis <[email protected]>
Co-authored-by: Ruling-0 <[email protected]>
2025-05-30 21:35:35 -06:00
Martin Robertz 5cc8534ba2 update 2025-05-25 21:10:05 +02:00
Kogepan229andMaya 410e33faa0 Fix fluid import/export bus GUI when WAILA is disabled (#298)
Co-authored-by: Maya <[email protected]>
2025-05-25 18:36:05 +00:00
Martin Robertz f235a68266 update 2025-05-25 15:10:33 +02:00
Kogepan229 47e41751df Fix NEI search always showing void cell (#300) 2025-05-24 21:02:42 -05:00
Martin Robertz df1384a7ee update 2025-05-24 22:27:58 +02:00
Kogepan229andboubou19 a70854c832 Restore NEI highlighting when searching for fluid in cells (#299)
Co-authored-by: boubou19 <[email protected]>
2025-05-24 18:09:11 +00:00
Martin Robertz a57cb5db52 update 2025-05-23 22:59:21 +02:00
Kogepan229 c0d438f774 Use long stack size in NEI CellView (#297) 2025-05-23 21:46:16 +02:00
lordIcocain 830ac91521 make baubles optional (#296) 2025-05-23 05:14:36 -04:00
Martin Robertz 1a959b5b8d update 2025-05-16 21:33:36 +02:00
Caedis f629b3a7da Update dependencies.gradle (#292) 2025-05-13 22:00:56 +08:00
149 changed files with 6164 additions and 3989 deletions

No files matched your search

+12 -13
View File
@@ -34,30 +34,29 @@
* 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.40-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-602-GTNH:dev')
api('com.github.GTNewHorizons:NotEnoughItems:2.8.33-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-739-GTNH:dev')
api('curse.maven:cofh-core-69162:2388751')
api('com.github.GTNewHorizons:waila:1.8.4:dev')
api("com.github.GTNewHorizons:GTNHLib:0.6.21:dev")
api('com.github.GTNewHorizons:waila:1.9.7:dev')
api("com.github.GTNewHorizons:GTNHLib:0.8.0:dev")
implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.12.0:dev") {
implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.12.7:dev") {
exclude group: 'com.github.GTNewHorizons', module: 'Applied-Energistics-2-Unofficial'
}
compileOnly('com.github.GTNewHorizons:Baubles-Expanded:2.1.7-GTNH:dev')
compileOnly('com.github.GTNewHorizons:Baubles-Expanded:2.2.2-GTNH:dev')
compileOnly('com.github.GTNewHorizons:ExtraCells2:2.5.35:dev') { transitive = false }
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') {
compileOnly('com.github.GTNewHorizons:ForestryMC:4.11.2:dev')
compileOnly('com.github.GTNewHorizons:EnderIO:2.10.3:dev')
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.52.99: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.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 }
compileOnly('com.github.GTNewHorizons:OpenComputers:1.12.4-GTNH:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:ThaumicEnergistics:1.7.14-GTNH:dev') { transitive = false }
runtimeOnlyNonPublishable("com.github.GTNewHorizons:DuraDisplay:1.3.4:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:DuraDisplay:1.4.0:dev")
}
+10 -2
View File
@@ -96,7 +96,9 @@ usesMixinDebug = false
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
mixinPlugin =
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
# Specify the package that contains all of your Mixins. The package must exist or
# the build will fail. If you have a package property defined in your mixins.<modid>.json,
# it must match with this or the build will fail.
mixinsPackage =
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
@@ -151,7 +153,7 @@ modrinthProjectId =
# type can be one of [project, version],
# and the name is the Modrinth project or version slug/id of the other mod.
# Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
# Note: UniMixins is automatically set as a required dependency if usesMixins = true.
modrinthRelations =
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.
@@ -172,6 +174,12 @@ curseForgeRelations =
# projects. New projects should not use this parameter.
# customArchiveBaseName =
# Optional parameter to customize the default working directory used by the runClient* tasks. Relative to the project directory.
# runClientWorkingDirectory = run/client
# Optional parameter to customize the default working directory used by the runServer* tasks. Relative to the project directory.
# runServerWorkingDirectory = run/server
# Optional parameter to have the build automatically fail if an illegal version is used.
# This can be useful if you e.g. only want to allow versions in the form of '1.1.xxx'.
# The check is ONLY performed if the version is a git tag.
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Vendored
+2 -2
View File
@@ -114,7 +114,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
CLASSPATH="\\\"\\\""
# Determine the Java command to use to start the JVM.
@@ -213,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
Vendored
+2 -2
View File
@@ -70,11 +70,11 @@ goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
set CLASSPATH=
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
+1 -1
View File
@@ -17,7 +17,7 @@ pluginManagement {
}
plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.38'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.48'
}
@@ -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;required-after:Baubles;after:waila;after:thaumicenergistics;after:ae2wct")
dependencies = "required-after:appliedenergistics2@[rv3-beta-238,);required-after:CoFHCore;after:waila;after:thaumicenergistics;after:ae2wct")
public class FluidCraft {
public static final String MODID = "ae2fc";
@@ -16,11 +16,13 @@ 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;
}
@@ -39,6 +41,7 @@ public interface ILevelViewable extends IGridHost, ISide, ISegmentedInventory, I
return 1;
};
@Deprecated
default ItemStack getSelfItemStack() {
return null;
}
@@ -46,8 +49,11 @@ public interface ILevelViewable extends IGridHost, ISide, ISegmentedInventory, I
/**
* "Target" Display representation
*/
@Deprecated
default ItemStack getDisplayItemStack() {
return null;
}
LevelItemInfo[] getLevelItemInfoList();
}
@@ -0,0 +1,20 @@
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;
}
}
@@ -0,0 +1,11 @@
package com.glodblock.github.api.registries;
public enum LevelState {
None,
Idle,
Craft,
Export,
Error,
NotFound,
CantCraft
}
@@ -0,0 +1,87 @@
package com.glodblock.github.client.gui;
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;
// copy from WirelessCraftingTerminal WCTGuiButton
public class FCGuiBaseButton extends GuiButton {
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,13 +22,11 @@ import com.glodblock.github.util.Ae2ReflectClient;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.AEBaseContainer;
import appeng.helpers.InventoryAction;
public class GuiCraftingStatus extends appeng.client.gui.implementations.GuiCraftingStatus {
private GuiTabButton originalGuiBtn;
private final ITerminalHost host;
public GuiCraftingStatus(InventoryPlayer inventoryPlayer, ITerminalHost te) {
@@ -38,26 +36,21 @@ public class GuiCraftingStatus extends appeng.client.gui.implementations.GuiCraf
@Override
public void initGui() {
if (host instanceof PartFluidPatternTerminal)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.FLUID_TERMINAL.stack());
else if (host instanceof PartFluidPatternTerminalEx)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.FLUID_TERMINAL_EX.stack());
else if (host instanceof PartFluidTerminal)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.FLUID_TERM.stack());
else if (host instanceof PartLevelTerminal)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.LEVEL_TERMINAL.stack());
if (host instanceof PartFluidPatternTerminal) this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL.stack();
else if (host instanceof PartFluidPatternTerminalEx) this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL_EX.stack();
else if (host instanceof PartFluidTerminal) this.myIcon = ItemAndBlockHolder.FLUID_TERM.stack();
else if (host instanceof PartLevelTerminal) this.myIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack();
else if (host instanceof IWirelessTerminal terminal && terminal.isUniversal(host))
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack());
this.myIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack();
else if (host instanceof WirelessFluidTerminalInventory)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.WIRELESS_FLUID_TERM.stack());
this.myIcon = ItemAndBlockHolder.WIRELESS_FLUID_TERM.stack();
else if (host instanceof WirelessPatternTerminalInventory)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.WIRELESS_PATTERN_TERM.stack());
this.myIcon = ItemAndBlockHolder.WIRELESS_PATTERN_TERM.stack();
else if (host instanceof WirelessInterfaceTerminalInventory)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.WIRELESS_INTERFACE_TERM.stack());
this.myIcon = ItemAndBlockHolder.WIRELESS_INTERFACE_TERM.stack();
else if (host instanceof WirelessLevelTerminalInventory)
Ae2ReflectClient.rewriteIcon(this, ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack());
this.myIcon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack();
super.initGui();
originalGuiBtn = Ae2ReflectClient.getOriginalGuiButton(this);
}
@Override
@@ -92,7 +85,7 @@ public class GuiCraftingStatus extends appeng.client.gui.implementations.GuiCraf
new CPacketInventoryAction(
InventoryAction.AUTO_CRAFT,
Ae2ReflectClient.getInventorySlots(this).size(),
0,
hoveredAEStack.getStackSize(),
hoveredAEStack));
return;
}
@@ -17,6 +17,7 @@ import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.NameConst;
import appeng.api.config.AdvancedBlockingMode;
import appeng.api.config.FuzzyMode;
import appeng.api.config.InsertionMode;
import appeng.api.config.LockCraftingMode;
import appeng.api.config.Settings;
@@ -43,6 +44,7 @@ public class GuiDualInterface extends GuiUpgradeable {
private GuiTabButton switcher;
private GuiImgButton BlockMode;
private GuiImgButton SmartBlockMode;
private GuiImgButton fuzzyMode;
private GuiToggleButton interfaceMode;
private GuiImgButton insertionMode;
private GuiImgButton sidelessMode;
@@ -152,6 +154,16 @@ public class GuiDualInterface extends GuiUpgradeable {
LockCraftingMode.NONE);
this.lockCraftingMode.visible = this.bc.getInstalledUpgrades(Upgrades.LOCK_CRAFTING) > 0;
this.buttonList.add(lockCraftingMode);
offset += 18;
this.fuzzyMode = new GuiImgButton(
this.guiLeft - 18,
this.guiTop + offset,
Settings.FUZZY_MODE,
FuzzyMode.IGNORE_ALL);
this.fuzzyMode.visible = this.bc.getInstalledUpgrades(Upgrades.FUZZY) > 0;
this.buttonList.add(fuzzyMode);
}
@Override
@@ -187,6 +199,9 @@ public class GuiDualInterface extends GuiUpgradeable {
if (this.lockCraftingMode != null) {
this.lockCraftingMode.set(((ContainerInterface) this.cvb).getLockCraftingMode());
}
if (this.fuzzyMode != null) {
this.fuzzyMode.set(((ContainerInterface) this.cvb).getFuzzyMode());
}
this.fontRendererObj.drawString(
getGuiDisplayName(StatCollector.translateToLocal(NameConst.GUI_FLUID_INTERFACE)),
8,
@@ -198,7 +213,7 @@ public class GuiDualInterface extends GuiUpgradeable {
protected String getBackground() {
if (!ModAndClassUtil.isBigInterface) return "guis/interface.png";
return switch (((ContainerInterface) this.cvb).getPatternCapacityCardsInstalled()) {
case -1 -> "guis/interfacenone.png";
case -1 -> "guis/interfacenonenoconfig.png";
case 1 -> "guis/interface2.png";
case 2 -> "guis/interface3.png";
case 3 -> "guis/interface4.png";
@@ -240,6 +255,8 @@ public class GuiDualInterface extends GuiUpgradeable {
.sendToServer(new PacketConfigButton(this.advancedBlockingMode.getSetting(), backwards));
} else if (btn == this.lockCraftingMode) {
NetworkHandler.instance.sendToServer(new PacketConfigButton(this.lockCraftingMode.getSetting(), backwards));
} else if (btn == this.fuzzyMode) {
NetworkHandler.instance.sendToServer(new PacketConfigButton(this.fuzzyMode.getSetting(), backwards));
}
}
@@ -256,5 +273,8 @@ public class GuiDualInterface extends GuiUpgradeable {
if (this.lockCraftingMode != null) {
this.lockCraftingMode.setVisibility(this.bc.getInstalledUpgrades(Upgrades.LOCK_CRAFTING) > 0);
}
if (this.fuzzyMode != null) {
this.fuzzyMode.setVisibility(this.bc.getInstalledUpgrades(Upgrades.FUZZY) > 0);
}
}
}
@@ -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,14 @@ 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, "ENABLE_12x", "ENABLE", "enable");
this.registerApp(33, "DISABLE_12x", "DISABLE", "disable");
this.registerApp(34, "RESTOCK", "ENABLE", "restock.on");
this.registerApp(35, "RESTOCK", "DISABLE", "restock.off");
}
}
@@ -135,6 +144,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 +172,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 +234,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();
}
@@ -55,6 +55,7 @@ public class GuiFCPriority extends FCGuiAmount {
protected void addQty(final int i) {
try {
this.amountBox.setText(Long.toString(getAmount() + i));
this.amountBox.setCursorPositionEnd();
} catch (final NumberFormatException ignore) {}
try {
NetworkHandler.instance
@@ -45,9 +45,7 @@ public class GuiFluidCraftAmount extends FCGuiAmount {
this.guiTop + 53,
Settings.CRAFTING_MODE,
CraftingMode.STANDARD));
this.amountBox.setText("1");
this.amountBox.setSelectionPos(0);
((ContainerCraftAmount) this.inventorySlots).setAmountField(this.amountBox);
}
@Override
@@ -2,22 +2,35 @@ package com.glodblock.github.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerFluidLevelEmitter;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import com.glodblock.github.common.parts.PartFluidLevelEmitter;
import com.glodblock.github.common.parts.PartLevelTerminal;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.network.CPacketLevelTerminalCommands;
import com.glodblock.github.network.CPacketValueConfig;
import com.glodblock.github.util.NameConst;
import com.glodblock.github.util.Util;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.util.DimensionalCoord;
import appeng.client.gui.implementations.GuiUpgradeable;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.container.AEBaseContainer;
import appeng.core.AEConfig;
import appeng.core.localization.GuiColors;
import appeng.core.localization.GuiText;
@@ -28,6 +41,11 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable {
private MEGuiTextField amountTextField;
protected GuiType originalGui;
protected Util.DimensionalCoordSide originalBlockPos;
protected ItemStack originalGuiIcon;
protected GuiTabButton originalGuiBtn;
private GuiButton plus1;
private GuiButton plus10;
private GuiButton plus100;
@@ -43,6 +61,43 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable {
public GuiFluidLevelEmitter(final InventoryPlayer inventoryPlayer, final PartFluidLevelEmitter te) {
super(new ContainerFluidLevelEmitter(inventoryPlayer, te));
if (inventoryPlayer.player.openContainer instanceof AEBaseContainer container) {
var target = container.getTarget();
if (target instanceof PartLevelTerminal terminal) {
originalGuiIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack();
originalGui = GuiType.LEVEL_TERMINAL;
DimensionalCoord blockPos = new DimensionalCoord(terminal.getTile());
originalBlockPos = new Util.DimensionalCoordSide(
blockPos.x,
blockPos.y,
blockPos.z,
blockPos.getDimension(),
terminal.getSide(),
"");
} else if (target instanceof IWirelessTerminal terminal && terminal.isUniversal(target)) {
originalGuiIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack();
originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack());
originalBlockPos = new Util.DimensionalCoordSide(
terminal.getInventorySlot(),
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
0,
inventoryPlayer.player.worldObj.provider.dimensionId,
ForgeDirection.UNKNOWN,
"");
} else if (target instanceof WirelessLevelTerminalInventory terminal) {
originalGuiIcon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack();
originalGui = GuiType.WIRELESS_LEVEL_TERMINAL;
originalBlockPos = new Util.DimensionalCoordSide(
terminal.getInventorySlot(),
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
0,
inventoryPlayer.player.worldObj.provider.dimensionId,
ForgeDirection.UNKNOWN,
"");
}
}
}
@Override
@@ -55,6 +110,17 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable {
this.amountTextField.setFocused(true);
((ContainerFluidLevelEmitter) this.inventorySlots).setTextField(this.amountTextField);
this.validateText();
if (this.originalGuiIcon != null) {
this.originalGuiBtn = new GuiTabButton(
this.guiLeft + 151,
this.guiTop - 4,
this.originalGuiIcon,
this.originalGuiIcon.getDisplayName(),
itemRender);
this.originalGuiBtn.setHideEdge(13);
this.buttonList.add(originalGuiBtn);
}
}
@Override
@@ -143,9 +209,18 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable {
@Override
protected void actionPerformed(final GuiButton btn) {
super.actionPerformed(btn);
if (btn == this.setButton && this.setButton.enabled) {
if (btn == this.originalGuiBtn) {
CPacketLevelTerminalCommands message = new CPacketLevelTerminalCommands(
CPacketLevelTerminalCommands.Action.BACK,
originalBlockPos.x,
originalBlockPos.y,
originalBlockPos.z,
originalBlockPos.getDimension(),
originalBlockPos.getSide());
message.setOriginalGui(originalGui.ordinal());
FluidCraft.proxy.netHandler.sendToServer(message);
} else if (btn == this.setButton && this.setButton.enabled) {
final long amount = this.getAmountLong();
this.amountTextField.setText(Long.toString(amount));
@@ -161,6 +236,8 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable {
if (isPlus || isMinus) {
long result = addOrderAmount(this.getQty(btn));
this.amountTextField.setText(Long.toString(result));
} else {
super.actionPerformed(btn);
}
}
}
@@ -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;
}
}
@@ -19,9 +19,7 @@ import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.network.CPacketFluidUpdate;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.Util;
import com.mitchej123.hodgepodge.textures.IPatchedTextureAtlasSprite;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEFluidStack;
@@ -97,10 +95,6 @@ public class GuiFluidTerminal extends GuiFluidMonitor {
IIcon icon = fluid.getIcon();
if (icon == null) return;
if (ModAndClassUtil.HODGEPODGE && icon instanceof IPatchedTextureAtlasSprite) {
((IPatchedTextureAtlasSprite) icon).markNeedsAnimationUpdate();
}
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
@@ -109,7 +103,7 @@ public class GuiFluidTerminal extends GuiFluidMonitor {
(fluid.getColor() >> 16 & 0xFF) / 255.0F,
(fluid.getColor() >> 8 & 0xFF) / 255.0F,
(fluid.getColor() & 0xFF) / 255.0F);
drawTexturedModelRectFromIcon(posX, posY, fluid.getIcon(), 16, 16);
drawTexturedModelRectFromIcon(posX, posY, icon, 16, 16);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND);
GL11.glColor3f(1, 1, 1);
@@ -7,12 +7,10 @@ import net.minecraft.item.ItemStack;
import com.glodblock.github.client.gui.base.FCGuiMonitor;
import com.glodblock.github.client.gui.container.ContainerItemMonitor;
import com.glodblock.github.util.ModAndClassUtil;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.me.ItemRepo;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
public class GuiItemMonitor extends FCGuiMonitor<IAEItemStack> {
@@ -37,13 +35,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);
}
@Override
public void drawScreen(final int mouseX, final int mouseY, final float btn) {
super.drawScreen(mouseX, mouseY, btn);
if (ModAndClassUtil.isSearchBar && AEConfig.instance.preserveSearchBar && searchField != null)
handleTooltip(mouseX, mouseY, searchField.new TooltipProvider());
super.drawFG(offsetX, offsetY, mouseX, mouseY);
}
@Override
@@ -0,0 +1,104 @@
package com.glodblock.github.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import com.glodblock.github.common.parts.PartLevelTerminal;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.network.CPacketLevelTerminalCommands;
import com.glodblock.github.util.Util;
import appeng.api.util.DimensionalCoord;
import appeng.client.gui.implementations.GuiLevelEmitter;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.AEBaseContainer;
import appeng.parts.automation.PartLevelEmitter;
public class GuiLevelEmitterProxy extends GuiLevelEmitter {
protected GuiType originalGui;
protected Util.DimensionalCoordSide originalBlockPos;
protected ItemStack originalGuiIcon;
protected GuiTabButton originalGuiBtn;
public GuiLevelEmitterProxy(final InventoryPlayer inventoryPlayer, final PartLevelEmitter te) {
super(inventoryPlayer, te);
if (inventoryPlayer.player.openContainer instanceof AEBaseContainer container) {
var target = container.getTarget();
if (target instanceof PartLevelTerminal terminal) {
originalGuiIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack();
originalGui = GuiType.LEVEL_TERMINAL;
DimensionalCoord blockPos = new DimensionalCoord(terminal.getTile());
originalBlockPos = new Util.DimensionalCoordSide(
blockPos.x,
blockPos.y,
blockPos.z,
blockPos.getDimension(),
terminal.getSide(),
"");
} else if (target instanceof IWirelessTerminal terminal && terminal.isUniversal(target)) {
originalGuiIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack();
originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack());
originalBlockPos = new Util.DimensionalCoordSide(
terminal.getInventorySlot(),
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
0,
inventoryPlayer.player.worldObj.provider.dimensionId,
ForgeDirection.UNKNOWN,
"");
} else if (target instanceof WirelessLevelTerminalInventory terminal) {
originalGuiIcon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack();
originalGui = GuiType.WIRELESS_LEVEL_TERMINAL;
originalBlockPos = new Util.DimensionalCoordSide(
terminal.getInventorySlot(),
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
0,
inventoryPlayer.player.worldObj.provider.dimensionId,
ForgeDirection.UNKNOWN,
"");
}
}
}
@Override
public void initGui() {
super.initGui();
if (this.originalGuiIcon != null) {
this.originalGuiBtn = new GuiTabButton(
this.guiLeft + 151,
this.guiTop - 4,
this.originalGuiIcon,
this.originalGuiIcon.getDisplayName(),
itemRender);
this.originalGuiBtn.setHideEdge(13);
this.buttonList.add(originalGuiBtn);
}
}
@Override
protected void actionPerformed(GuiButton btn) {
if (btn == this.originalGuiBtn) {
CPacketLevelTerminalCommands message = new CPacketLevelTerminalCommands(
CPacketLevelTerminalCommands.Action.BACK,
originalBlockPos.x,
originalBlockPos.y,
originalBlockPos.z,
originalBlockPos.getDimension(),
originalBlockPos.getSide());
message.setOriginalGui(originalGui.ordinal());
FluidCraft.proxy.netHandler.sendToServer(message);
} else {
super.actionPerformed(btn);
}
}
}
@@ -1,7 +1,5 @@
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;
@@ -13,7 +11,6 @@ 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;
@@ -23,12 +20,11 @@ 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;
@@ -49,9 +45,6 @@ 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;
@@ -70,8 +63,6 @@ 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;
@@ -89,7 +80,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) {
@@ -114,7 +105,7 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
ForgeDirection.UNKNOWN,
"");
} else if (target instanceof WirelessLevelTerminalInventory terminal) {
icon = ItemAndBlockHolder.LEVEL_TERMINAL.stack();
icon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack();
originalGui = GuiType.WIRELESS_LEVEL_TERMINAL;
originalBlockPos = new Util.DimensionalCoordSide(
terminal.getInventorySlot(),
@@ -126,40 +117,11 @@ 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(
@@ -176,7 +138,8 @@ 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.buttonList,
this.cont);
}
if (this.icon != null) {
this.originalGuiBtn = new GuiTabButton(
@@ -188,11 +151,10 @@ 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);
@@ -205,12 +167,7 @@ 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();
}
@@ -294,20 +251,6 @@ 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) {
@@ -351,6 +294,15 @@ 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) {
@@ -366,11 +318,9 @@ 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)) {
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);
slot.putStack(draggedStack);
component[i].reset();
NetworkHandler.instance.sendToServer(new PacketNEIDragClick(draggedStack, slot.getSlotIndex()));
return true;
}
}
@@ -382,26 +332,44 @@ 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 = true;
public boolean isEnable = false;
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 State state;
private LevelState state;
private final ContainerLevelMaintainer container;
public Component(Widget qtyInput, Widget batchInput, GuiFCImgButton submitBtn, GuiFCImgButton enableBtn,
GuiFCImgButton disableBtn, FCGuiLineField line, List<GuiButton> buttonList) {
GuiFCImgButton disableBtn, FCGuiLineField line, List<GuiButton> buttonList,
ContainerLevelMaintainer container) {
this.qty = qtyInput;
this.batch = batchInput;
this.enable = enableBtn;
this.disable = disableBtn;
this.submit = submitBtn;
this.line = line;
this.state = State.None;
this.state = LevelState.None;
this.container = container;
buttonList.add(this.submit);
buttonList.add(this.enable);
buttonList.add(this.disable);
@@ -435,18 +403,25 @@ 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) {
FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer(Action.Disable, this.getIndex()));
didSomething = true;
if (this.container.getInventory().get(this.getIndex()) != null) {
this.setEnable(true);
FluidCraft.proxy.netHandler
.sendToServer(new CPacketLevelMaintainer(Action.Disable, this.getIndex()));
didSomething = true;
}
}
return didSomething;
}
@@ -499,6 +474,18 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_CURRENT) + " "
+ NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_ERROR));
}
case NotFound -> {
this.line.setColor(FCGuiColors.StateError.getColor());
message.add(
NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_CURRENT) + " "
+ NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_NOT_FOUND));
}
case CantCraft -> {
this.line.setColor(FCGuiColors.StateError.getColor());
message.add(
NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_CURRENT) + " "
+ NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_CANT_CRAFT));
}
default -> {
this.line.setColor(FCGuiColors.StateNone.getColor());
message.add(
@@ -515,7 +502,11 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
message.add(NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_EXPORT));
message.add(NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_EXPORT_DESC) + "\n");
message.add(NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_ERROR));
message.add(NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_ERROR_DESC));
message.add(NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_ERROR_DESC) + "\n");
message.add(NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_NOT_FOUND));
message.add(NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_NOT_FOUND_DESC) + "\n");
message.add(NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_CANT_CRAFT));
message.add(NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_CANT_CRAFT_DESC));
} else {
message.add(NameConst.i18n(NameConst.TT_SHIFT_FOR_MORE));
}
@@ -531,9 +522,18 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
}
}
public void setState(State state) {
public void setState(LevelState 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 {
@@ -585,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)) {
if (Double.isNaN(result) || result < 0) {
this.amount = null;
this.textField.setTextColor(0xFF0000);
} else {
@@ -1,13 +1,6 @@
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;
@@ -17,7 +10,6 @@ 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;
@@ -34,8 +26,6 @@ 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;
@@ -45,16 +35,17 @@ 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;
@@ -65,7 +56,6 @@ 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;
@@ -83,7 +73,6 @@ 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;
@@ -151,6 +140,7 @@ 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) {
@@ -184,8 +174,6 @@ 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,
@@ -290,7 +278,6 @@ 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);
@@ -322,11 +309,6 @@ 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);
@@ -362,7 +344,8 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
/* Draws the top part. */
drawTexturedModalRect(offsetX, offsetY, 0, 0, xSize, HEADER_HEIGHT);
/* Draws the middle part. */
Tessellator.instance.startDrawingQuads();
final Tessellator tess = Tessellator.instance;
tess.startDrawingQuads();
addTexturedRectToTesselator(
offsetX,
offsetY + HEADER_HEIGHT,
@@ -373,7 +356,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
(HEADER_HEIGHT + LevelTerminalSection.TITLE_HEIGHT + 1.0f) / 256.0f,
xSize / 256.0f,
(HEADER_HEIGHT + 106.0f) / 256.0f);
Tessellator.instance.draw();
tess.draw();
/* Draw the bottom part */
drawTexturedModalRect(offsetX, offsetY + HEADER_HEIGHT + viewHeight, 0, 158, xSize, INV_HEIGHT);
if (online) {
@@ -501,7 +484,8 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
private int drawEntry(LevelTerminalEntry entry, int viewY, int titleBottom, int relMouseX, int relMouseY) {
final EntityPlayer player = Minecraft.getMinecraft().thePlayer;
mc.getTextureManager().bindTexture(TEX_BG);
Tessellator.instance.startDrawingQuads();
final Tessellator tess = Tessellator.instance;
tess.startDrawingQuads();
int relY = 0;
final int slotLeftMargin = (VIEW_WIDTH - entry.rowSize * 18);
float lastZLevel = renderItem.zLevel;
@@ -530,7 +514,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
(173 + 18) / 256f);
}
}
Tessellator.instance.draw();
tess.draw();
/* Draw button */
if (viewY + entry.highlightButton.height > 0 && viewY < viewHeight) {
entry.highlightButton.yPosition = viewY + 1;
@@ -566,26 +550,21 @@ 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;
ItemStack stack = inv.getStackInSlot(slotIdx);
LevelItemInfo info = entry.infoList[slotIdx];
boolean tooltip = relMouseX > colLeft - 1 && relMouseX < colRight - 1
&& relMouseY >= Math.max(viewY + rowYTop, LevelTerminalSection.TITLE_HEIGHT)
&& relMouseY < Math.min(viewY + rowYBot, viewHeight);
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)];
if (info != null) {
ItemStack itemStack = info.stack;
long quantity = info.quantity;
long batch = info.batchSize;
LevelState state = info.state;
GL11.glPushMatrix();
GL11.glTranslatef(colLeft, viewY + rowYTop + 1, ITEM_STACK_Z);
@@ -600,7 +579,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
case Idle -> FCGuiColors.StateIdle.getColor();
case Craft -> FCGuiColors.StateCraft.getColor();
case Export -> FCGuiColors.StateExport.getColor();
case Error -> FCGuiColors.StateError.getColor();
case Error, NotFound, CantCraft -> FCGuiColors.StateError.getColor();
case None -> FCGuiColors.StateNone.getColor();
};
int offset = 0;
@@ -608,7 +587,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();
@@ -622,7 +601,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
drawRect(0, 0, 16, 16, GuiColors.ItemSlotOverlayUnpowered.getColor());
}
} else {
tooltipStack = stack;
tooltipStack = itemStack;
}
GL11.glPopMatrix();
} else if (entry.filteredRecipes[slotIdx]) {
@@ -846,58 +825,50 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
&& mouseY < guiTop + HEADER_HEIGHT + viewHeight;
}
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);
public void receivePackets(List<SPacketLevelTerminalUpdate.PacketEntry> packets) {
for (SPacketLevelTerminalUpdate.PacketEntry packet : packets) {
parsePacket(packet);
}
masterList.markDirty();
}
private void parsePacketCmd(PacketEntry cmd) {
long id = cmd.entryId;
if (cmd instanceof PacketAdd addCmd) {
private void parsePacket(SPacketLevelTerminalUpdate.PacketEntry packet) {
if (packet instanceof SPacketLevelTerminalUpdate.PacketAdd packetAdd) {
LevelTerminalEntry entry = new LevelTerminalEntry(
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);
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;
if (entry == null) {
return;
}
if (owCmd.itemsValid) {
if (owCmd.allItemUpdate) {
entry.fullItemUpdate(owCmd.items, owCmd.validIndices.length);
} else {
entry.partialItemUpdate(owCmd.items, owCmd.validIndices);
}
if (StatCollector.canTranslate(packetRename.newName)) {
entry.customName = StatCollector.translateToLocal(packetRename.newName);
} else {
entry.customName = StatCollector.translateToFallback(packetRename.newName);
}
masterList.isDirty = true;
} else if (cmd instanceof PacketRename renameCmd) {
LevelTerminalEntry entry = masterList.list.get(id);
} else if (packet instanceof SPacketLevelTerminalUpdate.PacketDisconnect) {
online = false;
}
if (entry != null) {
if (StatCollector.canTranslate(renameCmd.newName)) {
entry.customName = StatCollector.translateToLocal(renameCmd.newName);
} else {
entry.customName = StatCollector.translateToFallback(renameCmd.newName);
}
}
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;
masterList.isDirty = true;
}
}
@@ -932,22 +903,23 @@ 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;
if (stack != null && isShiftKeyDown() && stack.hasTagCompound()) {
NBTTagCompound data = stack.getTagCompound();
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 (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));
if (info.batchSize >= 0) {
currentToolTip.add(
I18n.format(NameConst.TT_LEVEL_MAINTAINER_BATCH_SIZE, "\n", false) + ": "
+ NumberFormat.getInstance().format(info.batchSize));
}
break;
}
}
}
}
@@ -1102,13 +1074,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
String name;
List<LevelTerminalEntry> entries = new ArrayList<>();
Set<LevelTerminalEntry> visibleEntries = new TreeSet<>(Comparator.comparing(e -> {
if (e.displayItemStack != null) {
return e.displayItemStack.getDisplayName() + e.id;
} else {
return String.valueOf(e.id);
}
}));
Set<LevelTerminalEntry> visibleEntries = new TreeSet<>(Comparator.comparing(e -> e.customName + e.id));
int height;
private boolean isDirty = true;
boolean visible = false;
@@ -1148,18 +1114,22 @@ 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 < inv.getSizeInventory(); ++i) {
ItemStack stack = inv.getStackInSlot(i);
if (itemStackMatchesSearchTerm(stack, output)) {
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)) {
shouldAdd = true;
entry.filteredRecipes[i] = false;
} else {
entry.filteredRecipes[i] = true;
}
}
if (!shouldAdd) {
continue;
}
@@ -1207,12 +1177,9 @@ 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;
@@ -1220,7 +1187,8 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
int guiHeight;
int dispY = -9999;
boolean[] filteredRecipes;
int numItems = 0;
LevelItemInfo[] infoList;
LevelTerminalEntry(long id, String name, int rows, int rowSize, boolean online) {
this.id = id;
@@ -1236,7 +1204,6 @@ 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");
@@ -1254,53 +1221,11 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
return this;
}
LevelTerminalEntry setIcons(ItemStack selfItemStack, ItemStack displayItemStack) {
this.displayItemStack = displayItemStack;
LevelTerminalEntry setInfoList(LevelItemInfo[] infoList) {
this.infoList = infoList;
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;
@@ -1316,7 +1241,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
dim,
ForgeDirection.getOrientation(side),
"");
if (isCtrlKeyDown() && isShiftKeyDown() && hasInfinityBoosterCard(mc.thePlayer)) {
if (isCtrlKeyDown() && isShiftKeyDown()) {
FluidCraft.proxy.netHandler.sendToServer(
new CPacketLevelTerminalCommands(
Action.EDIT,
@@ -1337,8 +1262,8 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
BlockPosHighlighter.highlightBlocks(
mc.thePlayer,
Collections.singletonList(blockPos),
PlayerMessages.LevelEmitterHighlighted.getName(),
PlayerMessages.LevelEmitterInAnotherDim.getName());
PlayerMessages.LevelEmitterHighlighted.getUnlocalized(),
PlayerMessages.LevelEmitterInAnotherDim.getUnlocalized());
mc.thePlayer.closeScreen();
}
return true;
@@ -1368,20 +1293,10 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel
default -> null;// drop item:
};
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));
}
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));
}
return true;
@@ -0,0 +1,212 @@
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.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);
}
}
@@ -117,8 +117,9 @@ public class GuiPatternMulti extends GuiAmount {
}
@Override
protected long addOrderAmount(final int i) {
return i + getAmount();
protected void addAmount(int i) {
this.amountTextField.setText(Long.toString(i + getAmount()));
this.amountTextField.setCursorPositionEnd();
}
@Override
@@ -9,18 +9,18 @@ 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.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.network.CPacketPatternValueSet;
import appeng.api.storage.ITerminalHost;
import appeng.core.localization.GuiText;
public class GuiPatternValueAmount extends FCGuiAmount {
public GuiPatternValueAmount(final InventoryPlayer inventoryPlayer, final ITerminalHost te) {
public GuiPatternValueAmount(final InventoryPlayer inventoryPlayer, final Object te) {
super(new ContainerPatternValueAmount(inventoryPlayer, te));
}
@@ -77,6 +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;
}
}
@@ -0,0 +1,116 @@
package com.glodblock.github.client.gui;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
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.common.item.ItemFluidPacket;
import com.glodblock.github.common.tile.TileSuperStockReplenisher;
import com.glodblock.github.network.CPacketInventoryAction;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.client.gui.AEBaseGui;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotFake;
import appeng.core.localization.GuiText;
import appeng.helpers.InventoryAction;
import appeng.util.item.AEItemStack;
public class GuiSuperStockReplenisher extends AEBaseGui {
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/superStockReplenisher.png");
private Map<Integer, IAEStack<?>> list = new HashMap<>();
public GuiSuperStockReplenisher(InventoryPlayer ipl, TileSuperStockReplenisher tile) {
super(new ContainerSuperStockReplenisher(ipl, tile));
this.ySize = 251;
this.xSize = 216;
}
@Override
protected void handleMouseClick(Slot slot, int slotIdx, int ctrlDown, int mouseButton) {
if (mouseButton == 3) {
if (slot instanceof SlotFake) {
if (slot.getHasStack()) {
InventoryAction action = InventoryAction.SET_PATTERN_VALUE;
IAEItemStack stack = AEItemStack.create(slot.getStack());
((AEBaseContainer) this.inventorySlots).setTargetStack(stack);
for (int i = 0; i < this.inventorySlots.inventorySlots.size(); i++) {
if (slot.equals(this.inventorySlots.inventorySlots.get(i))) {
FluidCraft.proxy.netHandler.sendToServer(new CPacketInventoryAction(action, i, 0, stack));
}
}
return;
}
}
}
super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton);
}
@Override
public void func_146977_a(Slot s) {
if (s instanceof SlotFake) {
this.drawFillStatus(s);
}
super.func_146977_a(s);
}
private void drawFillStatus(Slot slotIn) {
int offsetX = slotIn.xDisplayPosition - 8;
int offsetY = slotIn.yDisplayPosition - 11;
ItemStack itemstack = slotIn.getStack();
int slotInt = slotIn.slotNumber;
if (itemstack != null) {
String s = "0%";
if (slotInt > 0 && slotInt < 10) {
IAEStack<?> aeStack = list.get(slotInt - 1);
if (aeStack != null)
s = (int) (((float) aeStack.getStackSize() / ItemFluidPacket.getFluidAmount(itemstack)) * 100)
+ "%";
} else if (slotInt > 9 && slotInt < 73) {
IAEStack<?> aeStack = list.get(slotInt + 90);
if (aeStack != null && itemstack.stackSize > 0) {
long i = aeStack.getStackSize();
s = (int) (((float) i / itemstack.stackSize) * 100) + "%";
}
}
float scale = 0.5f;
float shiftX = 2;
float shiftY = 1;
final float inverseScaleFactor = 1.0f / scale;
final int X = (int) (((float) offsetX - shiftX + 10.0f) * inverseScaleFactor);
final int Y = (int) (((float) offsetY - shiftY + 16.0f - 7.0f * scale) * inverseScaleFactor);
GL11.glTranslatef(0.0f, 0.0f, 200.0f);
GL11.glScaled(scale, scale, scale);
this.fontRendererObj.drawStringWithShadow(s, X, Y, 16777215);
GL11.glScaled(inverseScaleFactor, inverseScaleFactor, inverseScaleFactor);
GL11.glTranslatef(0.0f, 0.0f, -200.0f);
}
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, ySize - 94, 0x404040);
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.bindTexture(TEX_BG);
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, xSize, ySize);
}
public void update(Map<Integer, IAEStack<?>> map) {
this.list = map;
}
}
@@ -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,7 +1,6 @@
package com.glodblock.github.client.gui.base;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
@@ -12,6 +11,7 @@ import com.glodblock.github.inventory.gui.GuiType;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.container.AEBaseContainer;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
@@ -20,7 +20,7 @@ import appeng.util.calculators.Calculator;
public abstract class FCGuiAmount extends AEBaseGui {
protected GuiTextField amountBox;
protected MEGuiTextField amountBox;
protected GuiTabButton originalGuiBtn;
protected GuiButton submit;
protected GuiButton plus1;
@@ -72,16 +72,10 @@ public abstract class FCGuiAmount extends AEBaseGui {
this.originalGuiBtn.setHideEdge(13);
}
this.amountBox = new GuiTextField(
this.fontRendererObj,
this.guiLeft + 62,
this.guiTop + 57,
59,
this.fontRendererObj.FONT_HEIGHT);
this.amountBox.setEnableBackgroundDrawing(false);
this.amountBox = new MEGuiTextField(61, 12);
this.amountBox.x = this.guiLeft + 60;
this.amountBox.y = this.guiTop + 55;
this.amountBox.setMaxStringLength(16);
this.amountBox.setTextColor(0xFFFFFF);
this.amountBox.setVisible(true);
this.amountBox.setFocused(true);
}
@@ -134,6 +128,7 @@ public abstract class FCGuiAmount extends AEBaseGui {
}
String out = Long.toString(resultI);
this.amountBox.setText(out);
this.amountBox.setCursorPositionEnd();
} catch (final NumberFormatException ignore) {}
}
@@ -16,7 +16,7 @@ import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.FCGuiTextField;
import com.glodblock.github.client.gui.GuiFluidMonitor;
import com.glodblock.github.client.gui.GuiItemMonitor;
import com.glodblock.github.client.gui.container.base.FCContainerMonitor;
import com.glodblock.github.inventory.InventoryHandler;
@@ -26,12 +26,15 @@ import com.glodblock.github.util.Ae2ReflectClient;
import com.glodblock.github.util.ModAndClassUtil;
import appeng.api.config.CraftingStatus;
import appeng.api.config.PinsState;
import appeng.api.config.SearchBoxFocusPriority;
import appeng.api.config.SearchBoxMode;
import appeng.api.config.Settings;
import appeng.api.config.TerminalStyle;
import appeng.api.config.YesNo;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.ITerminalPins;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IDisplayRepo;
@@ -42,7 +45,10 @@ import appeng.client.gui.widgets.GuiScrollbar;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.IDropToFillTextField;
import appeng.client.gui.widgets.ISortSource;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.client.me.InternalSlotME;
import appeng.client.me.ItemRepo;
import appeng.client.me.PinSlotME;
import appeng.client.me.SlotDisconnected;
import appeng.client.me.SlotME;
import appeng.container.AEBaseContainer;
@@ -60,7 +66,9 @@ import appeng.core.localization.ButtonToolTips;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.core.sync.packets.PacketPinsUpdate;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.IPinsHandler;
import appeng.helpers.InventoryAction;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
@@ -72,7 +80,7 @@ import codechicken.nei.util.TextHistory;
// TODO why is this copy pasting all the UI code from AE2 instead of reusing it ???
public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
implements ISortSource, IConfigManagerHost, IDropToFillTextField {
implements ISortSource, IConfigManagerHost, IDropToFillTextField, IPinsHandler {
public static int craftingGridOffsetX;
public static int craftingGridOffsetY;
@@ -86,7 +94,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
public GuiTabButton craftingStatusBtn;
protected IDisplayRepo repo;
protected GuiImgButton craftingStatusImgBtn;
protected FCGuiTextField searchField;
protected MEGuiTextField searchField;
protected int perRow = 9;
protected int reservedSpace = 0;
protected boolean customSortOrder = true;
@@ -102,7 +110,14 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
protected GuiImgButton terminalStyleBox;
protected GuiImgButton searchStringSave;
protected GuiImgButton typeFilter;
protected GuiImgButton pinsStateButton;
protected boolean hasShiftKeyDown = false;
private PinsState pinsState;
public final boolean hasPinHost;
private boolean canBeAutoFocused;
private boolean isAutoFocused;
protected int currentMouseY;
protected int currentMouseX;
@SuppressWarnings("unchecked")
public FCGuiMonitor(final InventoryPlayer inventoryPlayer, final ITerminalHost te, final FCContainerMonitor<T> c) {
@@ -115,6 +130,8 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
this.configSrc = ((IConfigurableObject) this.inventorySlots).getConfigManager();
(this.monitorableContainer = (FCContainerMonitor<T>) this.inventorySlots).setGui(this);
this.viewCell = te instanceof IViewCellStorage;
pinsState = (PinsState) configSrc.getSetting(Settings.PINS_STATE);
hasPinHost = te instanceof ITerminalPins && !(this instanceof GuiFluidMonitor);
}
public int getOffsetY() {
@@ -131,12 +148,13 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
this.getScrollBar().setTop(18).setLeft(175).setHeight(this.rows * 18 - 2);
this.getScrollBar().setRange(
0,
(this.repo.size() + this.perRow - 1) / this.perRow - this.rows,
(this.repo.size() + pinsState.ordinal() * 9 + this.perRow - 1) / this.perRow - this.rows,
Math.max(1, this.rows / 6));
}
@Override
protected void actionPerformed(final GuiButton btn) {
memoryText = this.searchField.getText();
if (btn == this.craftingStatusBtn || btn == this.craftingStatusImgBtn) {
InventoryHandler.switchGui(GuiType.CRAFTING_STATUS);
}
@@ -151,6 +169,15 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
AEConfig.instance.settings.putSetting(iBtn.getSetting(), next);
} else if (ModAndClassUtil.isSaveText && btn == this.searchStringSave) {
AEConfig.instance.preserveSearchBar = next == YesNo.YES;
} else if (btn == this.pinsStateButton) {
try {
if (next.ordinal() >= rows) return; // ignore to avoid hiding terminal inventory
final PacketPinsUpdate p = new PacketPinsUpdate((PinsState) next);
NetworkHandler.instance.sendToServer(p);
} catch (final IOException e) {
AELog.debug(e);
}
} else {
try {
NetworkHandler.instance
@@ -161,7 +188,6 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
}
iBtn.set(next);
if (next.getClass() == SearchBoxMode.class || next.getClass() == TerminalStyle.class) {
memoryText = this.searchField.getText();
super.scheduleGuiResize();
}
}
@@ -169,6 +195,19 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
super.actionPerformed(btn);
}
private void adjustPinsSize() {
final int pinMaxSize = rows - 1;
if (pinsState.ordinal() <= pinMaxSize) return;
try {
PinsState newState = PinsState.fromOrdinal(pinMaxSize);
final PacketPinsUpdate p = new PacketPinsUpdate(newState);
NetworkHandler.instance.sendToServer(p);
} catch (final IOException e) {
AELog.debug(e);
}
}
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
@@ -199,10 +238,26 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
}
this.getMeSlots().clear();
for (int y = 0; y < this.rows; y++) {
// make sure we have space at least for one row of normal slots, because pins not adjusted by scroll bar
adjustPinsSize();
int pinsRows = pinsState.ordinal();
for (int y = 0; y < pinsRows; y++) {
for (int x = 0; x < this.perRow; x++) {
this.getMeSlots()
.add(new InternalSlotME(this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + y * 18));
.add(new PinSlotME(this.repo, x + y * this.perRow, this.offsetX + x * 18, y * 18 + 18));
}
}
for (int y = 0; y < this.rows - pinsRows; y++) {
for (int x = 0; x < this.perRow; x++) {
this.getMeSlots().add(
new InternalSlotME(
this.repo,
x + y * this.perRow,
this.offsetX + x * 18,
18 + y * 18 + pinsRows * 18));
}
}
@@ -224,6 +279,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
this.offsetY = this.guiTop + 8;
buttonList.clear();
if (this.customSortOrder) {
this.buttonList.add(
this.SortByBox = new GuiImgButton(
@@ -286,18 +342,19 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE)));
this.offsetY += 20;
// Right now 80 > offsetX, but that can be changed later.
// noinspection DataFlowIssue
this.searchField = new FCGuiTextField(
this.fontRendererObj,
this.guiLeft + Math.max(80, this.offsetX),
this.guiTop + 4,
90,
12);
this.searchField.setEnableBackgroundDrawing(false);
this.searchField = new MEGuiTextField(90, 12) {
@Override
public void onTextChange(final String oldText) {
final String text = getText();
repo.setSearchString(text);
repo.updateView();
setScrollBar();
}
};
this.searchField.x = this.guiLeft + Math.max(80, this.offsetX);
this.searchField.y = this.guiTop + 4;
this.searchField.setMaxStringLength(25);
this.searchField.setTextColor(0xFFFFFF);
this.searchField.setVisible(true);
if (ModAndClassUtil.isSearchStringTooltip)
searchField.setMessage(ButtonToolTips.SearchStringTooltip.getLocal());
@@ -323,8 +380,19 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
}
}
if (hasPinHost) {
this.buttonList.add(
this.pinsStateButton = new GuiImgButton(
this.guiLeft + 177,
this.guiTop + 18 + (rows * 18) + 26,
Settings.PINS_STATE,
configSrc.getSetting(Settings.PINS_STATE)));
}
final Enum<?> setting = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
this.searchField.setFocused(SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting);
this.canBeAutoFocused = SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting;
this.searchField.setFocused(this.canBeAutoFocused);
this.isAutoFocused = this.canBeAutoFocused;
if (ModAndClassUtil.isSearchBar && (AEConfig.instance.preserveSearchBar || this.isSubGui())) {
setSearchString(memoryText, false);
@@ -360,6 +428,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
public void setSearchString(String memoryText, boolean updateView) {
this.searchField.setText(memoryText);
this.searchField.setCursorPositionEnd();
this.repo.setSearchString(memoryText);
if (updateView) {
this.repo.updateView();
@@ -369,13 +438,8 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
@Override
protected void mouseClicked(final int xCoord, final int yCoord, final int btn) {
final Enum<?> searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
if (searchMode != SearchBoxMode.AUTOSEARCH && searchMode != SearchBoxMode.NEI_AUTOSEARCH) {
this.searchField.mouseClicked(xCoord, yCoord, btn);
}
if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) {
setSearchString("", true);
}
this.searchField.mouseClicked(xCoord, yCoord, btn);
isAutoFocused = false;
super.mouseClicked(xCoord, yCoord, btn);
}
@@ -441,7 +505,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
action = InventoryAction.PICKUP_SINGLE;
}
}
if (Ae2ReflectClient.getDragClick(this).size() > 1) {
if (this.drag_click.size() > 1) {
return;
}
final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0);
@@ -492,7 +556,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
}
if (slot instanceof SlotDisconnected) {
if (Ae2ReflectClient.getDragClick(this).size() > 1) {
if (this.drag_click.size() > 1) {
return;
}
InventoryAction action = null;
@@ -527,13 +591,22 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
return;
}
if (slot instanceof SlotME) {
if (slot instanceof SlotME sme) {
InventoryAction action = null;
IAEItemStack stack = null;
switch (mouseButton) {
case 0: // pickup / set-down.
action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
stack = ((SlotME) slot).getAEStack();
if (sme.isPin() && player.inventory.getItemStack() != null) {
final PacketInventoryAction p = new PacketInventoryAction(
InventoryAction.SET_PIN,
sme.getPinIndex(),
0);
NetworkHandler.instance.sendToServer(p);
return;
}
stack = sme.getAEStack();
if (stack != null && action == InventoryAction.PICKUP_OR_SET_DOWN
&& stack.getStackSize() == 0
&& player.inventory.getItemStack() == null) {
@@ -541,6 +614,15 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
}
break;
case 1:
if (sme.isPin() && ctrlDown == 1) { // clear pin
final PacketInventoryAction p = new PacketInventoryAction(
InventoryAction.SET_PIN,
sme.getPinIndex(),
-1);
NetworkHandler.instance.sendToServer(p);
return;
}
action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
stack = ((SlotME) slot).getAEStack();
break;
@@ -640,6 +722,9 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
if (this.searchField != null) {
this.searchField.drawTextBox();
}
this.currentMouseX = mouseX;
this.currentMouseY = mouseY;
}
protected String getBackground() {
@@ -662,18 +747,29 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
@Override
protected void keyTyped(final char character, final int key) {
if (!this.checkHotbarKeys(key)) {
if (character == ' ' && this.searchField.getText().isEmpty()) {
return;
}
if (character == ' ' && this.searchField.getText().isEmpty()) {
return;
}
if (this.searchField.textboxKeyTyped(character, key)) {
this.repo.setSearchString(this.searchField.getText());
this.repo.updateView();
this.setScrollBar();
} else {
super.keyTyped(character, key);
}
boolean skipHotbarCheck = searchField.isFocused()
&& (AEConfig.instance.searchBoxFocusPriority == SearchBoxFocusPriority.ALWAYS
|| (AEConfig.instance.searchBoxFocusPriority == SearchBoxFocusPriority.NO_AUTOSEARCH
&& !isAutoFocused));
if (!skipHotbarCheck && checkHotbarKeys(key)) {
return;
}
final boolean mouseInGui = this
.isPointInRegion(0, 0, this.xSize, this.ySize, this.currentMouseX, this.currentMouseY);
if (this.canBeAutoFocused && !searchField.isFocused() && mouseInGui) {
searchField.setFocused(true);
isAutoFocused = true;
}
if (!searchField.textboxKeyTyped(character, key)) {
super.keyTyped(character, key);
}
}
@@ -721,6 +817,13 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
this.typeFilter.set(this.configSrc.getSetting(Settings.TYPE_FILTER));
}
if (this.pinsStateButton != null) {
pinsState = (PinsState) this.configSrc.getSetting(Settings.PINS_STATE);
this.pinsStateButton.set(pinsState);
initGui();
}
this.repo.updateView();
}
@@ -748,13 +851,6 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
this.standardSize = standardSize;
}
@Override
public void drawScreen(final int mouseX, final int mouseY, final float btn) {
super.drawScreen(mouseX, mouseY, btn);
if (ModAndClassUtil.isSearchBar && AEConfig.instance.preserveSearchBar && searchField != null)
handleTooltip(mouseX, mouseY, searchField.new TooltipProvider());
}
public boolean isOverSearchField(int x, int y) {
return searchField.isMouseIn(x, y);
}
@@ -786,4 +882,33 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
public boolean isOverTextField(int mousex, int mousey) {
return searchField.isMouseIn(mousex, mousey);
}
@Override
public void setAEPins(IAEItemStack[] pins) {
if (repo instanceof ItemRepo) repo.setAEPins(pins);
}
@Override
public void setPinsState(PinsState state) {
configSrc.putSetting(Settings.PINS_STATE, state);
}
@SuppressWarnings("SameParameterValue")
protected boolean isPointInRegion(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY) {
pointX -= this.guiLeft;
pointY -= this.guiTop;
return pointX >= rectX - 1 && pointX < rectX + rectWidth + 1
&& pointY >= rectY - 1
&& pointY < rectY + rectHeight + 1;
}
// Moving items via hotbar keys in terminals isn't working anyway.
// Let's disable hotbar keys processing for terminal slots to allow proper input of numbers in the search field
@Override
protected boolean checkHotbarKeys(int keyCode) {
if (theSlot instanceof SlotME) {
return false;
}
return super.checkHotbarKeys(keyCode);
}
}
@@ -13,11 +13,9 @@ import com.glodblock.github.common.parts.PartLevelTerminal;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.BlockPos;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.security.IActionHost;
import appeng.api.storage.ITerminalHost;
import appeng.container.implementations.ContainerCraftConfirm;
@@ -71,8 +69,8 @@ public class ContainerFluidCraftConfirm extends ContainerCraftConfirm {
@Override
public void optimizePatterns() {
// only V2 supported
IGrid grid = Ae2Reflect.getGrid(this);
ICraftingJob result = Ae2Reflect.getResult(this);
IGrid grid = this.getGrid();
if (result instanceof CraftingJobV2 && !this.isSimulation()
&& grid != null
&& !grid.getMachines(TilePatternOptimizationMatrix.class).isEmpty()) {
@@ -5,7 +5,6 @@ import net.minecraft.entity.player.InventoryPlayer;
import com.glodblock.github.client.gui.container.base.FCContainerFluidConfigurable;
import com.glodblock.github.common.parts.PartFluidExportBus;
import com.glodblock.github.common.parts.base.FCSharedFluidBus;
import com.glodblock.github.util.Ae2Reflect;
import appeng.api.config.SchedulingMode;
import appeng.api.config.Settings;
@@ -34,7 +33,7 @@ public class ContainerFluidIO extends FCContainerFluidConfigurable {
@Override
protected void loadSettingsFromHost(IConfigManager cm) {
super.loadSettingsFromHost(cm);
if (Ae2Reflect.getUpgradeableHost(this) instanceof PartFluidExportBus) {
if (this.getUpgradeable() instanceof PartFluidExportBus) {
this.setCraftingMode((YesNo) cm.getSetting(Settings.CRAFT_ONLY));
this.setSchedulingMode((SchedulingMode) cm.getSetting(Settings.SCHEDULING_MODE));
}
@@ -7,12 +7,10 @@ import net.minecraft.inventory.IInventory;
import com.glodblock.github.client.gui.container.base.FCContainerFluidConfigurable;
import com.glodblock.github.common.parts.PartFluidLevelEmitter;
import com.glodblock.github.inventory.slot.OptionalFluidSlotFakeTypeOnly;
import com.glodblock.github.util.Ae2Reflect;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.implementations.IUpgradeableHost;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.container.guisync.GuiSync;
import appeng.tile.inventory.AppEngInternalAEInventory;
@@ -39,10 +37,6 @@ public class ContainerFluidLevelEmitter extends FCContainerFluidConfigurable {
return this.lvlEmitter;
}
protected IUpgradeableHost getUpgradeable() {
return Ae2Reflect.getUpgradeableHost(this);
}
public AppEngInternalAEInventory getFakeFluidInv() {
return (AppEngInternalAEInventory) this.lvlEmitter.getInventoryByName("config");
}
@@ -84,8 +78,7 @@ public class ContainerFluidLevelEmitter extends FCContainerFluidConfigurable {
if (Platform.isServer()) {
this.EmitterValue = this.lvlEmitter.getReportingValue();
this.setRedStoneMode(
(RedstoneMode) Ae2Reflect.getUpgradeableHost(this).getConfigManager()
.getSetting(Settings.REDSTONE_EMITTER));
(RedstoneMode) this.getUpgradeable().getConfigManager().getSetting(Settings.REDSTONE_EMITTER));
}
this.standardDetectAndSendChanges();
@@ -9,7 +9,6 @@ import com.glodblock.github.client.gui.container.base.FCContainerFluidConfigurab
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.parts.PartFluidStorageBus;
import com.glodblock.github.inventory.slot.OptionalFluidSlotFakeTypeOnly;
import com.glodblock.github.util.Ae2Reflect;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
@@ -51,8 +50,8 @@ public class ContainerFluidStorageBus extends FCContainerFluidConfigurable {
protected void setupConfig() {
final int xo = 8;
final int yo = 23 + 6;
final IInventory upgrades = Ae2Reflect.getUpgradeList(this).getInventoryByName("upgrades");
final IInventory config = Ae2Reflect.getUpgradeList(this).getInventoryByName("config");
final IInventory upgrades = getUpgradeable().getInventoryByName("upgrades");
final IInventory config = getUpgradeable().getInventoryByName("config");
for (int y = 0; y < 7; y++) {
for (int x = 0; x < 9; x++) {
this.addSlotToContainer(
@@ -104,7 +103,7 @@ public class ContainerFluidStorageBus extends FCContainerFluidConfigurable {
@Override
protected boolean isValidForConfig(int slot, IAEFluidStack fs) {
if (this.supportCapacity()) {
final int upgrades = Ae2Reflect.getUpgradeList(this).getInstalledUpgrades(Upgrades.CAPACITY);
final int upgrades = getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
final int y = slot / 9;
return y < upgrades + 2;
}
@@ -126,11 +125,9 @@ public class ContainerFluidStorageBus extends FCContainerFluidConfigurable {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if (Platform.isServer()) {
this.setReadWriteMode(
(AccessRestriction) Ae2Reflect.getUpgradeList(this).getConfigManager().getSetting(Settings.ACCESS));
this.setReadWriteMode((AccessRestriction) getUpgradeable().getConfigManager().getSetting(Settings.ACCESS));
this.setStorageFilter(
(StorageFilter) Ae2Reflect.getUpgradeList(this).getConfigManager()
.getSetting(Settings.STORAGE_FILTER));
(StorageFilter) getUpgradeable().getConfigManager().getSetting(Settings.STORAGE_FILTER));
}
this.standardDetectAndSendChanges();
@@ -138,8 +135,8 @@ public class ContainerFluidStorageBus extends FCContainerFluidConfigurable {
@Override
public boolean isSlotEnabled(final int idx) {
if (Ae2Reflect.getUpgradeList(this).getInstalledUpgrades(Upgrades.ORE_FILTER) > 0) return false;
final int upgrades = Ae2Reflect.getUpgradeList(this).getInstalledUpgrades(Upgrades.CAPACITY);
if (getUpgradeable().getInstalledUpgrades(Upgrades.ORE_FILTER) > 0) return false;
final int upgrades = getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
return upgrades > (idx - 2);
}
@@ -1,20 +1,15 @@
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.util.Util;
import com.glodblock.github.network.SPacketLevelMaintainerGuiUpdate;
import appeng.api.config.SecurityPermissions;
import appeng.container.AEBaseContainer;
@@ -26,6 +21,10 @@ 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;
@@ -48,49 +47,14 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
@Override
public void doAction(EntityPlayerMP player, InventoryAction action, int slotId, long id) {
Slot slot = getSlot(slotId);
if (slot instanceof SlotFluidConvertingFake) {
if (getSlot(slotId) instanceof SlotFluidConvertingFake slot) {
final ItemStack stack = player.inventory.getItemStack();
switch (action) {
case PICKUP_OR_SET_DOWN -> {
case PICKUP_OR_SET_DOWN, PLACE_SINGLE, SPLIT_OR_PLACE_SINGLE -> {
if (stack == null) {
slot.putStack(null);
} else {
((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))));
slot.putConvertedStack(stack);
}
}
default -> {}
@@ -109,10 +73,8 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
for (int i = 0; i < this.getRequestSlots().length; i++) {
SlotFluidConvertingFake slot = this.getRequestSlots()[i];
if (!slot.getHasStack()) {
ItemStack itemStack = ((Slot) this.inventorySlots.get(idx)).getStack();
ItemStack configuration = createLevelValues(itemStack.copy());
configuration.getTagCompound().setInteger(TLMTags.Index.tagName, i);
slot.putConvertedStack(configuration);
ItemStack itemStack = this.inventorySlots.get(idx).getStack();
tile.updateStack(i, itemStack.copy());
break;
}
}
@@ -123,35 +85,23 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (Platform.isClient()) {
return;
}
this.verifyPermissions(SecurityPermissions.BUILD, false);
super.detectAndSendChanges();
if (this.updateCount++ >= UPDATE_INTERVAL) {
this.updateGui();
}
}
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;
public void updateGui() {
FluidCraft.proxy.netHandler.sendTo(
new SPacketLevelMaintainerGuiUpdate(this.tile.requests, !this.isFirstUpdate),
(EntityPlayerMP) this.getInventoryPlayer().player);
this.isFirstUpdate = false;
this.updateCount = 0;
}
}
@@ -1,30 +1,27 @@
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;
@@ -32,12 +29,7 @@ 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 {
@@ -50,8 +42,8 @@ public class ContainerLevelTerminal extends FCBaseContainer {
private final Map<Long, ContainerLevelTerminal.InvTracker> trackedById = new HashMap<>();
private IGrid grid;
private SPacketLevelTerminalUpdate dirty;
private boolean isDirty;
private SPacketLevelTerminalUpdate updatePacket;
private boolean isPacketDirty;
private boolean wasOff;
private int ticks = 0;
@@ -63,11 +55,13 @@ public class ContainerLevelTerminal extends FCBaseContainer {
} else if (monitorable instanceof IWirelessTerminal wirelessTerminal) {
grid = wirelessTerminal.getActionableNode().getGrid();
}
dirty = this.updateList();
if (dirty != null) {
this.isDirty = true;
updatePacket = this.updateList();
if (updatePacket != null) {
this.isPacketDirty = true;
} else {
dirty = new SPacketLevelTerminalUpdate();
updatePacket = new SPacketLevelTerminalUpdate();
this.isPacketDirty = false;
}
}
@@ -92,7 +86,7 @@ public class ContainerLevelTerminal extends FCBaseContainer {
if (!wasOff) {
SPacketLevelTerminalUpdate update = new SPacketLevelTerminalUpdate();
update.setDisconnect();
update.addDisconnectEntry();
wasOff = true;
FluidCraft.proxy.netHandler.sendTo(update, (EntityPlayerMP) this.getPlayerInv().player);
}
@@ -100,149 +94,20 @@ public class ContainerLevelTerminal extends FCBaseContainer {
}
wasOff = false;
if (isDirty) {
FluidCraft.proxy.netHandler.sendTo(dirty, (EntityPlayerMP) this.getPlayerInv().player);
dirty = new SPacketLevelTerminalUpdate();
isDirty = false;
if (isPacketDirty) {
FluidCraft.proxy.netHandler.sendTo(updatePacket, (EntityPlayerMP) this.getPlayerInv().player);
updatePacket = new SPacketLevelTerminalUpdate();
isPacketDirty = false;
} else if (++ticks % 20 == 0) {
ticks = 0;
SPacketLevelTerminalUpdate update = this.updateList();
if (update != null) {
FluidCraft.proxy.netHandler.sendTo(update, (EntityPlayerMP) this.getPlayerInv().player);
SPacketLevelTerminalUpdate updateNew = this.updateList();
if (updateNew != null) {
FluidCraft.proxy.netHandler.sendTo(updateNew, (EntityPlayerMP) this.getPlayerInv().player);
}
}
}
/**
* 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;
}
@Nullable
private SPacketLevelTerminalUpdate updateList() {
SPacketLevelTerminalUpdate update = null;
var supported = LevelTerminalRegistry.instance().getSupportedClasses();
@@ -257,64 +122,67 @@ 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)) {
if (update == null) update = new SPacketLevelTerminalUpdate();
update.addRenamedEntry(knownTracker.id, name);
knownTracker.name = name;
if (update == null) update = new SPacketLevelTerminalUpdate();
update.addRenameEntry(knownTracker.id, name);
}
/* Status changed? */
boolean isActive = gridNode.isActive() || machine.shouldDisplay();
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;
if (!knownTracker.online && isActive) {
/* Node offline -> online */
knownTracker.online = true;
if (update == null) update = new SPacketLevelTerminalUpdate();
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);
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 (update == null) update = new SPacketLevelTerminalUpdate();
update.addOverwriteAllSlotEntry(knownTracker.id, curr);
}
} else {
/* Add a new entry */
if (update == null) update = new SPacketLevelTerminalUpdate();
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());
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);
tracked.put(gridHost, entry);
trackedById.put(entry.id, entry);
}
visited.add(gridHost);
}
}
@@ -327,10 +195,9 @@ 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;
}
@@ -340,23 +207,10 @@ 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;
@@ -364,16 +218,15 @@ public class ContainerLevelTerminal extends FCBaseContainer {
private final int z;
private final int dim;
private final ForgeDirection side;
private boolean online;
private NBTTagList inventoryNbt;
public InvTracker(long id, ILevelViewable machine, boolean online) {
private LevelItemInfo[] infoList;
public InvTracker(long id, ILevelViewable machine) {
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;
@@ -381,26 +234,8 @@ public class ContainerLevelTerminal extends FCBaseContainer {
this.z = location.z;
this.dim = location.getDimension();
this.side = machine.getSide();
this.online = online;
this.inventoryNbt = new NBTTagList();
updateNBT();
this.infoList = machine.getLevelItemInfoList();
}
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,106 @@
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;
}
}
@@ -4,7 +4,6 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import appeng.api.config.SecurityPermissions;
import appeng.api.storage.ITerminalHost;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotInaccessible;
@@ -17,7 +16,7 @@ public class ContainerPatternValueAmount extends AEBaseContainer {
@GuiSync(11)
public int valueIndex;
public ContainerPatternValueAmount(final InventoryPlayer ip, final ITerminalHost te) {
public ContainerPatternValueAmount(final InventoryPlayer ip, final Object te) {
super(ip, te);
this.patternValue = new SlotInaccessible(new AppEngInternalInventory(null, 1), 0, 34, 53);
this.addSlotToContainer(patternValue);
@@ -0,0 +1,154 @@
package com.glodblock.github.client.gui.container;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.FCBaseItemCell;
import com.glodblock.github.common.tile.TileSuperStockReplenisher;
import com.glodblock.github.inventory.slot.OptionalFluidSlotFake;
import com.glodblock.github.network.SPacketSuperStockReplenisherUpdate;
import appeng.api.storage.data.IAEStack;
import appeng.container.AEBaseContainer;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.SlotPatternOutputs;
import appeng.container.slot.SlotRestrictedInput;
import appeng.items.storage.ItemBasicStorageCell;
import appeng.util.item.AEItemStack;
public class ContainerSuperStockReplenisher extends AEBaseContainer implements IOptionalSlotHost {
private final TileSuperStockReplenisher tile;
private final IInventory configFluids;
private final IInventory configItems;
private int lastUpdated = 0;
public ContainerSuperStockReplenisher(InventoryPlayer ipl, TileSuperStockReplenisher tile) {
super(ipl, tile);
this.tile = tile;
configFluids = tile.getConfigFluid();
configItems = tile.getConfigItems();
final IInventory cell = tile.getCell();
final int x = 8;
final int fy = 8;
this.addSlotToContainer(
new SlotRestrictedInput(
SlotRestrictedInput.PlacableItemType.WORKBENCH_CELL,
cell,
0,
173,
fy,
this.getInventoryPlayer()));
for (int i = 0; i < 9; i++) {
addSlotToContainer(new OptionalFluidSlotFake(configFluids, this, i, x, fy, i, 0, 0));
}
final int io = 29;
for (int y = 0; y < 7; y++) {
for (int ix = 0; ix < 9; ix++) {
this.addSlotToContainer(new SlotPatternOutputs(configItems, this, y * 9 + ix, x, io, ix, y, y));
}
}
bindPlayerInventory(ipl, 0, 251 - 82);
}
@Override
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer player) {
if (slotId == 0 && player.inventory.getItemStack() == null && isConfigurated()) {
return null;
}
return super.slotClick(slotId, clickedButton, mode, player);
}
@Override
public boolean isSlotEnabled(int idx) {
return true;
}
@Override
public void addCraftingToCrafters(ICrafting p_75132_1_) {
super.addCraftingToCrafters(p_75132_1_);
lastUpdated = 24;
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (lastUpdated > 20) {
lastUpdated = 0;
Map<Integer, IAEStack<?>> tmp = new HashMap<>();
for (int i = 0; i < tile.getInternalFluid().getSlots(); i++) {
tmp.put(i, tile.getInternalFluid().getFluidInSlot(i));
}
for (int i = 0; i < tile.getInternalInventory().getSizeInventory(); i++) {
tmp.put(i + 100, AEItemStack.create(tile.getInternalInventory().getStackInSlot(i)));
}
for (final Object g : this.crafters) {
if (g instanceof EntityPlayer) {
FluidCraft.proxy.netHandler.sendTo(new SPacketSuperStockReplenisherUpdate(tmp), (EntityPlayerMP) g);
}
}
}
lastUpdated++;
}
private boolean isConfigurated() {
for (int i = 0; i < configItems.getSizeInventory(); i++) {
if (configItems.getStackInSlot(i) != null) {
return true;
}
}
for (int i = 0; i < configFluids.getSizeInventory(); i++) {
if (configFluids.getStackInSlot(i) != null) {
return true;
}
}
return false;
}
@Override
public boolean isValidForSlot(Slot s, ItemStack is) {
if (s.slotNumber == 0 && s.getHasStack() && isConfigurated()) {
long currentBytes = 0;
long newBytes = -1;
if (s.getStack().getItem() instanceof ItemBasicStorageCell ibsc) {
currentBytes = ibsc.getBytesLong(is);
} else if (s.getStack().getItem() instanceof FCBaseItemCell fcbic) {
currentBytes = fcbic.getBytes(is);
}
if (is.getItem() instanceof ItemBasicStorageCell ibsc) {
newBytes = ibsc.getBytesLong(is);
} else if (is.getItem() instanceof FCBaseItemCell fcbic) {
newBytes = fcbic.getBytes(is);
}
if (currentBytes > newBytes) {
return false;
}
}
return super.isValidForSlot(s, is);
}
public TileSuperStockReplenisher 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;
}
}
@@ -1,5 +1,7 @@
package com.glodblock.github.client.gui.container.base;
import static appeng.util.Platform.writeStackNBT;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -25,13 +27,12 @@ import com.glodblock.github.common.item.ItemFluidEncodedPattern;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.IPatternConsumer;
import com.glodblock.github.inventory.item.IItemPatternTerminal;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.FluidPatternDetails;
import com.glodblock.github.util.Util;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.definitions.IDefinitions;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.guisync.GuiSync;
@@ -43,11 +44,11 @@ import appeng.container.slot.SlotPatternTerm;
import appeng.container.slot.SlotRestrictedInput;
import appeng.helpers.IContainerCraftingPacket;
import appeng.helpers.InventoryAction;
import appeng.items.misc.ItemEncodedPattern;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.item.AEFluidStack;
import appeng.util.item.AEItemStack;
public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
@@ -172,7 +173,7 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
ItemStack is = clickSlot.getStack();
if (is != null && !patternSlotOUT.getHasStack()
&& is.stackSize == 1
&& (is.getItem() instanceof ItemFluidEncodedPattern || is.getItem() instanceof ItemEncodedPattern)) {
&& is.getItem() instanceof ICraftingPatternItem) {
ItemStack output = is.copy();
patternSlotOUT.putStack(output);
p.inventory.setInventorySlotContents(clickSlot.getSlotIndex(), null);
@@ -243,20 +244,6 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
return object > 0;
}
protected boolean checkHasFluidPattern() {
if (this.craftingMode) {
return false;
}
boolean hasFluid = containsFluid(this.craftingSlots);
boolean search = nonNullSlot(this.craftingSlots);
if (!search) { // search=false -> inputs were empty
return false;
}
hasFluid |= containsFluid(this.outputSlots);
search = nonNullSlot(this.outputSlots);
return hasFluid && search; // search=false -> outputs were empty
}
protected ItemStack stampAuthor(ItemStack patternStack) {
if (patternStack.stackTagCompound == null) {
patternStack.stackTagCompound = new NBTTagCompound();
@@ -266,13 +253,52 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
}
protected void encodeFluidPattern() {
ItemStack patternStack = new ItemStack(ItemAndBlockHolder.PATTERN);
FluidPatternDetails pattern = new FluidPatternDetails(patternStack);
pattern.setInputs(collectInventory(this.craftingSlots));
pattern.setOutputs(collectInventory(this.outputSlots));
pattern.setCanBeSubstitute(this.beSubstitute ? 1 : 0);
pattern.setCombine(this.combine ? 1 : 0);
patternSlotOUT.putStack(stampAuthor(pattern.writeToStack()));
ItemStack patternStack = AEApi.instance().definitions().items().encodedUltimatePattern().maybeStack(1).orNull();
if (patternStack != null) {
final NBTTagCompound encodedValue = new NBTTagCompound();
final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs();
final NBTTagList tagIn = new NBTTagList();
final NBTTagList tagOut = new NBTTagList();
for (final ItemStack i : in) {
if (i != null) {
if (i.getItem() instanceof ItemFluidPacket) {
tagIn.appendTag(
writeStackNBT(
AEFluidStack.create(ItemFluidPacket.getFluidStack(i)),
new NBTTagCompound(),
true));
} else {
tagIn.appendTag(writeStackNBT(AEItemStack.create(i), new NBTTagCompound(), true));
}
}
}
for (final ItemStack i : out) {
if (i != null) {
if (i.getItem() instanceof ItemFluidPacket) {
tagOut.appendTag(
writeStackNBT(
AEFluidStack.create(ItemFluidPacket.getFluidStack(i)),
new NBTTagCompound(),
true));
} else {
tagOut.appendTag(writeStackNBT(AEItemStack.create(i), new NBTTagCompound(), true));
}
}
}
encodedValue.setTag("in", tagIn);
encodedValue.setTag("out", tagOut);
encodedValue.setBoolean("substitute", substitute);
encodedValue.setBoolean("beSubstitute", beSubstitute);
encodedValue.setString("author", this.getPlayerInv().player.getCommandSenderName());
patternStack.setTagCompound(encodedValue);
patternSlotOUT.putStack(patternStack);
}
}
protected static IAEItemStack[] collectInventory(Slot[] slots) {
@@ -369,25 +395,27 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
}
public void encode() {
fillPattern();
if (!checkHasFluidPattern()) {
encodeItemPattern();
return;
}
ItemStack stack = this.patternSlotOUT.getStack();
if (stack == null) {
stack = this.patternSlotIN.getStack();
if (notPattern(stack)) {
if (getInputs() != null && getOutputs() != null) {
fillPattern();
if (isCraftingMode()) {
encodeItemPattern();
return;
}
if (stack.stackSize == 1) {
this.patternSlotIN.putStack(null);
} else {
stack.stackSize--;
ItemStack stack = this.patternSlotOUT.getStack();
if (stack == null) {
stack = this.patternSlotIN.getStack();
if (notPattern(stack)) {
return;
}
if (stack.stackSize == 1) {
this.patternSlotIN.putStack(null);
} else {
stack.stackSize--;
}
encodeFluidPattern();
} else if (!notPattern(stack)) {
encodeFluidPattern();
}
encodeFluidPattern();
} else if (!notPattern(stack)) {
encodeFluidPattern();
}
}
@@ -396,10 +424,6 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs();
// if there is no input, this would be silly.
if (in == null || out == null) {
return;
}
// first check the output slots, should either be null, or a pattern
if (output != null && this.notPattern(output)) {
return;
@@ -487,7 +511,10 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
boolean isPattern = definitions.items().encodedPattern().isSameAs(output);
isPattern |= definitions.materials().blankPattern().isSameAs(output);
return !isPattern;
boolean isUltimatePattern = definitions.items().encodedUltimatePattern().isSameAs(output);
isUltimatePattern |= definitions.materials().blankPattern().isSameAs(output);
return !isPattern && !isUltimatePattern;
}
protected NBTBase createItemTag(final ItemStack i) {
@@ -569,7 +596,7 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
for (Slot s : slots) {
ItemStack st = s.getStack();
if (st == null) continue;
final int count;
final long count;
if (st.getItem() instanceof ItemFluidPacket) {
count = ItemFluidPacket.getFluidAmount(st);
} else {
@@ -14,7 +14,6 @@ import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.slot.OptionalFluidSlotFakeTypeOnly;
import com.glodblock.github.network.SPacketFluidUpdate;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.Util;
import appeng.api.config.Upgrades;
@@ -64,7 +63,7 @@ public abstract class FCContainerFluidConfigurable extends ContainerUpgradeable
protected void setupConfig() {
this.setupUpgrades();
final IInventory inv = Ae2Reflect.getUpgradeList(this).getInventoryByName("config");
final IInventory inv = getUpgradeable().getInventoryByName("config");
final int y = 40;
final int x = 80;
this.addSlotToContainer(new OptionalFluidSlotFakeTypeOnly(inv, null, this, 0, x, y, 0, 0, 0));
@@ -84,7 +83,7 @@ public abstract class FCContainerFluidConfigurable extends ContainerUpgradeable
protected boolean isValidForConfig(int slot, IAEFluidStack fs) {
if (this.supportCapacity()) {
// assumes 4 slots per upgrade
final int upgrades = Ae2Reflect.getUpgradeList(this).getInstalledUpgrades(Upgrades.CAPACITY);
final int upgrades = getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
if (slot > 0 && upgrades < 1) {
return false;
@@ -1,6 +1,8 @@
package com.glodblock.github.client.gui.container.base;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
@@ -10,10 +12,15 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import com.glodblock.github.inventory.item.BaseWirelessInventory;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.network.SPacketMEUpdateBuffer;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import appeng.api.config.Actionable;
import appeng.api.config.CraftingAllow;
import appeng.api.config.PinsState;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
@@ -22,10 +29,16 @@ import appeng.api.config.SortOrder;
import appeng.api.config.TypeFilter;
import appeng.api.config.ViewItems;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.security.PlayerSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.ITerminalPins;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
@@ -34,18 +47,22 @@ import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.IPinsHandler;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.items.contents.PinsHandler;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
public abstract class FCContainerMonitor<T extends IAEStack<T>> extends FCBaseContainer
implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<T> {
implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<T>, IPinsHandler {
protected final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5];
protected final IConfigManager clientCM;
protected final ITerminalHost host;
protected PinsHandler pinsHandler = null;
@GuiSync(99)
public boolean canAccessViewCells = false;
@@ -70,6 +87,14 @@ public abstract class FCContainerMonitor<T extends IAEStack<T>> extends FCBaseCo
this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
this.clientCM.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL);
this.clientCM.registerSetting(Settings.PINS_STATE, PinsState.DISABLED); // use for GUI
if (Platform.isServer()) {
if (monitorable instanceof ITerminalPins t && !(monitorable instanceof BaseWirelessInventory bwi
&& bwi.getChannel() == StorageChannel.FLUIDS)) {
pinsHandler = t.getPinsHandler(ip.player);
}
}
}
public IMEMonitor<T> getMonitor() {
@@ -105,6 +130,16 @@ public abstract class FCContainerMonitor<T extends IAEStack<T>> extends FCBaseCo
}
}
}
if (pinsHandler != null) {
if (clientCM.getSetting(Settings.PINS_STATE) != pinsHandler.getPinsState()) {
this.clientCM.putSetting(Settings.PINS_STATE, pinsHandler.getPinsState());
updatePins(true);
} else {
updatePins(false);
}
}
processItemList();
this.updatePowerStatus();
final boolean oldAccessible = this.canAccessViewCells;
@@ -122,6 +157,84 @@ public abstract class FCContainerMonitor<T extends IAEStack<T>> extends FCBaseCo
}
}
private int lastUpdate = 0;
public void updatePins(boolean forceUpdate) {
if (pinsHandler == null || !(host instanceof ITerminalPins itp)) return;
boolean isActive = pinsHandler.getPinsState() != PinsState.DISABLED;
++lastUpdate;
if (!forceUpdate && lastUpdate <= 20) return;
lastUpdate = 0;
if (isActive) {
final ICraftingGrid cc = itp.getGrid().getCache(ICraftingGrid.class);
final ImmutableList<ICraftingCPU> cpuList = cc.getCpus().asList();
List<IAEItemStack> craftedItems = new ArrayList<>();
// fetch the first available crafting output
for (int i = 0; i < cpuList.size(); i++) {
ICraftingCPU cpu = cpuList.get(i);
if (cpu.getCraftingAllowMode() != CraftingAllow.ONLY_NONPLAYER && cpu.getFinalOutput() != null
&& cpu.getCurrentJobSource() instanceof PlayerSource src
&& src.player == pinsHandler.getPlayer()) {
if (craftedItems.contains(cpu.getFinalOutput())) {
continue; // skip if already added
}
if (cpu.isBusy()) craftedItems.add(0, cpu.getFinalOutput().copy());
else craftedItems.add(cpu.getFinalOutput().copy());
}
}
pinsHandler.addItemsToPins(craftedItems);
}
pinsHandler.update(forceUpdate);
onListUpdate(); // notify the repo that the pins have changed
}
@Override
public void setPin(ItemStack is, int idx) {
if (pinsHandler == null || !(host instanceof ITerminalPins itp)) return;
if (is == null) {
final ICraftingGrid cc = itp.getGrid().getCache(ICraftingGrid.class);
final ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();
for (ICraftingCPU cpu : cpuSet) {
if (cpu.getCraftingAllowMode() != CraftingAllow.ONLY_NONPLAYER && cpu.getFinalOutput() != null
&& cpu.getFinalOutput().isSameType(getPin(idx))) {
if (!cpu.isBusy()) {
cpu.resetFinalOutput();
} else {
return;
}
}
}
}
pinsHandler.setPin(idx, is);
updatePins(true);
}
@Override
public ItemStack getPin(int idx) {
if (pinsHandler == null) return null;
return pinsHandler.getPin(idx);
}
public void setPinsState(PinsState pinsState) {
if (pinsHandler == null) return;
clientCM.putSetting(Settings.PINS_STATE, pinsState);
pinsHandler.setPinsState(pinsState);
updatePins(true);
}
public PinsState getPinsState() {
return pinsHandler != null ? pinsHandler.getPinsState() : PinsState.DISABLED;
}
public PinsHandler getPinsHandler() {
return pinsHandler;
}
protected abstract void processItemList();
protected boolean isInvalid() {
@@ -230,8 +343,4 @@ public abstract class FCContainerMonitor<T extends IAEStack<T>> extends FCBaseCo
this.getGui().updateSetting(manager, settingName, newValue);
}
}
public ITerminalHost getHost() {
return this.host;
}
}
@@ -17,10 +17,9 @@ import org.lwjgl.opengl.GL11;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.render.tank.ModelCertusTank;
import com.glodblock.github.common.item.ItemCertusQuartzTank;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.ModAndClassUtil;
import com.mitchej123.hodgepodge.textures.IPatchedTextureAtlasSprite;
import cpw.mods.fml.client.registry.ClientRegistry;
@@ -35,7 +34,7 @@ public class ItemCertusQuartzTankRender implements IItemRenderer {
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
return type != ItemRenderType.EQUIPPED_FIRST_PERSON;
return true;
}
@Override
@@ -49,31 +48,32 @@ public class ItemCertusQuartzTankRender implements IItemRenderer {
.bindTexture(FluidCraft.resource("textures/blocks/certus_quartz_tank/map.png"));
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_BLEND);
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
GL11.glScalef(1, -1, -1);
this.model.render(0.0625f);
GL11.glScalef(1, -1, 1);
this.model.render(0.0625f);
if (type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON) {
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
}
if (item != null && item.hasTagCompound()) {
FluidStack storedFluid = FluidStack
.loadFluidStackFromNBT(item.getTagCompound().getCompoundTag("tileEntity"));
int tankCapacity = 32000;
GL11.glRotatef(180F, 1F, 0F, 0F);
this.model.render(0.0625f);
GL11.glRotatef(180F, 1F, 0F, 0F);
if (item.getItem() instanceof ItemCertusQuartzTank itemCertusQuartzTank) {
FluidStack storedFluid = itemCertusQuartzTank.getFluid(item);
int tankCapacity = itemCertusQuartzTank.getCapacity(item);
if (storedFluid != null && storedFluid.getFluid() != null) {
IIcon fluidIcon = storedFluid.getFluid().getIcon();
if (fluidIcon == null) fluidIcon = FluidRegistry.LAVA.getIcon();
if (ModAndClassUtil.HODGEPODGE && fluidIcon instanceof IPatchedTextureAtlasSprite) {
((IPatchedTextureAtlasSprite) fluidIcon).markNeedsAnimationUpdate();
}
Tessellator tessellator = Tessellator.instance;
RenderBlocks renderer = new RenderBlocks();
GL11.glScalef(1, 1, -1);
Block waterBlock = FluidRegistry.WATER.getBlock();
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
renderer.setRenderBounds(
0.08F,
0.001F,
@@ -81,9 +81,12 @@ public class ItemCertusQuartzTankRender implements IItemRenderer {
0.92F,
(float) storedFluid.amount / (float) tankCapacity * 0.999F,
0.92F);
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
Block waterBlock = FluidRegistry.WATER.getBlock();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(
(storedFluid.getFluid().getColor() >> 16 & 0xFF) / 255.0F,
@@ -13,9 +13,7 @@ import org.lwjgl.opengl.GL11;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.RenderUtil;
import com.mitchej123.hodgepodge.textures.IPatchedTextureAtlasSprite;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -46,16 +44,9 @@ public class ItemPacketRender implements IItemRenderer {
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
FluidStack fluid = ItemFluidPacket.getFluidStack(item);
int RGB = 0xFFFFFF;
if (fluid != null) {
RGB = fluid.getFluid().getColor(fluid);
}
int RGB = fluid == null ? 0xFFFFFF : fluid.getFluid().getColor(fluid);
IIcon icon = fluid == null ? FluidRegistry.WATER.getStillIcon() : fluid.getFluid().getStillIcon();
if (ModAndClassUtil.HODGEPODGE && icon instanceof IPatchedTextureAtlasSprite) {
((IPatchedTextureAtlasSprite) icon).markNeedsAnimationUpdate();
}
if (RGB != 0xFFFFFF) {
GL11.glColor3f((RGB >> 16 & 0xFF) / 255.0F, (RGB >> 8 & 0xFF) / 255.0F, (RGB & 0xFF) / 255.0F);
}
@@ -25,8 +25,7 @@ public class ModelCertusTank extends ModelBase {
this.textureHeight = 64;
this.Shape1 = new ModelRenderer(this, 0, 0);
this.Shape1.addBox(0F, 0F, 0F, 14, 16, 14);
this.Shape1.setRotationPoint(-7F, -8F, -7F);
this.Shape1.addBox(-7F, -8F, -7F, 14, 16, 14);
this.Shape1.setTextureSize(this.textureWidth, this.textureHeight);
this.Shape1.mirror = true;
setRotation(this.Shape1, 0F, 0F, 0F);
@@ -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();
}
@@ -2,10 +2,10 @@ package com.glodblock.github.common.block;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@@ -16,11 +16,12 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidContainerItem;
import com.glodblock.github.common.item.ItemCertusQuartzTank;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import com.glodblock.github.loader.ChannelLoader;
import com.glodblock.github.loader.IRegister;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.NameConst;
@@ -106,71 +107,104 @@ public class BlockCertusQuartzTank extends BaseBlockContainer implements IRegist
}
@Override
public boolean onBlockActivated(World worldObj, int x, int y, int z, EntityPlayer entityplayer, int blockID,
float offsetX, float offsetY, float offsetZ) {
ItemStack current = entityplayer.inventory.getCurrentItem();
public boolean onBlockActivated(World worldObj, int x, int y, int z, EntityPlayer player, int side, float offsetX,
float offsetY, float offsetZ) {
ItemStack itemInHand = player.inventory.getCurrentItem();
if (entityplayer.isSneaking() && current != null) {
if (current.getItem() instanceof IAEWrench
&& ((IAEWrench) current.getItem()).canWrench(current, entityplayer, x, y, z)) {
if (itemInHand == null || itemInHand.getItem() == null) {
return false;
}
// In case if we're holding a IFluidContainerItem which is also a block we'll just allow to place a block
// instead of trying to fill or drain it. In other cases we don't need to handle blocks either way
if (itemInHand.getItem() instanceof ItemBlock) {
return false;
}
if (player.isSneaking()) {
if (itemInHand.getItem() instanceof IAEWrench wrench && wrench.canWrench(itemInHand, player, x, y, z)) {
dropBlockAsItem(worldObj, x, y, z, getDropWithNBT(worldObj, x, y, z));
worldObj.setBlockToAir(x, y, z);
return true;
}
}
if (current != null) {
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
TileCertusQuartzTank tank = (TileCertusQuartzTank) worldObj.getTileEntity(x, y, z);
if (liquid != null) {
int amountFilled = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
if (amountFilled != 0 && !entityplayer.capabilities.isCreativeMode && current.getItem() != null) {
ItemStack empty;
if (FluidContainerRegistry.isContainer(current)) {
empty = FluidContainerRegistry.drainFluidContainer(current);
} else {
// Try this as a fallback.
entityplayer.inventory.addItemStackToInventory(current.getItem().getContainerItem(current));
empty = current.getItem().getContainerItem(current);
}
if (current.stackSize > 1) {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize -= 1;
entityplayer.inventory.addItemStackToInventory(empty);
} else {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = empty;
}
TileCertusQuartzTank tank = (TileCertusQuartzTank) worldObj.getTileEntity(x, y, z);
boolean isCreativeMode = player.capabilities.isCreativeMode;
if (FluidContainerRegistry.isFilledContainer(itemInHand)) {
// Fill the tank from the container in hand
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(itemInHand);
if (fluid == null) {
return false;
}
int amountFilled = tank.fill(ForgeDirection.UNKNOWN, fluid, true);
if (amountFilled > 0 && !isCreativeMode) {
ItemStack empty = FluidContainerRegistry.drainFluidContainer(itemInHand);
replaceItemInInventory(worldObj, player, itemInHand, empty);
}
return true;
} else if (FluidContainerRegistry.isEmptyContainer(itemInHand)) {
// Fill the container in hand from the tank
FluidStack available = tank.getTankInfo(true)[0].fluid;
ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, itemInHand);
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(filled);
if (fluid == null) {
return false;
}
tank.drain(ForgeDirection.UNKNOWN, fluid.amount, true);
if (!isCreativeMode) {
replaceItemInInventory(worldObj, player, itemInHand, filled);
}
return true;
} else if (itemInHand.getItem() instanceof IFluidContainerItem) {
ItemStack singleContainerItem = itemInHand.copy();
singleContainerItem.stackSize = 1;
IFluidContainerItem fluidContainer = (IFluidContainerItem) singleContainerItem.getItem();
assert fluidContainer != null;
FluidStack fluid = fluidContainer.getFluid(itemInHand);
if (fluid != null && fluid.amount > 0) {
// Fill the tank from the container in hand
int filled = tank.fill(ForgeDirection.UNKNOWN, fluid, true);
if (filled > 0 && !isCreativeMode) {
fluidContainer.drain(singleContainerItem, filled, true);
replaceItemInInventory(worldObj, player, itemInHand, singleContainerItem);
}
return true;
} else {
FluidStack available = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;
if (available != null) {
ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current);
liquid = FluidContainerRegistry.getFluidForFilledItem(filled);
if (liquid != null) {
tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
if (!entityplayer.capabilities.isCreativeMode) {
if (current.stackSize == 1) {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = filled;
} else {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize--;
if (!entityplayer.inventory.addItemStackToInventory(filled))
entityplayer.entityDropItem(filled, 0);
}
}
return true;
}
// Fill the container in hand from the tank
int containerCapacity = fluidContainer.getCapacity(itemInHand);
FluidStack drained = tank.drain(ForgeDirection.UNKNOWN, containerCapacity, true);
if (drained != null && drained.amount > 0 && !isCreativeMode) {
fluidContainer.fill(singleContainerItem, drained, true);
replaceItemInInventory(worldObj, player, itemInHand, singleContainerItem);
}
}
return true;
}
return false;
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlock) {
if (!world.isRemote) {
ChannelLoader.sendPacketToAllPlayers(world.getTileEntity(x, y, z).getDescriptionPacket(), world);
private void replaceItemInInventory(World world, EntityPlayer player, ItemStack item, ItemStack replacement) {
if (item.stackSize > 1) {
item.stackSize--;
// This method meant to be called both from client and server side, and trying to drop an item
// from the client side would create a doubled ghost item, so we don't allow to do that
if (!player.inventory.addItemStackToInventory(replacement) && !world.isRemote) {
player.entityDropItem(replacement, 0);
}
} else {
player.inventory.setInventorySlotContents(player.inventory.currentItem, replacement);
}
}
@@ -209,4 +243,22 @@ public class BlockCertusQuartzTank extends BaseBlockContainer implements IRegist
setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
@Override
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride(World worldIn, int x, int y, int z, int side) {
TileEntity tileEntity = worldIn.getTileEntity(x, y, z);
if (tileEntity instanceof TileCertusQuartzTank tileCertusQuartzTank) {
FluidTankInfo info = tileCertusQuartzTank.getTankInfo(false)[0];
if (info.fluid != null) {
int nonEmptyBump = info.fluid.amount > 0 ? 1 : 0;
return (int) (14.0 * info.fluid.amount / info.capacity) + nonEmptyBump;
}
}
return 0;
}
}
@@ -0,0 +1,66 @@
package com.glodblock.github.common.block;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
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.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.util.BlockPos;
import com.glodblock.github.util.NameConst;
import appeng.block.AEBaseItemBlock;
import cpw.mods.fml.common.registry.GameRegistry;
public class BlockSuperStockReplenisher extends FCBaseBlock {
public BlockSuperStockReplenisher() {
super(Material.web, NameConst.BLOCK_SUPER_STOCK_REPLENISHER);
setTileEntity(TileSuperStockReplenisher.class);
setOpaque(true);
setFullBlock(true);
this.lightOpacity = 4;
}
@Override
public boolean onActivated(World world, int x, int y, int z, EntityPlayer player, int facing, float hitX,
float hitY, float hitZ) {
if (player.isSneaking()) {
return false;
}
TileSuperStockReplenisher tile = getTileEntity(world, x, y, z);
if (tile != null) {
if (!world.isRemote) {
InventoryHandler.openGui(
player,
world,
new BlockPos(x, y, z),
ForgeDirection.getOrientation(facing),
GuiType.GUI_SUPER_STOCK_REPLENISHER);
}
return true;
}
return false;
}
@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);
if (tss != null) {
tss.fullRefund();
}
super.breakBlock(w, x, y, z, a, b);
}
@Override
public BlockSuperStockReplenisher register() {
GameRegistry.registerBlock(this, AEBaseItemBlock.class, NameConst.BLOCK_SUPER_STOCK_REPLENISHER);
GameRegistry.registerTileEntity(TileSuperStockReplenisher.class, NameConst.BLOCK_SUPER_STOCK_REPLENISHER);
setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
}
@@ -20,6 +20,7 @@ import com.glodblock.github.common.storage.CellType;
import com.glodblock.github.common.storage.FluidCellInventory;
import com.glodblock.github.common.storage.FluidCellInventoryHandler;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.inventory.FluidCellConfig;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.NameConst;
import com.google.common.base.Optional;
@@ -36,7 +37,6 @@ import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.helpers.ICellRestriction;
import appeng.items.AEBaseItem;
import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades;
import appeng.util.InventoryAdaptor;
import appeng.util.IterationCounter;
@@ -145,7 +145,7 @@ public abstract class FCBaseItemCell extends AEBaseItem implements IStorageFluid
}
if (handler.isPreformatted()) {
final String list = (handler.getIncludeExcludeMode() == IncludeExclude.WHITELIST ? GuiText.Included
final String list = (handler.getWhitelist() == IncludeExclude.WHITELIST ? GuiText.Included
: GuiText.Excluded).getLocal();
lines.add(GuiText.Partitioned.getLocal() + " - " + list + ' ' + GuiText.Precise.getLocal());
@@ -208,7 +208,7 @@ public abstract class FCBaseItemCell extends AEBaseItem implements IStorageFluid
@Override
public IInventory getConfigInventory(ItemStack is) {
return new CellConfig(is);
return new FluidCellConfig(is);
}
@Override
@@ -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,7 @@ 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";
public ItemBaseWirelessTerminal(GuiType t) {
super();
@@ -52,19 +54,19 @@ public class ItemBaseWirelessTerminal extends ToolWirelessTerminal implements II
}
IWirelessTermRegistry term = AEApi.instance().registries().wireless();
if (!term.isWirelessTerminal(item)) {
player.addChatMessage(PlayerMessages.DeviceNotWirelessTerminal.get());
player.addChatMessage(PlayerMessages.DeviceNotWirelessTerminal.toChat());
return item;
}
final IWirelessTermHandler handler = term.getWirelessTerminalHandler(item);
final String unparsedKey = handler.getEncryptionKey(item);
if (unparsedKey.isEmpty()) {
player.addChatMessage(PlayerMessages.DeviceNotLinked.get());
player.addChatMessage(PlayerMessages.DeviceNotLinked.toChat());
return item;
}
final long parsedKey = Long.parseLong(unparsedKey);
final ILocatable securityStation = AEApi.instance().registries().locatable().getLocatableBy(parsedKey);
if (securityStation == null) {
player.addChatMessage(PlayerMessages.StationCanNotBeLocated.get());
player.addChatMessage(PlayerMessages.StationCanNotBeLocated.toChat());
return item;
}
if (handler.hasPower(player, 0.5, item)) {
@@ -75,7 +77,7 @@ public class ItemBaseWirelessTerminal extends ToolWirelessTerminal implements II
ForgeDirection.UNKNOWN,
this.guiGuiType(item));
} else {
player.addChatMessage(PlayerMessages.DeviceNotPowered.get());
player.addChatMessage(PlayerMessages.DeviceNotPowered.toChat());
}
}
@@ -131,4 +133,8 @@ public class ItemBaseWirelessTerminal extends ToolWirelessTerminal implements II
return this.type;
}
public static void toggleRestockItemsMode(ItemStack is, boolean state) {
NBTTagCompound data = Platform.openNbtData(is);
data.setBoolean(restockItems, state);
}
}
@@ -138,19 +138,14 @@ public class ItemCertusQuartzTank extends BaseItemBlockContainer implements IFlu
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side,
float hitX, float hitY, float hitZ, int metadata) {
if (!world.setBlock(x, y, z, this.field_150939_a, metadata, 3)) {
if (!super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata)) {
return false;
}
if (world.getBlock(x, y, z) == this.field_150939_a) {
this.field_150939_a.onBlockPlacedBy(world, x, y, z, player, stack);
this.field_150939_a.onPostBlockPlaced(world, x, y, z, metadata);
if (stack != null) {
((TileCertusQuartzTank) world.getTileEntity(x, y, z)).readFromItemNBT(stack.getTagCompound());
}
if (stack != null && stack.hasTagCompound()) {
((TileCertusQuartzTank) world.getTileEntity(x, y, z))
.readFromNBTWithoutCoords(stack.getTagCompound().getCompoundTag("tileEntity"));
}
return true;
}
}
@@ -8,12 +8,12 @@ import net.minecraft.item.ItemStack;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.inventory.FluidCellConfig;
import com.glodblock.github.loader.IRegister;
import com.glodblock.github.util.NameConst;
import appeng.api.config.FuzzyMode;
import appeng.core.features.AEFeature;
import appeng.items.contents.CellConfig;
import appeng.util.Platform;
import cpw.mods.fml.common.registry.GameRegistry;
@@ -30,7 +30,7 @@ public class ItemCreativeFluidStorageCell extends ItemBaseInfinityStorageCell
@Override
public IInventory getConfigInventory(ItemStack is) {
return new CellConfig(is);
return new FluidCellConfig(is);
}
@Override
@@ -1,7 +1,6 @@
package com.glodblock.github.common.item;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
@@ -23,6 +22,7 @@ import com.glodblock.github.util.NameConst;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.item.AEFluidStack;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
@@ -40,11 +40,34 @@ public class ItemFluidPacket extends FCBaseItem {
if (stack == null || !stack.hasTagCompound()) {
return null;
}
FluidStack fluid = FluidStack
.loadFluidStackFromNBT(Objects.requireNonNull(stack.getTagCompound()).getCompoundTag("FluidStack"));
NBTTagCompound tag = stack.getTagCompound().getCompoundTag("FluidStack");
FluidStack fluid = FluidStack.loadFluidStackFromNBT(tag);
if (fluid != null && tag.getLong("Amount") > Integer.MAX_VALUE) fluid.amount = Integer.MAX_VALUE;
return (fluid != null && fluid.amount > 0) ? fluid : null;
}
@Nullable
public static FluidStack getFluidStack(@Nullable IAEItemStack stack) {
return stack != null ? getFluidStack(stack.getItemStack()) : null;
}
@Nullable
public static IAEFluidStack getFluidAEStack(ItemStack stack) {
if (stack != null && stack.hasTagCompound()) {
NBTTagCompound tag = stack.getTagCompound().getCompoundTag("FluidStack");
IAEFluidStack ifs = AEFluidStack.create(FluidStack.loadFluidStackFromNBT(tag));
if (ifs != null && tag.hasKey("Amount")) ifs.setStackSize(tag.getLong("Amount"));
return ifs;
}
return null;
}
@Nullable
public static IAEFluidStack getFluidAEStack(@Nullable IAEItemStack stack) {
return stack != null ? getFluidAEStack(stack.getItemStack()) : null;
}
@Override
public String getUnlocalizedName(ItemStack stack) {
FluidStack fluid = getFluidStack(stack);
@@ -83,25 +106,20 @@ public class ItemFluidPacket extends FCBaseItem {
}
}
@Nullable
public static FluidStack getFluidStack(@Nullable IAEItemStack stack) {
return stack != null ? getFluidStack(stack.getItemStack()) : null;
}
public static void setFluidAmount(ItemStack stack, int amount) {
public static void setFluidAmount(ItemStack stack, long amount) {
if (stack == null || !stack.hasTagCompound()
|| !stack.getTagCompound().hasKey("FluidStack", Constants.NBT.TAG_COMPOUND)) {
return;
}
stack.getTagCompound().getCompoundTag("FluidStack").setInteger("Amount", amount);
stack.getTagCompound().getCompoundTag("FluidStack").setLong("Amount", amount);
}
public static int getFluidAmount(ItemStack stack) {
public static long getFluidAmount(ItemStack stack) {
if (stack == null || !stack.hasTagCompound()) {
return 0;
}
// Default to 0 if no tag exists
return stack.getTagCompound().getCompoundTag("FluidStack").getInteger("Amount");
return stack.getTagCompound().getCompoundTag("FluidStack").getLong("Amount");
}
@Nullable
@@ -120,10 +138,22 @@ public class ItemFluidPacket extends FCBaseItem {
@Nullable
public static ItemStack newStack(@Nullable IAEFluidStack fluid) {
if (fluid == null || fluid.getStackSize() == 0) {
return null;
if (fluid != null && fluid.getStackSize() > 0) {
ItemStack stack = new ItemStack(ItemAndBlockHolder.PACKET);
NBTTagCompound tag = new NBTTagCompound();
NBTTagCompound fluidTag = new NBTTagCompound();
fluid.getFluidStack().writeToNBT(fluidTag);
fluidTag.setLong("Amount", fluid.getStackSize());
tag.setTag("FluidStack", fluidTag);
stack.setTagCompound(tag);
return stack;
}
return newStack(fluid.getFluidStack());
return null;
}
@Nullable
public static IAEItemStack newAeStack(@Nullable FluidStack fluid) {
return AEItemStack.create(newStack(fluid));
}
@Nullable
@@ -143,11 +173,6 @@ public class ItemFluidPacket extends FCBaseItem {
return stack;
}
@Nullable
public static IAEItemStack newAeStack(@Nullable FluidStack fluid) {
return AEItemStack.create(newStack(fluid));
}
@Override
public int getSpriteNumber() {
return 0;
@@ -14,6 +14,7 @@ import com.glodblock.github.common.storage.IFluidCellInventory;
import com.glodblock.github.common.storage.IFluidCellInventoryHandler;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.inventory.FluidCellConfig;
import com.glodblock.github.loader.IRegister;
import com.glodblock.github.util.NameConst;
@@ -25,7 +26,6 @@ import appeng.api.storage.data.IAEFluidStack;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades;
import appeng.util.Platform;
import cpw.mods.fml.common.registry.GameRegistry;
@@ -116,7 +116,7 @@ public class ItemFluidVoidStorageCell extends AEBaseItem
@Override
public IInventory getConfigInventory(ItemStack is) {
return new CellConfig(is);
return new FluidCellConfig(is);
}
@Override
@@ -20,6 +20,7 @@ import com.glodblock.github.common.storage.IFluidCellInventory;
import com.glodblock.github.common.storage.IFluidCellInventoryHandler;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.inventory.FluidCellConfig;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IItemInventory;
@@ -37,7 +38,6 @@ import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades;
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.util.Platform;
@@ -163,7 +163,7 @@ public class ItemPortableFluidCell extends AEBasePoweredItem
@Override
public IInventory getConfigInventory(final ItemStack is) {
return new CellConfig(is);
return new FluidCellConfig(is);
}
@Override
@@ -44,7 +44,7 @@ public class ItemWirelessFluidTerminal extends ItemBaseWirelessTerminal
IGridNode gridNode = Util.getWirelessGrid(stack);
return new WirelessFluidTerminalInventory(stack, x, gridNode, player);
} catch (Exception e) {
player.addChatMessage(PlayerMessages.OutOfRange.get());
player.addChatMessage(PlayerMessages.OutOfRange.toChat());
}
return null;
}
@@ -44,7 +44,7 @@ public class ItemWirelessInterfaceTerminal extends ItemBaseWirelessTerminal
IGridNode gridNode = Util.getWirelessGrid(stack);
return new WirelessInterfaceTerminalInventory(stack, x, gridNode, player);
} catch (Exception e) {
player.addChatMessage(PlayerMessages.OutOfRange.get());
player.addChatMessage(PlayerMessages.OutOfRange.toChat());
}
return null;
}
@@ -44,7 +44,7 @@ public class ItemWirelessLevelTerminal extends ItemBaseWirelessTerminal
IGridNode gridNode = Util.getWirelessGrid(stack);
return new WirelessLevelTerminalInventory(stack, x, gridNode, player);
} catch (Exception e) {
player.addChatMessage(PlayerMessages.OutOfRange.get());
player.addChatMessage(PlayerMessages.OutOfRange.toChat());
}
return null;
}
@@ -44,7 +44,7 @@ public class ItemWirelessPatternTerminal extends ItemBaseWirelessTerminal
IGridNode gridNode = Util.getWirelessGrid(stack);
return new WirelessPatternTerminalInventory(stack, x, gridNode, player);
} catch (Exception e) {
player.addChatMessage(PlayerMessages.OutOfRange.get());
player.addChatMessage(PlayerMessages.OutOfRange.toChat());
}
return null;
}
@@ -7,8 +7,10 @@ import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
@@ -25,6 +27,8 @@ 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.WirelessMagnet;
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;
@@ -40,6 +44,7 @@ import appeng.core.features.AEFeature;
import appeng.core.localization.PlayerMessages;
import appeng.util.Platform;
import baubles.api.BaubleType;
import baubles.api.BaublesApi;
import baubles.api.IBauble;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.registry.GameRegistry;
@@ -102,7 +107,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,12 +128,14 @@ 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);
}
} catch (Exception e) {
player.addChatMessage(PlayerMessages.OutOfRange.get());
player.addChatMessage(PlayerMessages.OutOfRange.toChat());
}
return null;
}
@@ -226,7 +235,21 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal
@Override
public void onWornTick(ItemStack itemStack, EntityLivingBase entityLivingBase) {
if (Platform.isServer() && entityLivingBase instanceof EntityPlayer player) {
IInventory handler = BaublesApi.getBaubles(player);
if (handler != null) {
for (int i = 0; i < handler.getSizeInventory(); ++i) {
if (handler.getStackInSlot(i) == itemStack) {
onUpdate(
itemStack,
null,
player,
Util.GuiHelper.encodeType(i, Util.GuiHelper.InvType.PLAYER_BAUBLES),
false);
}
}
}
}
}
@Override
@@ -248,4 +271,13 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal
public boolean canUnequip(ItemStack itemStack, EntityLivingBase entityLivingBase) {
return true;
}
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int slot, boolean p_77663_5_) {
if (entityIn instanceof EntityPlayer player) {
if (WirelessMagnet.getMode(stack) != WirelessMagnet.Mode.Off) {
WirelessMagnet.doMagnet(stack, player);
}
}
}
}
@@ -1,5 +1,8 @@
package com.glodblock.github.common.parts;
import static appeng.util.Platform.convertStack;
import static appeng.util.Platform.stackConvert;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@@ -11,11 +14,11 @@ import com.glodblock.github.client.textures.FCPartsTexture;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.parts.base.FCSharedFluidBus;
import com.glodblock.github.inventory.FluidConvertingInventoryAdaptor;
import com.google.common.collect.ImmutableSet;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.InsertionMode;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SchedulingMode;
@@ -43,7 +46,6 @@ import appeng.me.GridAccessException;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.item.AEFluidStack;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -112,10 +114,9 @@ public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingReq
this.didSomething = false;
this.fluidToSend = this.calculateAmountToSend();
final TileEntity te = this.getConnectedTE();
if (te instanceof IFluidHandler) {
InventoryAdaptor destination;
if (te instanceof IFluidHandler && (destination = this.getHandler(te)) != null) {
try {
final InventoryAdaptor destination = this.getHandler(te);
final ICraftingGrid cg = this.getProxy().getCrafting();
final IFluidHandler fh = (IFluidHandler) te;
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getFluidInventory();
@@ -270,7 +271,7 @@ public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingReq
}
protected InventoryAdaptor getHandler(TileEntity target) {
return target != null ? FluidConvertingInventoryAdaptor.wrap(target, this.getSide().getOpposite()) : null;
return target != null ? InventoryAdaptor.getAdaptor(target, getSide().getOpposite()) : null;
}
@Override
@@ -283,17 +284,15 @@ public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingReq
final double power = Math.ceil(items.getStackSize() / 1000D);
if (energy.extractAEPower(power, mode, PowerMultiplier.CONFIG) > power - 0.01) {
ItemStack inputStack = items.getItemStack();
ItemStack remaining;
IAEItemStack remaining;
if (mode == Actionable.SIMULATE) {
remaining = d.simulateAdd(inputStack);
remaining = stackConvert(d.simulateAddStack(convertStack(items), InsertionMode.DEFAULT));
} else {
remaining = d.addItems(inputStack);
remaining = stackConvert(d.addStack(convertStack(items), InsertionMode.DEFAULT));
}
return AEItemStack.create(remaining);
return remaining;
}
}
} catch (final GridAccessException e) {
@@ -18,6 +18,8 @@ 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;
@@ -314,9 +316,10 @@ public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatc
@SideOnly(Side.CLIENT)
public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) {
rh.setTexture(this.getItemStack().getIconIndex());
Tessellator.instance.startDrawingQuads();
final Tessellator tess = Tessellator.instance;
tess.startDrawingQuads();
this.renderTorchAtAngle(0, -0.5, 0);
Tessellator.instance.draw();
tess.draw();
}
private void renderTorchAtAngle(double baseX, double baseY, double baseZ) {
@@ -586,4 +589,15 @@ 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) };
}
}
@@ -1,5 +1,7 @@
package com.glodblock.github.common.parts;
import static appeng.helpers.DualityInterface.NUMBER_OF_STORAGE_SLOTS;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
@@ -33,6 +35,7 @@ import com.google.common.collect.ImmutableSet;
import appeng.api.config.Actionable;
import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.tiles.ITileStorageMonitorable;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingLink;
@@ -46,16 +49,17 @@ import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.parts.IPart;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.IConfigManager;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.IPriorityHost;
import appeng.me.GridAccessException;
import appeng.me.cache.CraftingGridCache;
import appeng.parts.automation.UpgradeInventory;
import appeng.parts.p2p.PartP2PTunnel;
import appeng.parts.p2p.PartP2PTunnelStatic;
@@ -64,28 +68,45 @@ import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.AdaptorIInventory;
import appeng.util.inv.IInventoryDestination;
import appeng.util.inv.WrapperInvSlot;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInterface>
implements IGridTickable, IStorageMonitorable, IInventoryDestination, IDualHost, ISidedInventory,
IAEAppEngInventory, ITileStorageMonitorable, IPriorityHost, IInterfaceHost {
boolean needUpdateOnNetworkBooted = false;
boolean lastPowerStart = false;
public PartFluidP2PInterface(ItemStack is) {
super(is);
}
private final DualityInterface duality = new DualityInterface(this.getProxy(), this) {
@Override
public void updateCraftingList() {
if (!isOutput()) {
CraftingGridCache.pauseRebuilds();
super.updateCraftingList();
try {
for (PartFluidP2PInterface p2p : getOutputs()) p2p.duality.updateCraftingList();
for (PartFluidP2PInterface p2p : getOutputs()) {
p2p.duality.updateCraftingList();
}
} catch (GridAccessException e) {
// ?
}
CraftingGridCache.unpauseRebuilds();
} else {
PartFluidP2PInterface p2p = getInput();
if (p2p != null) {
this.craftingList = p2p.duality.craftingList;
try {
this.gridProxy.getGrid()
.postEvent(new MENetworkCraftingPatternChange(this, this.gridProxy.getNode()));
@@ -96,29 +117,169 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
}
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
final boolean powerState = proxy.isActive();
if (needUpdateOnNetworkBooted || lastPowerStart != powerState) {
needUpdateOnNetworkBooted = false;
lastPowerStart = powerState;
updateSharingInventory();
}
return super.tickingRequest(node, ticksSinceLastCall);
}
@Override
protected boolean hasWorkToDo() {
if (isOutput()) {
return hasItemsToSend() || hasConfig() || !getStorage().isEmpty();
} else return super.hasWorkToDo();
}
@Override
public void readConfig() {
if (isOutput()) {
PartFluidP2PInterface p2p = getInput();
boolean alertDevice = false;
if (p2p != null) {
this.setHasConfig(p2p.duality.hasConfig());
alertDevice = hasWorkToDo();
} else {
this.setHasConfig(false);
}
if (alertDevice) {
try {
this.gridProxy.getTick().alertDevice(this.gridProxy.getNode());
} catch (final GridAccessException ignored) {}
} else {
try {
this.gridProxy.getTick().sleepDevice(this.gridProxy.getNode());
} catch (final GridAccessException ignored) {}
}
this.notifyNeighbors();
} else {
super.readConfig();
}
}
@Override
public void addDrops(final List<ItemStack> drops) {
if (!isOutput()) {
super.addDrops(drops);
try {
for (PartFluidP2PInterface p2p : getOutputs()) p2p.duality.addDrops(drops);
} catch (GridAccessException ignored) {}
} else {
List<IAEStack<?>> waitingList = this.getWaitingToSend();
if (waitingList != null) {
for (final IAEStack<?> as : waitingList) {
if (as instanceof IAEItemStack ais) {
drops.add(ais.getItemStack());
} else if (as instanceof IAEFluidStack afs) {
drops.add(ItemFluidPacket.newStack(afs));
}
}
}
for (final ItemStack is : this.getUpgrades()) {
if (is != null) {
drops.add(is);
}
}
for (final ItemStack is : this.getPatterns()) {
if (is != null) {
drops.add(is);
}
}
}
}
@Override
public int getInstalledUpgrades(Upgrades u) {
if (isOutput() && u == Upgrades.PATTERN_CAPACITY) return -1;
return super.getInstalledUpgrades(u);
}
@Override
public int getConfigSize() {
if (isOutput()) return -1;
return super.getConfigSize();
}
};
private final DualityFluidInterface dualityFluid = new DualityFluidInterface(this.getProxy(), this);
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 6);
public PartFluidP2PInterface(ItemStack is) {
super(is);
private void updateSharingInventory() {
duality.readConfig();
if (isOutput()) {
PartFluidP2PInterface p2p = getInput();
if (proxy.isActive() && p2p != null) {
if (!duality.sharedInventory && !duality.getStorage().isEmpty()) {
ArrayList<ItemStack> drops = new ArrayList<>();
AppEngInternalInventory storageAppEng = this.duality.getStorage();
AdaptorIInventory p2pInv = new AdaptorIInventory(p2p.duality.getStorage());
for (ItemStack itemStack : storageAppEng) {
if (itemStack == null) continue;
ItemStack drop = p2pInv.addItems(itemStack);
if (drop != null && drop.stackSize > 0) {
drops.add(drop);
}
}
TileEntity te = getTileEntity();
Platform.spawnDrops(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, drops);
}
duality.setStorage(p2p.duality.getStorage());
duality.setSlotInv(p2p.duality.getSlotInv());
duality.sharedInventory = true;
} else {
if (duality.sharedInventory) {
duality.setStorage(new AppEngInternalInventory(this, NUMBER_OF_STORAGE_SLOTS));
duality.setSlotInv(new WrapperInvSlot(duality.getStorage()));
duality.sharedInventory = false;
}
}
} else {
if (duality.sharedInventory) {
duality.setStorage(new AppEngInternalInventory(this, NUMBER_OF_STORAGE_SLOTS));
duality.setSlotInv(new WrapperInvSlot(duality.getStorage()));
duality.sharedInventory = false;
}
try {
for (PartFluidP2PInterface p2p : getOutputs()) {
p2p.duality.readConfig();
}
} catch (GridAccessException ignored) {}
}
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkChannelsChanged c) {
dualityFluid.onChannelStateChange(c);
duality.notifyNeighbors();
this.duality.notifyNeighbors();
updateSharingInventory();
needUpdateOnNetworkBooted = true;
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkPowerStatusChange c) {
dualityFluid.onPowerStateChange(c);
duality.notifyNeighbors();
this.duality.notifyNeighbors();
updateSharingInventory();
needUpdateOnNetworkBooted = true;
}
@Override
public int getInstalledUpgrades(final Upgrades u) {
return this.duality.getInstalledUpgrades(u);
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getTypeTexture() {
return ItemAndBlockHolder.INTERFACE.getBlockTextureFromSide(0);
}
@Override
@@ -127,52 +288,80 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
dualityFluid.gridChanged();
}
@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.duality.readFromNBT(data);
}
@Override
public void writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
this.duality.writeToNBT(data);
}
@Override
public NBTTagCompound getMemoryCardData() {
final NBTTagCompound output = super.getMemoryCardData();
this.duality.getConfigManager().writeToNBT(output);
return output;
}
@Override
public PartP2PTunnel<?> applyMemoryCard(EntityPlayer player, IMemoryCard memoryCard, ItemStack is) {
PartP2PTunnel<?> newTunnel = super.applyMemoryCard(player, memoryCard, is);
if (Platform.isClient()) return newTunnel;
NBTTagCompound data = memoryCard.getData(is);
if (newTunnel instanceof PartFluidP2PInterface p2PInterface) {
p2PInterface.duality.getConfigManager().readFromNBT(data);
}
return newTunnel;
}
@Override
public void addToWorld() {
super.addToWorld();
this.duality.initialize();
}
@Override
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
this.duality.addDrops(drops);
}
@Override
public int cableConnectionRenderTo() {
return 4;
}
@Override
public IConfigManager getConfigManager() {
return this.duality.getConfigManager();
}
@Override
public IInventory getInventoryByName(final String name) {
return this.duality.getInventoryByName(name);
}
@Override
public void onNeighborChanged() {
this.duality.updateRedstoneState();
}
@Override
public boolean onPartActivate(final EntityPlayer player, final Vec3 pos) {
AppEngInternalInventory patterns = (AppEngInternalInventory) duality.getPatterns();
if (super.onPartActivate(player, pos)) {
ArrayList<ItemStack> drops = new ArrayList<>();
for (int i = 0; i < patterns.getSizeInventory(); i++) {
if (patterns.getStackInSlot(i) == null) continue;
drops.add(patterns.getStackInSlot(i));
}
final IPart tile = this.getHost().getPart(this.getSide());
if (tile instanceof PartFluidP2PInterface dualTile) {
DualityInterface newDuality = dualTile.duality;
// Copy interface storage, upgrades, and settings over
UpgradeInventory upgrades = (UpgradeInventory) duality.getInventoryByName("upgrades");
dualTile.duality.getStorage();
UpgradeInventory newUpgrade = (UpgradeInventory) newDuality.getInventoryByName("upgrades");
for (int i = 0; i < upgrades.getSizeInventory(); ++i) {
newUpgrade.setInventorySlotContents(i, upgrades.getStackInSlot(i));
}
IInventory storage = duality.getStorage();
IInventory newStorage = newDuality.getStorage();
for (int i = 0; i < storage.getSizeInventory(); ++i) {
newStorage.setInventorySlotContents(i, storage.getStackInSlot(i));
}
IConfigManager config = duality.getConfigManager();
config.getSettings().forEach(
setting -> newDuality.getConfigManager().putSetting(setting, config.getSetting(setting)));
}
TileEntity te = getTileEntity();
Platform.spawnDrops(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, drops);
public boolean onPartActivate(final EntityPlayer p, final Vec3 pos) {
if (super.onPartActivate(p, pos)) {
return true;
}
if (player.isSneaking()) {
if (p.isSneaking()) {
return false;
}
if (Platform.isServer()) {
InventoryHandler.openGui(
player,
p,
this.getHost().getTile().getWorldObj(),
new BlockPos(this.getHost().getTile()),
Objects.requireNonNull(this.getSide()),
@@ -182,14 +371,88 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
return true;
}
@Override
public IIcon getTypeTexture() {
return ItemAndBlockHolder.INTERFACE.getBlockTextureFromSide(0);
private void dropPatterns(final PartFluidP2PInterface p2p) {
final AppEngInternalInventory patterns = p2p.duality.getPatterns();
final List<ItemStack> drops = new ArrayList<>();
for (int i = 0; i < patterns.getSizeInventory(); i++) {
if (patterns.getStackInSlot(i) == null) continue;
drops.add(patterns.getStackInSlot(i));
}
if (!drops.isEmpty()) {
final TileEntity te = p2p.getTileEntity();
Platform.spawnDrops(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, drops);
}
}
@Override
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src) {
return duality.getMonitorable(side, src, this);
protected void copyContents(final PartP2PTunnel<?> from) {
if (from instanceof PartFluidP2PInterface fromInterface) {
DualityInterface newDuality = this.duality;
// Copy interface storage, upgrades, and settings over
UpgradeInventory upgrades = (UpgradeInventory) fromInterface.duality.getInventoryByName("upgrades");
UpgradeInventory newUpgrade = (UpgradeInventory) newDuality.getInventoryByName("upgrades");
for (int i = 0; i < upgrades.getSizeInventory(); ++i) {
newUpgrade.setInventorySlotContents(i, upgrades.getStackInSlot(i));
}
if (!fromInterface.duality.sharedInventory) {
IInventory storage = fromInterface.duality.getStorage();
IInventory newStorage = newDuality.getStorage();
for (int i = 0; i < storage.getSizeInventory(); ++i) {
newStorage.setInventorySlotContents(i, storage.getStackInSlot(i));
}
IInventory config = fromInterface.duality.getInventoryByName("config");
IInventory newConfig = newDuality.getInventoryByName("config");
for (int i = 0; i < config.getSizeInventory(); ++i) {
newConfig.setInventorySlotContents(i, config.getStackInSlot(i));
}
}
AppEngInternalInventory patterns = fromInterface.duality.getPatterns();
boolean drop = true;
if (!from.isOutput() && !this.isOutput()) { // input to input
for (int i = 0; i < patterns.getSizeInventory(); i++) {
newDuality.getPatterns().setInventorySlotContents(i, patterns.getStackInSlot(i));
}
drop = false;
}
if (drop) {
this.dropPatterns(fromInterface);
}
}
}
@Override
protected void copySettings(final PartP2PTunnel<?> from) {
if (from instanceof PartFluidP2PInterface fromInterface) {
DualityInterface newDuality = this.duality;
IConfigManager config = fromInterface.duality.getConfigManager();
config.getSettings()
.forEach(setting -> newDuality.getConfigManager().putSetting(setting, config.getSetting(setting)));
}
}
@Override
public IIcon getBreakingTexture() {
return this.getItemStack().getIconIndex();
}
@Override
public boolean canInsert(final ItemStack stack) {
return this.duality.canInsert(stack);
}
@Override
public IMEMonitor<IAEItemStack> getItemInventory() {
return this.duality.getItemInventory();
}
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory() {
return this.duality.getFluidInventory();
}
@Override
@@ -214,142 +477,216 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
}
}
@Override
public int getInstalledUpgrades(Upgrades u) {
return duality.getInstalledUpgrades(u);
}
@Override
public IMEMonitor<IAEItemStack> getItemInventory() {
return duality.getItemInventory();
}
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory() {
return duality.getFluidInventory();
}
@Override
public int getPriority() {
return duality.getPriority();
}
@Override
public void setPriority(int newValue) {
duality.setPriority(newValue);
}
@Override
public void onTunnelNetworkChange() {
duality.updateCraftingList();
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation op, ItemStack removedStack,
ItemStack newStack) {
duality.onChangeInventory(inv, slot, op, removedStack, newStack);
}
@Override
public boolean canInsert(ItemStack stack) {
return duality.canInsert(stack);
}
@Override
public int getSizeInventory() {
return duality.getStorage().getSizeInventory();
return this.duality.getStorage().getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int slotIn) {
return duality.getStorage().getStackInSlot(slotIn);
public ItemStack getStackInSlot(final int i) {
return this.duality.getStorage().getStackInSlot(i);
}
@Override
public ItemStack decrStackSize(int index, int count) {
return duality.getStorage().decrStackSize(index, count);
public ItemStack decrStackSize(final int i, final int j) {
return this.duality.getStorage().decrStackSize(i, j);
}
@Override
public ItemStack getStackInSlotOnClosing(int index) {
return duality.getStorage().getStackInSlotOnClosing(index);
public ItemStack getStackInSlotOnClosing(final int i) {
return this.duality.getStorage().getStackInSlotOnClosing(i);
}
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
duality.getStorage().setInventorySlotContents(index, stack);
}
@Override
public IInventory getInventoryByName(String name) {
return duality.getInventoryByName(name);
}
@Override
public IConfigManager getConfigManager() {
return duality.getConfigManager();
}
@Override
public IIcon getBreakingTexture() {
return getItemStack().getIconIndex();
public void setInventorySlotContents(final int i, final ItemStack itemstack) {
this.duality.getStorage().setInventorySlotContents(i, itemstack);
}
@Override
public String getInventoryName() {
return duality.getStorage().getInventoryName();
return this.duality.getStorage().getInventoryName();
}
@Override
public boolean hasCustomInventoryName() {
return duality.getStorage().hasCustomInventoryName();
return this.duality.getStorage().hasCustomInventoryName();
}
@Override
public int getInventoryStackLimit() {
return duality.getStorage().getInventoryStackLimit();
return this.duality.getStorage().getInventoryStackLimit();
}
@Override
public void markDirty() {
duality.markDirty();
this.duality.getStorage().markDirty();
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return duality.getStorage().isUseableByPlayer(player);
public boolean isUseableByPlayer(final EntityPlayer entityplayer) {
return this.duality.getStorage().isUseableByPlayer(entityplayer);
}
@Override
public void openInventory() {
duality.getStorage().openInventory();
this.duality.getStorage().openInventory();
}
@Override
public void closeInventory() {
duality.getStorage().closeInventory();
this.duality.getStorage().closeInventory();
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
return duality.getStorage().isItemValidForSlot(index, stack);
public boolean isItemValidForSlot(final int i, final ItemStack itemstack) {
return this.duality.getStorage().isItemValidForSlot(i, itemstack);
}
@Override
public int[] getAccessibleSlotsFromSide(int side) {
return duality.getAccessibleSlotsFromSide(side);
public int[] getAccessibleSlotsFromSide(final int s) {
return this.duality.getAccessibleSlotsFromSide(s);
}
@Override
public boolean canInsertItem(int p_102007_1_, ItemStack itemStack, int p_102007_3_) {
public boolean canInsertItem(final int i, final ItemStack itemstack, final int j) {
return true;
}
@Override
public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, int p_102008_3_) {
public boolean canExtractItem(final int i, final ItemStack itemstack, final int j) {
return true;
}
@Override
public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc,
final ItemStack removedStack, final ItemStack newStack) {
this.duality.onChangeInventory(inv, slot, mc, removedStack, newStack);
}
@Override
public DualityInterface getInterfaceDuality() {
return this.duality;
}
@Override
public EnumSet<ForgeDirection> getTargets() {
return EnumSet.of(this.getSide());
}
@Override
public TileEntity getTileEntity() {
return super.getHost().getTile();
}
@Override
public IStorageMonitorable getMonitorable(final ForgeDirection side, final BaseActionSource src) {
return this.duality.getMonitorable(side, src, this);
}
@Override
public boolean pushPattern(final ICraftingPatternDetails patternDetails, final InventoryCrafting table) {
return this.duality.pushPattern(patternDetails, table);
}
@Override
public boolean isBusy() {
return this.duality.isBusy();
}
@Override
public void provideCrafting(final ICraftingProviderHelper craftingTracker) {
this.duality.provideCrafting(craftingTracker);
}
@Override
public ImmutableSet<ICraftingLink> getRequestedJobs() {
return this.duality.getRequestedJobs();
}
@Override
public IAEItemStack injectCraftedItems(final ICraftingLink link, final IAEItemStack items, final Actionable mode) {
return this.duality.injectCraftedItems(link, items, mode);
}
@Override
public void jobStateChange(final ICraftingLink link) {
this.duality.jobStateChange(link);
}
@Override
public int getPriority() {
return this.duality.getPriority();
}
@Override
public void setPriority(final int newValue) {
this.duality.setPriority(newValue);
}
@Override
public void onTunnelNetworkChange() {
this.duality.updateCraftingList();
updateSharingInventory();
}
@Override
public void onTunnelConfigChange() {
updateSharingInventory();
}
@Override
public IInventory getPatterns() {
if (isOutput()) {
PartFluidP2PInterface input = getInput();
if (input != null) {
return input.getPatterns();
}
return IInterfaceHost.super.getPatterns();
}
return IInterfaceHost.super.getPatterns();
}
@Override
public int rows() {
if (isOutput()) {
PartFluidP2PInterface input = getInput();
if (input != null) {
return input.rows();
}
return IInterfaceHost.super.rows();
}
return IInterfaceHost.super.rows();
}
@Override
public int rowSize() {
if (isOutput()) {
PartFluidP2PInterface input = getInput();
if (input != null) {
return input.rowSize();
}
return IInterfaceHost.super.rowSize();
}
return IInterfaceHost.super.rowSize();
}
@Override
public String getName() {
if (isOutput()) {
PartFluidP2PInterface input = getInput();
if (input != null) {
return input.getName();
}
return IInterfaceHost.super.getName();
}
return IInterfaceHost.super.getName();
}
@Override
public ItemStack getSelfRep() {
return this.getItemStack();
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
return dualityFluid.fill(from, resource, doFill);
@@ -420,138 +757,9 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic<PartFluidP2PInter
}
}
@Override
public DualityInterface getInterfaceDuality() {
return duality;
}
@Override
public EnumSet<ForgeDirection> getTargets() {
return EnumSet.of(this.getSide());
}
@Override
public TileEntity getTileEntity() {
return super.getHost().getTile();
}
@Override
public void provideCrafting(ICraftingProviderHelper craftingTracker) {
duality.provideCrafting(craftingTracker);
}
@Override
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) {
return duality.pushPattern(patternDetails, table);
}
@Override
public boolean isBusy() {
return duality.isBusy();
}
@Override
public ImmutableSet<ICraftingLink> getRequestedJobs() {
return duality.getRequestedJobs();
}
@Override
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) {
return duality.injectCraftedItems(link, items, mode);
}
@Override
public void jobStateChange(ICraftingLink link) {
duality.jobStateChange(link);
}
@Override
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
duality.readFromNBT(data);
}
@Override
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
duality.writeToNBT(data);
}
@Override
public NBTTagCompound getMemoryCardData() {
final NBTTagCompound output = super.getMemoryCardData();
this.duality.getConfigManager().writeToNBT(output);
return output;
}
@Override
public void pasteMemoryCardData(PartP2PTunnel<?> newTunnel, NBTTagCompound data) throws GridAccessException {
this.duality.getConfigManager().readFromNBT(data);
super.pasteMemoryCardData(newTunnel, data);
}
@Override
public void addToWorld() {
super.addToWorld();
this.duality.initialize();
}
@Override
public void getDrops(List<ItemStack> drops, boolean wrenched) {
super.getDrops(drops, wrenched);
duality.addDrops(drops);
}
@Override
public boolean shouldDisplay() {
return IInterfaceHost.super.shouldDisplay();
}
@Override
public IInventory getPatterns() {
if (isOutput()) {
PartFluidP2PInterface input = getInput();
if (input != null) {
return input.getPatterns();
}
return IInterfaceHost.super.getPatterns();
}
return IInterfaceHost.super.getPatterns();
}
@Override
public int rows() {
if (isOutput()) {
PartFluidP2PInterface input = getInput();
if (input != null) {
return input.rows();
}
return IInterfaceHost.super.rows();
}
return IInterfaceHost.super.rows();
}
@Override
public int rowSize() {
if (isOutput()) {
PartFluidP2PInterface input = getInput();
if (input != null) {
return input.rowSize();
}
return IInterfaceHost.super.rowSize();
}
return IInterfaceHost.super.rowSize();
}
@Override
public String getName() {
if (isOutput()) {
PartFluidP2PInterface input = getInput();
if (input != null) {
return input.getName();
}
return IInterfaceHost.super.getName();
}
return IInterfaceHost.super.getName();
}
}
@@ -3,6 +3,7 @@ package com.glodblock.github.common.parts.base;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -10,14 +11,19 @@ import net.minecraft.nbt.NBTTagCompound;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.item.IItemPatternTerminal;
import appeng.api.networking.IGrid;
import appeng.api.storage.ITerminalPins;
import appeng.api.storage.data.IAEItemStack;
import appeng.items.contents.PinsHandler;
import appeng.items.contents.PinsHolder;
import appeng.tile.inventory.AppEngInternalInventory;
public abstract class FCFluidEncodeTerminal extends FCPart implements IItemPatternTerminal {
public abstract class FCFluidEncodeTerminal extends FCPart implements IItemPatternTerminal, ITerminalPins {
protected AppEngInternalInventory crafting;
protected AppEngInternalInventory output;
protected final AppEngInternalInventory pattern = new AppEngInternalInventory(this, 2);
private final PinsHolder pinsInv = new PinsHolder(this);
protected boolean craftingMode = true;
protected boolean substitute = false;
@@ -56,6 +62,7 @@ public abstract class FCFluidEncodeTerminal extends FCPart implements IItemPatte
this.pattern.readFromNBT(data, "pattern");
this.output.readFromNBT(data, "outputList");
this.crafting.readFromNBT(data, "craftingGrid");
pinsInv.readFromNBT(data, "pins");
}
@Override
@@ -72,6 +79,7 @@ public abstract class FCFluidEncodeTerminal extends FCPart implements IItemPatte
this.pattern.writeToNBT(data, "pattern");
this.output.writeToNBT(data, "outputList");
this.crafting.writeToNBT(data, "craftingGrid");
pinsInv.writeToNBT(data, "pins");
}
@Override
@@ -217,4 +225,14 @@ public abstract class FCFluidEncodeTerminal extends FCPart implements IItemPatte
public void setAutoFillPattern(boolean canFill) {
this.autoFillPattern = canFill;
}
@Override
public PinsHandler getPinsHandler(EntityPlayer player) {
return pinsInv.getHandler(player);
}
@Override
public IGrid getGrid() {
return getGridNode().getGrid();
}
}
@@ -366,21 +366,22 @@ public abstract class FCPart extends AEBasePart
rh.setBounds(2, 2, 14, 14, 14, 16);
rh.renderBlock(x, y, z, renderer);
final Tessellator tess = Tessellator.instance;
if (this.getLightLevel() > 0) {
final int l = 13;
Tessellator.instance.setBrightness(l << 20 | l << 4);
tess.setBrightness(l << 20 | l << 4);
}
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = this
.getSpin();
Tessellator.instance.setColorOpaque_I(this.getColor().whiteVariant);
tess.setColorOpaque_I(this.getColor().whiteVariant);
rh.renderFace(x, y, z, this.getFrontBright().getIcon(), ForgeDirection.SOUTH, renderer);
Tessellator.instance.setColorOpaque_I(this.getColor().mediumVariant);
tess.setColorOpaque_I(this.getColor().mediumVariant);
rh.renderFace(x, y, z, this.getFrontDark().getIcon(), ForgeDirection.SOUTH, renderer);
Tessellator.instance.setColorOpaque_I(this.getColor().blackVariant);
tess.setColorOpaque_I(this.getColor().blackVariant);
rh.renderFace(x, y, z, this.getFrontColored().getIcon(), ForgeDirection.SOUTH, renderer);
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
@@ -404,15 +405,15 @@ public abstract class FCPart extends AEBasePart
if (hasChan) {
final int l = 14;
Tessellator.instance.setBrightness(l << 20 | l << 4);
Tessellator.instance.setColorOpaque_I(this.getColor().blackVariant);
tess.setBrightness(l << 20 | l << 4);
tess.setColorOpaque_I(this.getColor().blackVariant);
} else if (hasPower) {
final int l = 9;
Tessellator.instance.setBrightness(l << 20 | l << 4);
Tessellator.instance.setColorOpaque_I(this.getColor().whiteVariant);
tess.setBrightness(l << 20 | l << 4);
tess.setColorOpaque_I(this.getColor().whiteVariant);
} else {
Tessellator.instance.setBrightness(0);
Tessellator.instance.setColorOpaque_I(0x000000);
tess.setBrightness(0);
tess.setColorOpaque_I(0x000000);
}
final IIcon sideStatusLightTexture = CableBusTextures.PartMonitorSidesStatusLights.getIcon();
@@ -148,7 +148,7 @@ public abstract class FCPartMonitor extends AbstractPartDisplay implements IPart
if (Platform.isWrench(player, eq, te.xCoord, te.yCoord, te.zCoord)) {
this.isLocked = !this.isLocked;
player.addChatMessage((this.isLocked ? PlayerMessages.isNowLocked : PlayerMessages.isNowUnlocked).get());
player.addChatMessage((this.isLocked ? PlayerMessages.isNowLocked : PlayerMessages.isNowUnlocked).toChat());
this.getHost().markForUpdate();
} else if (!this.isLocked) {
this.configuredFluid = AEFluidStack.create(Util.FluidUtil.getFluidFromContainer(eq));
@@ -399,21 +399,22 @@ public abstract class FCPartMonitor extends AbstractPartDisplay implements IPart
rh.setBounds(2, 2, 14, 14, 14, 16);
rh.renderBlock(x, y, z, renderer);
final Tessellator tess = Tessellator.instance;
if (this.getLightLevel() > 0) {
final int l = 13;
Tessellator.instance.setBrightness(l << 20 | l << 4);
tess.setBrightness(l << 20 | l << 4);
}
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = this
.getSpin();
Tessellator.instance.setColorOpaque_I(this.getColor().whiteVariant);
tess.setColorOpaque_I(this.getColor().whiteVariant);
rh.renderFace(x, y, z, this.getFrontBright().getIcon(), ForgeDirection.SOUTH, renderer);
Tessellator.instance.setColorOpaque_I(this.getColor().mediumVariant);
tess.setColorOpaque_I(this.getColor().mediumVariant);
rh.renderFace(x, y, z, this.getFrontDark().getIcon(), ForgeDirection.SOUTH, renderer);
Tessellator.instance.setColorOpaque_I(this.getColor().blackVariant);
tess.setColorOpaque_I(this.getColor().blackVariant);
rh.renderFace(x, y, z, this.getFrontColored().getIcon(), ForgeDirection.SOUTH, renderer);
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
@@ -437,15 +438,15 @@ public abstract class FCPartMonitor extends AbstractPartDisplay implements IPart
if (hasChan) {
final int l = 14;
Tessellator.instance.setBrightness(l << 20 | l << 4);
Tessellator.instance.setColorOpaque_I(this.getColor().blackVariant);
tess.setBrightness(l << 20 | l << 4);
tess.setColorOpaque_I(this.getColor().blackVariant);
} else if (hasPower) {
final int l = 9;
Tessellator.instance.setBrightness(l << 20 | l << 4);
Tessellator.instance.setColorOpaque_I(this.getColor().whiteVariant);
tess.setBrightness(l << 20 | l << 4);
tess.setColorOpaque_I(this.getColor().whiteVariant);
} else {
Tessellator.instance.setBrightness(0);
Tessellator.instance.setColorOpaque_I(0x000000);
tess.setBrightness(0);
tess.setColorOpaque_I(0x000000);
}
final IIcon sideStatusLightTexture = CableBusTextures.PartMonitorSidesStatusLights.getIcon();
@@ -13,6 +13,8 @@ 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;
@@ -82,16 +84,15 @@ public class FluidCellInventory implements IFluidCellInventory {
}
final IInventory upgrades = this.getUpgradesInventory();
Upgrades u;
for (int x = 0; x < upgrades.getSizeInventory(); x++) {
final ItemStack is = upgrades.getStackInSlot(x);
if (is != null && is.getItem() instanceof IUpgradeModule) {
final Upgrades u = ((IUpgradeModule) is.getItem()).getType(is);
if (u != null) {
switch (u) {
case VOID_OVERFLOW -> cardVoidOverflow = true;
case DISTRIBUTION -> cardDistribution = true;
default -> {}
}
if (is == null) continue;
if (is.getItem() instanceof IUpgradeModule upgradeItem && (u = upgradeItem.getType(is)) != null) {
switch (u) {
case VOID_OVERFLOW -> cardVoidOverflow = true;
case DISTRIBUTION -> cardDistribution = true;
default -> {}
}
}
}
@@ -198,7 +199,7 @@ public class FluidCellInventory implements IFluidCellInventory {
@Override
public long getRemainingFluidTypes() {
final long basedOnStorage = this.getFreeBytes() / this.getBytesPerType();
final long basedOnStorage = this.getFreeBytes() / Math.max(1, this.getBytesPerType());
final long baseOnTotal = this.getTotalFluidTypes() - this.getStoredFluidTypes();
return Math.min(basedOnStorage, baseOnTotal);
}
@@ -218,12 +219,16 @@ public class FluidCellInventory implements IFluidCellInventory {
public long getRemainingFluidCountDist(IAEFluidStack l) {
long remaining;
long types = 0;
for (int i = 0; i < this.getTotalFluidTypes(); i++) {
if (this.getConfigInventory().getStackInSlot(i) != null) {
long maxFluidTypes = this.getTotalFluidTypes();
IInventory configInventory = this.getConfigInventory();
for (int i = 0; i < configInventory.getSizeInventory(); i++) {
// Check all partition slots to determine min distribution behaviour until max fluid types is reached
if (types >= maxFluidTypes) break;
if (configInventory.getStackInSlot(i) != null) {
types++;
}
}
if (types == 0) types = this.getTotalFluidTypes();
if (types == 0) types = maxFluidTypes;
if (l != null) {
if (restrictionLong > 0) {
remaining = Math.min((restrictionLong / types) - l.getStackSize(), getRemainingFluidCount());
@@ -476,7 +481,7 @@ public class FluidCellInventory implements IFluidCellInventory {
}
@Override
public List<IAEFluidStack> getContents() {
public @NotNull List<IAEFluidStack> getContents() {
List<IAEFluidStack> ret = new ArrayList<>();
for (IAEFluidStack fluid : this.getCellFluids()) {
ret.add(fluid);
@@ -6,7 +6,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.util.Util;
import appeng.api.AEApi;
@@ -42,6 +42,12 @@ public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack>
AEFluidStack stack = AEFluidStack.create(fluid);
stack.setStackSize(1);
priorityList.add(stack);
// convert partition on cells in network
if (!(is.getItem() instanceof ItemFluidPacket)) {
config.setInventorySlotContents(x, ItemFluidPacket.newDisplayStack(fluid));
config.markDirty();
}
}
}
if (!priorityList.isEmpty()) {
@@ -71,8 +77,8 @@ public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack>
@Override
public IFluidCellInventory getCellInv() {
Object o = this.getInternal();
if (o instanceof MEPassThrough) {
o = Ae2Reflect.getInternal((MEPassThrough<?>) o);
if (o instanceof MEPassThrough<?>pt) {
o = pt.getInternal();
}
return (IFluidCellInventory) (o instanceof IFluidCellInventory ? o : null);
}
@@ -80,16 +86,22 @@ public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack>
@Override
@SuppressWarnings("unchecked")
public Iterable<IAEFluidStack> getPartitionInv() {
return (Iterable<IAEFluidStack>) Ae2Reflect.getPartitionList(this).getItems();
return getPartitionList().getItems();
}
@Override
public boolean isPreformatted() {
return !Ae2Reflect.getPartitionList(this).isEmpty();
return !getPartitionList().isEmpty();
}
@Override
@Deprecated
public IncludeExclude getIncludeExcludeMode() {
return getWhitelist();
}
@Override
public IncludeExclude getWhitelist() {
return IncludeExclude.WHITELIST;
}
@@ -106,11 +118,7 @@ public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack>
@Override
public boolean canGetInv() {
IFluidCellInventory cellInv = this.getCellInv();
if (cellInv instanceof CreativeFluidCellInventory) {
return false;
} else {
return true;
}
return !(cellInv instanceof CreativeFluidCellInventory);
}
@Override
@@ -157,7 +165,6 @@ public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack>
IFluidCellInventory cellInventory = this.getCellInv();
if (cellInventory instanceof FluidCellInventory ci) {
return ci.getRestriction();
}
return null;
}
@@ -1,11 +1,14 @@
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;
@@ -109,7 +112,7 @@ public class FluidVoidStorageCellInventory extends FluidCellInventory {
}
@Override
public List<IAEFluidStack> getContents() {
return null;
public @NotNull List<IAEFluidStack> getContents() {
return Collections.emptyList();
}
}
@@ -5,6 +5,8 @@ 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;
@@ -90,6 +92,7 @@ public interface IFluidCellInventory extends IMEInventory<IAEFluidStack> {
*/
long getTotalFluidTypes();
@NotNull
List<IAEFluidStack> getContents();
/**
@@ -11,5 +11,9 @@ public interface IFluidCellInventoryHandler {
boolean isPreformatted();
/** use {@link IFluidCellInventoryHandler#getWhitelist} instead */
@Deprecated
IncludeExclude getIncludeExcludeMode();
IncludeExclude getWhitelist();
}
@@ -1,12 +1,10 @@
package com.glodblock.github.common.tile;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
@@ -14,26 +12,11 @@ import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import com.glodblock.github.loader.ChannelLoader;
import com.glodblock.github.util.BlockPos;
public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
private FluidStack lastBeforeUpdate = null;
public FluidTank tank = new FluidTank(32000) {
@Override
public FluidTank readFromNBT(NBTTagCompound nbt) {
if (!nbt.hasKey("Empty")) {
FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt);
setFluid(fluid);
} else {
setFluid(null);
}
return this;
}
};
private boolean hasUpdate;
public FluidTank tank = new FluidTank(32000);
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
@@ -50,80 +33,51 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
return tankFluid == null || tankFluid.amount == 0 ? 0 : tankFluid.getFluid().getLuminosity(tankFluid);
}
public void compareAndUpdate() {
if (!this.worldObj.isRemote) {
FluidStack current = this.tank.getFluid();
if (current != null) {
if (this.lastBeforeUpdate != null) {
if (Math.abs(current.amount - this.lastBeforeUpdate.amount) >= 500) {
ChannelLoader.sendPacketToAllPlayers(getDescriptionPacket(), this.worldObj);
this.lastBeforeUpdate = current.copy();
} else if (this.lastBeforeUpdate.amount < this.tank.getCapacity()
&& current.amount == this.tank.getCapacity()
|| this.lastBeforeUpdate.amount == this.tank.getCapacity()
&& current.amount < this.tank.getCapacity()) {
ChannelLoader.sendPacketToAllPlayers(getDescriptionPacket(), this.worldObj);
this.lastBeforeUpdate = current.copy();
}
} else {
ChannelLoader.sendPacketToAllPlayers(getDescriptionPacket(), this.worldObj);
this.lastBeforeUpdate = current.copy();
}
} else if (this.lastBeforeUpdate != null) {
ChannelLoader.sendPacketToAllPlayers(getDescriptionPacket(), this.worldObj);
this.lastBeforeUpdate = null;
}
}
}
public FluidStack drain(FluidStack fluid, boolean doDrain, boolean findMainTank) {
if (fluid == null || this.getFluid() == null || this.getFluid() != fluid.getFluid()) {
return null;
}
if (findMainTank) {
int yOff = 0;
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
// Main tank is the highest tank in the column with desired fluid
TileCertusQuartzTank mainTank = this;
while (true) {
if (offTE instanceof TileCertusQuartzTank) {
Fluid offFluid = ((TileCertusQuartzTank) offTE).getFluid();
if (offFluid != null && offFluid == fluid.getFluid()) {
mainTank = (TileCertusQuartzTank) this.worldObj
.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
yOff++;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
continue;
}
TileCertusQuartzTank tankAbove;
while ((tankAbove = mainTank.getTankAbove()) != null) {
// We can't drain tank with different or null fluid
if (fluid.getFluid() != tankAbove.getFluid()) {
break;
}
break;
mainTank = tankAbove;
}
return mainTank != null ? mainTank.drain(fluid, doDrain, false) : null;
return mainTank.drain(fluid, doDrain, false);
}
FluidStack drained = this.tank.drain(fluid.amount, doDrain);
compareAndUpdate();
FluidStack drainedFluid = this.tank.drain(fluid.amount, doDrain);
int drained = drainedFluid != null ? drainedFluid.amount : 0;
if (drained == null || drained.amount < fluid.amount) {
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord);
if (offTE instanceof TileCertusQuartzTank tileCertusQuartzTank) {
FluidStack externallyDrained = tileCertusQuartzTank.drain(
new FluidStack(fluid.getFluid(), fluid.amount - (drained != null ? drained.amount : 0)),
doDrain,
false);
if (drained > 0) {
update();
}
if (externallyDrained != null) return new FluidStack(
fluid.getFluid(),
(drained != null ? drained.amount : 0) + externallyDrained.amount);
else return drained;
if (drained < fluid.amount) {
TileCertusQuartzTank tankBelow = this.getTankBelow();
if (tankBelow != null) {
FluidStack fluidToDrain = new FluidStack(fluid.getFluid(), fluid.amount - drained);
FluidStack externallyDrained = tankBelow.drain(fluidToDrain, doDrain, false);
if (externallyDrained != null) {
return new FluidStack(fluid.getFluid(), drained + externallyDrained.amount);
}
}
}
return drained;
return drainedFluid;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
if (this.tank.getFluid() == null || resource == null || resource.getFluid() != this.tank.getFluid().getFluid())
return null;
return drain(resource, doDrain, true);
}
@@ -135,35 +89,42 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
}
public int fill(FluidStack fluid, boolean doFill, boolean findMainTank) {
if (fluid == null || this.getFluid() != null && this.getFluid() != fluid.getFluid()) {
return 0;
}
if (findMainTank) {
int yOff = 0;
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
// Main tank is the lowest tank in the column with desired fluid
TileCertusQuartzTank mainTank = this;
while (true) {
if (offTE instanceof TileCertusQuartzTank) {
Fluid offFluid = ((TileCertusQuartzTank) offTE).getFluid();
if (offFluid == null || offFluid == fluid.getFluid()) {
mainTank = (TileCertusQuartzTank) this.worldObj
.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
yOff++;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
continue;
}
TileCertusQuartzTank tankBelow;
while ((tankBelow = mainTank.getTankBelow()) != null) {
FluidStack fluidBelow = tankBelow.tank.getFluid();
// We can't fill already full tank
if (fluidBelow != null && fluidBelow.amount == tankBelow.tank.getCapacity()) {
break;
}
break;
// We can't fill tank with different fluid
if (tankBelow.getFluid() != null && fluid.getFluid() != tankBelow.getFluid()) {
break;
}
mainTank = tankBelow;
}
return mainTank != null ? mainTank.fill(fluid, doFill, false) : 0;
return mainTank.fill(fluid, doFill, false);
}
int filled = this.tank.fill(fluid, doFill);
compareAndUpdate();
if (filled > 0) {
update();
}
if (filled < fluid.amount) {
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord);
if (offTE instanceof TileCertusQuartzTank tileCertusQuartzTank) {
return filled + tileCertusQuartzTank
.fill(new FluidStack(fluid.getFluid(), fluid.amount - filled), doFill, false);
TileCertusQuartzTank tankAbove = this.getTankAbove();
if (tankAbove != null) {
FluidStack fluidToFill = new FluidStack(fluid.getFluid(), fluid.amount - filled);
return filled + tankAbove.fill(fluidToFill, doFill, false);
}
}
@@ -175,18 +136,9 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
*/
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
if (resource == null || this.tank.getFluid() != null && resource.getFluid() != this.tank.getFluid().getFluid())
return 0;
return fill(resource, doFill, true);
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}
public Fluid getFluid() {
FluidStack tankFluid = this.tank.getFluid();
return tankFluid != null && tankFluid.amount > 0 ? tankFluid.getFluid() : null;
@@ -200,84 +152,57 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
return (float) this.tank.getFluidAmount() / this.tank.getCapacity();
}
private void onComparatorUpdate(World world, int x, int y, int z, Block block) {
world.func_147453_f(x, y, z, block);
}
@Override
public void updateEntity() {
super.updateEntity();
if (this.tank.getFluid() != null) {
TileCertusQuartzTank below = getTankBelow(this);
if (below != null) {
FluidStack filled = this.tank.getFluid().copy();
filled.amount = below.fill(this.tank.getFluid(), true, true);
if (filled.amount >= 0) {
this.drain(filled, true, true);
this.hasUpdate = true;
below.hasUpdate = true;
}
}
}
if (this.hasUpdate) {
onComparatorUpdate(this.worldObj, this.xCoord, this.yCoord, this.zCoord, this.getBlockType());
this.hasUpdate = false;
}
}
private TileCertusQuartzTank getTankBelow(TileEntity tile) {
TileEntity tank = new BlockPos(tile).getOffSet(0, -1, 0).getTileEntity();
if (tank instanceof TileCertusQuartzTank) {
return (TileCertusQuartzTank) tank;
private TileCertusQuartzTank getTankAbove() {
TileEntity tile = new BlockPos(this).getOffSet(0, 1, 0).getTileEntity();
if (tile instanceof TileCertusQuartzTank tankTile) {
return tankTile;
}
return null;
}
public FluidTankInfo[] getTankInfo(boolean goToMainTank) {
if (!goToMainTank) return new FluidTankInfo[] { this.tank.getInfo() };
private TileCertusQuartzTank getTankBelow() {
TileEntity tile = new BlockPos(this).getOffSet(0, -1, 0).getTileEntity();
if (tile instanceof TileCertusQuartzTank tankTile) {
return tankTile;
}
return null;
}
int amount = 0, capacity = 0;
Fluid fluid = null;
int yOff = 0;
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
TileCertusQuartzTank mainTank;
while (true) {
if (offTE instanceof TileCertusQuartzTank) {
if (((TileCertusQuartzTank) offTE).getFluid() == null
|| ((TileCertusQuartzTank) offTE).getFluid() == getFluid()) {
yOff++;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
continue;
}
}
break;
public FluidTankInfo[] getTankInfo(boolean countAllTanksInColumn) {
if (!countAllTanksInColumn) {
return new FluidTankInfo[] { this.tank.getInfo() };
}
yOff -= 1;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
while (true) {
if (offTE instanceof TileCertusQuartzTank) {
mainTank = (TileCertusQuartzTank) offTE;
if (mainTank.getFluid() == null || getFluid() == null || mainTank.getFluid() == getFluid()) {
FluidTankInfo info = mainTank.getTankInfo(false)[0];
if (info != null) {
capacity += info.capacity;
if (info.fluid != null) {
amount += info.fluid.amount;
if (info.fluid.getFluid() != null) fluid = info.fluid.getFluid();
}
}
offTE = new BlockPos(offTE).getOffSet(0, 1, 0).getTileEntity();
continue;
}
final FluidStack tankFluidStack = this.tank.getFluid();
final Fluid mainFluid = tankFluidStack != null ? tankFluidStack.getFluid() : null;
int amount = tankFluidStack == null ? 0 : tankFluidStack.amount;
int capacity = this.tank.getCapacity();
TileCertusQuartzTank tankAbove = this;
while ((tankAbove = tankAbove.getTankAbove()) != null) {
if (tankAbove.getFluid() == null || mainFluid != tankAbove.getFluid()) {
break;
}
break;
FluidTankInfo info = tankAbove.tank.getInfo();
amount += info.fluid == null ? 0 : info.fluid.amount;
capacity += info.capacity;
}
TileCertusQuartzTank tankBelow = this;
while ((tankBelow = tankBelow.getTankBelow()) != null) {
if (mainFluid == null || mainFluid != tankBelow.getFluid()) {
break;
}
FluidTankInfo info = tankBelow.tank.getInfo();
amount += info.fluid == null ? 0 : info.fluid.amount;
capacity += info.capacity;
}
return new FluidTankInfo[] {
new FluidTankInfo(fluid != null ? new FluidStack(fluid, amount) : null, capacity) };
new FluidTankInfo(mainFluid != null ? new FluidStack(mainFluid, amount) : null, capacity) };
}
@Override
@@ -285,6 +210,49 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
return getTankInfo(true);
}
public FluidTankInfo[] getInternalFluid() {
return this.getTankInfo(true);
}
private void flowFluidDown(boolean checkTankAbove) {
if (this.getFluid() != null) {
TileCertusQuartzTank below = getTankBelow();
if (below != null) {
FluidStack fluid = this.tank.getFluid().copy();
int amount = below.tank.fill(fluid, true);
if (amount > 0) {
this.tank.drain(amount, true);
this.update();
below.update();
below.flowFluidDown(false);
}
}
}
if (checkTankAbove) {
TileCertusQuartzTank above = getTankAbove();
if (above != null && above.getFluid() != null) {
if (this.getFluid() == null || this.getFluid() == above.getFluid()) {
above.flowFluidDown(true);
}
}
}
}
public void update() {
if (!this.worldObj.isRemote) {
markDirty();
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
this.worldObj.markBlockRangeForRenderUpdate(
@@ -307,6 +275,15 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
this.tank.readFromNBT(tag);
}
// Specifically used when player is placing a tank in world,
// so we can apply the item's NBT and flow down its fluid in lower tanks
public void readFromItemNBT(NBTTagCompound tag) {
if (tag != null) {
this.readFromNBTWithoutCoords(tag.getCompoundTag("tileEntity"));
}
this.flowFluidDown(true);
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
@@ -316,8 +293,4 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
public void writeToNBTWithoutCoords(NBTTagCompound tag) {
this.tank.writeToNBT(tag);
}
public FluidTankInfo[] getInternalFluid() {
return this.getTankInfo(true);
}
}
@@ -1,5 +1,6 @@
package com.glodblock.github.common.tile;
import static appeng.util.Platform.writeStackNBT;
import static com.glodblock.github.loader.RecipeLoader.BUCKET;
import javax.annotation.Nonnull;
@@ -17,7 +18,8 @@ import net.minecraftforge.fluids.FluidStack;
import org.apache.commons.lang3.tuple.MutablePair;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.util.NameConst;
import com.glodblock.github.util.Util;
import appeng.api.AEApi;
@@ -53,6 +55,8 @@ import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkInvTile;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.common.registry.GameRegistry;
public class TileFluidAutoFiller extends AENetworkInvTile
implements ICraftingProvider, IMEMonitorHandlerReceiver<IAEFluidStack>, IGridTickable {
@@ -60,7 +64,7 @@ public class TileFluidAutoFiller extends AENetworkInvTile
private final AppEngInternalInventory inventory = new AppEngInternalInventory(this, 1);
private final BaseActionSource source = new MachineSource(this);
private IItemList<IAEFluidStack> fluids = AEApi.instance().storage().createFluidList();
private final Item encodedPattern = AEApi.instance().definitions().items().encodedPattern().maybeItem().orNull();
private final Item encodedPattern = GameRegistry.findItem(FluidCraft.MODID, NameConst.ITEM_FLUID_ENCODED_PATTERN);
private IAEItemStack returnStack;
private boolean isPowered;
@@ -156,19 +160,21 @@ public class TileFluidAutoFiller extends AENetworkInvTile
MutablePair<Integer, ItemStack> filled = Util.FluidUtil
.fillStack(this.getContainerItem().copy(), new FluidStack(fluid, maxCapacity));
if (filled.right == null) continue;
ItemStack pattern = getPattern(this.getContainerItem(), filled.right);
ItemStack pattern = getPattern(
this.getContainerItem(),
filled.right,
fluidStack.copy().setStackSize(maxCapacity));
ICraftingPatternItem patter = (ICraftingPatternItem) pattern.getItem();
craftingTracker.addCraftingOption(this, patter.getPatternForItem(pattern, getWorldObj()));
}
}
private ItemStack getPattern(ItemStack emptyContainer, ItemStack filledContainer) {
private ItemStack getPattern(ItemStack emptyContainer, ItemStack filledContainer, IAEFluidStack ifs) {
NBTTagList in = new NBTTagList();
NBTTagList out = new NBTTagList();
in.appendTag(emptyContainer.writeToNBT(new NBTTagCompound()));
ItemStack fluidDrop = ItemFluidDrop.newStack(Util.FluidUtil.getFluidFromContainer(filledContainer));
in.appendTag(createItemTag(fluidDrop));
out.appendTag(filledContainer.writeToNBT(new NBTTagCompound()));
in.appendTag(writeStackNBT(AEItemStack.create(emptyContainer), new NBTTagCompound()));
in.appendTag(writeStackNBT(ifs, new NBTTagCompound()));
out.appendTag(writeStackNBT(AEItemStack.create(filledContainer), new NBTTagCompound()));
NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setTag("in", in);
itemTag.setTag("out", out);
@@ -188,8 +194,7 @@ public class TileFluidAutoFiller extends AENetworkInvTile
@Override
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) {
this.returnStack = AEApi.instance().storage()
.createItemStack(patternDetails.getCondensedOutputs()[0].getItemStack());
this.returnStack = (IAEItemStack) patternDetails.getCondensedOutputs()[0];
try {
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
} catch (GridAccessException ignored) {
@@ -272,11 +277,20 @@ public class TileFluidAutoFiller extends AENetworkInvTile
@Override
public TickingRequest getTickingRequest(IGridNode node) {
return new TickingRequest(1, 5, this.returnStack == null, true);
return new TickingRequest(1, 5, false, true);
}
boolean initialized = false;
@Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) {
if (!initialized) { // run postEvent on AE network is ready
initialized = true;
postEvent();
}
if (this.returnStack == null) return TickRateModulation.SLEEP;
if (this.getStorageGrid() == null) {
return TickRateModulation.SLOWER;
}
@@ -224,7 +224,6 @@ public class TileFluidInterface extends TileInterface implements IDualHost {
@Override
public void getDrops(World w, int x, int y, int z, List<ItemStack> drops) {
this.fluidDuality.addDrops(drops);
this.fluidDuality.convertDrops(drops, this.getInterfaceDuality().getWaitingToSend());
super.getDrops(w, x, y, z, drops);
}
}
@@ -1,23 +1,30 @@
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.function.UnaryOperator;
import java.util.stream.Stream;
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;
@@ -42,19 +49,17 @@ 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.SettingsFrom;
import appeng.util.item.AEItemStack;
import io.netty.buffer.ByteBuf;
@@ -62,10 +67,19 @@ public class TileLevelMaintainer extends AENetworkTile
implements IAEAppEngInventory, IGridTickable, ICraftingRequester, IPowerChannelState, ILevelViewable {
public static final int REQ_COUNT = 5;
public final InventoryRequest requests = new InventoryRequest(this);
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);
private int firstRequest = 0;
private final BaseActionSource source;
private final IInventory inv = new AeItemStackHandler(requests.requestStacks);
private final IInventory inv = new AeItemStackHandler(inventory);
private boolean isPowered = false;
public TileLevelMaintainer() {
@@ -75,17 +89,20 @@ public class TileLevelMaintainer extends AENetworkTile
}
public AeStackInventory<IAEItemStack> getRequestSlots() {
return requests.requestStacks;
return inventory;
}
@Override
public ImmutableSet<ICraftingLink> getRequestedJobs() {
return ImmutableSet.copyOf(new NonNullArrayIterator<>(requests.links));
return ImmutableSet.copyOf(
Arrays.stream(this.requests).filter(Objects::nonNull).map(info -> info.link).filter(Objects::nonNull)
.iterator());
}
@Override
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) {
int idx = requests.getIdxByLink(link);
int idx = this.getRequestIndexByLink(link);
try {
if (getProxy().isActive()) {
final IEnergyGrid energy = getProxy().getEnergy();
@@ -97,7 +114,9 @@ public class TileLevelMaintainer extends AENetworkTile
.injectItems(ItemFluidDrop.getAeFluidStack(items), mode, source);
if (notInjectedItems != null) {
items.setStackSize(notInjectedItems.getStackSize());
requests.updateState(idx, State.Export);
if (idx != -1) {
this.updateState(idx, LevelState.Export);
}
return items;
} else {
@@ -117,10 +136,12 @@ public class TileLevelMaintainer extends AENetworkTile
@Override
public void jobStateChange(ICraftingLink link) {
for (int x = 0; x < REQ_COUNT; x++) {
if (requests.getLink(x) == link) {
requests.updateLink(x, link);
return;
for (int i = 0; i < REQ_COUNT; i++) {
if (requests[i] != null && link != null) {
ICraftingLink prevLink = requests[i].link;
if (prevLink != null && prevLink.getCraftingID().equals(link.getCraftingID())) {
this.updateLink(i, null);
}
}
}
}
@@ -142,7 +163,8 @@ public class TileLevelMaintainer extends AENetworkTile
try {
final ICraftingGrid craftingGrid = getProxy().getCrafting();
final IGrid grid = getProxy().getGrid();
final IItemList<IAEItemStack> inv = getProxy().getStorage().getItemInventory().getStorageList();
final IItemList<IAEItemStack> invItems = getProxy().getStorage().getItemInventory().getStorageList();
final IItemList<IAEFluidStack> invFluid = getProxy().getStorage().getFluidInventory().getStorageList();
// Check there are available crafting CPUs before doing any work.
// This hopefully stops level maintainers busy-looping calculating
@@ -164,92 +186,114 @@ public class TileLevelMaintainer extends AENetworkTile
for (int j = 0; j < REQ_COUNT; ++j) {
int i = (firstRequest + j) % REQ_COUNT;
if (requests[i] == null) continue;
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);
final long quantity = requests[i].quantity;
final long batchSize = requests[i].batchSize;
final boolean isEnable = requests[i].enable;
if (ModAndClassUtil.ThE) {
if (craftItem != null && ThaumicEnergisticsCrafting.isAspectStack(craftItem.getItemStack())) {
craftItem = ThaumicEnergisticsCrafting.convertAspectStack(craftItem);
}
}
if (!isEnable || quantity == 0 || batchSize == 0) {
this.updateState(i, LevelState.None);
continue;
}
IAEItemStack aeItem = inv.findPrecise(craftItem);
IAEItemStack craftItem = requests[i].itemStack.copy();
craftItem.setStackSize(batchSize);
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);
}
if (ModAndClassUtil.ThE) {
if (ThaumicEnergisticsCrafting.isAspectStack(craftItem.getItemStack())) {
craftItem = ThaumicEnergisticsCrafting.convertAspectStack(craftItem);
}
}
IAEItemStack aeItem = invItems.findPrecise(craftItem);
long stackSize;
if (craftItem.getItem() instanceof ItemFluidDrop) {
IAEFluidStack ifs = invFluid.findPrecise(ItemFluidDrop.getAeFluidStack(craftItem));
stackSize = ifs == null ? 0 : ifs.getStackSize();
} else {
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.NotFound);
}
}
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);
}
} 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.updateJob(jobToSubmitIdx, null);
requests[jobToSubmitIdx].job = null;
if (link != null) {
requests.updateState(jobToSubmitIdx, State.Craft);
requests.updateLink(jobToSubmitIdx, link);
this.updateState(jobToSubmitIdx, LevelState.Craft);
this.updateLink(jobToSubmitIdx, link);
} else {
requests.updateState(jobToSubmitIdx, State.Error);
this.updateState(jobToSubmitIdx, LevelState.CantCraft);
}
} else if (itemToBegin != null) {
// No jobs to submit, start calculating some item.
requests.updateJob(
itemToBeginIdx,
craftingGrid.beginCraftingJob(getWorldObj(), grid, source, itemToBegin, null));
requests.updateState(itemToBeginIdx, State.Craft);
requests[itemToBeginIdx].job = craftingGrid
.beginCraftingJob(getWorldObj(), grid, source, itemToBegin, null);
this.updateState(itemToBeginIdx, LevelState.Craft);
// Try the next item next time.
firstRequest = (firstRequest + 1) % REQ_COUNT;
@@ -284,9 +328,6 @@ public class TileLevelMaintainer extends AENetworkTile
return getProxy().isActive();
}
@Override
public void gridChanged() {}
@Override
public boolean isPowered() {
return isPowered;
@@ -297,120 +338,208 @@ public class TileLevelMaintainer extends AENetworkTile
return isPowered;
}
public InventoryRequest getRequestInventory() {
return requests;
}
public IInventory getInventory() {
return inv;
}
public IInventory getInventoryByName(String name) {
if (name == "config") return new AeItemStackHandler(requests.requestStacks);
if (Objects.equals(name, "config")) return new AeItemStackHandler(this.inventory);
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) {
requests.updateQuantity(idx, size);
if (requests[idx] == null) return;
requests[idx].quantity = size > 0 ? size : 0;
this.checkState(idx);
this.saveChanges();
}
public void updateBatchSize(int idx, long size) {
requests.updateBatchSize(idx, size);
if (requests[idx] == null) return;
requests[idx].batchSize = size > 0 ? size : 0;
this.checkState(idx);
this.saveChanges();
}
public void updateStatus(int idx, boolean enable) {
requests.updateStatus(idx, enable);
if (requests[idx] == null) return;
requests[idx].enable = enable;
this.checkState(idx);
this.saveChanges();
}
/**
* @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);
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 targetLink) {
for (int i = 0; i < REQ_COUNT; i++) {
if (requests[i] != null && targetLink != null) {
ICraftingLink link = requests[i].link;
if (link != null && link.getCraftingID().equals(targetLink.getCraftingID())) {
return i;
}
}
} catch (Exception ignore) {}
}
return -1;
}
@TileEvent(TileEventType.WORLD_NBT_WRITE)
public void writeToNBTEvent(NBTTagCompound data) {
requests.requestStacks.writeToNbt(data, TLMTags.RequestStacks.tagName);
NBTTagList tagList = new NBTTagList();
for (int i = 0; i < REQ_COUNT; i++) {
if (this.requests[i] != null) {
tagList.appendTag(this.requests[i].writeToNBT(true));
} else {
tagList.appendTag(new NBTTagCompound());
}
}
data.setTag(NBT_REQUESTS, tagList);
}
@TileEvent(TileEventType.WORLD_NBT_READ)
public void readFromNBTEvent(NBTTagCompound data) {
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}"));
}
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;
}
} 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 data storage
// Migration from old old data storage
long[] batches = new long[REQ_COUNT];
long[] quantyties = new long[REQ_COUNT];
requests.requestStacks.readFromNbt(data, "Batch");
ItemStack[] stacks = new ItemStack[REQ_COUNT];
NBTTagList batchTag = data.getCompoundTag("Batch").getTagList("Contents", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < REQ_COUNT; i++) {
IAEItemStack batchStack = requests.requestStacks.getStack(i);
batches[i] = batchStack != null ? batchStack.getStackSize() : 0;
NBTTagCompound stackTag = batchTag.getCompoundTagAt(i);
IAEItemStack stack = AEItemStack.loadItemStackFromNBT(stackTag);
batches[i] = stack != null ? stack.getStackSize() : 0;
}
requests.requestStacks.readFromNbt(data, "Count");
NBTTagList quantityTag = data.getCompoundTag("Count").getTagList("Contents", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < REQ_COUNT; i++) {
IAEItemStack quantityStack = requests.requestStacks.getStack(i);
quantyties[i] = quantityStack != null ? quantityStack.getStackSize() : 0;
NBTTagCompound stackTag = quantityTag.getCompoundTagAt(i);
IAEItemStack stack = AEItemStack.loadItemStackFromNBT(stackTag);
quantyties[i] = stack != null ? stack.getStackSize() : 0;
}
requests.requestStacks.readFromNbt(data, "Inventory");
NBTTagList inventoryTag = data.getCompoundTag("Count").getTagList("Contents", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < REQ_COUNT; 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]);
}
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];
}
readLinkFromNBT__old(data);
}
}
// Remove old format NBT data from ItemStack
private ItemStack removeRecursion(ItemStack itemStack) {
if (itemStack != null && itemStack.hasTagCompound()
&& itemStack.getTagCompound().hasKey(TLMTags.Stack.tagName)) {
return removeRecursion(loadItemStackFromTag(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")));
}
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;
@@ -423,6 +552,42 @@ public class TileLevelMaintainer extends AENetworkTile
data.writeBoolean(isActive());
}
@Override
public void uploadSettings(SettingsFrom from, NBTTagCompound compound) {
super.uploadSettings(from, compound);
NBTTagList tagList = compound.getTagList(NBT_REQUESTS, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound tag = tagList.getCompoundTagAt(i);
if (tag == null || !tag.hasKey(NBT_STACK)) {
this.requests[i] = null;
} else {
try {
this.requests[i] = new RequestInfo(tag, this);
this.requests[i].state = LevelState.None;
} catch (Exception ignored) {
this.requests[i] = null;
}
}
}
this.saveChanges();
}
@Override
public NBTTagCompound downloadSettings(SettingsFrom from) {
NBTTagCompound compound = super.downloadSettings(from);
compound = compound == null ? new NBTTagCompound() : compound;
NBTTagList tagList = new NBTTagList();
for (int i = 0; i < REQ_COUNT; i++) {
if (this.requests[i] != null) {
tagList.appendTag(this.requests[i].writeToNBT(false));
} else {
tagList.appendTag(new NBTTagCompound());
}
}
compound.setTag(NBT_REQUESTS, tagList);
return compound;
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkPowerStatusChange p) {
updatePowerState();
@@ -449,7 +614,7 @@ public class TileLevelMaintainer extends AENetworkTile
}
@Override
public TileEntity getTile() {
public @NotNull TileEntity getTile() {
return this;
}
@@ -463,209 +628,140 @@ public class TileLevelMaintainer extends AENetworkTile
return REQ_COUNT;
}
@Override
public ItemStack getSelfItemStack() {
return getItemFromTile(this);
}
public static class RequestInfo {
public enum State {
None,
Idle,
Craft,
Export,
Error
}
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 TLMTags {
RequestStacks("RequestStacks"),
Enable("Enable"),
Quantity("Quantity"),
Batch("Batch"),
Link("Link"),
State("State"),
Index("Index"),
Stack("Stack");
public final String tagName;
TLMTags(String tagName) {
this.tagName = tagName;
}
}
public static final class InventoryRequest {
private final AeStackInventoryImpl<IAEItemStack> requestStacks;
private final Future<ICraftingJob>[] jobs;
private final ICraftingLink[] links;
private final State[] state = new State[REQ_COUNT];
@SuppressWarnings("unchecked")
public InventoryRequest(TileLevelMaintainer tile) {
requestStacks = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
jobs = new Future[REQ_COUNT];
links = new ICraftingLink[REQ_COUNT];
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 State getState(int idx) {
IAEItemStack ias = requestStacks.getStack(idx);
if (ias == null) {
return State.None;
} else {
return state[idx] == null ? State.Idle : state[idx];
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!");
}
}
public int getIdxByLink(ICraftingLink link) {
for (int i = 0; i < REQ_COUNT; i++) {
if (links[i] == link) {
return i;
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;
}
}
return 0;
job = null;
}
public boolean isEnable(int idx) {
IAEItemStack ias = requestStacks.getStack(idx);
if (ias == null) {
return true;
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;
}
}
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;
public NBTTagCompound writeToNBT(boolean includeLink) {
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 && includeLink) {
NBTTagCompound linkTag = new NBTTagCompound();
this.link.writeToNBT(linkTag);
tag.setTag(NBT_LINK, linkTag);
}
return links[index].isDone() || links[index].isCanceled();
return tag;
}
public Future<ICraftingJob> getJob(int idx) {
return jobs[idx];
public IAEItemStack getAEItemStack() {
return this.itemStack;
}
public ICraftingLink getLink(int idx) {
return links[idx];
public long getQuantity() {
return quantity;
}
public void updateJob(int idx, Future<ICraftingJob> job) {
jobs[idx] = job;
public long getBatchSize() {
return batchSize;
}
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 boolean isEnable() {
return enable;
}
public void updateLink(int idx, ICraftingLink link) {
links[idx] = link;
public LevelState getState() {
return state;
}
}
updateField(idx, data -> {
NBTTagCompound linkData = new NBTTagCompound();
if (link != null) link.writeToNBT(linkData);
data.setTag(TLMTags.Link.tagName, linkData);
private static class LevelMaintainerInventory implements AeStackInventory<IAEItemStack> {
return data;
});
private final RequestInfo[] requests;
private final TileLevelMaintainer tile;
private LevelMaintainerInventory(RequestInfo[] requests, TileLevelMaintainer tile) {
this.requests = requests;
this.tile = tile;
}
public void updateState(int idx, State nextState) {
state[idx] = nextState;
updateField(idx, data -> {
data.setInteger(TLMTags.State.tagName, nextState.ordinal());
return data;
});
@Override
public @NotNull Iterator<IAEItemStack> iterator() {
return Arrays.stream(requests).map(info -> info != null ? info.itemStack : null).iterator();
}
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;
});
@Override
public int getSlotCount() {
return requests.length;
}
public void updateQuantity(int idx, long quantity) {
updateField(idx, data -> {
data.setLong(TLMTags.Quantity.tagName, quantity);
return data;
});
@Override
public @Nullable IAEItemStack getStack(int slot) {
return requests[slot] != null ? requests[slot].itemStack : null;
}
public void updateBatchSize(int idx, long batch) {
updateField(idx, data -> {
data.setLong(TLMTags.Batch.tagName, batch);
data.setBoolean(TLMTags.Enable.tagName, true);
return data;
});
@Override
public void setStack(int slot, @Nullable IAEItemStack stack) {
if (stack == null) {
this.tile.updateStack(slot, null);
} else {
this.tile.updateStack(slot, stack.getItemStack());
}
}
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;
@Override
public Stream<IAEItemStack> stream() {
return Arrays.stream(requests).map(info -> info != null ? info.itemStack : null);
}
}
}
@@ -0,0 +1,463 @@
package com.glodblock.github.common.tile;
import java.util.List;
import java.util.stream.IntStream;
import javax.annotation.Nonnull;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import com.glodblock.github.common.item.FCBaseItemCell;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.AEFluidInventory;
import com.glodblock.github.inventory.IAEFluidInventory;
import com.glodblock.github.inventory.IAEFluidTank;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.implementations.IPowerChannelState;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkBootingStatusChange;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.BaseActionSource;
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.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AECableType;
import appeng.api.util.DimensionalCoord;
import appeng.core.AELog;
import appeng.items.storage.ItemBasicStorageCell;
import appeng.me.GridAccessException;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkInvTile;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.item.AEFluidStack;
import appeng.util.item.AEItemStack;
import io.netty.buffer.ByteBuf;
public class TileSuperStockReplenisher extends AENetworkInvTile
implements IAEFluidInventory, IFluidHandler, IPowerChannelState, IGridTickable {
private final AppEngInternalInventory cell = new AppEngInternalInventory(this, 1);
private final AppEngInternalInventory invItems = new AppEngInternalInventory(this, 63);
private final AEFluidInventory invFluids = new AEFluidInventory(this, 9, Integer.MAX_VALUE);
private final AppEngInternalAEInventory configFluids = new AppEngInternalAEInventory(this, 9);
private final AppEngInternalAEInventory configItems = new AppEngInternalAEInventory(this, 63);
private final BaseActionSource source;
private boolean isPowered;
private long totalBytes;
private long storedFluidCount;
private long storedItemCount;
public TileSuperStockReplenisher() {
getProxy().setIdlePowerUsage(4D);
getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
this.source = new MachineSource(this);
invItems.setMaxStackSize(Integer.MAX_VALUE);
}
private TickRateModulation doWork() {
for (int i = 0; i < 9; i++) {
IAEFluidStack invFluid = invFluids.getFluidInSlot(i);
IAEItemStack configFluid = configFluids.getAEStackInSlot(i);
if (configFluid != null) {
IAEFluidStack fs = AEFluidStack.create(ItemFluidPacket.getFluidStack(configFluid));
if (invFluid == null) requestFluid(fs, i);
else if (invFluid.equals(fs)) {
long invSize = invFluid.getStackSize();
long confSize = fs.getStackSize();
if (invSize < confSize / 2f) {
fs.setStackSize(confSize - invSize);
requestFluid(fs, i);
} else if (invSize > confSize) {
returnFluid(i, invSize - confSize);
}
} else {
returnFluid(i, Long.MAX_VALUE);
}
} else if (invFluid != null) {
returnFluid(i, Long.MAX_VALUE);
}
}
for (int i = 0; i < 63; i++) {
ItemStack invItem = invItems.getStackInSlot(i);
IAEItemStack configItem = configItems.getAEStackInSlot(i);
if (configItem != null) {
IAEItemStack is = configItem.copy();
if (invItem == null) requestItem(is, i);
else if (is.equals(invItem)) {
int confSize = (int) is.getStackSize();
if (invItem.stackSize < confSize / 2f) {
is.setStackSize(confSize - invItem.stackSize);
requestItem(is, i);
} else if (invItem.stackSize > confSize) {
returnItem(i, invItem.stackSize - confSize);
}
} else {
returnItem(i, Integer.MAX_VALUE);
}
} else if (invItem != null) {
returnItem(i, Integer.MAX_VALUE);
}
}
return TickRateModulation.SAME;
}
private void returnFluid(int index, long amount) {
try {
IAEFluidStack ias = invFluids.drain(index, amount, true);
storedFluidCount -= ias.getStackSize();
IAEFluidStack notInserted = this.getProxy().getStorage().getFluidInventory()
.injectItems(ias, Actionable.MODULATE, this.source);
if (notInserted != null) {
invFluids.fill(index, notInserted, true);
storedFluidCount += notInserted.getStackSize();
}
} catch (final GridAccessException ignored) {}
}
private void requestFluid(IAEFluidStack fs, int index) {
if (getRemainingFluidCount() == 0) return;
try {
long remFluid = getRemainingFluidCount();
if (fs.getStackSize() > remFluid) fs.setStackSize(remFluid);
IAEFluidStack extracted = this.getProxy().getStorage().getFluidInventory()
.extractItems(fs, Actionable.MODULATE, this.source);
if (extracted != null) {
storedFluidCount += extracted.getStackSize();
invFluids.fill(index, extracted, true);
}
} catch (final GridAccessException ignored) {}
}
private void returnItem(int index, int amount) {
try {
ItemStack is = invItems.getStackInSlot(index);
if (amount != Integer.MAX_VALUE) {
is.stackSize = is.stackSize - amount;
is = is.copy();
is.stackSize = amount;
storedItemCount -= is.stackSize;
} else {
invItems.setInventorySlotContents(index, null);
}
IAEItemStack notInserted = this.getProxy().getStorage().getItemInventory()
.injectItems(AEItemStack.create(is), Actionable.MODULATE, this.source);
if (notInserted != null) {
ItemStack tempStack = invItems.getStackInSlot(index);
if (tempStack != null) {
tempStack.stackSize = tempStack.stackSize + (int) notInserted.getStackSize();
storedItemCount += notInserted.getStackSize();
} else invItems.setInventorySlotContents(index, notInserted.getItemStack());
}
} catch (final GridAccessException ignored) {}
}
private void requestItem(IAEItemStack is, int index) {
if (getRemainingItemCount() == 0) return;
try {
long remItem = getRemainingItemCount();
if (is.getStackSize() > remItem) is.setStackSize(remItem);
IAEItemStack extracted = this.getProxy().getStorage().getItemInventory()
.extractItems(is, Actionable.MODULATE, this.source);
if (extracted != null) {
ItemStack tempStack = invItems.getStackInSlot(index);
if (tempStack != null) {
tempStack.stackSize = tempStack.stackSize + (int) extracted.getStackSize();
storedItemCount += extracted.getStackSize();
} else invItems.setInventorySlotContents(index, extracted.getItemStack());
}
} catch (final GridAccessException ignored) {}
}
@Override
public int[] getAccessibleSlotsBySide(ForgeDirection whichSide) {
return IntStream.rangeClosed(0, 62).toArray();
}
@Nonnull
@Override
public IInventory getInternalInventory() {
return invItems;
}
public AppEngInternalAEInventory getConfigFluid() {
return configFluids;
}
public AppEngInternalAEInventory getConfigItems() {
return configItems;
}
public AppEngInternalInventory getCell() {
return cell;
}
public long getFreeBytes() {
return totalBytes - (((storedItemCount + getUnusedItemCount()) / 8)
+ ((storedFluidCount + getUnusedFluidCount()) / 2048));
}
public long getRemainingFluidCount() {
final double remaining = (double) getFreeBytes() * 2048 + this.getUnusedFluidCount();
if (remaining > Long.MAX_VALUE) return Long.MAX_VALUE;
return remaining > 0 ? (long) remaining : 0;
}
public int getUnusedFluidCount() {
final int div = (int) (storedFluidCount % 2048);
if (div == 0) {
return 0;
}
return 2048 - div;
}
public long getRemainingItemCount() {
final long remaining = getFreeBytes() * 8 + this.getUnusedItemCount();
return remaining > 0 ? remaining : 0;
}
public int getUnusedItemCount() {
final long div = storedItemCount % 8;
if (div == 0) {
return 0;
}
return (int) (8 - div);
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) {
switch (mc) {
case setInventorySlotContents -> {
if (added != null) {
if (inv == cell) {
if (added.getItem() instanceof ItemBasicStorageCell ibsc) {
totalBytes = ibsc.getBytesLong(added);
} else if (added.getItem() instanceof FCBaseItemCell fcbic) {
totalBytes = fcbic.getBytes(added);
}
getProxy().setIdlePowerUsage(Math.sqrt(Math.pow(totalBytes, 0.576D)));
} else if (inv == invItems) {
storedItemCount += added.stackSize;
}
}
if (removed != null) {
if (inv == cell) {
totalBytes = 0;
getProxy().setIdlePowerUsage(4d);
} else if (inv == invItems) {
storedItemCount -= removed.stackSize;
}
}
}
case decreaseStackSize -> {
if (inv == cell) {
totalBytes = 0;
getProxy().setIdlePowerUsage(4d);
}
if (inv == invItems) {
storedItemCount -= removed.stackSize;
}
}
case markDirty -> {}
}
try {
getProxy().getTick().alertDevice(getProxy().getNode());
} catch (GridAccessException e) {
AELog.error(e, "Couldn't wake up level emitter for delayed updates");
}
markForUpdate();
}
public void fullRefund() {
for (int i = 0; i < 9; i++) {
if (invFluids.getFluidStackInSlot(i) != null) {
returnFluid(i, Long.MAX_VALUE);
}
}
for (int i = 0; i < 63; i++) {
if (invItems.getStackInSlot(i) != null) {
returnItem(i, Integer.MAX_VALUE);
}
}
}
@Override
public void getDrops(World w, int x, int y, int z, List<ItemStack> drops) {
if (cell.getStackInSlot(0) != null) drops.add(cell.getStackInSlot(0));
for (int i = 0; i < 9; i++) {
ItemStack ifp = ItemFluidPacket.newStack(invFluids.getFluidStackInSlot(i));
if (ifp != null) drops.add(ifp);
}
super.getDrops(w, x, y, z, drops);
}
@Override
public boolean canInsertItem(int slotIndex, ItemStack insertingItem, int side) {
return false;
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
return 0;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
FluidStack fs = invFluids.drain(from, resource, doDrain);
if (doDrain && fs != null) storedFluidCount -= fs.amount;
return fs;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
FluidStack fs = invFluids.drain(from, maxDrain, doDrain);
if (doDrain && fs != null) storedFluidCount -= fs.amount;
return fs;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
return false;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
return invFluids.canDrain(from, fluid);
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
return invFluids.getTankInfo(from);
}
@Override
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
saveChanges();
markForUpdate();
}
@Override
public AEFluidInventory getInternalFluid() {
return this.invFluids;
}
@TileEvent(TileEventType.NETWORK_READ)
public boolean readFromStream_TileSuperStockReplenisher(final ByteBuf data) {
final boolean oldPower = isPowered;
isPowered = data.readBoolean();
return isPowered != oldPower;
}
@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStream_TileSuperStockReplenisher(final ByteBuf data) {
data.writeBoolean(isActive());
}
@TileEvent(TileEventType.WORLD_NBT_READ)
public void readFromNBTEvent(NBTTagCompound data) {
invItems.readFromNBT(data, "ItemInv");
invFluids.readFromNBT(data, "FluidInv");
configItems.readFromNBT(data, "configItems");
configFluids.readFromNBT(data, "configFluids");
cell.readFromNBT(data, "cellHolder");
totalBytes = data.getLong("totalBytes");
storedFluidCount = data.getLong("storedFluidCount");
storedItemCount = data.getLong("storedItemCount");
getProxy().setIdlePowerUsage(data.getDouble("powerDraw"));
}
@TileEvent(TileEventType.WORLD_NBT_WRITE)
public NBTTagCompound writeToNBTEvent(NBTTagCompound data) {
invItems.writeToNBT(data, "ItemInv");
invFluids.writeToNBT(data, "FluidInv");
configItems.writeToNBT(data, "configItems");
configFluids.writeToNBT(data, "configFluids");
cell.writeToNBT(data, "cellHolder");
data.setLong("totalBytes", totalBytes);
data.setLong("storedFluidCount", storedFluidCount);
data.setLong("storedItemCount", storedItemCount);
data.setDouble("powerDraw", getProxy().getIdlePowerUsage());
return data;
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkPowerStatusChange p) {
this.updatePowerState();
}
@MENetworkEventSubscribe
public final void bootingRender(final MENetworkBootingStatusChange c) {
this.updatePowerState();
}
@Override
public boolean isPowered() {
return this.isPowered;
}
@Override
public boolean isActive() {
return this.isPowered;
}
private void updatePowerState() {
boolean newState = false;
try {
newState = this.getProxy().isActive()
&& this.getProxy().getEnergy().extractAEPower(1, Actionable.SIMULATE, PowerMultiplier.CONFIG)
> 0.0001;
} catch (final GridAccessException ignored) {}
if (newState != this.isPowered) {
this.isPowered = newState;
this.markForUpdate();
}
}
@Override
public DimensionalCoord getLocation() {
return new DimensionalCoord(this);
}
@Override
public AECableType getCableConnectionType(ForgeDirection dir) {
return AECableType.SMART;
}
@Override
public TickingRequest getTickingRequest(IGridNode node) {
return new TickingRequest(120, 120, false, false);
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) {
return doWork();
}
}
@@ -8,10 +8,6 @@ import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import com.glodblock.github.coremod.transform.CraftingCpuTransformer;
import com.glodblock.github.coremod.transform.CraftingGridCacheTransformer;
import com.glodblock.github.coremod.transform.CraftingTreeNodeTransformer;
import com.glodblock.github.coremod.transform.DualityInterfaceTransformer;
import com.glodblock.github.coremod.transform.ExternalStorageRegistryTransformer;
import com.glodblock.github.coremod.transform.GuiCraftingTransformer;
import com.glodblock.github.coremod.transform.NEITransformer;
@@ -25,10 +21,6 @@ public class FCClassTransformer implements IClassTransformer {
public byte[] transform(String name, String transformedName, byte[] basicClass) {
ClassMapper tform;
switch (transformedName) {
case "appeng.crafting.CraftingTreeNode" -> tform = CraftingTreeNodeTransformer.INSTANCE;
case "appeng.me.cache.CraftingGridCache" -> tform = CraftingGridCacheTransformer.INSTANCE;
case "appeng.me.cluster.implementations.CraftingCPUCluster" -> tform = CraftingCpuTransformer.INSTANCE;
case "appeng.helpers.DualityInterface" -> tform = DualityInterfaceTransformer.INSTANCE;
case "appeng.client.gui.implementations.GuiCraftingCPU", "appeng.client.gui.implementations.GuiCraftConfirm", "net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm", "appeng.client.gui.widgets.GuiCraftingTree" -> tform = GuiCraftingTransformer.INSTANCE;
case "appeng.integration.modules.NEI" -> tform = NEITransformer.INSTANCE;
case "appeng.core.features.registries.ExternalStorageRegistry" -> tform = ExternalStorageRegistryTransformer.INSTANCE;
@@ -1,86 +1,18 @@
package com.glodblock.github.coremod.hooker;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import com.glodblock.github.client.gui.GuiFluidCraftConfirm;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.CraftingGridCacheFluidInventoryProxyCell;
import com.glodblock.github.inventory.FluidConvertingInventoryAdaptor;
import com.glodblock.github.inventory.FluidConvertingInventoryCrafting;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.Ae2Reflect;
import appeng.api.config.Actionable;
import appeng.api.networking.IGrid;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.IGuiTooltipHandler;
import appeng.crafting.MECraftingInventory;
import appeng.me.cache.CraftingGridCache;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.util.InventoryAdaptor;
public class CoreModHooks {
public static InventoryCrafting wrapCraftingBuffer(InventoryCrafting inv) {
return new FluidConvertingInventoryCrafting(
inv.eventHandler,
inv.inventoryWidth,
inv.getSizeInventory() / inv.inventoryWidth);
}
public static IAEItemStack wrapFluidPacketStack(IAEItemStack stack) {
if (stack.getItem() == ItemAndBlockHolder.PACKET) {
IAEItemStack dropStack = ItemFluidDrop.newAeStack(ItemFluidPacket.getFluidStack(stack.getItemStack()));
if (dropStack != null) {
return dropStack;
}
}
return stack;
}
public static ItemStack removeFluidPackets(InventoryCrafting inv, int index) {
ItemStack stack = inv.getStackInSlot(index);
if (stack != null && stack.getItem() instanceof ItemFluidPacket) {
FluidStack fluid = ItemFluidPacket.getFluidStack(stack);
return ItemFluidDrop.newStack(fluid);
} else {
return stack;
}
}
@Nullable
public static InventoryAdaptor wrapInventory(@Nullable TileEntity tile, ForgeDirection face) {
return tile != null ? FluidConvertingInventoryAdaptor.wrap(tile, face) : null;
}
public static long getCraftingByteCost(IAEItemStack stack) {
return stack.getItem() instanceof ItemFluidDrop ? (long) Math.ceil(stack.getStackSize() / 1000D)
: stack.getStackSize();
}
public static long getFluidDropsByteCost(long totalBytes, long originByte, IAEItemStack stack) {
if (stack != null && stack.getItem() instanceof ItemFluidDrop) {
return (long) Math.ceil(originByte / 1000D) + totalBytes;
}
return originByte + totalBytes;
}
public static ItemStack displayFluid(IAEItemStack aeStack) {
if (aeStack.getItemStack() != null && aeStack.getItemStack().getItem() instanceof ItemFluidDrop) {
FluidStack fluid = ItemFluidDrop.getFluidStack(aeStack.getItemStack());
@@ -88,61 +20,6 @@ public class CoreModHooks {
} else return aeStack.getItemStack();
}
public static long getFluidSize(IAEItemStack aeStack) {
if (aeStack.getItemStack() != null && aeStack.getItemStack().getItem() instanceof ItemFluidDrop) {
return (long) Math.max(aeStack.getStackSize() / 1000D, 1);
} else return aeStack.getStackSize();
}
public static List<IMEInventoryHandler<?>> craftingGridCacheGetCellArray(final CraftingGridCache instance,
final StorageChannel channel) {
// Equivalent to original function, but using the proxy for fluid channel
return channel == StorageChannel.ITEMS ? Arrays.asList(instance)
: Arrays.asList(new CraftingGridCacheFluidInventoryProxyCell(instance));
}
public static void storeFluidItem(CraftingCPUCluster instance) {
final IGrid g = Ae2Reflect.getGrid(instance);
if (g == null) {
return;
}
final IStorageGrid sg = g.getCache(IStorageGrid.class);
final IMEInventory<IAEItemStack> ii = sg.getItemInventory();
final IMEInventory<IAEFluidStack> jj = sg.getFluidInventory();
final MECraftingInventory inventory = Ae2Reflect.getCPUInventory(instance);
for (IAEItemStack is : inventory.getItemList()) {
is = inventory.extractItems(is.copy(), Actionable.MODULATE, Ae2Reflect.getCPUSource(instance));
if (is != null) {
Ae2Reflect.postCPUChange(instance, is, Ae2Reflect.getCPUSource(instance));
if (is.getItem() instanceof ItemFluidDrop) {
IAEFluidStack fluidDrop = ItemFluidDrop.getAeFluidStack(is);
fluidDrop = jj.injectItems(fluidDrop, Actionable.MODULATE, Ae2Reflect.getCPUSource(instance));
if (fluidDrop == null) {
is = null;
} else {
is.setStackSize(fluidDrop.getStackSize());
}
} else {
is = ii.injectItems(is, Actionable.MODULATE, Ae2Reflect.getCPUSource(instance));
}
}
if (is != null) {
inventory.injectItems(is, Actionable.MODULATE, Ae2Reflect.getCPUSource(instance));
}
}
if (inventory.getItemList().isEmpty()) {
Ae2Reflect.setCPUInventory(instance, new MECraftingInventory());
}
Ae2Reflect.markCPUDirty(instance);
}
public static ItemStack getStackUnderMouse(GuiContainer gui, int mousex, int mousey) {
if (gui instanceof IGuiTooltipHandler guiTooltipHandler) {
return guiTooltipHandler.getHoveredStack();
@@ -1,7 +1,5 @@
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;
@@ -9,8 +7,9 @@ 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;
@@ -45,10 +44,7 @@ public class PartFluidLevelEmitterAdapter implements ILevelViewable, ILevelViewa
@Override
public IInventory getInventoryByName(String name) {
long value = delegate.getReportingValue();
State state = delegate.isProvidingStrongPower() > 0 ? State.Craft : State.Idle;
return getPatchedInventory(delegate.getInventoryByName(name), value, state);
return delegate.getInventoryByName(name);
}
@Override
@@ -82,7 +78,13 @@ public class PartFluidLevelEmitterAdapter implements ILevelViewable, ILevelViewa
}
@Override
public ItemStack getSelfItemStack() {
return delegate.getItemStack();
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) };
}
}
@@ -2,34 +2,24 @@ 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.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 com.glodblock.github.api.registries.LevelItemInfo;
import com.glodblock.github.api.registries.LevelState;
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) {
@@ -37,21 +27,6 @@ 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();
@@ -64,10 +39,7 @@ public class PartLevelEmitterAdapter implements ILevelViewable, ILevelViewableAd
@Override
public IInventory getInventoryByName(String name) {
long value = delegate.getReportingValue();
State state = delegate.isProvidingStrongPower() > 0 ? State.Craft : State.Idle;
return getPatchedInventory(delegate.getInventoryByName(name), value, state);
return delegate.getInventoryByName(name);
}
@Override
@@ -106,12 +78,13 @@ public class PartLevelEmitterAdapter implements ILevelViewable, ILevelViewableAd
}
@Override
public ItemStack getSelfItemStack() {
return delegate.getItemStack();
}
@Override
public ItemStack getDisplayItemStack() {
return delegate.getCrafterIcon();
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) };
}
}
@@ -1,142 +0,0 @@
package com.glodblock.github.coremod.transform;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import com.glodblock.github.coremod.FCClassTransformer;
public class CraftingCpuTransformer extends FCClassTransformer.ClassMapper {
public static final CraftingCpuTransformer INSTANCE = new CraftingCpuTransformer();
private CraftingCpuTransformer() {
// NO-OP
}
@Override
protected ClassVisitor getClassMapper(ClassVisitor downstream) {
return new TransformCraftingCPUCluster(Opcodes.ASM5, downstream);
}
private static class TransformCraftingCPUCluster extends ClassVisitor {
TransformCraftingCPUCluster(int api, ClassVisitor cv) {
super(api, cv);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (name.equals("executeCrafting")) {
return new TransformExecuteCrafting(api, super.visitMethod(access, name, desc, signature, exceptions));
} else if (name.equals("cancel")) {
return new TransformStoreItems(api, super.visitMethod(access, name, desc, signature, exceptions));
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
}
private static class TransformExecuteCrafting extends MethodVisitor {
private boolean gotInventory = false;
private int reach_stack = 0;
TransformExecuteCrafting(int api, MethodVisitor mv) {
super(api, mv);
}
@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
if (opcode == Opcodes.GETFIELD && owner.equals("appeng/me/cluster/implementations/CraftingCPUCluster")
&& name.equals("inventory")) {
gotInventory = true;
}
super.visitFieldInsn(opcode, owner, name, desc);
}
@Override
public void visitLineNumber(int line, Label start) {
gotInventory = false;
super.visitLineNumber(line, start);
}
@Override
public void visitJumpInsn(int opcode, Label label) {
if (opcode == Opcodes.IFNULL && reach_stack == 0) {
reach_stack = 1;
}
super.visitJumpInsn(opcode, label);
}
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (reach_stack == 1) {
if (opcode == Opcodes.INVOKEINTERFACE && owner.equals("appeng/api/storage/data/IAEItemStack")
&& name.equals("getStackSize")) {
reach_stack = 2;
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"getFluidSize",
"(Lappeng/api/storage/data/IAEItemStack;)J",
false);
return;
}
}
if (opcode == Opcodes.INVOKEVIRTUAL && owner.equals("net/minecraft/inventory/InventoryCrafting")
&& (name.equals("getStackInSlot") || name.equals("func_70301_a"))) {
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"removeFluidPackets",
"(Lnet/minecraft/inventory/InventoryCrafting;I)Lnet/minecraft/item/ItemStack;",
false);
return;
}
super.visitMethodInsn(opcode, owner, name, desc, itf);
if (gotInventory) {
if (opcode == Opcodes.INVOKESTATIC && owner.equals("appeng/util/item/AEItemStack")
&& name.equals("create")) {
gotInventory = false;
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"wrapFluidPacketStack",
"(Lappeng/api/storage/data/IAEItemStack;)Lappeng/api/storage/data/IAEItemStack;",
false);
}
} else if (opcode == Opcodes.INVOKESPECIAL && owner.equals("net/minecraft/inventory/InventoryCrafting")
&& name.equals("<init>")) {
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"wrapCraftingBuffer",
"(Lnet/minecraft/inventory/InventoryCrafting;)Lnet/minecraft/inventory/InventoryCrafting;",
false);
}
}
}
private static class TransformStoreItems extends MethodVisitor {
TransformStoreItems(int api, MethodVisitor mv) {
super(api, mv);
}
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (opcode == Opcodes.INVOKESPECIAL && owner.equals("appeng/me/cluster/implementations/CraftingCPUCluster")
&& name.equals("storeItems")) {
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"storeFluidItem",
"(Lappeng/me/cluster/implementations/CraftingCPUCluster;)V",
false);
} else {
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
}
}
}
@@ -1,67 +0,0 @@
package com.glodblock.github.coremod.transform;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import com.glodblock.github.coremod.FCClassTransformer;
public class CraftingGridCacheTransformer extends FCClassTransformer.ClassMapper {
public static final CraftingGridCacheTransformer INSTANCE = new CraftingGridCacheTransformer();
private CraftingGridCacheTransformer() {
// NO-OP
}
@Override
protected ClassVisitor getClassMapper(ClassVisitor downstream) {
return new CraftingGridCacheTransformer.TransformCraftingGridCache(Opcodes.ASM5, downstream);
}
private static class TransformCraftingGridCache extends ClassVisitor {
TransformCraftingGridCache(int api, ClassVisitor cv) {
super(api, cv);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (name.equals("getCellArray")) {
return new CraftingGridCacheTransformer.ReplaceGetCellArray(
api,
super.visitMethod(access, name, desc, signature, exceptions));
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
}
private static class ReplaceGetCellArray extends MethodVisitor {
private final MethodVisitor target;
ReplaceGetCellArray(int api, MethodVisitor mv) {
// Original method is replaced
super(api, null);
target = mv;
}
@Override
public void visitCode() {
target.visitCode();
// Equivalent to
// return CoreModHooks::craftingGridCacheGetCellArray(this, channel);
target.visitVarInsn(Opcodes.ALOAD, 0);
target.visitVarInsn(Opcodes.ALOAD, 1);
target.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"craftingGridCacheGetCellArray",
"(Lappeng/me/cache/CraftingGridCache;Lappeng/api/storage/StorageChannel;)Ljava/util/List;",
false);
target.visitInsn(Opcodes.ARETURN);
target.visitMaxs(2, 3);
target.visitEnd();
}
}
}
@@ -1,102 +0,0 @@
package com.glodblock.github.coremod.transform;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import com.glodblock.github.coremod.FCClassTransformer;
public class CraftingTreeNodeTransformer extends FCClassTransformer.ClassMapper {
public static final CraftingTreeNodeTransformer INSTANCE = new CraftingTreeNodeTransformer();
private CraftingTreeNodeTransformer() {
// NO-OP
}
@Override
protected ClassVisitor getClassMapper(ClassVisitor downstream) {
return new TransformCraftingTreeNode(Opcodes.ASM5, downstream);
}
private static class TransformCraftingTreeNode extends ClassVisitor {
TransformCraftingTreeNode(int api, ClassVisitor cv) {
super(api, cv);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (name.equals("request")) {
return new TransformRequest(api, super.visitMethod(access, name, desc, signature, exceptions));
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
}
private static class TransformRequest extends MethodVisitor {
private boolean writingBytes = false;
private int cnt = 0;
TransformRequest(int api, MethodVisitor mv) {
super(api, mv);
}
@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
if (opcode == Opcodes.GETFIELD && owner.equals("appeng/crafting/CraftingTreeNode")
&& name.equals("bytes")) {
writingBytes = true;
}
super.visitFieldInsn(opcode, owner, name, desc);
}
@Override
public void visitLineNumber(int line, Label start) {
writingBytes = false; // no write here
super.visitLineNumber(line, start);
}
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (writingBytes && opcode == Opcodes.INVOKEINTERFACE
&& owner.equals("appeng/api/storage/data/IAEItemStack")
&& name.equals("getStackSize")) {
writingBytes = false;
cnt++;
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"getCraftingByteCost",
"(Lappeng/api/storage/data/IAEItemStack;)J",
false);
} else {
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
}
@Override
public void visitInsn(int opcode) {
if (writingBytes && cnt == 5 && opcode == Opcodes.LADD) {
super.visitVarInsn(Opcodes.ALOAD, 0);
super.visitFieldInsn(
Opcodes.GETFIELD,
"appeng/crafting/CraftingTreeNode",
"what",
"Lappeng/api/storage/data/IAEItemStack;");
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"getFluidDropsByteCost",
"(JJLappeng/api/storage/data/IAEItemStack;)J",
false);
writingBytes = false;
cnt++;
return;
}
super.visitInsn(opcode);
}
}
}
@@ -1,60 +0,0 @@
package com.glodblock.github.coremod.transform;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import com.glodblock.github.coremod.FCClassTransformer;
public class DualityInterfaceTransformer extends FCClassTransformer.ClassMapper {
public static final DualityInterfaceTransformer INSTANCE = new DualityInterfaceTransformer();
private DualityInterfaceTransformer() {
// NO-OP
}
@Override
protected ClassVisitor getClassMapper(ClassVisitor downstream) {
return new TransformDualityInterface(Opcodes.ASM5, downstream);
}
private static class TransformDualityInterface extends ClassVisitor {
TransformDualityInterface(int api, ClassVisitor cv) {
super(api, cv);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
return switch (name) {
case "pushItemsOut", "pushPattern", "isBusy" -> new TransformInvAdaptorCalls(
api,
super.visitMethod(access, name, desc, signature, exceptions));
default -> super.visitMethod(access, name, desc, signature, exceptions);
};
}
}
private static class TransformInvAdaptorCalls extends MethodVisitor {
private TransformInvAdaptorCalls(int api, MethodVisitor mv) {
super(api, mv);
}
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (opcode == Opcodes.INVOKESTATIC && owner.equals("appeng/util/InventoryAdaptor")
&& name.equals("getAdaptor")) {
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"wrapInventory",
"(Lnet/minecraft/tileentity/TileEntity;Lnet/minecraftforge/common/util/ForgeDirection;)Lappeng/util/InventoryAdaptor;",
false);
} else {
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
}
}
}
@@ -14,7 +14,9 @@ import net.minecraft.world.World;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.FCBaseItem;
import com.glodblock.github.util.ModAndClassUtil;
import codechicken.nei.api.API;
import cpw.mods.fml.common.registry.GameRegistry;
/**
@@ -38,6 +40,10 @@ public class ProxyItem extends FCBaseItem {
@Override
public FCBaseItem register() {
GameRegistry.registerItem(this, "ec2placeholder." + name, FluidCraft.MODID);
if (!ModAndClassUtil.EC2) {
API.hideItem("ec2placeholder." + name);
}
return this;
}
@@ -6,10 +6,10 @@ import net.minecraft.item.ItemStack;
import com.glodblock.github.api.FluidCraftAPI;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.crossmod.extracells.ProxyItem;
import com.glodblock.github.inventory.FluidCellConfig;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEFluidStack;
import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades;
import appeng.util.Platform;
@@ -88,7 +88,7 @@ public class ProxyFluidStorageCell extends ProxyItem implements IStorageFluidCel
@Override
public IInventory getConfigInventory(ItemStack is) {
return new CellConfig(is);
return new FluidCellConfig(is);
}
@Override
@@ -61,7 +61,7 @@ public class DriverLevelMaintainer extends DriverSidedTileEntity {
if (slot < 0 || slot >= TileLevelMaintainer.REQ_COUNT) {
throw new IllegalArgumentException("Invalid slot");
}
return tileEntity.requests.isDone(slot);
return tileEntity.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.isEnable(slot);
return tileEntity.requests[slot].isEnable();
}
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.requests.updateStatus(slot, enable);
tileEntity.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.getQuantity(slot));
result.put("batch", tileEntity.requests.getBatchSize(slot));
result.put("quantity", tileEntity.requests[slot].getQuantity());
result.put("batch", tileEntity.requests[slot].getBatchSize());
result.put("isFluid", ItemFluidDrop.isFluidStack(stack));
if (ItemFluidDrop.isFluidStack(stack)) result.put("fluid", ItemFluidDrop.getFluidStack(stack));
result.put("isEnable", tileEntity.requests.isEnable(slot));
result.put("isDone", tileEntity.requests.isDone(slot));
result.put("isEnable", tileEntity.requests[slot].isEnable());
result.put("isDone", tileEntity.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.requests.updateStack(slot, dbStack);
tileEntity.updateStack(slot, dbStack);
} else {
throw new IllegalArgumentException("Not a database");
}
@@ -0,0 +1,30 @@
package com.glodblock.github.crossmod.waila;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidTankInfo;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
public class CertusQuartzTankWailaDataProvider extends BaseWailaDataProvider {
@Override
public List<String> getWailaBody(final ItemStack itemStack, final List<String> currentToolTip,
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
TileEntity tileEntity = accessor.getTileEntity();
if (tileEntity instanceof TileCertusQuartzTank quartzTank) {
FluidTankInfo info = quartzTank.getTankInfo(true)[0];
if (info.fluid != null) {
currentToolTip
.add(Tooltip.fluidFormat(info.fluid.getLocalizedName(), info.fluid.amount, info.capacity));
}
}
return currentToolTip;
}
}
@@ -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;
}
@@ -1,71 +0,0 @@
package com.glodblock.github.crossmod.waila;
import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import com.glodblock.github.crossmod.waila.vanilla.FluidInvWailaDataProvider;
import com.google.common.collect.Lists;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
public class VanillaTileWailaDataProvider implements IWailaDataProvider {
private final List<IWailaDataProvider> providers;
public VanillaTileWailaDataProvider() {
final IWailaDataProvider fluidInv = new FluidInvWailaDataProvider();
this.providers = Lists.newArrayList(fluidInv);
}
@Override
public ItemStack getWailaStack(final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaHead(final ItemStack itemStack, final List<String> currentToolTip,
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
for (final IWailaDataProvider provider : this.providers) {
provider.getWailaHead(itemStack, currentToolTip, accessor, config);
}
return currentToolTip;
}
@Override
public List<String> getWailaBody(final ItemStack itemStack, final List<String> currentToolTip,
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
for (final IWailaDataProvider provider : this.providers) {
provider.getWailaBody(itemStack, currentToolTip, accessor, config);
}
return currentToolTip;
}
@Override
public List<String> getWailaTail(final ItemStack itemStack, final List<String> currentToolTip,
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
for (final IWailaDataProvider provider : this.providers) {
provider.getWailaTail(itemStack, currentToolTip, accessor, config);
}
return currentToolTip;
}
@Override
public NBTTagCompound getNBTData(final EntityPlayerMP player, final TileEntity te, final NBTTagCompound tag,
final World world, final int x, final int y, final int z) {
for (final IWailaDataProvider provider : this.providers) {
provider.getNBTData(player, te, tag, world, x, y, z);
}
return tag;
}
}
@@ -1,6 +1,7 @@
package com.glodblock.github.crossmod.waila;
import net.minecraft.tileentity.TileEntity;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import com.glodblock.github.util.ModAndClassUtil;
import appeng.api.parts.IPartHost;
import appeng.tile.AEBaseTile;
@@ -26,9 +27,9 @@ public class WailaInit {
registrar.registerBodyProvider(tile, AEBaseTile.class);
registrar.registerNBTProvider(tile, AEBaseTile.class);
final IWailaDataProvider vanillaTile = new VanillaTileWailaDataProvider();
registrar.registerBodyProvider(vanillaTile, TileEntity.class);
registrar.registerNBTProvider(vanillaTile, TileEntity.class);
if (!ModAndClassUtil.WAILA_PLUGINS) {
final IWailaDataProvider certusQuartzTank = new CertusQuartzTankWailaDataProvider();
registrar.registerBodyProvider(certusQuartzTank, TileCertusQuartzTank.class);
}
}
}
@@ -20,9 +20,8 @@ public class SpeedWailaDataProvider extends BasePartWailaDataProvider {
@Override
public List<String> getWailaBody(final IPart part, final List<String> currentToolTip,
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
if (part instanceof FCSharedFluidBus) {
part.readFromNBT(accessor.getNBTData());
currentToolTip.add(Tooltip.partFluidBusFormat(((FCSharedFluidBus) part).calculateAmountToSend() / 5));
if (accessor.getNBTData().hasKey("BusSpeed")) {
currentToolTip.add(Tooltip.partFluidBusFormat(accessor.getNBTData().getInteger("BusSpeed")));
}
return currentToolTip;
}
@@ -30,8 +29,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) {
part.writeToNBT(tag);
if (part instanceof FCSharedFluidBus bus) {
tag.setInteger("BusSpeed", bus.calculateAmountToSend() / 5);
}
return tag;
}
@@ -5,13 +5,14 @@ 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;
@@ -23,16 +24,24 @@ public class LevelMaintainerWailaDataProvider extends BaseWailaDataProvider {
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
final TileEntity te = accessor.getTileEntity();
if (te instanceof TileLevelMaintainer tileLevelMaintainer) {
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)));
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) {}
}
}
}
@@ -1,50 +0,0 @@
package com.glodblock.github.crossmod.waila.vanilla;
import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidTankInfo;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import com.glodblock.github.crossmod.waila.Tooltip;
import com.glodblock.github.util.Util;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
public class FluidInvWailaDataProvider extends BaseWailaDataProvider {
@Override
public List<String> getWailaBody(final ItemStack itemStack, final List<String> currentToolTip,
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
final TileEntity te = accessor.getTileEntity();
if (te instanceof TileCertusQuartzTank) {
if (accessor.getNBTData().hasKey("fluidInv")) {
NBTTagCompound data = (NBTTagCompound) accessor.getNBTData().getTag("fluidInv");
for (FluidTankInfo info : Util.FluidUtil.fluidTankInfoReadFromNBT(data)) {
if (info.fluid == null) continue;
currentToolTip
.add(Tooltip.fluidFormat(info.fluid.getLocalizedName(), info.fluid.amount, info.capacity));
}
}
}
return currentToolTip;
}
@Override
public NBTTagCompound getNBTData(final EntityPlayerMP player, final TileEntity te, final NBTTagCompound tag,
final World world, final int x, final int y, final int z) {
if (te instanceof TileCertusQuartzTank) {
NBTTagCompound data = new NBTTagCompound();
Util.FluidUtil.fluidTankInfoWriteToNBT(((TileCertusQuartzTank) te).getInternalFluid(), data);
tag.setTag("fluidInv", data);
te.writeToNBT(tag);
}
return tag;
}
}
@@ -22,12 +22,21 @@ public class AEFluidInventory implements IAEFluidTank {
private final IAEFluidStack[] fluids;
private final IAEFluidInventory handler;
private final int capacity;
private final long capacityLong;
public int lastIndex;
public AEFluidInventory(final IAEFluidInventory handler, final int slots, final int capcity) {
this.fluids = new IAEFluidStack[slots];
this.handler = handler;
this.capacity = capcity;
this.capacityLong = capcity;
}
public AEFluidInventory(final IAEFluidInventory handler, final int slots, final long capcity) {
this.fluids = new IAEFluidStack[slots];
this.handler = handler;
this.capacity = Integer.MAX_VALUE;
this.capacityLong = capcity;
}
public AEFluidInventory(final IAEFluidInventory handler, final int slots) {
@@ -122,6 +131,37 @@ public class AEFluidInventory implements IAEFluidTank {
return amountToStore;
}
public long fill(final int slot, final IAEFluidStack resource, final boolean doFill) {
if (resource == null || resource.getStackSize() <= 0) {
return 0;
}
final IAEFluidStack fluid = this.fluids[slot];
if (fluid != null && !(fluid.getFluid() == resource.getFluid())) {
return 0;
}
long amountToStore = this.capacityLong;
if (fluid != null) {
amountToStore -= fluid.getStackSize();
}
amountToStore = Math.min(amountToStore, resource.getStackSize());
if (doFill) {
if (fluid == null) {
this.setFluidInSlot(slot, resource);
} else {
fluid.setStackSize(fluid.getStackSize() + amountToStore);
this.onContentChanged(slot);
}
}
return amountToStore;
}
public FluidStack drain(final int slot, final FluidStack resource, final boolean doDrain) {
final IAEFluidStack fluid = this.fluids[slot];
if (fluid == null || !fluid.getFluidStack().isFluidEqual(resource)) {
@@ -152,6 +192,28 @@ public class AEFluidInventory implements IAEFluidTank {
return stack;
}
public IAEFluidStack drain(final int slot, final long maxDrain, boolean doDrain) {
final IAEFluidStack fluid = this.fluids[slot];
if (fluid == null || maxDrain <= 0) {
return null;
}
long drained = maxDrain;
if (fluid.getStackSize() < drained) {
drained = fluid.getStackSize();
}
IAEFluidStack stack = fluid.copy().setStackSize(drained);
if (doDrain) {
fluid.setStackSize(fluid.getStackSize() - drained);
if (fluid.getStackSize() <= 0) {
this.fluids[slot] = null;
}
this.onContentChanged(slot);
}
return stack;
}
@Override
public int fill(ForgeDirection from, final FluidStack fluid, final boolean doFill) {
if (fluid == null || fluid.amount <= 0) {
@@ -1,85 +0,0 @@
package com.glodblock.github.inventory;
import org.jetbrains.annotations.NotNull;
import com.glodblock.github.common.item.ItemFluidDrop;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.me.cache.CraftingGridCache;
public class CraftingGridCacheFluidInventoryProxyCell implements IMEInventoryHandler<IAEFluidStack> {
private final CraftingGridCache inner;
public CraftingGridCacheFluidInventoryProxyCell(final CraftingGridCache craftingGridCache) {
inner = craftingGridCache;
}
@Override
public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, BaseActionSource src) {
return ItemFluidDrop
.getAeFluidStack((IAEItemStack) inner.injectItems(ItemFluidDrop.newAeStack(input), type, src));
}
@Override
public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, BaseActionSource src) {
return null;
}
@Override
public IItemList<IAEFluidStack> getAvailableItems(IItemList<IAEFluidStack> out, int iteration) {
return out;
}
@Override
public IAEFluidStack getAvailableItem(@NotNull IAEFluidStack request, int iteration) {
return null;
}
@Override
public StorageChannel getChannel() {
return StorageChannel.FLUIDS;
}
@Override
public AccessRestriction getAccess() {
return inner.getAccess();
}
@Override
public boolean isPrioritized(IAEFluidStack input) {
return inner.isPrioritized(input);
}
@Override
public boolean canAccept(IAEFluidStack input) {
return inner.canAccept(ItemFluidDrop.newAeStack(input));
}
@Override
public int getPriority() {
return inner.getPriority();
}
@Override
public int getSlot() {
return inner.getSlot();
}
@Override
public boolean validForPass(int i) {
return inner.validForPass(i);
}
@Override
public boolean isAutoCraftingInventory() {
return inner.isAutoCraftingInventory();
}
}
@@ -0,0 +1,27 @@
package com.glodblock.github.inventory;
import net.minecraft.item.ItemStack;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.util.Util;
import appeng.items.contents.CellConfig;
public class FluidCellConfig extends CellConfig {
public FluidCellConfig(ItemStack is) {
super(is);
}
@Override
public void setInventorySlotContents(int slot, ItemStack newItemStack) {
if (newItemStack != null && !(newItemStack.getItem() instanceof ItemFluidPacket)) {
ItemStack fluidPacket = ItemFluidPacket.newDisplayStack(Util.getFluidFromItem(newItemStack));
if (fluidPacket != null) {
super.setInventorySlotContents(slot, fluidPacket);
return;
}
}
super.setInventorySlotContents(slot, newItemStack);
}
}
Loaded 100 of 149 files, more files were not shown because too many files have changed in this diff. Show more