Jump to content

[SOLVED][1.7.10] Get Block in TileEntity slot


FirstOrderKylo

Recommended Posts

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)

 

Link to comment
Share on other sites

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";

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Instale el mod en mi servidor y este se queda iniciando por horas, en la consola me habla de algo de permisos y trate de seguir la ruta que me da pero no existe.   [13:05:32 INFO]: CustomNPC Permissions available: [13:05:32 INFO]: customnpcs.edit.blocks [13:05:32 INFO]: customnpcs.edit.villager [13:05:32 INFO]: customnpcs.global.bank [13:05:32 INFO]: customnpcs.global.dialog [13:05:32 INFO]: customnpcs.global.faction [13:05:32 INFO]: customnpcs.global.linked [13:05:32 INFO]: customnpcs.global.naturalspawn [13:05:32 INFO]: customnpcs.global.playerdata [13:05:32 INFO]: customnpcs.global.quest [13:05:32 INFO]: customnpcs.global.recipe [13:05:32 INFO]: customnpcs.global.transport [13:05:32 INFO]: customnpcs.npc.advanced [13:05:32 INFO]: customnpcs.npc.ai [13:05:32 INFO]: customnpcs.npc.clone [13:05:32 INFO]: customnpcs.npc.create [13:05:32 INFO]: customnpcs.npc.delete [13:05:32 INFO]: customnpcs.npc.display [13:05:32 INFO]: customnpcs.npc.freeze [13:05:32 INFO]: customnpcs.npc.gui [13:05:32 INFO]: customnpcs.npc.inventory [13:05:32 INFO]: customnpcs.npc.reset [13:05:32 INFO]: customnpcs.npc.stats [13:05:32 INFO]: customnpcs.scenes [13:05:32 INFO]: customnpcs.soulstone.all [13:05:32 INFO]: customnpcs.spawner.create [13:05:32 INFO]: customnpcs.spawner.mob [13:05:32 INFO]: customnpcs.tool.mounter [13:05:32 INFO]: customnpcs.tool.nbtbook [13:05:32 INFO]: customnpcs.tool.pather [13:05:32 INFO]: customnpcs.tool.scripter
    • I have created a very simple mod that is just supposed to send a message to a player when they join. Upon adding it to a server (that has other mods on it), the following crash message appears: [12:13:01] [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [         Epic Mod (epicmod) has failed to load correctly §7java.lang.NoSuchMethodException: net.ed.epicmod.EpicMod.<init>() ]         at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:243) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$24(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] {re:mixin}         at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$14(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {re:mixin,re:computing_frames}         at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.server.loading.ServerModLoader.load(ServerModLoader.java:32) ~[forge-1.19.2-43.2.14-universal.jar%23552!/:?] {re:classloading}         at net.minecraft.server.Main.main(Main.java:113) ~[server-1.19.2-20220805.130853-srg.jar%23547!/:?] {re:classloading,re:mixin,pl:mixin:A}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}         at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}         at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}         at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:29) ~[fmlloader-1.19.2-43.2.14.jar%2367!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] {} Why could this be? I have tried using the mod on another forge server with only this mod installed and it works there. Is my mod somehow interfering with other mods? MC version is 1.19.2
    • how to make animated doors?, maybe geckolib, but i don't know how to code it?
    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.