2016-08-02 16:32:13 +02:00
/ *
* 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
2016-08-02 16:32:13 +02:00
* /
package de.ellpeck.actuallyadditions.mod.inventory.gui ;
2021-11-14 00:20:29 +01:00
import com.mojang.blaze3d.systems.RenderSystem ;
2023-12-20 22:02:25 +01:00
import de.ellpeck.actuallyadditions.mod.inventory.SackContainer ;
2024-03-05 23:23:49 +01:00
import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer ;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler ;
2016-08-02 16:32:13 +02:00
import de.ellpeck.actuallyadditions.mod.util.AssetUtil ;
2024-03-05 23:23:49 +01:00
import net.minecraft.ChatFormatting ;
import net.minecraft.client.Minecraft ;
2024-03-03 01:20:53 +01:00
import net.minecraft.client.gui.GuiGraphics ;
2024-03-02 21:23:08 +01:00
import net.minecraft.client.gui.components.Button ;
2024-03-05 23:23:49 +01:00
import net.minecraft.nbt.CompoundTag ;
2024-03-02 21:23:08 +01:00
import net.minecraft.network.chat.Component ;
import net.minecraft.resources.ResourceLocation ;
import net.minecraft.world.entity.player.Inventory ;
2024-03-05 23:23:49 +01:00
import net.neoforged.neoforge.network.PacketDistributor ;
2016-08-02 16:32:13 +02:00
2021-12-29 03:36:23 +01:00
import javax.annotation.Nonnull ;
2024-03-05 23:23:49 +01:00
import java.util.ArrayList ;
import java.util.List ;
import java.util.Optional ;
2021-12-29 03:36:23 +01:00
2023-12-20 22:02:25 +01:00
public class SackGui extends AAScreen < SackContainer > {
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
2023-12-20 22:02:25 +01:00
private final SackContainer container ;
2016-08-02 16:32:13 +02:00
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 ;
2016-08-02 16:32:13 +02:00
2024-03-02 21:23:08 +01:00
public SackGui ( SackContainer container , Inventory inventory , Component title ) {
2021-12-29 03:36:23 +01:00
super ( container , inventory , title ) ;
2021-08-22 17:09:06 +02:00
this . imageWidth = 176 ;
this . imageHeight = 90 + 86 ;
2023-03-16 00:17:57 +01:00
this . isVoid = false ; //TODO fix later
2016-08-02 16:32:13 +02:00
this . container = container ;
}
@Override
2021-03-01 20:14:50 +01:00
public void init ( ) {
super . init ( ) ;
2016-08-02 16:32:13 +02:00
2024-03-06 19:59:34 +01:00
this . filter = new FilterSettingsGui ( this . container . filter , this . leftPos + 137 , this . topPos + 10 , this : : addRenderableWidget , 1 ) ;
2024-03-05 23:23:49 +01:00
this . buttonAutoInsert = Button . builder (
2024-03-06 00:02:32 +01:00
Component . literal ( " I " )
2024-03-05 23:23:49 +01:00
. withStyle ( this . container . autoInsert ? ChatFormatting . DARK_GREEN : ChatFormatting . RED ) ,
( button ) - > {
this . container . autoInsert = ! this . container . autoInsert ;
this . buttonAutoInsert . setMessage ( Component . literal ( this . container . autoInsert ? " I " : " O " )
. withStyle ( this . container . autoInsert ? ChatFormatting . DARK_GREEN : ChatFormatting . RED ) ) ;
this . buttonClicked ( 0 ) ;
} ) . pos ( leftPos - 21 , topPos + 8 ) . size ( 20 , 20 )
. build ( ) ;
this . addRenderableWidget ( this . buttonAutoInsert ) ;
2016-08-02 16:32:13 +02:00
}
2024-03-05 23:23:49 +01:00
public void buttonClicked ( int id ) {
CompoundTag data = new CompoundTag ( ) ;
data . putInt ( " ButtonID " , id ) ;
data . putInt ( " PlayerID " , Minecraft . getInstance ( ) . player . getId ( ) ) ;
2024-03-06 00:02:32 +01:00
data . putString ( " WorldID " , Minecraft . getInstance ( ) . level . dimension ( ) . location ( ) . toString ( ) ) ;
2024-03-05 23:23:49 +01:00
PacketDistributor . SERVER . noArg ( ) . send ( new PacketClientToServer ( data , PacketHandler . GUI_BUTTON_TO_CONTAINER_HANDLER ) ) ;
}
2016-08-02 16:32:13 +02:00
@Override
2024-03-02 21:23:08 +01:00
public void containerTick ( ) {
super . containerTick ( ) ;
2021-03-01 20:55:50 +01:00
this . filter . tick ( ) ;
2016-08-02 16:32:13 +02:00
}
2021-11-21 17:31:57 +01:00
/ * @Override
2019-05-02 09:10:29 +02:00
public void drawGuiContainerForegroundLayer ( int x , int y ) {
2021-08-22 17:09:06 +02:00
AssetUtil . displayNameString ( this . font , this . imageWidth , - 10 , StringUtil . localize ( " container. " + ActuallyAdditions . MODID + " . " + ( this . isVoid
2021-02-26 22:15:48 +01:00
? " voidBag "
: " bag " ) + " .name " ) ) ;
2021-11-21 17:31:57 +01:00
} * /
2016-08-02 16:32:13 +02:00
@Override
2024-03-03 01:20:53 +01:00
public void render ( @Nonnull GuiGraphics guiGraphics , int mouseX , int mouseY , float partialTicks ) {
super . render ( guiGraphics , mouseX , mouseY , partialTicks ) ;
this . filter . drawHover ( guiGraphics , mouseX , mouseY ) ;
2016-08-02 16:32:13 +02:00
2024-03-05 23:23:49 +01:00
if ( this . buttonAutoInsert . isMouseOver ( mouseX , mouseY ) ) {
List < Component > text = new ArrayList < > ( ) ;
text . add ( Component . literal ( " Auto-Insert " + ( this . container . autoInsert
2021-02-26 22:15:48 +01:00
? " On "
2024-03-05 23:23:49 +01:00
: " Off " ) ) . withStyle ( ChatFormatting . BOLD ) ) ;
text . add ( Component . literal ( " Turn this on to make items that get picked up automatically go into the bag. " ) ) ; //TODO how to word wrap these to 200?
text . add ( Component . literal ( " Note that this WON'T work when you are holding the bag in your hand. " ) . withStyle ( ChatFormatting . GRAY ) . withStyle ( ChatFormatting . ITALIC ) ) ; //TODO this too
guiGraphics . renderTooltip ( font , text , Optional . empty ( ) , mouseX , mouseY ) ; //TODO i have no idea what im doing here...
}
2016-08-02 16:32:13 +02:00
}
2021-02-27 21:24:26 +01:00
@Override
2024-03-03 01:20:53 +01:00
protected void renderBg ( GuiGraphics guiGraphics , float partialTicks , int x , int y ) {
2024-03-02 21:23:08 +01:00
RenderSystem . setShaderColor ( 1F , 1F , 1F , 1F ) ;
2021-02-27 21:24:26 +01:00
2024-03-03 01:20:53 +01:00
guiGraphics . blit ( AssetUtil . GUI_INVENTORY_LOCATION , this . leftPos , this . topPos + 90 , 0 , 0 , 176 , 86 ) ;
2021-02-27 21:24:26 +01:00
2024-03-03 01:20:53 +01:00
guiGraphics . blit ( this . isVoid ? RES_LOC_VOID : RES_LOC , this . leftPos , this . topPos , 0 , 0 , 176 , 90 ) ;
2021-02-27 21:24:26 +01:00
}
2021-02-26 22:15:48 +01:00
}