Java Code Examples for net.minecraft.entity.Entity#getEntityData()

The following examples show how to use net.minecraft.entity.Entity#getEntityData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Nyan.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
	final Entity entity = event.getEntity();
	final World world = entity.getEntityWorld();

	if(world.isRemote) {
		return;
	}

	final MinecraftServer server = world.getMinecraftServer();
	final NBTTagCompound data = entity.getEntityData();

	if(data.hasUniqueId(NYANED_ENTITY_UUID_KEY)) {
		final Entity nyanedEntity =
				server.getEntityFromUuid(data.getUniqueId(NYANED_ENTITY_UUID_KEY));

		if(nyanedEntity == null || nyanedEntity.isDead) {
			world.removeEntity(entity);
			return;
		}
	}

	if(data.getBoolean(HAS_NYAN_ENTITY_KEY)) {
		updateNyanEntity(server, (WorldServer) world, entity, data);
	} else if(!data.hasKey(HAS_NYAN_ENTITY_KEY)) {
		if(entity instanceof EntityPlayer || random.nextInt(10) == 0) {
			data.setBoolean(HAS_NYAN_ENTITY_KEY, true);
			updateNyanEntity(server, (WorldServer) world, entity, data);
		} else {
			data.setBoolean(HAS_NYAN_ENTITY_KEY, false);
		}
	}
}
 
Example 2
Source File: SlimeBlock.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
	NBTTagCompound data = entity.getEntityData();
	if (data.hasKey(Reference.MOD_ID + ":slime")) {
		entity.motionY = data.getDouble(Reference.MOD_ID + ":slime");
		data.removeTag(Reference.MOD_ID + ":slime");
	}

	if (Math.abs(entity.motionY) < 0.1 && !entity.isSneaking()) {
		double d = 0.4 + Math.abs(entity.motionY) * 0.2;
		entity.motionX *= d;
		entity.motionZ *= d;
	}
}