Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

GuiTextField crash


Stenbergcsgo
 Share

Recommended Posts

I created a custom GUI:

package com.mta.utzonmod.client.gui;
 
import java.io.IOException;
 
import org.lwjgl.input.Keyboard;
 
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.ChatAllowedCharacters;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
 
@SideOnly(Side.CLIENT)
public class signInputGui extends GuiScreen {
   
    private GuiButton doneBtn;
    private int updateCounter;
    public GuiTextField textfield = new GuiTextField(1, this.fontRenderer, this.width / 2 - 68, this.height / 2 - 46, 137, 20);
    public String playerInput;
   
   
    public void initGui() {
        this.buttonList.clear();
        Keyboard.enableRepeatEvents(true);
        this.doneBtn = this.addButton(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 120, I18n.format("gui.done"))); 
        textfield.setMaxStringLength(30);
        textfield.setText("");
        this.textfield.setFocused(true);
    }
   
    public void keyTyped(char c, int i) throws IOException {
        super.keyTyped(c, i);
        this.textfield.textboxKeyTyped(c, i);
       
    }
   
    public void onGuiClosed() {
        textfield.setFocused(false);
        Keyboard.enableRepeatEvents(false);
    }
   
    public void updateScreen() {
        ++this.updateCounter;
        this.textfield.updateCursorCounter();
        playerInput = textfield.getText();
    }
   
    protected void actionPerformed(GuiButton button) throws IOException {
        if(button.enabled) {
            if(button.id == 0) {
                this.mc.displayGuiScreen((GuiScreen)null);
            }
        }
    }
   
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
        this.drawDefaultBackground();
        this.drawCenteredString(this.fontRenderer, "Insert schematic name",this.width / 2, 40, 16777215);
        this.textfield.drawTextBox();
        super.drawScreen(mouseX, mouseY, partialTicks);
    }
   
    protected void mouseClicked(int x, int y, int btn) throws IOException {
        super.mouseClicked(x, y, btn);
        this.textfield.mouseClicked(x, y, btn);
    }
   
    public String getPlayerInput() {
        return playerInput;
    }
}

 

And it works (somewhat) - If I open the game, and wait for a bit, then use my custom item with GUI it works as expected, but if I use the item as soon as I get into the server, I get a crash. Because of the nature of the error I expect it has something to do with the initialization, but in what manner I am unclear.

 

Full error:

---- Minecraft Crash Report ----
// Oh - I know what I did wrong!

Time: 4/9/18 11:57 AM
Description: Rendering screen

java.lang.NullPointerException: Rendering screen
	at net.minecraft.client.gui.GuiTextField.drawTextBox(GuiTextField.java:545)
	at com.mta.utzonmod.client.gui.signInputGui.drawScreen(signInputGui.java:65)
	at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:368)
	at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1177)
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1207)
	at net.minecraft.client.Minecraft.run(Minecraft.java:441)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:26)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
	at net.minecraft.client.gui.GuiTextField.drawTextBox(GuiTextField.java:545)
	at com.mta.utzonmod.client.gui.signInputGui.drawScreen(signInputGui.java:65)
	at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:368)

-- Screen render details --
Details:
	Screen name: com.mta.utzonmod.client.gui.signInputGui
	Mouse location: Scaled: (105, 197). Absolute: (427, 240)
	Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2

