mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-17 19:05:29 +00:00
add fluid auto filler
This commit is contained in:
1 parent
3f35dadb41
commit
44ff338023
14 files changed
+522
-10
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package com.glodblock.github.client.gui;
|
||||
|
||||
import appeng.client.gui.AEBaseMEGui;
|
||||
import appeng.core.localization.GuiText;
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidAutoFiller;
|
||||
import com.glodblock.github.common.tile.TileFluidAutoFiller;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class GuiFluidAutoFiller extends AEBaseMEGui {
|
||||
protected EntityPlayer player;
|
||||
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/fluid_auto_filler.png");
|
||||
|
||||
public GuiFluidAutoFiller(InventoryPlayer ipl, TileFluidAutoFiller tile) {
|
||||
super(new ContainerFluidAutoFiller(ipl, tile));
|
||||
this.player = ipl.player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
mc.getTextureManager().bindTexture(TEX_BG);
|
||||
drawTexturedModalRect(offsetX, offsetY, 0, 0, 176, ySize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
fontRendererObj.drawString(getGuiDisplayName(I18n.format(NameConst.GUI_FLUID_AUTO_FILLER)), 8, 6, 0x404040);
|
||||
fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, ySize - 94, 0x404040);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.glodblock.github.client.gui.container;
|
||||
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import com.glodblock.github.common.tile.TileFluidAutoFiller;
|
||||
import com.glodblock.github.util.Util;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
|
||||
public class ContainerFluidAutoFiller extends AEBaseContainer {
|
||||
public static class FakeSlot extends SlotFake {
|
||||
public FakeSlot(IInventory inv, int idx, int x, int y) {
|
||||
super(inv, idx, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack is) {
|
||||
MutablePair<Boolean, ItemStack> result = ContainerFluidAutoFiller.isItemValid(is);
|
||||
if (result.left) {
|
||||
if (super.getHasStack()) super.clearStack();
|
||||
super.putStack(result.right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final TileFluidAutoFiller tile;
|
||||
|
||||
public ContainerFluidAutoFiller(InventoryPlayer ipl, TileFluidAutoFiller tile) {
|
||||
super(ipl, tile);
|
||||
this.tile = tile;
|
||||
addSlotToContainer(new FakeSlot(tile.getInventory(), 0, 80, 35));
|
||||
bindPlayerInventory(ipl, 0, 84);
|
||||
}
|
||||
|
||||
public static MutablePair<Boolean, ItemStack> isItemValid(ItemStack itemStack) {
|
||||
boolean result = Util.FluidUtil.isFluidContainer(itemStack);
|
||||
if (!result) return new MutablePair<>(false, null);
|
||||
ItemStack tank = itemStack.copy();
|
||||
tank.stackSize = 1;
|
||||
if (Util.FluidUtil.isFilled(tank)) {
|
||||
return new MutablePair<>(true, Util.FluidUtil.clearFluid(tank));
|
||||
} else {
|
||||
return new MutablePair<>(true, tank);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
tile.updatePattern();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user