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

Save Entity Data on tile entity


hsgill97@gmail.com
 Share

Recommended Posts

I have this "AlienCell" that is a tileEntity. I want to capture any entity that hits the block.I already have it setup, It crashes when saving though.

 

TileEntity

 

 

public class TileEntityAlienCell extends TileEntity {
public boolean empty=true;
public Entity mob;
@Override
public void readFromNBT(NBTTagCompound compound) {
	super.readFromNBT(compound);
	empty=compound.getBoolean("empty");
	if(!empty)
		mob=EntityList.createEntityFromNBT(compound.getCompoundTag("mob"), worldObj);

}

@Override
public void writeToNBT(NBTTagCompound compound) {
	super.writeToNBT(compound);
	NBTTagCompound EntityNBT=new NBTTagCompound();
	if(!empty)
		mob.writeToNBTOptional(EntityNBT);
	compound.setBoolean("empty", empty);
	compound.setTag("mob", EntityNBT);
        
}
}

 

 

Block

 

public class AlienCell extends BlockContainer {

public AlienCell() {
	super(Material.iron);
	this.setCreativeTab(Main.aliensTabTech);
	this.setHardness(12.0F);
	this.setCellBounds();

}

@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {

	TileEntityAlienCell cell = (TileEntityAlienCell) worldIn.getTileEntity(pos);
	if (entityIn.ridingEntity == null && entityIn.riddenByEntity == null) {
		if (entityIn instanceof EntityPlayerMP) {

		} else {
			cell.mob.copyDataFromOld(entityIn);
			cell.empty=false;
		}
	}

}


public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {
	this.setCellBounds();
}

private void setCellBounds() {
	this.setBlockBounds(-1.064F, 0.0F, -0.56F, 1.06F, 2.85F, 1.25F);
}

public int getRenderType() {
	return -1;
}

public boolean isOpaqueCube() {
	return false;
}

public boolean renderAsNormalBlock() {
	return false;
}

@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
	return new TileEntityAlienCell();
}

}

 

 

Crash

 

 

---- Minecraft Crash Report ----

// Ouch. That hurt :(

 

Time: 11/12/15 4:58 PM

Description: Colliding entity with block

 

java.lang.NullPointerException: Colliding entity with block

at com.madmodding.space.blocks.AlienCell.onEntityCollidedWithBlock(AlienCell.java:57)

at net.minecraft.entity.Entity.doBlockCollisions(Entity.java:924)

at net.minecraft.entity.Entity.moveEntity(Entity.java:850)

at net.minecraft.entity.EntityLivingBase.moveEntityWithHeading(EntityLivingBase.java:1699)

at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:2026)

at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:449)

at net.minecraft.entity.EntityAgeable.onLivingUpdate(EntityAgeable.java:173)

at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1828)

at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:273)

at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2031)

at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:758)

at net.minecraft.world.World.updateEntity(World.java:1997)

at net.minecraft.world.World.updateEntities(World.java:1823)

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(Unknown Source)

 

 

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

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at com.madmodding.space.blocks.AlienCell.onEntityCollidedWithBlock(AlienCell.java:57)

 

-- Block being collided with --

Details:

Block: space:alienCell

Block location: World: (-640,4,-1553), Chunk: (at 0,0,15 in -40,-98; contains blocks -640,0,-1568 to -625,255,-1553), Region: (-2,-4; contains chunks -64,-128 to -33,-97, blocks -1024,0,-2048 to -513,255,-1537)

Stacktrace:

at net.minecraft.entity.Entity.doBlockCollisions(Entity.java:924)

 

-- Entity being checked for collision --

Details:

Entity Type: Villager (net.minecraft.entity.passive.EntityVillager)

Entity ID: 230623

Entity Name: Villager

Entity's Exact location: -639.50, 4.67, -1553.29

