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

[1.16.5] TileEntityRenderer not accessing TileEntity inventory


Recommended Posts

Hi, so the thing is that I have a TileEntity for which I added a TileEntityRenderer, I already did this with two other TileEntities but this time it was not working and I found out that the Renderer class cannot reach TileEntity inventory, since when I have an ItemStack in a slot, it outputs Air. And also, my two other TileEntities uses ISidedInventory (which I know shouldn't be used but I will change this later), and this one uses IItemHandler. I don't know if it is what causes the issue or if I am networking bad or even if I am missing something, can someone help me please ?

 

TileEntityRenderer :

public class CelestialPowerPedestalTileEntityRenderer extends TileEntityRenderer<CelestialPowerPedestalTileEntity> {

	private Minecraft mc  = Minecraft.getInstance();

	public CelestialPowerPedestalTileEntityRenderer(
		TileEntityRendererDispatcher rendererDispatcherIn) {
		super(rendererDispatcherIn);
	}

	@Override
	public void render(
		CelestialPowerPedestalTileEntity te,
		float partialTicks,
		MatrixStack matrixStackIn,
		IRenderTypeBuffer bufferIn,
		int combinedLightIn,
		int combinedOverlayIn) {

		int lightLevel = getLightLevel(te.getWorld(), te.getPos());

		if (!te.isFillable()) {

			renderItem(te.inv.getStackInSlot(0), new double[] {0.48d, 0.83d, 0.42d},
			           90, 0, 0, matrixStackIn, bufferIn, partialTicks, combinedOverlayIn, lightLevel, 1.0f);

		}
	}

	private void renderItem(
		ItemStack stack, double[] translation, int rotX, int rotY, int rotZ, MatrixStack matrixStack, IRenderTypeBuffer buffer, float partialTicks, int combinedOverlay, int lightLevel, float scale) {

		matrixStack.push();
		matrixStack.translate(translation[0], translation[1], translation[2]);
		matrixStack.rotate(Vector3f.XP.rotationDegrees((float) rotX));
		matrixStack.rotate(Vector3f.YP.rotationDegrees((float) rotY));
		matrixStack.rotate(Vector3f.ZP.rotationDegrees((float) rotZ));
		matrixStack.scale(scale, scale, scale);

		IBakedModel model = mc.getItemRenderer().getItemModelWithOverrides(stack, null, null);
		mc.getItemRenderer().renderItem(stack,
		                                ItemCameraTransforms.TransformType.GROUND, true, matrixStack, buffer, lightLevel, combinedOverlay, model);
		matrixStack.pop();

	}

	private int getLightLevel(
		World world, BlockPos pos) {
		int blockLight = world.getLightFor(LightType.BLOCK, pos);
		int skyLight = world.getLightFor(LightType.SKY, pos);
		return LightTexture.packLight(blockLight, skyLight);
	}

}

TileEntity networking and writing :

public void read(
		BlockState state,
		CompoundNBT nbt) {
		super.read(
			state,
			nbt);

		NonNullList <ItemStack> inv = NonNullList.withSize(
			this.inv.getSlots(),
			ItemStack.EMPTY);
		ItemStackHelper.loadAllItems(
			nbt,
			inv);
		setItems(inv);
	}

	@Nonnull
	@Override
	public CompoundNBT write(
		CompoundNBT compound) {
		super.write(compound);

		ItemStackHelper.saveAllItems(
			compound,
			this.getItems());

		return compound;
	}

	@Nullable
	@Override
	public SUpdateTileEntityPacket getUpdatePacket() {
		CompoundNBT nbt = new CompoundNBT();
		this.write(nbt);
		return new SUpdateTileEntityPacket(
			this.pos,
			0,
			nbt);
	}

	@Override
	public void onDataPacket(
		NetworkManager net,
		SUpdateTileEntityPacket pkt) {
		this.read(
			world.getBlockState(pkt.getPos()),
			pkt.getNbtCompound());
	}

	@Override
	public CompoundNBT getUpdateTag() {
		CompoundNBT nbt = new CompoundNBT();
		this.write(nbt);
		return nbt;
	}

	@Override
	public void handleUpdateTag(
		BlockState state,
		CompoundNBT tag) {
		this.read(state, tag);
	}

 

Link to post
Share on other sites

why do you use IItemHandler as inventory?
Edit: use ItemStackHandler instead, reason:

you use Capability#getDefaultInstance to get an IItemHandler,
why don't you use a new ItemStackHandler that contains the methods serializeNBT and deserializeNBT
which you can execute in read and write the TE, wich is very simple

Edited by Luis_ST
Link to post
Share on other sites
55 minutes ago, diesieben07 said:

That is not at all what I said.

Yes, delete getItems, but use the proper alternative, don't just remove read and write.

Ok so I came up with this : https://pastebin.com/L01ZkFj2, however I think I did something wrong since it did not fixed it, for the Direction I put Direction#NORT but I don't know if it is ok to put a fixed direction like this.

 

49 minutes ago, Luis_ST said:

why do you use IItemHandler as inventory?
Edit: use ItemStackHandler instead, reason:

you use Capability#getDefaultInstance to get an IItemHandler,
why don't you use a new ItemStackHandler that contains the methods serializeNBT and deserializeNBT
which you can execute in read and write the TE, wich is very simple

I use the default instance since it creates a new IItemHandler with just one slot and it is to avoid creating more instances and classes

Link to post
Share on other sites
22 minutes ago, bibouche_ said:

Ok so I came up with this : https://pastebin.com/L01ZkFj2, however I think I did something wrong since it did not fixed it, for the Direction I put Direction#NORT but I don't know if it is ok to put a fixed direction like this.

you can use null

22 minutes ago, bibouche_ said:

I use the default instance since it creates a new IItemHandler with just one slot and it is to avoid creating more instances and classes

Capability#getDefaultInstance do the same as the ItemStackHandler#new
and if you use an ItemStackHandler as I explained above, your error would simply be fixed
this is the simplest solution for your problem:
https://pastebin.com/ntZssi9b

Edit: another issue in your code, you call the write inside the getUpdatePacket method of your TE

Edited by Luis_ST
Link to post
Share on other sites
19 minutes ago, Luis_ST said:

you can use null

 

Capability#getDefaultInstance do the same as the ItemStackHandler#new
and if you use an ItemStackHandler as I explained above, your error would simply be fixed
this is the simplest solution for your problem:
https://pastebin.com/ntZssi9b

Ok but I tried it and I keep having the same issue, I really don't see what is causing this

Link to post
Share on other sites
1 hour ago, Luis_ST said:

post your updated code
and take a look at some vanilla TEs,
how they synchronize the TE data with the client

https://pastebin.com/DKKj7JNG

 

Yeah, I looked at some vanilla TEs, however they are using CompoundNBT, so I am a litte lost since IItemHandler uses INBT, and like the read and write methods are using CompoundNBT

Link to post
Share on other sites
1 minute ago, bibouche_ said:

please post the full TE class

 

1 minute ago, bibouche_ said:

Yeah, I looked at some vanilla TEs, however they are using CompoundNBT, so I am a litte lost since IItemHandler uses INBT, and like the read and write methods are using CompoundNBT

that's basic java, INBT is an interfaces, and CompoundNBT is an implemention of INBT

Link to post
Share on other sites
1 minute ago, bibouche_ said:

https://pastebin.com/SjjXivkK

Yeah I know that, but I did not found a way yet, so I will look at it, maybe add a new CompoundNBT and use it in the functions

You're still doing what you shouldn't

 

13 hours ago, Luis_ST said:

Capability#getDefaultInstance do the same as the ItemStackHandler#new
and if you use an ItemStackHandler as I explained above, your error would simply be fixed
this is the simplest solution for your problem:
https://pastebin.com/ntZssi9b

this is optional

 

13 hours ago, Luis_ST said:

another issue in your code, you call the write inside the getUpdatePacket method of your TE

that is required

Link to post
Share on other sites
6 hours ago, diesieben07 said:

getUpdatePacket should use getUpdateTag and onDataPacket should call handleUpdateTag.

Then getUpdateTag needs to call super, not write. Then you need to write only the data that is necessary on the client in getUpdateTag. In handleUpdateTag you then read that data.

Like so ? https://pastebin.com/FuUvqppK

Link to post
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.

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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • i am looking for a mod that shows all the chunks that have been loaded or a mod that shows all of the chunks that are currently loaded for 1.17.1
    • Heya. I have been trying to figure out why using /tp keeps crashing me when Im using forge 1.16.5. the crash report is below. please help me out. ---- Minecraft Crash Report ---- // Don't do that. Time: 7/25/21 5:11 PM Description: Exception generating new chunk java.lang.IllegalArgumentException: bound must be positive     at java.util.Random.nextInt(Random.java:388) ~[?:1.8.0_51] {}     at net.minecraft.world.gen.feature.structure.Structure.func_236392_a_(Structure.java:202) ~[?:?] {re:classloading,pl:accesstransformer:B,re:mixin,pl:accesstransformer:B}     at net.minecraft.world.gen.feature.structure.Structure.func_242785_a(Structure.java:221) ~[?:?] {re:classloading,pl:accesstransformer:B,re:mixin,pl:accesstransformer:B}     at net.minecraft.world.gen.feature.StructureFeature.func_242771_a(SourceFile:35) ~[?:?] {re:classloading}     at net.minecraft.world.gen.ChunkGenerator.func_242705_a(SourceFile:278) ~[?:?] {re:mixin,re:classloading,pl:mixin:APP:repurposed_structures.mixins.json:ChunkGeneratorAccessor,pl:mixin:APP:repurposed_structures.mixins.json:ChunkGeneratorMixin,pl:mixin:A}     at net.minecraft.world.gen.ChunkGenerator.func_242707_a(SourceFile:267) ~[?:?] {re:mixin,re:classloading,pl:mixin:APP:repurposed_structures.mixins.json:ChunkGeneratorAccessor,pl:mixin:APP:repurposed_structures.mixins.json:ChunkGeneratorMixin,pl:mixin:A}     at net.minecraft.world.chunk.ChunkStatus.lambda$static$2(ChunkStatus.java:41) ~[?:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.world.chunk.ChunkStatus$$Lambda$2265/387194988.doWork(Unknown Source) ~[?:?] {}     at net.minecraft.world.chunk.ChunkStatus.func_223198_a(ChunkStatus.java:198) ~[?:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.world.server.ChunkManager.lambda$null$18(ChunkManager.java:524) ~[?:?] {re:classloading}     at net.minecraft.world.server.ChunkManager$$Lambda$6523/918777125.apply(Unknown Source) ~[?:?] {}     at com.mojang.datafixers.util.Either$Left.map(Either.java:38) ~[datafixerupper-4.0.26.jar:?] {re:classloading,re:classloading}     at net.minecraft.world.server.ChunkManager.lambda$chunkGenerate$20(ChunkManager.java:522) ~[?:?] {re:classloading}     at net.minecraft.world.server.ChunkManager$$Lambda$6520/530773096.apply(Unknown Source) ~[?:?] {}     at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:952) ~[?:1.8.0_51] {}     at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:926) ~[?:1.8.0_51] {}     at java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:442) ~[?:1.8.0_51] {}     at net.minecraft.world.chunk.ChunkTaskPriorityQueueSorter.func_219083_b(SourceFile:58) ~[?:?] {re:classloading}     at net.minecraft.world.chunk.ChunkTaskPriorityQueueSorter$$Lambda$6464/1211192729.run(Unknown Source) ~[?:?] {}     at net.minecraft.util.concurrent.DelegatedTaskExecutor.func_213148_e(SourceFile:94) ~[?:?] {re:classloading}     at net.minecraft.util.concurrent.DelegatedTaskExecutor.func_213145_a(SourceFile:137) ~[?:?] {re:classloading}     at net.minecraft.util.concurrent.DelegatedTaskExecutor.run(SourceFile:105) ~[?:?] {re:classloading}     at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402) ~[?:1.8.0_51] {}     at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[?:1.8.0_51] {}     at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) ~[?:1.8.0_51] {}     at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1689) ~[?:1.8.0_51] {}     at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) ~[?:1.8.0_51] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Server thread Stacktrace:     at java.util.Random.nextInt(Random.java:388) ~[?:1.8.0_51] {}     at net.minecraft.world.gen.feature.structure.Structure.func_236392_a_(Structure.java:202) ~[?:?] {re:classloading,pl:accesstransformer:B,re:mixin,pl:accesstransformer:B}     at net.minecraft.world.gen.feature.structure.Structure.func_242785_a(Structure.java:221) ~[?:?] {re:classloading,pl:accesstransformer:B,re:mixin,pl:accesstransformer:B}     at net.minecraft.world.gen.feature.StructureFeature.func_242771_a(SourceFile:35) ~[?:?] {re:classloading}     at net.minecraft.world.gen.ChunkGenerator.func_242705_a(SourceFile:278) ~[?:?] {re:mixin,re:classloading,pl:mixin:APP:repurposed_structures.mixins.json:ChunkGeneratorAccessor,pl:mixin:APP:repurposed_structures.mixins.json:ChunkGeneratorMixin,pl:mixin:A}     at net.minecraft.world.gen.ChunkGenerator.func_242707_a(SourceFile:267) ~[?:?] {re:mixin,re:classloading,pl:mixin:APP:repurposed_structures.mixins.json:ChunkGeneratorAccessor,pl:mixin:APP:repurposed_structures.mixins.json:ChunkGeneratorMixin,pl:mixin:A}     at net.minecraft.world.chunk.ChunkStatus.lambda$static$2(ChunkStatus.java:41) ~[?:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.world.chunk.ChunkStatus$$Lambda$2265/387194988.doWork(Unknown Source) ~[?:?] {}     at net.minecraft.world.chunk.ChunkStatus.func_223198_a(ChunkStatus.java:198) ~[?:?] {re:classloading,pl:accesstransformer:B} -- Chunk to be generated -- Details:     Location: 170,-183     Position hash: -785979014998     Generator: net.minecraft.world.gen.NoiseChunkGenerator@68c16e02 Stacktrace:     at net.minecraft.world.server.ChunkManager.lambda$null$18(ChunkManager.java:524) ~[?:?] {re:classloading}     at net.minecraft.world.server.ChunkManager$$Lambda$6523/918777125.apply(Unknown Source) ~[?:?] {}     at com.mojang.datafixers.util.Either$Left.map(Either.java:38) ~[datafixerupper-4.0.26.jar:?] {re:classloading,re:classloading,re:classloading}     at net.minecraft.world.server.ChunkManager.lambda$chunkGenerate$20(ChunkManager.java:522) ~[?:?] {re:classloading}     at net.minecraft.world.server.ChunkManager$$Lambda$6520/530773096.apply(Unknown Source) ~[?:?] {}     at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:952) ~[?:1.8.0_51] {}     at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:926) ~[?:1.8.0_51] {}     at java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:442) ~[?:1.8.0_51] {}     at net.minecraft.world.chunk.ChunkTaskPriorityQueueSorter.func_219083_b(SourceFile:58) ~[?:?] {re:classloading}     at net.minecraft.world.chunk.ChunkTaskPriorityQueueSorter$$Lambda$6464/1211192729.run(Unknown Source) ~[?:?] {}     at net.minecraft.util.concurrent.DelegatedTaskExecutor.func_213148_e(SourceFile:94) ~[?:?] {re:classloading} -- Affected level -- Details:     All players: 1 total; [ServerPlayerEntity['KrystalTheFox_'/132, l='ServerLevel[Modded Survival]', x=2748.50, y=77.00, z=-2911.50]]     Chunk stats: ServerChunkCache: 3347     Level dimension: minecraft:overworld     Level spawn location: World: (51,64,-90), Chunk: (at 3,4,6 in 3,-6; contains blocks 48,0,-96 to 63,255,-81), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)     Level time: 42412 game time, 227 day time     Level name: Modded Survival     Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false     Level weather: Rain time: 120492 (now: false), thunder time: 52965 (now: false)     Known server brands: forge     Level was modded: true     Level storage version: 0x04ABD - Anvil Stacktrace:     at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:854) ~[?:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:787) ~[?:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:78) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:642) [?:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.server.MinecraftServer.lambda$startServer$0(MinecraftServer.java:232) [?:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.server.MinecraftServer$$Lambda$6334/1896438195.run(Unknown Source) [?:?] {}     at java.lang.Thread.run(Thread.java:745) [?:1.8.0_51] {} -- System Details -- Details:     Minecraft Version: 1.16.5     Minecraft Version ID: 1.16.5     Operating System: Windows 10 (amd64) version 10.0     Java Version: 1.8.0_51, Oracle Corporation     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation     Memory: 1148904608 bytes (1095 MB) / 2147483648 bytes (2048 MB) up to 2147483648 bytes (2048 MB)     CPUs: 4     JVM Flags: 9 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xss1M -Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M     ModLauncher: 8.0.9+86+master.3cf110c     ModLauncher launch target: fmlclient     ModLauncher naming: srg     ModLauncher services:          /mixin-0.8.2.jar mixin PLUGINSERVICE          /eventbus-4.0.0.jar eventbus PLUGINSERVICE          /forge-1.16.5-36.0.45.jar object_holder_definalize PLUGINSERVICE          /forge-1.16.5-36.0.45.jar runtime_enum_extender PLUGINSERVICE          /accesstransformers-3.0.1.jar accesstransformer PLUGINSERVICE          /forge-1.16.5-36.0.45.jar capability_inject_definalize PLUGINSERVICE          /forge-1.16.5-36.0.45.jar runtimedistcleaner PLUGINSERVICE          /mixin-0.8.2.jar mixin TRANSFORMATIONSERVICE          /forge-1.16.5-36.0.45.jar fml TRANSFORMATIONSERVICE      FML: 36.0     Forge: net.minecraftforge:36.0.45     FML Language Providers:          javafml@36.0         minecraft@1     Mod List:          forge-1.16.5-36.0.45-client.jar                   |Minecraft                     |minecraft                     |1.16.5              |DONE      |NOSIGNATURE         dungeons_mobs-1.16.5-1.0.5.jar                    |Dungeons Mobs                 |dungeons_mobs                 |1.0.5               |DONE      |NOSIGNATURE         repurposed_structures-1.16.5-2.6.6-forge.jar      |Repurposed Structures         |repurposed_structures         |1.16.5-2.6.6-forge  |DONE      |NOSIGNATURE         illagers_plus-1.16.4v1.5.jar                      |Illagers+                     |illagers_plus                 |1.16.4v1.5          |DONE      |NOSIGNATURE         enchantwithmob-1.16.5-1.4.6.jar                   |Enchant With Mob              |enchantwithmob                |1.16.5-1.4.6        |DONE      |NOSIGNATURE         Ma-Enchants-1.16.5-3.6.0 (1).jar                  |Ma Enchants                   |ma-enchants                   |1.16.5-3.6.0        |DONE      |NOSIGNATURE         forge-1.16.5-36.0.45-universal.jar                |Forge                         |forge                         |36.0.45             |DONE      |22:af:21:d8:19:82:7f:93:94:fe:2b:ac:b7:e4:41:57:68:39:87:b1:a7:5c:c6:44:f9:25:74:21:14:f5:0d:90         torohealth-1.16.4-forge-4.jar                     |ToroHealth                    |torohealth                    |NONE                |DONE      |NOSIGNATURE         extragolems-11.3.0.jar                            |Extra Golems                  |golems                        |11.3.0              |DONE      |NOSIGNATURE         Deeper+in+The+Caves+Remake+1.1.jar                |Deeper In The Caves Remake    |stacked_dimensions_warden     |1.0.0               |DONE      |NOSIGNATURE         MobBattleMod-1.16.2-2.3.4 (2).jar                 |Mob Battle Mod                |mobbattle                     |1.16.2-2.3.4        |DONE      |NOSIGNATURE         supertools-1.16.5-4.5.jar                         |Vanilla+ Tools                |supertools                    |version             |DONE      |NOSIGNATURE     Crash Report UUID: 2888177d-2bf6-4908-99f1-1b7b6465ec05     Player Count: 1 / 8; [ServerPlayerEntity['KrystalTheFox_'/132, l='ServerLevel[Modded Survival]', x=2748.50, y=77.00, z=-2911.50]]     Data Packs: vanilla, mod:dungeons_mobs (incompatible), mod:repurposed_structures, mod:illagers_plus, mod:enchantwithmob, mod:ma-enchants (incompatible), mod:forge, mod:torohealth, mod:golems (incompatible), mod:stacked_dimensions_warden, mod:mobbattle (incompatible), mod:supertools (incompatible)     Type: Integrated Server (map_client.txt)     Is Modded: Definitely; Client brand changed to 'forge'
    • I installed a Forge server, ran the normal .jar file, accepted the EULA, tried to run the forge.jar file but it doesn't give me any folders (like the mods or config) folder. Already looked through the forum here but there weren't any help. I also updated to the newest Java version but it doesn't help.
    • I have a custom inventory that saves when i have the world running but when I rejoin the items are not there in the slots.
    • Hello, I have a weird issue with my server where I have to be on the multiplayer page on the same version as my friends for them to join the server. This has happened on all versions, no matter what mod, Forge and vanilla. It's not a LAN, and I've port forwarded, and I'm kinda new to this stuff anyways. Anybody have a reason to this?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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