Java Code Examples for net.minecraft.world.World#removeEntity()

The following examples show how to use net.minecraft.world.World#removeEntity() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@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
@Override
public void finish(World world, BlockPos pos, List<EntityItem> items) {
	EntityItem item = items.stream().filter(entity -> entity.getItem().getItem() instanceof IPotionEffectExplodable).findFirst().orElse(null);
	if (item != null) {
		((IPotionEffectExplodable) item.getItem().getItem()).explode(item);
		world.setBlockToAir(pos);
		world.removeEntity(item);
		world.playSound(null, item.posX, item.posY, item.posZ, ModSounds.GLASS_BREAK, SoundCategory.AMBIENT, 0.5F, (RandUtil.nextFloat() * 0.4F) + 0.8F);
	}
}
 
Example 3
Source Project: malmo   File: BlockDrawingHelper.java    License: MIT License 5 votes vote down vote up
public void clearEntities(World w, double x1, double y1, double z1, double x2, double y2, double z2)
{
    List<Entity> entities = w.getEntitiesWithinAABBExcludingEntity(null,  new AxisAlignedBB(x1, y1, z1, x2, y2, z2));
    for (Entity ent : entities)
        if (!(ent instanceof EntityPlayer))
            w.removeEntity(ent);
}
 
Example 4
@Override
public EnumActionResult onItemUse(final ItemStack item, final EntityPlayer player, final World w,
								  final BlockPos coord, EnumHand hand, final EnumFacing facing,
								  final float partialX, final float partialY, final float partialZ) {
	if(facing != EnumFacing.UP) return EnumActionResult.PASS;
	List<EntityItem> entities = w.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(
			coord.getX(),coord.getY()+1,coord.getZ(),
			coord.getX()+1,coord.getY()+2,coord.getZ()+1));
	boolean success = false;
	for(EntityItem target : entities){
			ItemStack targetItem = ((net.minecraft.entity.item.EntityItem)target).getEntityItem();
			if(targetItem != null ){
				ICrusherRecipe recipe = CrusherRecipeRegistry.getInstance().getRecipeForInputItem(targetItem);
				if(recipe != null){
					// hardness check
					if(BaseMetals.enforceHardness){
						if(targetItem.getItem() instanceof ItemBlock){
							Block b = ((ItemBlock)targetItem.getItem()).getBlock();
							if(!this.canHarvestBlock(b.getStateFromMeta(targetItem.getMetadata()))){
								// cannot harvest the block, no crush for you!
								return EnumActionResult.PASS;
							}
						}
					}
					// crush the item (server side only)
                       if(!w.isRemote) {
                           ItemStack output = recipe.getOutput().copy();
                           int count = output.stackSize;
                           output.stackSize = 1;
                           double x = target.posX;
                           double y = target.posY;
                           double z = target.posZ;

                           targetItem.stackSize--;
                           if (targetItem.stackSize <= 0) {
                               w.removeEntity(target);
                           }
                           for (int i = 0; i < count; i++) {
                               w.spawnEntityInWorld(new EntityItem(w, x, y, z, output.copy()));
                           }
                           item.damageItem(1, player);
                       }
					success = true;
					break;
				}
			}
	}
	if(success){
           w.playSound(player, coord, SoundEvents.BLOCK_GRAVEL_BREAK, SoundCategory.BLOCKS, 0.5F, 0.5F + (itemRand.nextFloat() * 0.3F));
	}
	return success ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}