Skip to content

Commit bee77d1

Browse files
authored
Merge pull request #88 from FakeDomi/feature-splitting
New feature: "Splitting" toggle on interfaces
2 parents f6aff8b + 6acd703 commit bee77d1

File tree

12 files changed

+129
-59
lines changed

12 files changed

+129
-59
lines changed

src/main/java/com/glodblock/github/client/GuiItemDualInterface.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class GuiItemDualInterface extends GuiInterface {
2424
private GuiTabButton priorityBtn;
2525
private GuiFCImgButton fluidPacketOffBtn;
2626
private GuiFCImgButton fluidPacketOnBtn;
27+
private GuiFCImgButton splittingBtn;
2728

2829
public GuiItemDualInterface(final InventoryPlayer inventoryPlayer, final IInterfaceHost te) {
2930
super(inventoryPlayer, te);
@@ -42,6 +43,8 @@ protected void addButtons() {
4243
buttonList.add(fluidPacketOffBtn);
4344
fluidPacketOnBtn = new GuiFCImgButton(this.guiLeft - 18, this.guiTop + 44, "SEND_PACKET", "FLUID_PACKET");
4445
buttonList.add(fluidPacketOnBtn);
46+
splittingBtn = new GuiFCImgButton(this.guiLeft - 18, this.guiTop + 62, "SPLITTING", "ALLOW");
47+
buttonList.add(splittingBtn);
4548
priorityBtn = Ae2ReflectClient.getPriorityButton(this);
4649
}
4750

@@ -58,6 +61,8 @@ protected void actionPerformed(final GuiButton btn) throws IOException {
5861
InventoryHandler.switchGui(GuiType.PRIORITY);
5962
} else if (btn == fluidPacketOffBtn || btn == fluidPacketOnBtn) {
6063
FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidPatternTermBtns("DualInterface.FluidPacket", btn == fluidPacketOnBtn ? "0" : "1"));
64+
} else if (btn == splittingBtn) {
65+
FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidPatternTermBtns("DualInterface.AllowSplitting", this.splittingBtn.getCurrentValue().equals("ALLOW") ? "0" : "1"));
6166
} else {
6267
super.actionPerformed(btn);
6368
}
@@ -73,6 +78,9 @@ public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
7378
this.fluidPacketOnBtn.visible = false;
7479
this.fluidPacketOffBtn.visible = true;
7580
}
81+
82+
this.splittingBtn.set(container.allowSplitting ? "ALLOW" : "PREVENT");
83+
7684
super.drawFG(offsetX, offsetY, mouseX, mouseY);
7785
}
7886

src/main/java/com/glodblock/github/client/button/GuiFCImgButton.java

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.glodblock.github.FluidCraft;
55
import com.glodblock.github.util.NameConst;
66
import net.minecraft.client.Minecraft;
7+
import net.minecraft.client.gui.Gui;
78
import net.minecraft.client.gui.GuiButton;
89
import net.minecraft.client.resources.I18n;
910
import org.lwjgl.opengl.GL11;
@@ -23,6 +24,8 @@ public class GuiFCImgButton extends GuiButton implements ITooltip {
2324
private String fillVar;
2425
private String currentValue;
2526
private static final String prefix = NameConst.TT_KEY;
27+
private static final int SPRITE_SHEET_GRID_SIZE = 4;
28+
private static final int MAX_INDEX = SPRITE_SHEET_GRID_SIZE * SPRITE_SHEET_GRID_SIZE - 1;
2629

2730
public GuiFCImgButton( final int x, final int y, final String idx, final String val ) {
2831
super(0, 0, 16, "");
@@ -43,6 +46,8 @@ public GuiFCImgButton( final int x, final int y, final String idx, final String
4346
this.registerApp( 4, "FLUID_FIRST", "FLUID", "fluid_first" );
4447
this.registerApp( 5, "ORIGIN_ORDER", "ITEM", "origin_order" );
4548
this.registerApp( 6, "CRAFT_FLUID", "ENCODE", "craft_fluid" );
49+
this.registerApp( 7, "SPLITTING", "ALLOW", "allow_splitting" );
50+
this.registerApp( 8, "SPLITTING", "PREVENT", "prevent_splitting" );
4651
}
4752
}
4853

@@ -68,11 +73,11 @@ private int getIconIndex()
6873
final ButtonAppearance app = appearances.get(new EnumPair( this.buttonSetting, this.currentValue ));
6974
if( app == null )
7075
{
71-
return 8;
76+
return MAX_INDEX;
7277
}
7378
return app.index;
7479
}
75-
return 8;
80+
return MAX_INDEX;
7681
}
7782

