Jump to content

[1.8] Transfering Data between two Tile Entities


Noxyper

Recommended Posts

Hello!

 

I've recently tried to get back to work on my mod that I've not worked on in months.

 

Where I left off, I was working on a system to transfer steam through pipes to power my machinery.

What I remember from back then was that some change in my code broke the system and now occasionally the game throws this crash:

 

[18:35:51] [server thread/ERROR]: This crash report has been saved to: C:\Users\Nemo\Desktop\Programming\Gears N' Clouds 1.8\eclipse\.\crash-reports\crash-2016-10-29_18.35.51-server.txt
[18:35:51] [server thread/INFO]: Stopping server
[18:35:51] [server thread/INFO]: Saving players
[18:35:51] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:663]: ---- Minecraft Crash Report ----
// You should try our sister game, Minceraft!

Time: 2016-10-29 18:35
Description: Ticking block entity

java.lang.NullPointerException: Ticking block entity
at com.minenemo.gearsandclouds.entities.tileentities.TileEntityPipe.distributeSteam(TileEntityPipe.java:66)
at com.minenemo.gearsandclouds.entities.tileentities.TileEntityPipe.update(TileEntityPipe.java:57)
at net.minecraft.world.World.updateEntities(World.java:1879)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:587)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:775)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540)
at java.lang.Thread.run(Thread.java:745)


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

-- Head --
Stacktrace:
at com.minenemo.gearsandclouds.entities.tileentities.TileEntityPipe.distributeSteam(TileEntityPipe.java:66)
at com.minenemo.gearsandclouds.entities.tileentities.TileEntityPipe.update(TileEntityPipe.java:57)

-- Block entity being ticked --
Details:
Name: Pipe // com.minenemo.gearsandclouds.entities.tileentities.TileEntityPipe
Block type: ID #7 (tile.bedrock // net.minecraft.block.Block)
Block data value: 0 / 0x0 / 0b0000
Block location: World: (0,0,0), Chunk: (at 0,0,0 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
Actual block type: ID #7 (tile.bedrock // net.minecraft.block.Block)
Actual block data value: 0 / 0x0 / 0b0000
Stacktrace:
at net.minecraft.world.World.updateEntities(World.java:1879)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:587)

-- Affected level --
Details:
Level name: GnC Testing World
All players: 1 total; [EntityPlayerMP['Player859'/34, l='GnC Testing World', x=107,55, y=57,38, z=165,19]]
Chunk stats: ServerChunkCache: 292 Drop: 0
Level seed: 8355312849087629082
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 3;minecraft:bedrock,3*minecraft:stone,52*minecraft:sandstone;2;
Level spawn location: 93,00,56,00,156,00 - World: (93,56,156), Chunk: (at 13,3,12 in 5,9; contains blocks 80,0,144 to 95,255,159), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
Level time: 336908 game time, 1000 day time
Level dimension: 0
Level storage version: 0x04ABD - Anvil
Level weather: Rain time: 1 (now: false), thunder time: 1 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:775)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540)
at java.lang.Thread.run(Thread.java:745)

