Skip to content

Commit

Permalink
bunch of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
GlodBlock committed Oct 1, 2022
1 parent 56337ee commit e5d40ae
Show file tree
Hide file tree
Showing 21 changed files with 197 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected void actionPerformed( final GuiButton btn )
}
else if( this.encodeBtn == btn )
{
FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Encode", isShiftKeyDown() ? "2" : "1" ) );
FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Encode", isShiftKeyDown() ? (isCtrlKeyDown() ? "3" : "2") : "1" ) );
}
else if( this.clearBtn == btn )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected void actionPerformed( final GuiButton btn )

if( this.encodeBtn == btn )
{
FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Encode", isShiftKeyDown() ? "2" : "1" ) );
FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Encode", isShiftKeyDown() ? (isCtrlKeyDown() ? "3" : "2") : "1" ) );
}
else if( this.clearBtn == btn )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void drawFG( final int offsetX, final int offsetY, final int mouseX, fina
this.interfaceMode.setState( ( (ContainerInterface) this.cvb ).getInterfaceTerminalMode() == YesNo.YES );
}

this.fontRendererObj.drawString( StatCollector.translateToLocal(NameConst.GUI_FLUID_INTERFACE), 8, 6, 4210752 );
this.fontRendererObj.drawString( getGuiDisplayName( StatCollector.translateToLocal(NameConst.GUI_FLUID_INTERFACE) ), 8, 6, 4210752 );
}

@Override
Expand Down
30 changes: 29 additions & 1 deletion src/main/java/com/glodblock/github/client/gui/GuiFluidIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.glodblock.github.client.gui.container.ContainerFluidIO;
import com.glodblock.github.common.parts.PartFluidImportBus;
import com.glodblock.github.common.parts.PartSharedFluidBus;
import com.glodblock.github.util.NameConst;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;

public class GuiFluidIO extends GuiUpgradeable
Expand All @@ -18,6 +20,32 @@ public GuiFluidIO(InventoryPlayer inventoryPlayer, PartSharedFluidBus te )
this.bus = te;
}

@Override
public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
this.fontRendererObj.drawString( this.getGuiDisplayName(this.bus instanceof PartFluidImportBus ? I18n.format(NameConst.GUI_FLUID_IMPORT) : I18n.format(NameConst.GUI_FLUID_EXPORT)), 8, 6, 4210752 );
this.fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752 );

if( this.redstoneMode != null )
{
this.redstoneMode.set( this.cvb.getRedStoneMode() );
}

if( this.fuzzyMode != null )
{
this.fuzzyMode.set( this.cvb.getFuzzyMode() );
}

if( this.craftMode != null )
{
this.craftMode.set( this.cvb.getCraftingMode() );
}

if( this.schedulingMode != null )
{
this.schedulingMode.set( this.cvb.getSchedulingMode() );
}
}

@Override
protected GuiText getName()
Expand All @@ -26,7 +54,7 @@ protected GuiText getName()
}

public void update(int id, IAEFluidStack stack) {
((ContainerFluidIO)this.cvb).getBus().setFluidInSlot(id, stack);
((ContainerFluidIO) this.cvb).getBus().setFluidInSlot(id, stack);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.glodblock.github.client.gui;

import appeng.api.storage.ITerminalHost;
import appeng.core.localization.GuiText;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerItemAmountChange;
import com.glodblock.github.network.CPacketPatternValueSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,12 @@ protected void standardDetectAndSendChanges()
super.standardDetectAndSendChanges();
}