-- Affected level --
Details:
	Level name: MpServer
	All players: 1 total; [EntityPlayerSP['Player503'/163, l='MpServer', x=2020.62, y=3.00, z=1209.47]]
	Chunk stats: MultiplayerChunkCache: 622, 622
	Level seed: 0
	Level generator: ID 01 - flat, ver 0. Features enabled: false
	Level generator options: 
	Level spawn location: World: (1994,4,1180), Chunk: (at 10,0,12 in 124,73; contains blocks 1984,0,1168 to 1999,255,1183), Region: (3,2; contains chunks 96,64 to 127,95, blocks 1536,0,1024 to 2047,255,1535)
	Level time: 13786 game time, 13786 day time
	Level dimension: 0
	Level storage version: 0x00000 - Unknown?
	Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
	Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
	Forced entities: 79 total; [EntitySlime['Slime'/128, l='MpServer', x=2056.45, y=4.89, z=1280.15], EntityChicken['Chicken'/130, l='MpServer', x=2066.11, y=4.00, z=1252.91], EntityVillager['Villager'/132, l='MpServer', x=2094.50, y=5.00, z=1206.49], EntityVillager['Villager'/133, l='MpServer', x=2081.49, y=5.00, z=1200.07], EntityPlayerSP['Player503'/163, l='MpServer', x=2020.62, y=3.00, z=1209.47], EntitySlime['Slime'/40, l='MpServer', x=1945.09, y=4.00, z=1152.57], EntitySkeleton['Skeleton'/42, l='MpServer', x=1945.50, y=4.00, z=1201.50], EntitySkeleton['Skeleton'/43, l='MpServer', x=1940.81, y=4.00, z=1203.76], EntityCreeper['Creeper'/44, l='MpServer', x=1944.48, y=4.00, z=1208.58], EntityCreeper['Creeper'/45, l='MpServer', x=1951.50, y=4.00, z=1209.89], EntityPig['Pig'/47, l='MpServer', x=1945.79, y=4.00, z=1223.39], EntitySlime['Slime'/48, l='MpServer', x=1949.68, y=4.00, z=1219.31], EntitySlime['Slime'/49, l='MpServer', x=1959.03, y=4.00, z=1238.07], EntitySlime['Slime'/50, l='MpServer', x=1941.76, y=4.11, z=1235.26], EntitySlime['Slime'/51, l='MpServer', x=1946.12, y=4.00, z=1241.39], EntitySlime['Slime'/53, l='MpServer', x=1951.55, y=4.00, z=1267.16], EntitySlime['Slime'/54, l='MpServer', x=1959.71, y=4.00, z=1279.04], EntitySlime['Slime'/56, l='MpServer', x=1961.88, y=4.28, z=1203.91], EntitySlime['Slime'/57, l='MpServer', x=1955.53, y=4.00, z=1213.90], EntityPig['Pig'/58, l='MpServer', x=1966.21, y=4.00, z=1214.67], EntitySheep['Sheep'/59, l='MpServer', x=1958.36, y=4.00, z=1225.19], EntitySlime['Slime'/60, l='MpServer', x=1957.15, y=5.04, z=1224.21], EntitySlime['Slime'/61, l='MpServer', x=1963.73, y=5.04, z=1211.60], EntitySlime['Slime'/62, l='MpServer', x=1962.09, y=4.11, z=1229.70], EntitySlime['Slime'/63, l='MpServer', x=1952.97, y=4.00, z=1235.64], EntitySlime['Slime'/64, l='MpServer', x=1960.68, y=4.14, z=1239.06], EntitySlime['Slime'/69, l='MpServer', x=1968.83, y=4.34, z=1154.73], EntitySheep['Sheep'/70, l='MpServer', x=1980.82, y=4.00, z=1168.44], EntitySlime['Slime'/71, l='MpServer', x=1988.63, y=4.34, z=1202.20], EntitySlime['Slime'/72, l='MpServer', x=1985.39, y=4.48, z=1204.31], EntitySlime['Slime'/73, l='MpServer', x=1980.55, y=4.00, z=1198.62], EntitySlime['Slime'/74, l='MpServer', x=1973.44, y=4.00, z=1224.57], EntitySlime['Slime'/75, l='MpServer', x=1983.09, y=4.00, z=1221.68], EntitySlime['Slime'/76, l='MpServer', x=1984.92, y=5.00, z=1240.47], EntitySlime['Slime'/77, l='MpServer', x=1980.69, y=4.03, z=1232.13], EntitySlime['Slime'/78, l='MpServer', x=1983.00, y=4.14, z=1239.41], EntitySlime['Slime'/79, l='MpServer', x=1973.35, y=4.00, z=1240.43], EntitySlime['Slime'/80, l='MpServer', x=1985.13, y=4.00, z=1246.03], EntitySlime['Slime'/81, l='MpServer', x=1970.89, y=5.00, z=1262.21], EntitySlime['Slime'/82, l='MpServer', x=1975.30, y=4.77, z=1257.05], EntitySlime['Slime'/84, l='MpServer', x=1977.84, y=4.00, z=1277.74], EntitySlime['Slime'/86, l='MpServer', x=1974.92, y=5.00, z=1280.19], EntitySlime['Slime'/91, l='MpServer', x=1996.85, y=4.77, z=1137.84], EntitySlime['Slime'/92, l='MpServer', x=1997.24, y=4.14, z=1142.90], EntitySlime['Slime'/93, l='MpServer', x=1986.24, y=4.00, z=1203.97], EntitySlime['Slime'/94, l='MpServer', x=2002.33, y=4.63, z=1199.57], EntitySlime['Slime'/95, l='MpServer', x=1986.77, y=4.78, z=1222.70], EntitySlime['Slime'/96, l='MpServer', x=1983.13, y=4.14, z=1254.33], EntitySlime['Slime'/97, l='MpServer', x=1988.22, y=4.00, z=1272.83], EntitySlime['Slime'/98, l='MpServer', x=1983.19, y=4.77, z=1289.70], EntitySlime['Slime'/99, l='MpServer', x=2010.67, y=4.18, z=1143.98], EntitySlime['Slime'/100, l='MpServer', x=2016.56, y=4.63, z=1225.59], EntitySlime['Slime'/101, l='MpServer', x=2007.20, y=4.00, z=1217.88], EntitySlime['Slime'/102, l='MpServer', x=2016.44, y=5.06, z=1239.04], EntityHorse['Horse'/103, l='MpServer', x=2013.70, y=4.00, z=1257.58], EntityCow['Cow'/104, l='MpServer', x=1998.74, y=4.00, z=1276.43], EntitySheep['Sheep'/105, l='MpServer', x=2019.45, y=4.00, z=1133.78], EntitySheep['Sheep'/106, l='MpServer', x=2029.23, y=4.00, z=1185.67], EntitySlime['Slime'/107, l='MpServer', x=2019.56, y=4.00, z=1215.09], EntitySlime['Slime'/108, l='MpServer', x=2023.58, y=4.03, z=1214.03], EntitySlime['Slime'/109, l='MpServer', x=2027.03, y=4.34, z=1235.00], EntitySlime['Slime'/110, l='MpServer', x=2014.67, y=4.00, z=1241.15], EntitySlime['Slime'/111, l='MpServer', x=2036.40, y=5.04, z=1259.85], EntityHorse['Horse'/112, l='MpServer', x=2022.44, y=4.00, z=1255.49], EntityHorse['Horse'/113, l='MpServer', x=2021.36, y=4.00, z=1255.50], EntitySlime['Slime'/114, l='MpServer', x=2028.02, y=4.78, z=1259.45], EntityPig['Pig'/115, l='MpServer', x=2037.19, y=4.00, z=1187.33], EntitySlime['Slime'/116, l='MpServer', x=2036.34, y=5.00, z=1219.13], EntityChicken['Chicken'/117, l='MpServer', x=2035.82, y=4.00, z=1231.89], EntityZombie['Zombie'/118, l='MpServer', x=2046.29, y=4.00, z=1219.43], EntityItem['item.item.egg'/119, l='MpServer', x=2043.57, y=4.00, z=1247.18], EntityCow['Cow'/120, l='MpServer', x=2058.47, y=4.00, z=1182.38], EntityPig['Pig'/121, l='MpServer', x=2061.77, y=4.00, z=1188.39], EntitySlime['Slime'/122, l='MpServer', x=2059.71, y=4.28, z=1195.77], EntitySlime['Slime'/123, l='MpServer', x=2061.93, y=4.78, z=1218.27], EntityChicken['Chicken'/124, l='MpServer', x=2048.45, y=4.00, z=1238.32], EntityChicken['Chicken'/125, l='MpServer', x=2061.10, y=4.00, z=1254.83], EntityItem['item.item.egg'/126, l='MpServer', x=2059.97, y=4.00, z=1261.94], EntitySlime['Slime'/127, l='MpServer', x=2048.50, y=4.03, z=1286.58]]
	Retry entities: 0 total; []
	Server brand: fml,forge
	Server type: Integrated singleplayer server
