2016-08-02 16:32:13 +02:00
package de.ellpeck.actuallyadditions.mod.inventory.gui ;
2019-05-02 09:10:29 +02:00
import java.io.IOException ;
import java.util.ArrayList ;
import java.util.List ;
2018-05-10 11:38:58 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions ;
2016-08-02 16:32:13 +02:00
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 ;
import net.minecraft.client.gui.GuiButton ;
import net.minecraft.client.renderer.GlStateManager ;
import net.minecraft.entity.player.InventoryPlayer ;
2017-11-30 08:58:26 +01:00
import net.minecraft.item.ItemStack ;
2016-08-02 16:32:13 +02:00
import net.minecraft.nbt.NBTTagCompound ;
import net.minecraft.util.ResourceLocation ;
import net.minecraft.util.text.TextFormatting ;
import net.minecraftforge.fml.relauncher.Side ;
import net.minecraftforge.fml.relauncher.SideOnly ;
@SideOnly ( Side . CLIENT )
2019-05-02 09:10:29 +02:00
public class GuiBag extends GuiWtfMojang {
2016-08-02 16:32:13 +02:00
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 " ) ;
2016-08-02 16:32:13 +02:00
private final ContainerBag container ;
private final boolean isVoid ;
2016-09-12 20:45:29 +02:00
private FilterSettingsGui filter ;
2016-08-02 16:32:13 +02:00
private GuiButton buttonAutoInsert ;
2019-05-02 09:10:29 +02:00
public GuiBag ( ItemStack sack , InventoryPlayer inventory , boolean isVoid ) {
2017-11-30 08:58:26 +01:00
this ( isVoid , new ContainerBag ( sack , inventory , isVoid ) ) ;
2016-08-02 16:32:13 +02:00
}
2019-05-02 09:10:29 +02:00
private GuiBag ( boolean isVoid , ContainerBag container ) {
2016-08-02 16:32:13 +02:00
super ( container ) ;
this . xSize = 176 ;
2019-05-02 09:10:29 +02:00
this . ySize = 90 + 86 ;
2016-08-02 16:32:13 +02:00
this . isVoid = isVoid ;
this . container = container ;
}
@Override
2019-05-02 09:10:29 +02:00
public void initGui ( ) {
2016-08-02 16:32:13 +02:00
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 ) ;
2016-08-02 16:32:13 +02:00
2019-05-02 09:10:29 +02:00
this . buttonAutoInsert = new GuiButton ( 0 , this . guiLeft - 21 , this . guiTop + 8 , 20 , 20 , ( this . container . autoInsert ? TextFormatting . DARK_GREEN : TextFormatting . RED ) + " I " ) ;
2016-08-02 16:32:13 +02:00
this . buttonList . add ( this . buttonAutoInsert ) ;
}
@Override
2019-05-02 09:10:29 +02:00
protected void actionPerformed ( GuiButton button ) throws IOException {
2016-08-02 16:32:13 +02:00
NBTTagCompound data = new NBTTagCompound ( ) ;
data . setInteger ( " ButtonID " , button . id ) ;
2016-11-26 21:32:27 +01:00
data . setInteger ( " PlayerID " , Minecraft . getMinecraft ( ) . player . getEntityId ( ) ) ;
data . setInteger ( " WorldID " , Minecraft . getMinecraft ( ) . world . provider . getDimension ( ) ) ;
2016-08-02 16:32:13 +02:00
PacketHandler . theNetwork . sendToServer ( new PacketClientToServer ( data , PacketHandler . GUI_BUTTON_TO_CONTAINER_HANDLER ) ) ;
}
@Override
2019-05-02 09:10:29 +02:00
public void updateScreen ( ) {
2016-08-02 16:32:13 +02:00
super . updateScreen ( ) ;
this . filter . update ( ) ;
2019-05-02 09:10:29 +02:00
this . buttonAutoInsert . displayString = ( this . container . autoInsert ? TextFormatting . DARK_GREEN : TextFormatting . RED ) + " I " ;
2016-08-02 16:32:13 +02:00
}
@Override
2019-05-02 09:10:29 +02:00
public void drawGuiContainerForegroundLayer ( int x , int y ) {
AssetUtil . displayNameString ( this . fontRenderer , this . xSize , - 10 , StringUtil . localize ( " container. " + ActuallyAdditions . MODID + " . " + ( this . isVoid ? " voidBag " : " bag " ) + " .name " ) ) ;
2016-08-02 16:32:13 +02:00
}
@Override
2019-05-02 09:10:29 +02:00
public void drawGuiContainerBackgroundLayer ( float f , int x , int y ) {
2016-08-02 16:32:13 +02:00
GlStateManager . color ( 1 . 0F , 1 . 0F , 1 . 0F , 1 . 0F ) ;
this . mc . getTextureManager ( ) . bindTexture ( AssetUtil . GUI_INVENTORY_LOCATION ) ;
2019-05-02 09:10:29 +02:00
this . drawTexturedModalRect ( this . guiLeft , this . guiTop + 90 , 0 , 0 , 176 , 86 ) ;
2016-08-02 16:32:13 +02:00
this . mc . getTextureManager ( ) . bindTexture ( this . isVoid ? RES_LOC_VOID : RES_LOC ) ;
this . drawTexturedModalRect ( this . guiLeft , this . guiTop , 0 , 0 , 176 , 90 ) ;
}
@Override
2019-05-02 09:10:29 +02:00
public void drawScreen ( int mouseX , int mouseY , float partialTicks ) {
2016-08-02 16:32:13 +02:00
super . drawScreen ( 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 < > ( ) ;
2019-05-02 09:10:29 +02:00
text . add ( TextFormatting . BOLD + " Auto-Insert " + ( this . container . autoInsert ? " On " : " Off " ) ) ;
2017-06-29 18:30:02 +02:00
text . addAll ( this . mc . fontRenderer . listFormattedStringToWidth ( " Turn this on to make items that get picked up automatically go into the bag. " , 200 ) ) ;
2019-05-02 09:10:29 +02:00
text . addAll ( this . mc . fontRenderer . listFormattedStringToWidth ( TextFormatting . GRAY + " " + TextFormatting . ITALIC + " Note that this WON'T work when you are holding the bag in your hand. " , 200 ) ) ;
2016-08-02 16:32:13 +02:00
this . drawHoveringText ( text , mouseX , mouseY ) ;
}
}
}