@Override
public boolean isSlotEnabled( final int idx ) {
if (idx == 0) {
return true;
}
return super.isSlotEnabled(idx);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public void doAction(EntityPlayerMP player, InventoryAction action, int slotId,
}
Slot slot = getSlot(slotId);
ItemStack stack = player.inventory.getItemStack();
if (action == InventoryAction.SPLIT_OR_PLACE_SINGLE && slot.getStack() != null && stack == null && slot.getStack().stackSize == 1) {
return;
}
if (Util.getFluidFromItem(stack) == null || Util.getFluidFromItem(stack).amount <= 0) {
super.doAction(player, action, slotId, id);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.glodblock.github.inventory.PatternConsumer;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.FluidPatternDetails;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.Util;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
Expand All @@ -34,7 +35,7 @@ public ContainerFluidPatternTerminalEx(InventoryPlayer ip, ITerminalHost monitor

@Override
public void encode() {
if (!checkHasFluidPattern()) {
if (!checkHasFluidPattern() && ModAndClassUtil.isExPatternTerminal) {
super.encode();
return;
}
Expand Down Expand Up @@ -151,12 +152,14 @@ public void doAction(EntityPlayerMP player, InventoryAction action, int slotId,
}
Slot slot = getSlot(slotId);
ItemStack stack = player.inventory.getItemStack();
if (action == InventoryAction.SPLIT_OR_PLACE_SINGLE && slot.getStack() != null && stack == null && slot.getStack().stackSize == 1) {
return;
}
if (Util.getFluidFromItem(stack) == null || Util.getFluidFromItem(stack).amount <= 0) {
super.doAction(player, action, slotId, id);
return;
}
if ((slot instanceof SlotFakeCraftingMatrix || slot instanceof SlotPatternOutputs) && stack != null
&& (stack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isContainer(stack))) {
if ((slot instanceof SlotFakeCraftingMatrix || slot instanceof SlotPatternOutputs) && (stack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isContainer(stack))) {
FluidStack fluid = null;
switch (action) {
case PICKUP_OR_SET_DOWN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ public void onChangeInventory(final IInventory inv, final int slot, final InvOpe

}

public void encodeAllItemAndMoveToInventory() {
encode();
ItemStack output = this.patternSlotOUT.getStack();
if(output != null) {
if(this.patternSlotIN.getStack() != null) output.stackSize += this.patternSlotIN.getStack().stackSize;
if (!getPlayerInv().addItemStackToInventory(output)) {
getPlayerInv().player.entityDropItem(output, 0);
}
this.patternSlotOUT.putStack(null);
this.patternSlotIN.putStack(null);
}
}

public void encodeAndMoveToInventory()
{
encode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ public void onChangeInventory(final IInventory inv, final int slot, final InvOpe

}

public void encodeAllItemAndMoveToInventory() {
encode();
ItemStack output = this.patternSlotOUT.getStack();
if(output != null) {
if(this.patternSlotIN.getStack() != null) output.stackSize += this.patternSlotIN.getStack().stackSize;
if (!getPlayerInv().addItemStackToInventory(output)) {
getPlayerInv().player.entityDropItem(output, 0);
}
this.patternSlotOUT.putStack(null);
this.patternSlotIN.putStack(null);
}
}

public void encodeAndMoveToInventory()
{
encode();
Expand Down Expand Up @@ -180,6 +193,7 @@ else if( output == null )
encodedValue.setTag( "in", tagIn );
encodedValue.setTag( "out", tagOut );
encodedValue.setBoolean( "substitute", this.isSubstitute() );
encodedValue.setBoolean( "crafting", false );

output.setTagCompound( encodedValue );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ public ItemFluidEncodedPattern register() {
return this;
}

public ItemStack stack() {
return new ItemStack(this, 1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ public static IAEItemStack wrapFluidPacketStack(IAEItemStack stack) {
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, Util.from(face)) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc,
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.glodblock.github.inventory;

import appeng.api.config.FuzzyMode;
import appeng.tile.misc.TileInterface;
import appeng.tile.networking.TileCableBus;
import appeng.util.InventoryAdaptor;
import appeng.util.inv.IInventoryDestination;
import appeng.util.inv.ItemSlot;
import cofh.api.transport.IItemDuct;
import com.glodblock.github.common.Config;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.parts.PartFluidInterface;
import com.glodblock.github.common.tile.TileFluidInterface;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.BlockPos;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.Util;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
Expand All @@ -34,17 +38,31 @@ public static InventoryAdaptor wrap(TileEntity capProvider, EnumFacing face) {
return InventoryAdaptor.getAdaptor(capProvider, f);
InventoryAdaptor item = InventoryAdaptor.getAdaptor(capProvider, f);
IFluidHandler fluid = capProvider instanceof IFluidHandler ? (IFluidHandler) capProvider : null;
return new FluidConvertingInventoryAdaptor(item, fluid, face);
boolean onmi = false;
if (inter instanceof TileInterface) {
onmi = ((TileInterface) inter).getTargets().size() > 1;
}
Object conduct = null;
if (ModAndClassUtil.COFH && capProvider instanceof IItemDuct) {
conduct = capProvider;
}
return new FluidConvertingInventoryAdaptor(item, fluid, face, new BlockPos(inter), onmi, conduct);
}

private final InventoryAdaptor invItems;
private final IFluidHandler invFluids;
private final ForgeDirection side;
private final BlockPos posInterface;
private final Object eioDuct;
private final boolean onmi;

public FluidConvertingInventoryAdaptor(@Nullable InventoryAdaptor invItems, @Nullable IFluidHandler invFluids, EnumFacing facing) {
public FluidConvertingInventoryAdaptor(@Nullable InventoryAdaptor invItems, @Nullable IFluidHandler invFluids, EnumFacing facing, BlockPos pos, boolean isOnmi, Object eioConduct) {
this.invItems = invItems;
this.invFluids = invFluids;
this.side = Util.from(facing);
this.posInterface = pos;
this.eioDuct = eioConduct;
this.onmi = isOnmi;
}

@Override
Expand All @@ -62,12 +80,34 @@ public ItemStack addItems(ItemStack toBeAdded) {
}
return toBeAdded;
}
if (eioDuct != null) {
return ((IItemDuct) eioDuct).insertItem(side, toBeAdded);
}
return invItems != null ? invItems.addItems(toBeAdded) : toBeAdded;
}

@Override
public ItemStack simulateAdd(ItemStack toBeSimulated) {
if (toBeSimulated.getItem() instanceof ItemFluidPacket) {
if (onmi) {
boolean sus = false;
FluidStack fluid = ItemFluidPacket.getFluidStack(toBeSimulated);
if (fluid != null) {
for (ForgeDirection dir : ForgeDirection.values()) {
TileEntity te = posInterface.getOffSet(dir).getTileEntity();
if (te instanceof IFluidHandler) {
int filled = ((IFluidHandler) te).fill(dir.getOpposite(), fluid, false);
if (filled > 0) {
sus = true;
break;
}
}
}
} else {
sus = true;
}
return sus ? null : toBeSimulated;
}
if (invFluids != null) {
FluidStack fluid = ItemFluidPacket.getFluidStack(toBeSimulated);
if (fluid != null) {
Expand All @@ -80,6 +120,10 @@ public ItemStack simulateAdd(ItemStack toBeSimulated) {
}
return toBeSimulated;
}
//Assert EIO conduct can hold all item, as it is the origin practice in AE2
if (eioDuct != null) {
return null;
}
return invItems != null ? invItems.simulateAdd(toBeSimulated) : toBeSimulated;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.glodblock.github.inventory.gui;

import appeng.client.gui.AEBaseGui;
import com.glodblock.github.util.Ae2ReflectClient;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.inventory.GuiContainer;
Expand Down Expand Up @@ -40,6 +41,7 @@ public void render(int mX, int mY) {
if (region.containsMouse(mX, mY)) {
List<String> tooltip = region.handler.getTooltip();
if (tooltip != null) {
((AEBaseGui) gui).drawTooltip(mX, mY, 0, String.join("\n", tooltip));
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void run() {
GameRegistry.addShapelessRecipe(FLUID_TERMINAL_EX.stack(), FLUID_TERMINAL.stack(), AE2_PROCESS_CAL, AE2_PROCESS_ENG, AE2_PROCESS_LOG);
GameRegistry.addRecipe(new ShapedOreRecipe(BUFFER.stack(), "ILI", "AGF", "IBI", 'I', "ingotIron", 'G', AE2_QUARTZ_GLASS, 'L', AE2_CELL_1K, 'A', AE2_CORE_ANN, 'F', AE2_CORE_FOM, 'B', BUCKET));
GameRegistry.addRecipe(new ShapedOreRecipe(LARGE_BUFFER.stack(), "BGB", "GEG", "BGB", 'B', BUFFER.stack(), 'G', AE2_QUARTZ_GLASS, 'E', AE2_PROCESS_ENG));
GameRegistry.addShapelessRecipe(AE2_BLANK_PATTERN, PATTERN.stack());

if (Config.fluidCells) {
OreDictionary.registerOre("anyCertusCrystal", AE2_PURE_CERTUS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public IMessage onMessage(CPacketFluidPatternTermBtns message, MessageContext ct
cpt.getPatternTerminal().setCraftingRecipe(Value.equals("1"));
break;
case "PatternTerminal.Encode":
if (Value.equals("2"))
if (Value.equals("3"))
cpt.encodeAllItemAndMoveToInventory();
else if (Value.equals("2"))
cpt.encodeAndMoveToInventory();
else
cpt.encode();
Expand All @@ -89,7 +91,9 @@ public IMessage onMessage(CPacketFluidPatternTermBtns message, MessageContext ct
final ContainerFluidPatternTerminalEx cpt = (ContainerFluidPatternTerminalEx) c;
switch (Name) {
case "PatternTerminal.Encode":
if (Value.equals("2"))
if (Value.equals("3"))
cpt.encodeAllItemAndMoveToInventory();
else if (Value.equals("2"))
cpt.encodeAndMoveToInventory();
else
cpt.encode();
Expand Down
Loading

0 comments on commit e5d40ae

Please sign in to comment.