Stacktrace:
	at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:461)
	at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2896)
	at net.minecraft.client.Minecraft.run(Minecraft.java:462)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:26)

-- System Details --
Details:
	Minecraft Version: 1.12.2
	Operating System: Windows 8.1 (amd64) version 6.3
	Java Version: 1.8.0_131, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 131987664 bytes (125 MB) / 844103680 bytes (805 MB) up to 1884815360 bytes (1797 MB)
	JVM Flags: 0 total; 
	IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
	FML: MCP 9.42 Powered by Forge 14.23.2.2624 5 mods loaded, 5 mods active
	States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

	| State     | ID        | Version      | Source                           | Signature |
	|:--------- |:--------- |:------------ |:-------------------------------- |:--------- |
	| UCHIJAAAA | minecraft | 1.12.2       | minecraft.jar                    | None      |
	| UCHIJAAAA | mcp       | 9.42         | minecraft.jar                    | None      |
	| UCHIJAAAA | FML       | 8.0.99.99    | forgeSrc-1.12.2-14.23.2.2624.jar | None      |
	| UCHIJAAAA | forge     | 14.23.2.2624 | forgeSrc-1.12.2-14.23.2.2624.jar | None      |
	| UCHIJAAAA | um        | 1.0          | bin                              | None      |

	Loaded coremods (and transformers): 
	GL info: ' Vendor: 'Intel' Version: '4.2.0 - Build 10.18.10.3910' Renderer: 'Intel(R) HD Graphics 4400'
	Launched Version: 1.12.2
	LWJGL: 2.9.4
	OpenGL: Intel(R) HD Graphics 4400 GL version 4.2.0 - Build 10.18.10.3910, Intel
	GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

	Using VBOs: Yes
	Is Modded: Definitely; Client brand changed to 'fml,forge'
	Type: Client (map_client.txt)
	Resource Packs: 
	Current Language: English (US)
	Profiler Position: N/A (disabled)
	CPU: 4x Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz

 

 