7883
public String getSetting()
@@ -203,65 +208,52 @@ public void drawButton(@Nonnull final Minecraft par1Minecraft, final int par2, f
203208
if( this.visible )
204209
{
205210
final int iconIndex = this.getIconIndex();
211+
int relativeX = this.x;
212+
int relativeY = this.y;
206213

207-
if( this.halfSize )
214+
if ( this.halfSize )
208215
{
209216
this.width = 8;
210217
this.height = 8;
211218

212219
GL11.glPushMatrix();
213220
GL11.glTranslatef( this.x, this.y, 0.0F );
214-
GL11.glScalef( 0.5f / 16 * 3, 0.5f / 16 * 3, 0.5f / 16 * 3 );
221+
GL11.glScalef( 0.5f, 0.5f, 0.5f );
215222

216-
if( this.enabled )
217-
{
218-
GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
219-
}
220-
else
221-
{
222-
GL11.glColor4f( 0.5f, 0.5f, 0.5f, 1.0f );
223-
}
224-
225-
par1Minecraft.renderEngine.bindTexture( FluidCraft.resource("textures/gui/states.png") );
226-
this.hovered = par2 >= this.x && par3 >= this.y && par2 < this.x + this.width && par3 < this.y + this.height;
227-
228-
final int uv_y = (int) Math.floor( iconIndex / 3.0 );
229-
final int uv_x = iconIndex - uv_y * 3;
230-
231-
this.drawTexturedModalRect( 0, 0, Math.round(32F * 16F / 3F), Math.round(32F * 16F / 3F), Math.round(16F * 16F / 3F), Math.round(16F * 16F / 3F) );
232-
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) );
233-
this.mouseDragged( par1Minecraft, par2, par3 );
223+
relativeX = 0;
224+
relativeY = 0;
225+
}
234226

235-
GL11.glPopMatrix();
227+
if( this.enabled )
228+
{
229+
GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
236230
}
237231
else
238232
{
239-
GL11.glPushMatrix();
240-
GL11.glTranslatef( this.x, this.y, 0.0F );
241-
GL11.glScalef( 1f / 16 * 3, 1f / 16 * 3, 1f / 16 * 3 );
233+
GL11.glColor4f( 0.5f, 0.5f, 0.5f, 1.0f );
234+
}
242235

243-
if( this.enabled )
244-
{
245-
GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
246-
}
247-
else
248-
{
249-
GL11.glColor4f( 0.5f, 0.5f, 0.5f, 1.0f );
250-
}
236+
par1Minecraft.renderEngine.bindTexture( FluidCraft.resource("textures/gui/states.png") );
237+
this.hovered = par2 >= this.x && par3 >= this.y && par2 < this.x + this.width && par3 < this.y + this.height;
251238

252-
par1Minecraft.renderEngine.bindTexture( FluidCraft.resource("textures/gui/states.png") );
253-
this.hovered = par2 >= this.x && par3 >= this.y && par2 < this.x + this.width && par3 < this.y + this.height;
239+
// Base button icon will always be bottom right
240+
final int baseButtonUV = 16 * ( SPRITE_SHEET_GRID_SIZE - 1 );
241+
final int textureSize = 16 * SPRITE_SHEET_GRID_SIZE;
254242

255-
final int uv_y = (int) Math.floor( iconIndex / 3.0 );
256-
final int uv_x = iconIndex - uv_y * 3;
243+
final int overlayU = 16 * ( iconIndex % SPRITE_SHEET_GRID_SIZE );
244+
final int overlayV = 16 * ( iconIndex / SPRITE_SHEET_GRID_SIZE );
257245

