mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-12 08:17:32 +00:00
more gui stuff
This commit is contained in:
1 parent
5444d5312c
commit
29907760c3
14 files changed
+316
-10
No files matched your search
@@ -1,4 +1,131 @@
|
||||
package com.glodblock.github.client;
|
||||
|
||||
public class GuiFluidLevelMaintainer {
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.client.gui.widgets.GuiNumberBox;
|
||||
import appeng.core.localization.GuiText;
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.container.ContainerFluidLevelMaintainer;
|
||||
import com.glodblock.github.common.tile.TileFluidLevelMaintainer;
|
||||
import com.glodblock.github.network.CPacketUpdateFluidLevel;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiFluidLevelMaintainer extends AEBaseGui {
|
||||
|
||||
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/fluid_level_maintainer.png");
|
||||
|
||||
private final ContainerFluidLevelMaintainer cont;
|
||||
private final GuiNumberBox[] maintain = new GuiNumberBox[TileFluidLevelMaintainer.MAX_FLUID];
|
||||
private final GuiNumberBox[] request = new GuiNumberBox[TileFluidLevelMaintainer.MAX_FLUID];
|
||||
|
||||
public GuiFluidLevelMaintainer(InventoryPlayer ipl, TileFluidLevelMaintainer tile) {
|
||||
super(new ContainerFluidLevelMaintainer(ipl, tile));
|
||||
this.cont = (ContainerFluidLevelMaintainer) inventorySlots;
|
||||
this.ySize = 214;
|
||||
for (int i = 0; i < TileFluidLevelMaintainer.MAX_FLUID; i ++) {
|
||||
maintain[i] = new GuiNumberBox(this.fontRenderer, this.guiLeft + 39, this.guiTop + 22 + i * 20, 42, 10, Integer.class);
|
||||
request[i] = new GuiNumberBox(this.fontRenderer, this.guiLeft + 102, this.guiTop + 22 + i * 20, 42, 10, Integer.class);
|
||||
}
|
||||
}
|
||||
|
||||
protected void keyTyped(char character, int key) throws IOException {
|
||||
|
||||
if (!this.checkHotbarKeys(key)) {
|
||||
GuiNumberBox focus = null;
|
||||
int id = 0;
|
||||
for (int i = 0; i < TileFluidLevelMaintainer.MAX_FLUID; i ++) {
|
||||
if (maintain[i].isFocused()) {
|
||||
focus = maintain[i];
|
||||
id = i;
|
||||
}
|
||||
if (request[i].isFocused()) {
|
||||
focus = request[i];
|
||||
id = i + 10;
|
||||
}
|
||||
}
|
||||
if (focus != null) {
|
||||
if ((key == 211 || key == 205 || key == 203 || key == 14 || character == '-' || Character.isDigit(character)) && focus.textboxKeyTyped(character, key)) {
|
||||
try {
|
||||
String out = focus.getText();
|
||||
|
||||
boolean fixed;
|
||||
for(fixed = false; out.startsWith("0") && out.length() > 1; fixed = true) {
|
||||
out = out.substring(1);
|
||||
}
|
||||
|
||||
if (fixed) {
|
||||
focus.setText(out);
|
||||
}
|
||||
|
||||
if (out.isEmpty()) {
|
||||
out = "0";
|
||||
}
|
||||
|
||||
long result = Long.parseLong(out);
|
||||
if (result < 0L) {
|
||||
focus.setText("1");
|
||||
result = 1;
|
||||
}
|
||||
|
||||
FluidCraft.proxy.netHandler.sendToServer(new CPacketUpdateFluidLevel(id, (int) result));
|
||||
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
super.keyTyped(character, key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
TileFluidLevelMaintainer tile = this.cont.getTile();
|
||||
IItemHandler inv = tile.getInventoryHandler();
|
||||
for (int i = 0; i < inv.getSlots(); i ++) {
|
||||
if (!inv.getStackInSlot(i).isEmpty()) {
|
||||
this.maintain[i].setText(String.valueOf(inv.getStackInSlot(i).getCount()));
|
||||
}
|
||||
else {
|
||||
this.maintain[i].setText("0");
|
||||
}
|
||||
this.request[i].setText(String.valueOf(tile.getRequest()[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int xCoord, int yCoord, int btn) throws IOException {
|
||||
for (int i = 0; i < TileFluidLevelMaintainer.MAX_FLUID; i ++) {
|
||||
this.configNumberBar(request[i], xCoord, yCoord, btn);
|
||||
this.configNumberBar(maintain[i], xCoord, yCoord, btn);
|
||||
}
|
||||
super.mouseClicked(xCoord, yCoord, btn);
|
||||
}
|
||||
|
||||
private void configNumberBar(GuiNumberBox bar, int xCoord, int yCoord, int btn) {
|
||||
bar.mouseClicked(xCoord, yCoord, btn);
|
||||
if (btn == 1 && bar.isFocused()) {
|
||||
bar.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
fontRenderer.drawString(getGuiDisplayName(I18n.format(NameConst.GUI_FLUID_LEVEL_MAINTAINER)), 8, 6, 0x404040);
|
||||
fontRenderer.drawString(GuiText.inventory.getLocal(), 8, ySize - 94, 0x404040);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
mc.getTextureManager().bindTexture(TEX_BG);
|
||||
drawTexturedModalRect(offsetX, offsetY, 0, 0, 176, ySize);
|
||||
}
|
||||
}
|
||||
+12
-4
@@ -1,6 +1,5 @@
|
||||
package com.glodblock.github.client.container;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import com.glodblock.github.common.item.ItemFluidDrop;
|
||||
@@ -8,6 +7,7 @@ import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.common.tile.TileFluidLevelMaintainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidTankProperties;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
@@ -34,14 +34,13 @@ public class ContainerFluidLevelMaintainer extends AEBaseContainer {
|
||||
|
||||
private static class DisplayFluidSlot extends SlotFake {
|
||||
|
||||
IItemHandler icv;
|
||||
|
||||
public DisplayFluidSlot(IItemHandler inv, int idx, int x, int y) {
|
||||
super(inv, idx, x, y);
|
||||
this.icv = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack is) {
|
||||
//System.out.print(is + "\n");
|
||||
if (is.isEmpty()) {
|
||||
super.putStack(is);
|
||||
return;
|
||||
@@ -59,6 +58,15 @@ public class ContainerFluidLevelMaintainer extends AEBaseContainer {
|
||||
super.putStack(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public ItemStack getDisplayStack() {
|
||||
ItemStack drops = super.getDisplayStack();
|
||||
System.out.print(drops + "\n");
|
||||
FluidStack fluid = ItemFluidDrop.getFluidStack(drops);
|
||||
System.out.print(fluid + "\n");
|
||||
return ItemFluidPacket.newDisplayStack(fluid);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.glodblock.github.common.block;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import com.glodblock.github.common.tile.TileFluidLevelMaintainer;
|
||||
import com.glodblock.github.inventory.GuiType;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockFluidLevelMaintainer extends AEBaseTileBlock {
|
||||
|
||||
public BlockFluidLevelMaintainer() {
|
||||
super(Material.IRON);
|
||||
setTileEntity(TileFluidLevelMaintainer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
|
||||
EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||
if (player.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
TileFluidLevelMaintainer tile = getTileEntity(world, pos);
|
||||
if (tile != null) {
|
||||
if (!world.isRemote) {
|
||||
InventoryHandler.openGui(player, world, pos, facing, GuiType.FLUID_LEVEL_MAINTAINER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,6 +37,10 @@ public class ItemFluidPacket extends Item implements HasCustomModel {
|
||||
@Nonnull
|
||||
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
|
||||
FluidStack fluid = getFluidStack(stack);
|
||||
boolean display = isDisplay(stack);
|
||||
if (display) {
|
||||
return fluid != null ? fluid.getUnlocalizedName() : super.getItemStackDisplayName(stack);
|
||||
}
|
||||
return fluid != null ? String.format("%s, %,d mB", fluid.getLocalizedName(), fluid.amount)
|
||||
: super.getItemStackDisplayName(stack);
|
||||
}
|
||||
@@ -45,6 +49,8 @@ public class ItemFluidPacket extends Item implements HasCustomModel {
|
||||
@Override
|
||||
public void addInformation(@Nonnull ItemStack stack, @Nullable World world, @Nonnull List<String> tooltip, @Nonnull ITooltipFlag flags) {
|
||||
FluidStack fluid = getFluidStack(stack);
|
||||
boolean display = isDisplay(stack);
|
||||
if (display) return;
|
||||
if (fluid != null) {
|
||||
for (String line : I18n.translateToLocal(NameConst.TT_FLUID_PACKET).split("\\\\n")) {
|
||||
tooltip.add(TextFormatting.GRAY + line);
|
||||
@@ -63,6 +69,13 @@ public class ItemFluidPacket extends Item implements HasCustomModel {
|
||||
return (fluid != null && fluid.amount > 0) ? fluid : null;
|
||||
}
|
||||
|
||||
public static boolean isDisplay(ItemStack stack) {
|
||||
if (stack.isEmpty() || !stack.hasTagCompound() || stack.getTagCompound() == null) {
|
||||
return false;
|
||||
}
|
||||
return stack.getTagCompound().getBoolean("DisplayOnly");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FluidStack getFluidStack(@Nullable IAEItemStack stack) {
|
||||
return stack != null ? getFluidStack(stack.getDefinition()) : null;
|
||||
@@ -81,6 +94,22 @@ public class ItemFluidPacket extends Item implements HasCustomModel {
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack newDisplayStack(@Nullable FluidStack fluid) {
|
||||
if (fluid == null) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
FluidStack copy = fluid.copy();
|
||||
copy.amount = 1000;
|
||||
ItemStack stack = new ItemStack(FCItems.FLUID_PACKET);
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
NBTTagCompound fluidTag = new NBTTagCompound();
|
||||
copy.writeToNBT(fluidTag);
|
||||
tag.setTag("FluidStack", fluidTag);
|
||||
tag.setBoolean("DisplayOnly", true);
|
||||
stack.setTagCompound(tag);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IAEItemStack newAeStack(@Nullable FluidStack fluid) {
|
||||
return AEItemStack.fromItemStack(newStack(fluid));
|
||||
|
||||
@@ -14,7 +14,6 @@ import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
@@ -62,6 +61,13 @@ public class TileFluidLevelMaintainer extends AENetworkTile implements IStackWat
|
||||
this.config.setStackInSlot(id, item.getDefinition());
|
||||
}
|
||||
|
||||
public void setConfig(int id, int size) {
|
||||
if (id < 0 || id > MAX_FLUID || this.config.getStackInSlot(id).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
this.config.getStackInSlot(id).setCount(size);
|
||||
}
|
||||
|
||||
public void setRequest(int id, long amount) {
|
||||
if (id < 0 || id > MAX_FLUID) {
|
||||
return;
|
||||
@@ -73,6 +79,10 @@ public class TileFluidLevelMaintainer extends AENetworkTile implements IStackWat
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public long[] getRequest() {
|
||||
return this.request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
@@ -200,4 +210,5 @@ public class TileFluidLevelMaintainer extends AENetworkTile implements IStackWat
|
||||
public void onChangeInventory(IItemHandler iItemHandler, int i, InvOperation invOperation, ItemStack itemStack, ItemStack itemStack1) {
|
||||
markForUpdate();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,10 +16,7 @@ import appeng.parts.reporting.AbstractPartTerminal;
|
||||
import com.glodblock.github.client.*;
|
||||
import com.glodblock.github.client.container.*;
|
||||
import com.glodblock.github.common.part.PartFluidExportBus;
|
||||
import com.glodblock.github.common.tile.TileBurette;
|
||||
import com.glodblock.github.common.tile.TileFluidPacketDecoder;
|
||||
import com.glodblock.github.common.tile.TileFluidPatternEncoder;
|
||||
import com.glodblock.github.common.tile.TileIngredientBuffer;
|
||||
import com.glodblock.github.common.tile.*;
|
||||
import com.glodblock.github.interfaces.FCPriorityHost;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -35,6 +32,18 @@ import java.util.List;
|
||||
|
||||
public enum GuiType {
|
||||
|
||||
FLUID_LEVEL_MAINTAINER(new PartOrTileGuiFactory<TileFluidLevelMaintainer>(TileFluidLevelMaintainer.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, TileFluidLevelMaintainer inv) {
|
||||
return new ContainerFluidLevelMaintainer(player.inventory, inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createClientGui(EntityPlayer player, TileFluidLevelMaintainer inv) {
|
||||
return new GuiFluidLevelMaintainer(player.inventory, inv);
|
||||
}
|
||||
}),
|
||||
|
||||
FLUID_EXPORT_BUS(new PartOrTileGuiFactory<PartFluidExportBus>(PartFluidExportBus.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, PartFluidExportBus inv) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
public class ChannelLoader implements Runnable {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("all")
|
||||
public void run() {
|
||||
int id = 0;
|
||||
FluidCraft.proxy.netHandler.registerMessage(new CPacketSwitchGuis.Handler(), CPacketSwitchGuis.class, id ++, Side.SERVER);
|
||||
@@ -14,6 +15,7 @@ public class ChannelLoader implements Runnable {
|
||||
FluidCraft.proxy.netHandler.registerMessage(new CPacketTransposeFluid.Handler(), CPacketTransposeFluid.class, id ++, Side.SERVER);
|
||||
FluidCraft.proxy.netHandler.registerMessage(new CPacketEncodePattern.Handler(), CPacketEncodePattern.class, id ++, Side.SERVER);
|
||||
FluidCraft.proxy.netHandler.registerMessage(new CPacketLoadPattern.Handler(), CPacketLoadPattern.class, id ++, Side.SERVER);
|
||||
FluidCraft.proxy.netHandler.registerMessage(new CPacketUpdateFluidLevel.Handler(), CPacketUpdateFluidLevel.class, id ++, Side.SERVER);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,8 @@ public class FCBlocks {
|
||||
public static BlockBurette BURETTE;
|
||||
@GameRegistry.ObjectHolder(FluidCraft.MODID + ":" + NameConst.BLOCK_DUAL_INTERFACE)
|
||||
public static BlockDualInterface DUAL_INTERFACE;
|
||||
/*@GameRegistry.ObjectHolder(FluidCraft.MODID + ":" + NameConst.BLOCK_FLUID_LEVEL_MAINTAINER)
|
||||
public static BlockFluidLevelMaintainer FLUID_LEVEL_MAINTAINER;*/
|
||||
|
||||
public static void init(RegistryHandler regHandler) {
|
||||
regHandler.block(NameConst.BLOCK_FLUID_DISCRETIZER, new BlockFluidDiscretizer());
|
||||
@@ -28,6 +30,7 @@ public class FCBlocks {
|
||||
regHandler.block(NameConst.BLOCK_INGREDIENT_BUFFER, new BlockIngredientBuffer());
|
||||
regHandler.block(NameConst.BLOCK_BURETTE, new BlockBurette());
|
||||
regHandler.block(NameConst.BLOCK_DUAL_INTERFACE, new BlockDualInterface());
|
||||
//regHandler.block(NameConst.BLOCK_FLUID_LEVEL_MAINTAINER, new BlockFluidLevelMaintainer());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import com.glodblock.github.client.container.ContainerFluidLevelMaintainer;
|
||||
import com.glodblock.github.common.tile.TileFluidLevelMaintainer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class CPacketUpdateFluidLevel implements IMessage {
|
||||
|
||||
private int index;
|
||||
private int size;
|
||||
|
||||
public CPacketUpdateFluidLevel() {
|
||||
//NO-OP
|
||||
}
|
||||
|
||||
public CPacketUpdateFluidLevel(int id, int value) {
|
||||
this.index = id;
|
||||
this.size = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
index = buf.readInt();
|
||||
size = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(index);
|
||||
buf.writeInt(size);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketUpdateFluidLevel, IMessage> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IMessage onMessage(CPacketUpdateFluidLevel message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().player;
|
||||
player.getServerWorld().addScheduledTask(() -> {
|
||||
if (player.openContainer instanceof ContainerFluidLevelMaintainer) {
|
||||
TileFluidLevelMaintainer te = ((ContainerFluidLevelMaintainer) player.openContainer).getTile();
|
||||
if (message.index > 10) {
|
||||
te.setRequest(message.index - 10, message.size);
|
||||
}
|
||||
else {
|
||||
te.setConfig(message.index, message.size);
|
||||
}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,6 +51,7 @@ public class CommonProxy {
|
||||
GameRegistry.registerTileEntity(TileIngredientBuffer.class, FluidCraft.resource(NameConst.BLOCK_INGREDIENT_BUFFER));
|
||||
GameRegistry.registerTileEntity(TileBurette.class, FluidCraft.resource(NameConst.BLOCK_BURETTE));
|
||||
GameRegistry.registerTileEntity(TileDualInterface.class, FluidCraft.resource(NameConst.BLOCK_DUAL_INTERFACE));
|
||||
//GameRegistry.registerTileEntity(TileFluidLevelMaintainer.class, FluidCraft.resource(NameConst.BLOCK_FLUID_LEVEL_MAINTAINER));
|
||||
(new ChannelLoader()).run();
|
||||
if (ModAndClassUtil.AUTO_P) {
|
||||
initPackagedAutoIntegration();
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"normal": {
|
||||
"model": "ae2fc:fluid_level_maintainer"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "ae2fc:blocks/fluid_level_maintainer"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"parent": "ae2fc:block/fluid_level_maintainer"
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 194 B |
Reference in new issue
Block a user