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

    • Try deliting feur builder  It caused this issue in my modpack
    • I am not using hardcoded recipes, I'm using Vanilla's already existing code for leather armor dying. (via extending and implementing DyeableArmorItem / DyeableLeatherItem respectively) I have actually figured out that it's something to do with registering item colors to the ItemColors instance, but I'm trying to figure out where exactly in my mod's code I would be placing a call to the required event handler. Unfortunately the tutorial is criminally undescriptive. The most I've found is that it has to be done during client initialization. I'm currently trying to do the necessary setup via hijacking the item registry since trying to modify the item classes directly (via using SubscribeEvent in the item's constructor didn't work. Class so far: // mrrp mrow - mcmod item painter v1.0 - catzrule ch package catzadvitems.init; import net.minecraft.client.color.item.ItemColors; import net.minecraft.world.item.Item; import net.minecraftforge.registries.ObjectHolder; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.client.event.ColorHandlerEvent; import catzadvitems.item.DyeableWoolArmorItem; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Painter { @ObjectHolder("cai:dyeable_wool_chestplate") public static final Item W_CHEST = null; @ObjectHolder("cai:dyeable_wool_leggings") public static final Item W_LEGS = null; @ObjectHolder("cai:dyeable_wool_boots") public static final Item W_SOCKS = null; public Painter() { // left blank, idk if forge throws a fit if constructors are missing, not taking the chance of it happening. } @SubscribeEvent public static void init(FMLClientSetupEvent event) { new Painter(); } @Mod.EventBusSubscriber private static class ForgeBusEvents { @SubscribeEvent public static void registerItemColors(ColorHandlerEvent.Item event) { ItemColors col = event.getItemColors(); col.register(DyeableUnderArmorItem::getItemDyedColor, W_CHEST, W_LEGS, W_SOCKS); //placeholder for other dye-able items here later.. } } } (for those wondering, i couldn't think of a creative wool helmet name)
    • nvm found out it was because i had create h and not f
    • Maybe there's something happening in the 'leather armor + dye' recipe itself that would be updating the held item texture?
    • @SubscribeEvent public static void onRenderPlayer(RenderPlayerEvent.Pre e) { e.setCanceled(true); model.renderToBuffer(e.getPoseStack(), pBuffer, e.getPackedLight(), 0f, 0f, 0f, 0f, 0f); //ToaPlayerRenderer.render(); } Since getting the render method from a separate class is proving to be bit of a brick wall for me (but seems to be the solution in older versions of minecraft/forge) I've decided to try and pursue using the renderToBuffer method directly from the model itself. I've tried this route before but can't figure out what variables to feed it for the vertexConsumer and still can't seem to figure it out; if this is even a path to pursue.  The vanilla model files do not include any form of render methods, and seem to be fully constructed from their layer definitions? Their renderer files seem to take their layers which are used by the render method in the vanilla MobRenderer class. But for modded entities we @Override this function and don't have to feed the method variables because of that? I assume that the render method in the extended renderer takes the layer definitions from the renderer classes which take those from the model files. Or maybe instead of trying to use a render method I should be calling the super from the renderer like   new ToaPlayerRenderer(context, false); Except I'm not sure what I would provide for context? There's a context method in the vanilla EntityRendererProvider class which doesn't look especially helpful. I've been trying something like <e.getEntity(), model<e.getEntity()>> since that generally seems to be what is provided to the renderers for context, but I don't know if it's THE context I'm looking for? Especially since the method being called doesn't want to take this or variations of this.   In short; I feel like I'm super super close but I have to be missing something obvious? Maybe this insane inane ramble post will provide some insight into this puzzle?
  • Topics

×
×
  • Create New...

Important Information

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