258-
this.drawTexturedModalRect( 0, 0, Math.round(32F * 16F / 3F), Math.round(32F * 16F / 3F), Math.round(16F * 16F / 3F), Math.round(16F * 16F / 3F) );
259-
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) );
260-
this.mouseDragged( par1Minecraft, par2, par3 );
246+
Gui.drawModalRectWithCustomSizedTexture( relativeX, relativeY, baseButtonUV, baseButtonUV, 16, 16, textureSize, textureSize );
247+
Gui.drawModalRectWithCustomSizedTexture( relativeX, relativeY, overlayU, overlayV, 16, 16, textureSize, textureSize );
261248

249+
this.mouseDragged( par1Minecraft, par2, par3 );
250+
251+
if ( this.halfSize )
252+
{
262253
GL11.glPopMatrix();
263254
}
264255
}
256+
265257
GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
266258
}
267259

src/main/java/com/glodblock/github/client/client/gui/GuiWrapInterface.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class GuiWrapInterface extends GuiInterface {
1818

1919
private GuiFCImgButton fluidPacketOffBtn;
2020
private GuiFCImgButton fluidPacketOnBtn;
21+
private GuiFCImgButton splittingBtn;
2122

2223
public GuiWrapInterface(final InventoryPlayer inventoryPlayer, final IInterfaceHost te) {
2324
super(inventoryPlayer, te);
@@ -33,12 +34,16 @@ protected void addButtons() {
3334
buttonList.add(fluidPacketOffBtn);
3435
fluidPacketOnBtn = new GuiFCImgButton(this.guiLeft - 18, this.guiTop + 44, "SEND_PACKET", "FLUID_PACKET");
3536
buttonList.add(fluidPacketOnBtn);
37+
splittingBtn = new GuiFCImgButton(this.guiLeft - 18, this.guiTop + 62, "SPLITTING", "ALLOW");
38+
buttonList.add(splittingBtn);
3639
}
3740

3841
@Override
3942
protected void actionPerformed(final GuiButton btn) throws IOException {
4043
if (btn == fluidPacketOffBtn || btn == fluidPacketOnBtn) {
4144
FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidPatternTermBtns("WrapDualInterface.FluidPacket", btn == fluidPacketOnBtn ? "0" : "1"));
45+
} else if (btn == splittingBtn) {
46+
FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidPatternTermBtns("WrapDualInterface.AllowSplitting", this.splittingBtn.getCurrentValue().equals("ALLOW") ? "0" : "1"));
4247
} else {
4348
super.actionPerformed(btn);
4449
}
@@ -54,6 +59,9 @@ public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
5459
this.fluidPacketOnBtn.visible = false;
5560
this.fluidPacketOffBtn.visible = true;
5661
}
62+
63+
this.splittingBtn.set(container.allowSplitting ? "ALLOW" : "PREVENT");
64+
5765
super.drawFG(offsetX, offsetY, mouseX, mouseY);
5866
}
5967