-- System Details --
Details:
Minecraft Version: 1.8
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.8.0_05, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 830440696 bytes (791 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.10 FML v8.0.99.99 Minecraft Forge 11.14.3.1450 4 mods loaded, 4 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCHIJAAAA	mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) 
UCHIJAAAA	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.8-11.14.3.1450.jar) 
UCHIJAAAA	Forge{11.14.3.1450} [Minecraft Forge] (forgeSrc-1.8-11.14.3.1450.jar) 
UCHIJAAAA	gnc{0.2} [Gears N' Clouds] (bin) 
Loaded coremods (and transformers): 
GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
Profiler Position: N/A (disabled)
Player Count: 1 / 8; [EntityPlayerMP['Player859'/34, l='GnC Testing World', x=107,55, y=57,38, z=165,19]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'
[18:35:51] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:663]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2016-10-29_18.35.51-server.txt
[18:35:51] [Client thread/INFO] [FML]: Waiting for the server to terminate/save.
[18:35:51] [server thread/INFO]: Saving worlds
[18:35:51] [server thread/INFO]: Saving chunks for level 'GnC Testing World'/Overworld
[18:35:51] [server thread/INFO]: Saving chunks for level 'GnC Testing World'/Nether
[18:35:51] [server thread/INFO]: Saving chunks for level 'GnC Testing World'/The End
[18:35:51] [server thread/INFO] [FML]: Unloading dimension 0
[18:35:51] [server thread/INFO] [FML]: Unloading dimension -1
[18:35:51] [server thread/INFO] [FML]: Unloading dimension 1
[18:35:51] [server thread/INFO] [FML]: Applying holder lookups
[18:35:51] [server thread/INFO] [FML]: Holder lookups applied
[18:35:51] [server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.
[18:35:51] [Client thread/INFO] [FML]: Server terminated.

 

 

I've decoded this and found the source of the problem which is in this if statement (I will warn you, this if statement is incredibly long and will therefore look strange in this post. If you copy it and post it in a notepad document, it will look normal):

 

				
			if((worldObj.getBlockState(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())).getBlock() == worldObj.getBlockState(pos).getBlock()) 
			&&((worldObj.getBlockState(pos).getBlock() == worldObj.getBlockState(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())).getBlock() && (worldObj.getTileEntity(pos).getTileData().getString("liquid") == worldObj.getTileEntity(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())).getTileData().getString("liquid") || worldObj.getTileEntity(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())).getTileData().getString("liquid") == "nothing") && worldObj.getTileEntity(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())).getTileData().getInteger("fillLevel") <= worldObj.getTileEntity(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())).getTileData().getInteger("fillLevel")) ^ (worldObj.getBlockState(pos).getBlock() != worldObj.getBlockState(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())).getBlock() || worldObj.getTileEntity(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())).getTileData().getString("liquid") != worldObj.getTileEntity(pos).getTileData().getString("liquid"))) 
			&&((worldObj.getBlockState(pos).getBlock() == worldObj.getBlockState(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)).getBlock() && (worldObj.getTileEntity(pos).getTileData().getString("liquid") == worldObj.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)).getTileData().getString("liquid") || worldObj.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)).getTileData().getString("liquid") == "nothing") && worldObj.getTileEntity(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())).getTileData().getInteger("fillLevel") <= worldObj.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)).getTileData().getInteger("fillLevel")) ^ (worldObj.getBlockState(pos).getBlock() != worldObj.getBlockState(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)).getBlock() || worldObj.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)).getTileData().getString("liquid") != worldObj.getTileEntity(pos).getTileData().getString("liquid"))) 
			&&((worldObj.getBlockState(pos).getBlock() == worldObj.getBlockState(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)).getBlock() && (worldObj.getTileEntity(pos).getTileData().getString("liquid") == worldObj.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)).getTileData().getString("liquid") || worldObj.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)).getTileData().getString("liquid") == "nothing") && worldObj.getTileEntity(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())).getTileData().getInteger("fillLevel") <= worldObj.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)).getTileData().getInteger("fillLevel")) ^ (worldObj.getBlockState(pos).getBlock() != worldObj.getBlockState(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)).getBlock() || worldObj.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)).getTileData().getString("liquid") != worldObj.getTileEntity(pos).getTileData().getString("liquid")))) {
				fillLevel = worldObj.getTileEntity(pos).getTileData().getInteger("fillLevel");
				NBTTagCompound tag = worldObj.getTileEntity(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())).getTileData();
				int temp = tag.getInteger("fillLevel");
				tag.setInteger("fillLevel", ((fillLevel - temp) / 2) + temp);
				tag.setString("liquid", "Steam");
				fillLevel = fillLevel - (fillLevel - temp) / 2;
				worldObj.getTileEntity(pos).getTileData().setInteger("fillLevel", fillLevel);
			}

 

The issue in the statement being this line of code:

worldObj.getTileEntity(pos).getTileData().getString("liquid") == worldObj.getTileEntity(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())).getTileData().getString("liquid")

My theory is that because if the block it is checking for is not a tile entity, it doesn't know what to do and therefore crashes.

I don't know how to solve this issue though and would appreciate any help I could get!

 

If any more code is required, just ask me and I'll add it to this main post!

Thanks in advance!

Link to comment
Share on other sites

Solution:

Not being a fucking idiot.

 

Step 1: get the TE

Step 2: check for null

Step 3: do your stuff

 

And bonus step: Not doing your stuff by manipulating NBT data.  Use Capabilities.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Also, if you want to change a

BlockPos

over 1 block, use

BlockPos#[direction]()

.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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



×
×
  • Create New...

Important Information

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