Link to comment
Share on other sites

Yeah, now that I looked up the cause of the error in GuiTextField

String s = this.fontRenderer.trimStringToWidth(this.text.substring(this.lineScrollOffset), this.getWidth());

It seems that the problem is that lineScrollOffset or this.getWidth() or this.text is null. You can debug that by putting

System.out.println("textbox.text : " + textbox.getText());
System.out.println("lineScrollOffset : " + textbox.getWidth());

before line 65 in your class, if both of these don't return null, then lineScrollOffset must be null, or there is something in hte trimStringToWidth method that makes it return null

Link to comment
Share on other sites

Alright I tried debugging and these are the results:

[09:39:18] [Server thread/INFO] [STDOUT]: [com.mta.utzonmod.client.gui.signInputGui:initGui:34]: textbox.text : 
[09:39:18] [Server thread/INFO] [STDOUT]: [com.mta.utzonmod.client.gui.signInputGui:initGui:35]: lineScrollOffset : 129

textbox.text is empty because I put it to: ""

 

So it's not null.

 

Doesn't seem like the textbox is the issue

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • As far as i know you able to replace only helmet, but not rest of the armor pieces) At least it was before 1.12
    • Ahh ok  But also in mods with custom armor you normally use resourcepacks for the model (every mod has a built-in resource pack), so there really is no need. If you want to do it anyway ... it's your choice 
    • Well, im just learning) Wanna make my own mods in future.
    • Hi! You don't need an extra Mod to do this, you can just use a resource pack and replace the armor texture and model
    • hello. I try to create my custom chest BUT that's make me crazy. 1.if I put an item in my custom chest it become doubled, and if I click it ,it will be dispeared.:( 2.the custom chest what i made use the same container in different blocks.   TileEntity: public class SFCTileEntity extends TileEntity implements INamedContainerProvider { public static final int NUMBER_OF_SLOTS = 27; public SFCTileEntity() { super(TileEntityTypeRegistry.TileEntity.get()); chestContents = ChestContents.createForTileEntity(NUMBER_OF_SLOTS, this::canPlayerAccessInventory, this::setChanged); } public boolean canPlayerAccessInventory(PlayerEntity player) { if (this.level.getBlockEntity(this.worldPosition) != this) return false; final double X_CENTRE_OFFSET = 0.5; final double Y_CENTRE_OFFSET = 0.5; final double Z_CENTRE_OFFSET = 0.5; final double MAXIMUM_DISTANCE_SQ = 8.0 * 8.0; return player.distanceToSqr(worldPosition.getX() + X_CENTRE_OFFSET, worldPosition.getY() + Y_CENTRE_OFFSET, worldPosition.getZ() + Z_CENTRE_OFFSET) < MAXIMUM_DISTANCE_SQ; } private static final String CHESTCONTENTS_INVENTORY_TAG = "contents"; @Override public CompoundNBT save(CompoundNBT parentNBTTagCompound) { super.save(parentNBTTagCompound); CompoundNBT inventoryNBT = chestContents.serializeNBT(); parentNBTTagCompound.put(CHESTCONTENTS_INVENTORY_TAG, inventoryNBT); return parentNBTTagCompound; } @Override public void load(BlockState blockState, CompoundNBT parentNBTTagCompound) { super.load(blockState, parentNBTTagCompound); CompoundNBT inventoryNBT = parentNBTTagCompound.getCompound(CHESTCONTENTS_INVENTORY_TAG); chestContents.deserializeNBT(inventoryNBT); } @Override @Nullable public SUpdateTileEntityPacket getUpdatePacket() { CompoundNBT nbtTagCompound = new CompoundNBT(); save(nbtTagCompound); int tileEntityType = 42; return new SUpdateTileEntityPacket(this.worldPosition, tileEntityType, nbtTagCompound); } @Override public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { BlockState blockState = level.getBlockState(worldPosition); load(blockState, pkt.getTag()); } @Override public CompoundNBT getUpdateTag() { CompoundNBT nbtTagCompound = new CompoundNBT(); save(nbtTagCompound); return nbtTagCompound; } /* Populates this TileEntity with information from the tag, used by vanilla to transmit from server to client * The vanilla default is suitable for this example but I've included an explicit definition anyway. */ @Override public void handleUpdateTag(BlockState blockState, CompoundNBT tag) { this.load(blockState, tag); } @Override public ITextComponent getDisplayName() { return null; } @Nullable @Override public Container createMenu(int windowID, PlayerInventory playerInventory, PlayerEntity playerEntity) { return SFContainer.createContainerServerSide(windowID, playerInventory, chestContents); } public static ChestContents getChestContents() { return chestContents; } private static ChestContents chestContents; }   Container: public class SFContainer extends Container { private static final int HOTBAR_SLOT_COUNT = 9; private static final int PLAYER_INVENTORY_ROW_COUNT = 3; private static final int PLAYER_INVENTORY_COLUMN_COUNT = 9; private static final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT; private static final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT; private static final int VANILLA_FIRST_SLOT_INDEX = 0; private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT; private static final int TE_INVENTORY_SLOT_COUNT = SFCTileEntity.NUMBER_OF_SLOTS; public static final int TILE_INVENTORY_YPOS = 18; public static final int PLAYER_INVENTORY_YPOS = 86; public SFContainer(int windowID, PlayerInventory playerInventory, ChestContents chestContents) { super(ContainerTypeRegistry.Container.get(), windowID); PlayerInvWrapper playerInventoryForge = new PlayerInvWrapper(playerInventory); this.chestContents = chestContents; final int SLOT_X_SPACING = 18; final int SLOT_Y_SPACING = 18; final int HOTBAR_XPOS = 8; final int HOTBAR_YPOS = 144; for (int x = 0; x < HOTBAR_SLOT_COUNT; x++) { int slotNumber = x; addSlot(new SlotItemHandler(playerInventoryForge, slotNumber, HOTBAR_XPOS + SLOT_X_SPACING * x, HOTBAR_YPOS)); } final int PLAYER_INVENTORY_XPOS = 8; // Add the rest of the player's inventory to the gui for (int y = 0; y < PLAYER_INVENTORY_ROW_COUNT; y++) { for (int x = 0; x < PLAYER_INVENTORY_COLUMN_COUNT; x++) { int slotNumber = HOTBAR_SLOT_COUNT + y * PLAYER_INVENTORY_COLUMN_COUNT + x; int xpos = PLAYER_INVENTORY_XPOS + x * SLOT_X_SPACING; int ypos = PLAYER_INVENTORY_YPOS + y * SLOT_Y_SPACING; addSlot(new SlotItemHandler(playerInventoryForge, slotNumber, xpos, ypos)); } } // Add the tile inventory container to the gui for(int i = 0;i<9;i++){ addSlot(new Slot(chestContents, i, 8+18*i, 18)); addSlot(new Slot(chestContents, i+9, 8+18*i, 36)); addSlot(new Slot(chestContents, i+18, 8+18*i, 54)); } } public static SFContainer createContainerServerSide(int windowID, PlayerInventory playerInventory, ChestContents chestContents) { return new SFContainer(windowID, playerInventory, chestContents); } public static SFContainer createContainerClientSide(int windowID, PlayerInventory playerInventory, net.minecraft.network.PacketBuffer extraData) { ChestContents chestContents = ChestContents.createForClientSideContainer(SFCTileEntity.NUMBER_OF_SLOTS); return new SFContainer(windowID, playerInventory, chestContents); } @Override public boolean stillValid(PlayerEntity playerEntity) { return chestContents.stillValid(playerEntity); } @Override public ItemStack quickMoveStack(PlayerEntity playerEntity, int sourceSlotIndex) { Slot sourceSlot = getSlot(sourceSlotIndex); if (sourceSlot == null || !sourceSlot.hasItem()) return ItemStack.EMPTY; //EMPTY_ITEM ItemStack sourceStack = sourceSlot.getItem(); ItemStack copyOfSourceStack = sourceStack.copy(); // Check if the slot clicked is one of the vanilla container slots if (sourceSlotIndex >= VANILLA_FIRST_SLOT_INDEX && sourceSlotIndex < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) { // This is a vanilla container slot so merge the stack into the tile inventory if (!moveItemStackTo(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT, false)){ return ItemStack.EMPTY; // EMPTY_ITEM } } else if (sourceSlotIndex >= TE_INVENTORY_FIRST_SLOT_INDEX && sourceSlotIndex < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT) { // This is a TE slot so merge the stack into the players inventory if (!moveItemStackTo(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) { return ItemStack.EMPTY; } } else { LOGGER.warn("Invalid slotIndex:" + sourceSlotIndex); return ItemStack.EMPTY; } // If stack size == 0 (the entire stack was moved) set slot contents to null if (sourceStack.getCount() == 0) { sourceSlot.mayPlace(ItemStack.EMPTY); } else { sourceSlot.setChanged(); } sourceSlot.onTake(playerEntity, sourceStack); return copyOfSourceStack; } // pass the close container message to the parent inventory (not strictly needed for this example) // see ContainerChest and TileEntityChest - used to animate the lid when no players are accessing the chest any more @Override public void removed(PlayerEntity playerIn) { super.removed(playerIn); } private ChestContents chestContents; private static final Logger LOGGER = LogManager.getLogger(); }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.