src/main/java/com/glodblock/github/client/container/ContainerItemDualInterface.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class ContainerItemDualInterface extends ContainerInterface {
1414

1515
@GuiSync(95)
1616
public boolean fluidPacket = false;
17+
@GuiSync(96)
18+
public boolean allowSplitting = true;
1719
private final DualityInterface dualityInterfaceCopy;
1820

1921
public ContainerItemDualInterface(InventoryPlayer ip, IInterfaceHost te) {
@@ -26,6 +28,7 @@ public void detectAndSendChanges() {
2628
super.detectAndSendChanges();
2729
if (Platform.isServer()) {
2830
fluidPacket = Ae2Reflect.getFluidPacketMode(dualityInterfaceCopy);
31+
allowSplitting = Ae2Reflect.getSplittingMode(dualityInterfaceCopy);
2932
}
3033
}
3134

@@ -34,6 +37,11 @@ public void setFluidPacketInTile(boolean value) {
3437
Ae2Reflect.setFluidPacketMode(dualityInterfaceCopy, value);
3538
}
3639

40+
public void setAllowSplittingInTile(boolean value) {
41+
this.allowSplitting = value;
42+
Ae2Reflect.setSplittingMode(dualityInterfaceCopy, value);
43+
}
44+
3745
@Override
3846
protected void setupUpgrades() {
3947
IItemHandler upgrades = this.getUpgradeable().getInventoryByName("item_upgrades");

src/main/java/com/glodblock/github/client/container/ContainerWrapInterface.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class ContainerWrapInterface extends ContainerInterface {
1212

1313
@GuiSync(95)
1414
public boolean fluidPacket = false;
15+
@GuiSync(96)
16+
public boolean allowSplitting = true;
1517
private final DualityInterface dualityInterfaceCopy;
1618

1719
public ContainerWrapInterface(InventoryPlayer ip, IInterfaceHost te) {
@@ -24,6 +26,7 @@ public void detectAndSendChanges() {
2426
super.detectAndSendChanges();
2527
if (Platform.isServer()) {
2628
fluidPacket = Ae2Reflect.getFluidPacketMode(dualityInterfaceCopy);
29+
allowSplitting = Ae2Reflect.getSplittingMode(dualityInterfaceCopy);
2730
}
2831
}
2932

@@ -32,4 +35,9 @@ public void setFluidPacketInTile(boolean value) {
3235
Ae2Reflect.setFluidPacketMode(dualityInterfaceCopy, value);
3336
}
3437

38+
public void setAllowSplittingInTile(boolean value) {
39+
this.allowSplitting = value;
40+
Ae2Reflect.setSplittingMode(dualityInterfaceCopy, value);
41+
}
42+
3543
}

src/main/java/com/glodblock/github/coremod/CoreModHooks.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ public static BlockingInventoryAdaptor wrapBlockInventory(@Nullable TileEntity t
8181

8282
public static void writeExtraNBTInterface(DualityInterface dual, NBTTagCompound nbt) {
8383
nbt.setBoolean("fluidPacket", Ae2Reflect.getFluidPacketMode(dual));
84+
nbt.setBoolean("allowSplitting", Ae2Reflect.getSplittingMode(dual));
8485
}
8586

8687
public static void readExtraNBTInterface(DualityInterface dual, NBTTagCompound nbt) {
8788
Ae2Reflect.setFluidPacketMode(dual, nbt.getBoolean("fluidPacket"));
89+
Ae2Reflect.setSplittingMode(dual, !nbt.hasKey("allowSplitting") || nbt.getBoolean("allowSplitting"));
8890
}
8991

9092
public static ItemStack removeFluidPackets(InventoryCrafting inv, int index) {

src/main/java/com/glodblock/github/coremod/transform/DualityInterfaceTransformer.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ protected ClassVisitor getClassMapper(ClassVisitor downstream) {
1616
FieldVisitor fv = downstream.visitField(Opcodes.ACC_PUBLIC, "fluidPacket", "Z", null, false);
1717
fv.visitEnd();
1818

19+
// Cannot set instance fields directly, injecting initialization code into the constructor is necessary
20+
downstream.visitField(Opcodes.ACC_PUBLIC, "allowSplitting", "Z", null, false).visitEnd();
21+
1922
return new TransformDualityInterface(Opcodes.ASM5, downstream);
2023
}
2124

@@ -28,6 +31,8 @@ private static class TransformDualityInterface extends ClassVisitor {
2831
@Override
2932
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
3033
switch (name) {
34+
case "<init>":
35+
return new TransformConstructor(api, super.visitMethod(access, name, desc, signature, exceptions));
3136
case "pushItemsOut":
3237
case "pushPattern":
3338
case "isBusy":
@@ -45,6 +50,23 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
4550

4651
}
4752

53+
private static class TransformConstructor extends MethodVisitor {
54+
55+
TransformConstructor(int api, MethodVisitor mv) {
56+
super(api, mv);
57+
}
58+
59+
@Override
60+
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
61+
super.visitMethodInsn(opcode, owner, name, desc, itf);
62+
if (owner.equals("java/lang/Object") && name.equals("<init>") && desc.equals("()V")) {
63+
super.visitVarInsn(Opcodes.ALOAD, 0);
64+
super.visitInsn(Opcodes.ICONST_1);
65+
super.visitFieldInsn(Opcodes.PUTFIELD, "appeng/helpers/DualityInterface", "allowSplitting", "Z");
66+
}
67+
}
68+
}
69+
4870
private static class TransformNBTIO extends MethodVisitor {
4971

5072
boolean in;

src/main/java/com/glodblock/github/inventory/FluidConvertingInventoryAdaptor.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public ItemStack addItems(ItemStack toBeAdded) {
105105
}
106106
}
107107

108-
if (fluid != null && posInterface != null) {
108+
if (fluid != null && posInterface != null && Ae2Reflect.getSplittingMode(self)) {
109109
for (EnumFacing dir : EnumFacing.values()) {
110110
TileEntity te = posInterface.getWorld().getTileEntity(posInterface.getPos().add(dir.getDirectionVec()));
111111
if (te != null) {
@@ -173,23 +173,25 @@ public ItemStack simulateAdd(ItemStack toBeSimulated) {
173173
}
174174

175175
if (fluid != null && posInterface != null) {
176-
for (EnumFacing dir : EnumFacing.values()) {
177-
TileEntity te = posInterface.getWorld().getTileEntity(posInterface.getPos().add(dir.getDirectionVec()));
178-
if (te != null) {
179-
IInterfaceHost interTE = getInterfaceTE(te, dir);
180-
if (interTE != null && isSameGrid(interTE)) {
181-
continue;
182-
}
183-
IFluidInterfaceHost interFTE = getFluidInterfaceTE(te, dir);
184-
if (interFTE != null && isSameGrid(interFTE)) {
185-
continue;
186-
}
187-
IFluidHandler fh = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, dir.getOpposite());
188-
if (fh != null) {
189-
int filled = fh.fill(fluid, false);
190-
if (filled == fluid.amount) {
191-
sus = true;
192-
break;
176+
if (Ae2Reflect.getSplittingMode(self)) {
177+
for (EnumFacing dir : EnumFacing.values()) {
178+
TileEntity te = posInterface.getWorld().getTileEntity(posInterface.getPos().add(dir.getDirectionVec()));
179+
if (te != null) {
180+
IInterfaceHost interTE = getInterfaceTE(te, dir);
181+
if (interTE != null && isSameGrid(interTE)) {
182+
continue;
183+
}
184+
IFluidInterfaceHost interFTE = getFluidInterfaceTE(te, dir);
185+
if (interFTE != null && isSameGrid(interFTE)) {
186+
continue;
187+
}
188+
IFluidHandler fh = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, dir.getOpposite());
189+
if (fh != null) {
190+
int filled = fh.fill(fluid, false);
191+
if (filled == fluid.amount) {
192+
sus = true;
193+
break;
194+
}
193195
}
194196
}
195197
}

src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,19 @@ public IMessage onMessage(CPacketFluidPatternTermBtns message, MessageContext ct
9494
case "DualInterface.FluidPacket":
9595
cdi.setFluidPacketInTile(Value.equals("1"));
9696
break;
97+
case "DualInterface.AllowSplitting":
98+
cdi.setAllowSplittingInTile(Value.equals("1"));
99+
break;
97100
}
98101
} else if (c instanceof ContainerWrapInterface) {
99102
final ContainerWrapInterface cdi = (ContainerWrapInterface) c;
100103
switch (Name) {
101104
case "WrapDualInterface.FluidPacket":
102105
cdi.setFluidPacketInTile(Value.equals("1"));
103106
break;
107+
case "WrapDualInterface.AllowSplitting":
108+
cdi.setAllowSplittingInTile(Value.equals("1"));
109+
break;
104110
}
105111
}
106112
});

0 commit comments

Comments
 (0)