ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiBag.java

117 lines
4.8 KiB
Java
Raw Normal View History

/*
* This file ("GuiBag.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.inventory.gui;
2021-02-27 21:24:26 +01:00
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
2018-05-10 11:38:58 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerBag;
import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.client.Minecraft;
2021-02-27 21:24:26 +01:00
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.entity.player.PlayerInventory;
2021-02-26 22:15:48 +01:00
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation;
2021-02-27 21:24:26 +01:00
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
2021-02-26 22:15:48 +01:00
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
2021-02-27 21:24:26 +01:00
public class GuiBag extends GuiWtfMojang<ContainerBag> {
2016-11-19 23:12:22 +01:00
private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("gui_bag");
private static final ResourceLocation RES_LOC_VOID = AssetUtil.getGuiLocation("gui_void_bag");
private final ContainerBag container;
private final boolean isVoid;
2016-09-12 20:45:29 +02:00
private FilterSettingsGui filter;
2021-02-27 21:24:26 +01:00
private Button buttonAutoInsert;
2021-02-27 21:24:26 +01:00
public GuiBag(ContainerBag container, PlayerInventory inventory, ITextComponent title) {
super(container, inventory);
this.xSize = 176;
2019-05-02 09:10:29 +02:00
this.ySize = 90 + 86;
2021-02-27 21:24:26 +01:00
this.isVoid = container.isVoid;
this.container = container;
}
@Override
2019-05-02 09:10:29 +02:00
public void initGui() {
super.initGui();
2019-05-02 09:10:29 +02:00
this.filter = new FilterSettingsGui(this.container.filter, this.guiLeft + 138, this.guiTop + 10, this.buttonList);
2021-02-26 22:15:48 +01:00
this.buttonAutoInsert = new GuiButton(0, this.guiLeft - 21, this.guiTop + 8, 20, 20, (this.container.autoInsert
? TextFormatting.DARK_GREEN
: TextFormatting.RED) + "I");
this.addButton(this.buttonAutoInsert);
}
@Override
2019-05-02 09:10:29 +02:00
protected void actionPerformed(GuiButton button) throws IOException {
2021-02-26 22:15:48 +01:00
CompoundNBT data = new CompoundNBT();
data.setInteger("ButtonID", button.id);
2021-02-26 22:15:48 +01:00
data.setInteger("PlayerID", Minecraft.getInstance().player.getEntityId());
data.setInteger("WorldID", Minecraft.getInstance().world.provider.getDimension());
2021-02-27 16:33:00 +01:00
PacketHandler.THE_NETWORK.sendToServer(new PacketClientToServer(data, PacketHandler.GUI_BUTTON_TO_CONTAINER_HANDLER));
}
@Override
2019-05-02 09:10:29 +02:00
public void updateScreen() {
super.updateScreen();
this.filter.update();
2021-02-26 22:15:48 +01:00
this.buttonAutoInsert.displayString = (this.container.autoInsert
? TextFormatting.DARK_GREEN
: TextFormatting.RED) + "I";
}
@Override
2019-05-02 09:10:29 +02:00
public void drawGuiContainerForegroundLayer(int x, int y) {
2021-02-27 21:24:26 +01:00
AssetUtil.displayNameString(this.font, this.xSize, -10, StringUtil.localize("container." + ActuallyAdditions.MODID + "." + (this.isVoid
2021-02-26 22:15:48 +01:00
? "voidBag"
: "bag") + ".name"));
}
@Override
2021-02-27 21:24:26 +01:00
public void render(MatrixStack stack, int mouseX, int mouseY, float partialTicks) {
super.render(stack, mouseX, mouseY, partialTicks);
this.filter.drawHover(mouseX, mouseY);
2019-05-02 09:10:29 +02:00
if (this.buttonAutoInsert.isMouseOver()) {
2019-02-27 19:53:05 +01:00
List<String> text = new ArrayList<>();
2021-02-26 22:15:48 +01:00
text.add(TextFormatting.BOLD + "Auto-Insert " + (this.container.autoInsert
? "On"
: "Off"));
2021-02-27 21:24:26 +01:00
text.addAll(this.font.listFormattedStringToWidth("Turn this on to make items that get picked up automatically go into the bag.", 200));
text.addAll(this.font.listFormattedStringToWidth(TextFormatting.GRAY + "" + TextFormatting.ITALIC + "Note that this WON'T work when you are holding the bag in your hand.", 200));
this.renderToolTip(stack, text, mouseX, mouseY, this.getMinecraft().fontRenderer);
}
}
2021-02-27 21:24:26 +01:00
@Override
protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int x, int y) {
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
this.getMinecraft().getTextureManager().bindTexture(AssetUtil.GUI_INVENTORY_LOCATION);
this.blit(matrixStack, this.guiLeft, this.guiTop + 90, 0, 0, 176, 86);
this.getMinecraft().getTextureManager().bindTexture(this.isVoid
? RES_LOC_VOID
: RES_LOC);
this.blit(matrixStack, this.guiLeft, this.guiTop, 0, 0, 176, 90);
}
2021-02-26 22:15:48 +01:00
}