Posted April 8, 20169 yr Hello, so I'm trying to create a method in my TileEntity class to get the block in a specific slot so it can be used like "getBlockInSlot(index)" Currently I have: private ItemStack[] inventory; private Block[] inventory2; @Override public ItemStack getStackInSlot(int index) { if (index < 0 || index >= this.getSizeInventory()) return null; return this.inventory[index]; } public Block getBlockInSlot(int index) { if (index < 0 || index >= this.getSizeInventory()) return null; return this.inventory2[index]; } which is a copy of the getStackInSlot method with a different return type and location to return to and that one works, but getBlockInSlot gives this crash report when an item goes into the TileEntitySlot specified with getBlockInSlot() [p]Report:[/p] ---- Minecraft Crash Report ---- // Why did you do that? Time: 4/8/16 8:27 AM Description: Rendering screen java.lang.NullPointerException: Rendering screen at com.church.sciencemc.tileentities.TileEntityMicroscope.getBlockInSlot(TileEntityMicroscope.java:59) at com.church.sciencemc.ChemicalComposition.ChemicalCompositionList(ChemicalComposition.java:352) at com.church.sciencemc.gui.GuiTileEntityMicroscope.drawGuiContainerForegroundLayer(GuiTileEntityMicroscope.java:63) at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:134) at com.church.sciencemc.gui.GuiTileEntityMicroscope.drawScreen(GuiTileEntityMicroscope.java:97) at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1137) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1067) at net.minecraft.client.Minecraft.run(Minecraft.java:962) at net.minecraft.client.main.Main.main(Main.java:164) 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 net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at com.church.sciencemc.tileentities.TileEntityMicroscope.getBlockInSlot(TileEntityMicroscope.java:59) at com.church.sciencemc.ChemicalComposition.ChemicalCompositionList(ChemicalComposition.java:352) at com.church.sciencemc.gui.GuiTileEntityMicroscope.drawGuiContainerForegroundLayer(GuiTileEntityMicroscope.java:63) at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:134) at com.church.sciencemc.gui.GuiTileEntityMicroscope.drawScreen(GuiTileEntityMicroscope.java:97) -- Screen render details -- Details: Screen name: com.church.sciencemc.gui.GuiTileEntityMicroscope Mouse location: Scaled: (210, 68). Absolute: (421, 342) Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2 -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityClientPlayerMP['Player875'/167, l='MpServer', x=-321.55, y=5.62, z=163.47]] Chunk stats: MultiplayerChunkCache: 441, 441 Level seed: 0 Level generator: ID 01 - flat, ver 0. Features enabled: false Level generator options: Level spawn location: World: (-325,4,158), Chunk: (at 11,0,14 in -21,9; contains blocks -336,0,144 to -321,255,159), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511) Level time: 253230 game time, 142561 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: 53 total; [EntityCow['Cow'/129, l='MpServer', x=-255.94, y=4.00, z=90.94], EntityChicken['Chicken'/130, l='MpServer', x=-246.44, y=4.00, z=90.44], EntityCow['Cow'/131, l='MpServer', x=-255.56, y=4.00, z=109.25], EntitySheep['Sheep'/133, l='MpServer', x=-254.16, y=4.00, z=161.09], EntityPig['Pig'/134, l='MpServer', x=-241.72, y=4.00, z=180.91], EntityCow['Cow'/135, l='MpServer', x=-245.13, y=4.00, z=175.16], EntityHorse['Horse'/136, l='MpServer', x=-245.13, y=4.00, z=197.34], EntityPig['Pig'/137, l='MpServer', x=-246.66, y=4.00, z=192.19], EntityPig['Pig'/138, l='MpServer', x=-246.19, y=4.00, z=208.22], EntityChicken['Chicken'/139, l='MpServer', x=-254.47, y=4.00, z=203.53], EntityChicken['Chicken'/150, l='MpServer', x=-247.38, y=4.00, z=211.56], EntitySheep['Sheep'/29, l='MpServer', x=-396.81, y=4.00, z=183.22], EntityCow['Cow'/38, l='MpServer', x=-380.56, y=4.00, z=204.72], EntityClientPlayerMP['Player875'/167, l='MpServer', x=-321.55, y=5.62, z=163.47], EntityPig['Pig'/61, l='MpServer', x=-338.84, y=4.00, z=120.19], EntitySheep['Sheep'/62, l='MpServer', x=-343.88, y=4.00, z=199.91], EntitySheep['Sheep'/63, l='MpServer', x=-320.16, y=4.00, z=114.09], EntityCow['Cow'/64, l='MpServer', x=-320.69, y=4.00, z=199.22], EntitySheep['Sheep'/65, l='MpServer', x=-334.72, y=4.00, z=204.16], EntitySheep['Sheep'/66, l='MpServer', x=-333.09, y=4.00, z=211.91], EntityCow['Cow'/79, l='MpServer', x=-301.28, y=4.00, z=84.63], EntityPig['Pig'/80, l='MpServer', x=-304.84, y=4.00, z=87.41], EntityPig['Pig'/81, l='MpServer', x=-315.97, y=4.00, z=105.13], EntityPig['Pig'/82, l='MpServer', x=-313.09, y=4.00, z=109.06], EntityHorse['Horse'/83, l='MpServer', x=-311.56, y=4.00, z=109.00], EntityPig['Pig'/84, l='MpServer', x=-316.25, y=4.00, z=103.63], EntityCow['Cow'/85, l='MpServer', x=-301.88, y=4.00, z=204.19], EntityPig['Pig'/86, l='MpServer', x=-298.19, y=4.00, z=217.31], EntityHorse['Horse'/87, l='MpServer', x=-312.06, y=4.00, z=238.03], EntityHorse['Horse'/88, l='MpServer', x=-304.25, y=4.00, z=243.78], EntityCow['Cow'/96, l='MpServer', x=-295.38, y=4.00, z=92.72], EntitySheep['Sheep'/98, l='MpServer', x=-289.81, y=4.00, z=100.22], EntitySheep['Sheep'/99, l='MpServer', x=-303.13, y=4.00, z=100.72], EntityHorse['Horse'/100, l='MpServer', x=-299.09, y=4.00, z=114.00], EntityPig['Pig'/101, l='MpServer', x=-291.84, y=4.00, z=200.41], EntitySheep['Sheep'/102, l='MpServer', x=-300.50, y=4.00, z=218.25], EntityPig['Pig'/103, l='MpServer', x=-290.28, y=4.00, z=232.78], EntityChicken['Chicken'/104, l='MpServer', x=-303.47, y=4.00, z=242.47], EntitySheep['Sheep'/108, l='MpServer', x=-283.38, y=4.00, z=94.84], EntityCow['Cow'/109, l='MpServer', x=-273.97, y=4.00, z=109.88], EntityCow['Cow'/110, l='MpServer', x=-279.16, y=4.00, z=200.84], EntityPig['Pig'/111, l='MpServer', x=-280.84, y=4.00, z=221.09], EntityCow['Cow'/112, l='MpServer', x=-276.50, y=4.00, z=220.69], EntityCow['Cow'/113, l='MpServer', x=-276.72, y=4.00, z=218.81], EntityChicken['Chicken'/114, l='MpServer', x=-277.56, y=4.00, z=218.41], EntityPig['Pig'/115, l='MpServer', x=-276.88, y=4.00, z=242.88], EntityCow['Cow'/119, l='MpServer', x=-266.97, y=4.00, z=87.91], EntityPig['Pig'/120, l='MpServer', x=-266.91, y=4.00, z=105.13], EntitySheep['Sheep'/121, l='MpServer', x=-256.06, y=4.00, z=100.13], EntityPig['Pig'/122, l='MpServer', x=-256.81, y=4.00, z=132.28], EntitySheep['Sheep'/123, l='MpServer', x=-268.81, y=4.00, z=173.84], EntityPig['Pig'/124, l='MpServer', x=-265.75, y=4.00, z=215.41], EntityChicken['Chicken'/126, l='MpServer', x=-265.38, y=4.00, z=228.63]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2566) at net.minecraft.client.Minecraft.run(Minecraft.java:984) at net.minecraft.client.main.Main.main(Main.java:164) 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 net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source)
April 9, 20169 yr Author I got it to work. getBlockInSlot is used in this bit of code (composition is a string called in another class to write on the gui): if (te.getBlockInSlot(0) == Blocks.nether_brick) Composition = "it worked"; for anyone who comes along later, this is the code bit I used in replacement of: if (te.getBlockInSlot(0) == Blocks.nether_brick) Composition = "it worked"; new, working code: if (Block.getBlockFromItem(te.getStackInSlot(0).getItem())== Blocks.bedrock) Composition = "it worked";
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.