Entity's Block location: -640.00,4.00,-1554.00 - World: (-640,4,-1554), Chunk: (at 0,0,14 in -40,-98; contains blocks -640,0,-1568 to -625,255,-1553), Region: (-2,-4; contains chunks -64,-128 to -33,-97, blocks -1024,0,-2048 to -513,255,-1537)

Entity's Momentum: 0.00, 0.04, 0.06

Entity's Rider: ~~ERROR~~ NullPointerException: null

Entity's Vehicle: ~~ERROR~~ NullPointerException: null

Stacktrace:

at net.minecraft.entity.Entity.moveEntity(Entity.java:850)

at net.minecraft.entity.EntityLivingBase.moveEntityWithHeading(EntityLivingBase.java:1699)

at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:2026)

at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:449)

at net.minecraft.entity.EntityAgeable.onLivingUpdate(EntityAgeable.java:173)

at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1828)

at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:273)

at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2031)

at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:758)

at net.minecraft.world.World.updateEntity(World.java:1997)

 

-- Entity being ticked --

Details:

Entity Type: Villager (net.minecraft.entity.passive.EntityVillager)

Entity ID: 230623

Entity Name: Villager

Entity's Exact location: -639.50, 4.67, -1553.29

Entity's Block location: -640.00,4.00,-1554.00 - World: (-640,4,-1554), Chunk: (at 0,0,14 in -40,-98; contains blocks -640,0,-1568 to -625,255,-1553), Region: (-2,-4; contains chunks -64,-128 to -33,-97, blocks -1024,0,-2048 to -513,255,-1537)

Entity's Momentum: 0.00, 0.04, 0.06

Entity's Rider: ~~ERROR~~ NullPointerException: null

Entity's Vehicle: ~~ERROR~~ NullPointerException: null

Stacktrace:

at net.minecraft.world.World.updateEntities(World.java:1823)

at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:587)

 

-- Affected level --

Details:

Level name: New World

All players: 1 total; [EntityPlayerMP['Arideus'/26, l='New World', x=-638.38, y=5.00, z=-1556.23]]

Chunk stats: ServerChunkCache: 1347 Drop: 0

Level seed: 1319145234

Level generator: ID 01 - flat, ver 0. Features enabled: true

Level generator options:

Level spawn location: -633.00,4.00,-1546.00 - World: (-633,4,-1546), Chunk: (at 7,0,6 in -40,-97; contains blocks -640,0,-1552 to -625,255,-1537), Region: (-2,-4; contains chunks -64,-128 to -33,-97, blocks -1024,0,-2048 to -513,255,-1537)

Level time: 795 game time, 795 day time

Level dimension: 0

Level storage version: 0x04ABD - Anvil

Level weather: Rain time: 46645 (now: false), thunder time: 162414 (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(Unknown Source)

 

-- System Details --

Details:

Minecraft Version: 1.8

Operating System: Windows 10 (amd64) version 10.0

Java Version: 1.8.0_65, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 3876190920 bytes (3696 MB) / 4260102144 bytes (4062 MB) up to 4260102144 bytes (4062 MB)

JVM Flags: 3 total; -Xincgc -Xmx4096M -Xms4096M

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML: MCP v9.10 FML v8.0.99.99 Minecraft Forge 11.14.3.1561 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.1561.jar)

UCHIJAAAA Forge{11.14.3.1561} [Minecraft Forge] (forgeSrc-1.8-11.14.3.1561.jar)

UCHIJAAAA space{0.1.8} [beyondSolar] (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['Arideus'/26, l='New World', x=-638.38, y=5.00, z=-1556.23]]

Type: Integrated Server (map_client.txt)

Is Modded: Definitely; Client brand changed to 'fml,forge'

 

 

Link to comment
Share on other sites

You can write an Entity to NBT by first creating a new empty NBTTagCompound and then calling

writeToNBTOptional

on the entity with that compound. The entity will then write itself into that NBT compound and you can embed it in your TileEntity data.

To restore an entity from NBT, use EntityList.createEntityFromNBT.

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
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.

 Share



×
×
  • Create New...

Important Information

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