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

The following examples show how to use net.minecraft.world.World#getEntitiesWithinAABBExcludingEntity() . 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: MoCTools.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
public static void buckleMobsNotPlayers(EntityLiving entityattacker, Double dist, World worldObj)
{
    List list = worldObj.getEntitiesWithinAABBExcludingEntity(entityattacker, entityattacker.boundingBox.expand(dist, 2D, dist));
    for (int i = 0; i < list.size(); i++)
    {
        Entity entitytarget = (Entity) list.get(i);
        if (!(entitytarget instanceof EntityLiving) || (entitytarget instanceof EntityPlayer) ||(entityattacker.riddenByEntity != null && entitytarget == entityattacker.riddenByEntity))
        {
            continue;
        }
        //EntityMob entitymob = (EntityMob) entity;
        entitytarget.attackEntityFrom(DamageSource.causeMobDamage(entityattacker), 2);
        bigsmack(entityattacker, entitytarget, 0.6F);
        playCustomSound(entityattacker, "tud", worldObj);
        //todo tuck sound!!
    }
}
 
Example 2
Source File: MovingTargetDecoratorImplementation.java    From malmo with MIT License 6 votes vote down vote up
private boolean pinchedByPlayer(World world)
{
    for (BlockPos bp : this.path)
    {
        //Block b = world.getBlockState(bp).getBlock();
        //AxisAlignedBB aabb = b.getCollisionBoundingBox(world, bp, b.getDefaultState());
        //aabb.expand(0, 1, 0);
        BlockPos bp2 = new BlockPos(bp.getX()+1, bp.getY()+2, bp.getZ()+1);
        AxisAlignedBB aabb = new AxisAlignedBB(bp, bp2);
        List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, aabb);
        for (Entity ent : entities)
            if (ent instanceof EntityPlayer)
                return true;
    }
    return false;
}
 
Example 3
Source File: ModuleEffectTimeSlow.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@ModuleOverride("shape_zone_run")
public boolean onRunZone(World world, SpellData data, SpellRing ring, @ContextRing SpellRing childRing) {
	double aoe = ring.getAttributeValue(world, AttributeRegistry.AREA, data);
	double range = ring.getAttributeValue(world, AttributeRegistry.RANGE, data);

	Vec3d targetPos = data.getTarget(world);

	if (targetPos == null) return false;

	Vec3d min = targetPos.subtract(aoe, range, aoe);
	Vec3d max = targetPos.add(aoe, range, aoe);

	List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(min, max));
	for (Entity entity : entities) {
		if (entity instanceof EntityLivingBase) {
			if (!((EntityLivingBase) entity).isPotionActive(ModPotions.TIME_SLOW) && entity.getDistanceSq(targetPos.x, targetPos.y, targetPos.z) <= aoe * aoe) {
				data.processEntity(entity, false);
				runOnStart(world, data, childRing);
			}
		}
	}
	return true;
}
 
Example 4
Source File: RedstoneEtherServer.java    From WirelessRedstone with MIT License 6 votes vote down vote up
private void entityJamTest(World world)
{
    if(world.getTotalWorldTime() % 10 != 0)
        return;
    
    int dimension = CommonUtils.getDimension(world);
    for(Iterator<BlockCoord> iterator = ethers.get(dimension).jammerset.iterator(); iterator.hasNext();)
    {
        BlockCoord jammer = iterator.next();
        List<Entity> entitiesinrange = world.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(jammer.x-9.5, jammer.y-9.5, jammer.z-9.5, jammer.x+10.5, jammer.y+10.5, jammer.z+10.5));
        for(Iterator<Entity> iterator2 = entitiesinrange.iterator(); iterator2.hasNext();)
        {
            Entity entity = iterator2.next();
            if(!(entity instanceof EntityLivingBase))
                continue;
            
            if(entity instanceof EntityPlayer)
                if(isPlayerJammed((EntityPlayer)entity))
                    continue;
            
            jamEntitySometime((EntityLivingBase) entity);
        }
    }
}
 
Example 5
Source File: MoCEntityAmbient.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
public void repelMobs(Entity entity1, Double dist, World worldObj)
{
	List list = worldObj.getEntitiesWithinAABBExcludingEntity(entity1, entity1.boundingBox.expand(dist, 4D, dist));
	for (int i = 0; i < list.size(); i++)
	{
		Entity entity = (Entity) list.get(i);
		if (!(entity instanceof EntityMob))
		{
			continue;
		}
		EntityMob entitymob = (EntityMob) entity;
		entitymob.setAttackTarget(null);
		entitymob.setPathToEntity(null);
	}
}
 
Example 6
Source File: BlockSeat.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos,
		IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY,
		float hitZ) {
	
	if(!world.isRemote) {
		List<Entity> list = world.getEntitiesWithinAABBExcludingEntity(player, new AxisAlignedBB(pos, pos.add(1,1,1)));

		//Try to mount player to dummy entity in the block
		for(Entity e : list) {
			if(e instanceof EntityDummy) {
				if(!e.getPassengers().isEmpty()) {
					return true;
				}
				else {
					//Ensure that the entity is in the correct position
					e.setPosition(pos.getX() + 0.5f, pos.getY() + 0.2f, pos.getZ() + 0.5f);
					player.startRiding(e);
					return true;
				}
			}
		}
		EntityDummy entity = new EntityDummy(world, pos.getX() + 0.5f, pos.getY() + 0.2f, pos.getZ() + 0.5f);
		world.spawnEntity(entity);
		player.startRiding(entity);
	}

	return true;
}
 
Example 7
Source File: BlockArtifactsPressurePlate.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
//getPlateState
protected int func_150065_e(World world, int x, int y, int z)
{
	List list = null;

	if (this.triggerMobType == BlockPressurePlate.Sensitivity.everything)
	{
		list = world.getEntitiesWithinAABBExcludingEntity((Entity)null, this.func_150061_a/*getSensitiveAABB*/(x, y, z));
	}

	if (this.triggerMobType == BlockPressurePlate.Sensitivity.mobs)
	{
		list = world.getEntitiesWithinAABB(EntityLivingBase.class, this.func_150061_a(x, y, z));
	}

	if (this.triggerMobType == BlockPressurePlate.Sensitivity.players)
	{
		list = world.getEntitiesWithinAABB(EntityPlayer.class, this.func_150061_a(x, y, z));
	}

	if (!list.isEmpty())
	{
		Iterator iterator = list.iterator();

		while (iterator.hasNext())
		{
			Entity entity = (Entity)iterator.next();

			if (!entity.doesEntityNotTriggerPressurePlate())
			{
				return 15;
			}
		}
	}

	return 0;
}
 
Example 8
Source File: ModuleEffectFrost.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@ModuleOverride("shape_zone_run")
public boolean onRunZone(World world, SpellData data, SpellRing ring, @ContextRing SpellRing childRing) {
	if(!world.isRemote) return false;

	double aoe = ring.getAttributeValue(world, AttributeRegistry.AREA, data);
	double range = ring.getAttributeValue(world, AttributeRegistry.RANGE, data);

	Vec3d targetPos = data.getTarget(world);

	if (targetPos == null) return false;

	Vec3d min = targetPos.subtract(aoe, range, aoe);
	Vec3d max = targetPos.add(aoe, range, aoe);

	List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(min, max));
	for (Entity entity : entities) {
		entity.extinguish();
		if (entity instanceof EntityLivingBase) {
			if (!((EntityLivingBase) entity).isPotionActive(ModPotions.SLIPPERY) && entity.getDistanceSq(targetPos.x, targetPos.y, targetPos.z) <= aoe * aoe) {

				double time = childRing.getAttributeValue(world, AttributeRegistry.DURATION, data) * 10;
				world.playSound(null, entity.getPosition(), ModSounds.FROST_FORM, SoundCategory.NEUTRAL, 1, 1);
				((EntityLivingBase) entity).addPotionEffect(new PotionEffect(ModPotions.SLIPPERY, (int) time, 0, true, false));
			}
		}
	}
	return false;
}
 
Example 9
Source File: ModuleEffectTelekinesis.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
	Vec3d targetPos = spell.getTarget(world);
	Entity caster = spell.getCaster(world);

	double potency = spellRing.getAttributeValue(world, AttributeRegistry.AREA, spell) * 2;

	if (targetPos == null) return false;

	List<Entity> entityList = world.getEntitiesWithinAABBExcludingEntity(caster, new AxisAlignedBB(new BlockPos(targetPos)).grow(potency, potency, potency));

	if (RandUtil.nextInt(10) == 0)
		world.playSound(null, new BlockPos(targetPos), ModSounds.ETHEREAL_PASS_BY, SoundCategory.NEUTRAL, 0.5f, RandUtil.nextFloat());
	for (Entity entity : entityList) {
		double dist = entity.getPositionVector().distanceTo(targetPos);
		if (dist > potency) continue;
		if (!spellRing.taxCaster(world, spell, true)) return false;

		final double upperMag = 1;
		final double scale = 1;
		double mag = upperMag * (scale * dist / (-scale * dist - 1) + 1);

		Vec3d dir = targetPos.subtract(entity.getPositionVector()).normalize().scale(mag);

		entity.motionX = (dir.x);
		entity.motionY = (dir.y);
		entity.motionZ = (dir.z);
		entity.fallDistance = 0;
		entity.velocityChanged = true;

		if (entity instanceof EntityLivingBase) {
			((EntityLivingBase) entity).addPotionEffect(new PotionEffect(ModPotions.NULLIFY_GRAVITY, 2, 1, false, false));
		}

	}
	return true;
}
 
Example 10
Source File: MoCEntityAnimal.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
public void repelMobs(Entity entity1, Double dist, World worldObj)
{
	List list = worldObj.getEntitiesWithinAABBExcludingEntity(entity1, entity1.boundingBox.expand(dist, 4D, dist));
	for (int i = 0; i < list.size(); i++)
	{
		Entity entity = (Entity) list.get(i);
		if (!(entity instanceof EntityMob))
		{
			continue;
		}
		EntityMob entitymob = (EntityMob) entity;
		entitymob.setAttackTarget(null);
		entitymob.setPathToEntity(null);
	}
}
 
Example 11
Source File: ModuleEffectGravityWell.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
	Vec3d position = spell.getTarget(world);

	if (position == null) return false;

	double area = spellRing.getAttributeValue(world, AttributeRegistry.AREA, spell);

	for (Entity entity : world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(new BlockPos(position)).grow(area, area, area))) {
		if (entity == null) continue;
		double dist = entity.getPositionVector().distanceTo(position);
		if (dist < 2) continue;
		if (dist > area) continue;
		if (!spellRing.taxCaster(world, spell, false)) return false;

		final double upperMag = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell) / 50.0;
		final double scale = 1.5;
		double mag = upperMag * (scale * dist / (-scale * dist - 1) + 1);

		Vec3d dir = position.subtract(entity.getPositionVector()).normalize().scale(mag);

		entity.motionX += (dir.x);
		entity.motionY += (dir.y);
		entity.motionZ += (dir.z);
		entity.fallDistance = 0;
		entity.velocityChanged = true;

		spell.addData(ENTITY_HIT, entity.getEntityId());
		if (entity instanceof EntityPlayerMP)
			((EntityPlayerMP) entity).connection.sendPacket(new SPacketEntityVelocity(entity));
	}

	return true;
}
 
Example 12
Source File: ModuleEffectPoisonCloud.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
	Vec3d position = spell.getTarget(world);
	BlockPos pos = spell.getTargetPos();

	if (position == null || pos == null) return true;

	if (!spellRing.taxCaster(world, spell, true)) return false;

	double potency = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell);

	double area = spellRing.getAttributeValue(world, AttributeRegistry.AREA, spell);

	if (world.getTotalWorldTime() % 2 == 0)
		world.playSound(null, pos, ModSounds.FIZZING_LOOP, SoundCategory.NEUTRAL, RandUtil.nextFloat(0.6f, 1f), RandUtil.nextFloat(0.1f, 4f));
	for (Entity entity : world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(new BlockPos(position)).grow(area, area, area))) {
		if (entity instanceof EntityLivingBase) {
			EntityLivingBase living = (EntityLivingBase) entity;
			if (potency >= 3) {
				living.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 100));
			}
			living.addPotionEffect(new PotionEffect(MobEffects.POISON, 60, (int) (potency / 3)));
		}
	}

	return true;
}
 
Example 13
Source File: BlockWallPlate.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
//getPlateState
protected int func_150065_e(World world, int x, int y, int z)
{
	List list = null;
	int meta = world.getBlockMetadata(x, y, z);
	if (this.triggerMobType == BlockPressurePlate.Sensitivity.everything)
	{
		list = world.getEntitiesWithinAABBExcludingEntity((Entity)null, this.getMetaSensitiveAABB(x, y, z, meta));
	}

	if (this.triggerMobType == BlockPressurePlate.Sensitivity.mobs)
	{
		list = world.getEntitiesWithinAABB(EntityLivingBase.class, this.getMetaSensitiveAABB(x, y, z, meta));
	}

	if (this.triggerMobType == BlockPressurePlate.Sensitivity.players)
	{
		list = world.getEntitiesWithinAABB(EntityPlayer.class, this.getMetaSensitiveAABB(x, y, z, meta));
	}

	if (!list.isEmpty())
	{
		Iterator iterator = list.iterator();

		while (iterator.hasNext())
		{
			Entity entity = (Entity)iterator.next();
			if (!entity.doesEntityNotTriggerPressurePlate())
			{
				return 15;
			}
		}
	}


	return 0;
}
 
Example 14
Source File: BlockTofuFarmLand.java    From TofuCraftReload with MIT License 5 votes vote down vote up
protected static void turnToDirt(World p_190970_0_, BlockPos worldIn)
{
    p_190970_0_.setBlockState(worldIn, BlockLoader.tofuTerrain.getDefaultState());
    AxisAlignedBB axisalignedbb = field_194405_c.offset(worldIn);

    for (Entity entity : p_190970_0_.getEntitiesWithinAABBExcludingEntity((Entity)null, axisalignedbb))
    {
        double d0 = Math.min(axisalignedbb.maxY - axisalignedbb.minY, axisalignedbb.maxY - entity.getEntityBoundingBox().minY);
        entity.setPositionAndUpdate(entity.posX, entity.posY + d0 + 0.001D, entity.posZ);
    }
}
 
Example 15
Source File: BlockLaserBeam.java    From Artifacts with MIT License 4 votes vote down vote up
private boolean updateTripWireState(World par1World, int par2, int par3, int par4)
{
    int l = par1World.getBlockMetadata(par2, par3, par4);
    boolean flag = (l & 1) == 1;
    boolean flag1 = false;
    List list = par1World.getEntitiesWithinAABBExcludingEntity((Entity)null, AxisAlignedBB.getBoundingBox((double)par2 + this.minX, (double)par3 + this.minY, (double)par4 + this.minZ, (double)par2 + this.maxX, (double)par3 + this.maxY, (double)par4 + this.maxZ));

    if (!list.isEmpty())
    {
        Iterator iterator = list.iterator();

        while (iterator.hasNext())
        {
            Entity entity = (Entity)iterator.next();
            if (entity instanceof EntityLivingBase && !entity.doesEntityNotTriggerPressurePlate())
            {
                flag1 = true;
                break;
            }
        }
    }

    if (flag1 && !flag)
    {
        l |= 1;
    }

    if (!flag1 && flag)
    {
        l &= -2;
    }
    boolean ff = false;
    if (flag1 != flag)
    {
        par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 3);
        this.func_72149_e(par1World, par2, par3, par4, l);
        ff = true;
    }

    if (flag1)
    {
        par1World.scheduleBlockUpdate(par2, par3, par4, this.instance, this.tickRate(par1World));
    }
    return ff;
}
 
Example 16
Source File: PearlInfusionRecipe.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void complete(World world, BlockPos pos, ItemStack input, ItemStackHandler inventoryHandler) {
	ArrayList<ItemStack> stacks = new ArrayList<>();

	for (int i = 0; i < inventoryHandler.getSlots(); i++) {
		if (!inventoryHandler.getStackInSlot(i).isEmpty()) {
			stacks.add(inventoryHandler.getStackInSlot(i));
			inventoryHandler.setStackInSlot(i, ItemStack.EMPTY);
		}
	}

	// Process spellData multipliers based on nacre quality
	double pearlMultiplier = 1;
	if (input.getItem() instanceof INacreProduct) {
		float purity = ((INacreProduct) input.getItem()).getQuality(input);
		if (purity >= 1f) pearlMultiplier = ConfigValues.perfectPearlMultiplier * purity;
		else if (purity <= ConfigValues.damagedPearlMultiplier)
			pearlMultiplier = ConfigValues.damagedPearlMultiplier;
		else {
			double base = purity - 1;
			pearlMultiplier = 1 - (base * base * base * base);
		}
	}

	SpellBuilder builder = new SpellBuilder(stacks, pearlMultiplier);

	NBTTagList list = new NBTTagList();
	for (SpellRing spellRing : builder.getSpell()) {
		list.appendTag(spellRing.serializeNBT());
	}

	SpellUtils.infuseSpell(input, list);

	//markDirty();

	PacketHandler.NETWORK.sendToAllAround(new PacketExplode(new Vec3d(pos).add(0.5, 0.5, 0.5), Color.CYAN, Color.BLUE, 2, 2, 500, 300, 20, true),
			new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 256));

	world.playSound(null, pos, ModSounds.BASS_BOOM, SoundCategory.BLOCKS, 1f, (float) RandUtil.nextDouble(1, 1.5));

	List<Entity> entityList = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos).grow(32, 32, 32));
	for (Entity entity1 : entityList) {
		double dist = entity1.getDistance(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
		final double upperMag = 3;
		final double scale = 0.8;
		double mag = upperMag * (scale * dist / (-scale * dist - 1) + 1);
		Vec3d dir = entity1.getPositionVector().subtract(new Vec3d(pos).add(0.5, 0.5, 0.5)).normalize().scale(mag);

		entity1.motionX = (dir.x);
		entity1.motionY = (dir.y);
		entity1.motionZ = (dir.z);
		entity1.fallDistance = 0;
		entity1.velocityChanged = true;

		if (entity1 instanceof EntityPlayerMP)
			((EntityPlayerMP) entity1).connection.sendPacket(new SPacketEntityVelocity(entity1));
	}
}
 
Example 17
Source File: BlockLaserBeamSource.java    From Artifacts with MIT License 4 votes vote down vote up
@Override
  public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity)
  {
//System.out.println("Collide");
      if (!par1World.isRemote)
      {
      	/*int m = par1World.getBlockMetadata(par2, par3, par4);
          if ((m & 8) != 8)
          {
          	par1World.setBlockMetadataWithNotify(par2, par3, par4, m, 3);
          }*/
      	int l = par1World.getBlockMetadata(par2, par3, par4);
          boolean flag = (l & 8) == 8;
      	boolean flag1 = false;
      	List list = par1World.getEntitiesWithinAABBExcludingEntity((Entity)null, AxisAlignedBB.getBoundingBox((double)par2 + this.minX, (double)par3 + this.minY, (double)par4 + this.minZ, (double)par2 + this.maxX, (double)par3 + this.maxY, (double)par4 + this.maxZ));

          if (!list.isEmpty())
          {
              Iterator iterator = list.iterator();

              while (iterator.hasNext())
              {
                  Entity entity = (Entity)iterator.next();

                  if (entity instanceof EntityLivingBase && !entity.doesEntityNotTriggerPressurePlate())
                  {
                      flag1 = true;
                      break;
                  }
              }
          }
          if (flag1 && !flag)
          {
              l |= 8;
              par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 3);
              notifyNeighborOfChange(par1World, par2, par3, par4, l);
          //}
          //if (flag1)
          //{
              par1World.scheduleBlockUpdate(par2, par3, par4, this.instance, this.tickRate(par1World));
          }
      }
  }
 
Example 18
Source File: ItemMobHarness.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean mountTarget(ItemStack stack, World world, EntityPlayer player, Entity targetEntity)
{
    if (stack.getTagCompound() == null || targetEntity == null)
    {
        return false;
    }

    NBTTagCompound nbt = stack.getTagCompound();
    byte mode = nbt.getByte("Mode");
    UUID storedUUID = new UUID(nbt.getLong("TargetUUIDMost"), nbt.getLong("TargetUUIDLeast"));
    Entity storedEntity = null;
    double r = 64.0d;

    // The harness was clicked twice on the same entity, mount that entity on top of the player
    if (storedUUID.equals(targetEntity.getUniqueID()))
    {
        EntityUtils.unmountFirstRider(player);
        targetEntity.startRiding(player, true);
        this.clearData(stack);

        return true;
    }
    // The harness was clicked on two separate entities, mount the stored/first one on top of the currently targeted one
    else
    {
        // Mode 1: mount non-player entities to each other or to the player
        if (mode == 1)
        {
            List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player,
                    new AxisAlignedBB(player.posX - r, player.posY - r, player.posZ - r,
                            player.posX + r, player.posY + r, player.posZ + r));
            storedEntity = EntityUtils.findEntityByUUID(entities, storedUUID);
        }
        // Mode 2: mount a player
        else if (mode == 2)
        {
            storedEntity = world.getPlayerEntityByUUID(storedUUID);
        }

        // Matching (stored) entity found
        if (storedEntity != null && storedEntity.dimension == player.dimension)
        {
            // Don't allow mounting the entity into the same stack, or nasty infinite loops will happen >_>
            if (EntityUtils.doesEntityStackContainEntity(storedEntity, targetEntity) == false)
            {
                //EntityUtils.unmountFirstRider(targetEntity);
                storedEntity.startRiding(targetEntity, true);
                this.clearData(stack);
                return true;
            }
        }
        else if (storedEntity == null && world.isRemote == false)
        {
            player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.mobharness.targetnotfoundoroutofrange"), true);
        }
    }

    return false;
}
 
Example 19
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void deleteArea(ItemStack stack, World world, EntityPlayer player, BlockPos posStart, BlockPos posEnd, boolean removeEntities)
{
    if (posStart == null || posEnd == null)
    {
        return;
    }

    if (player.getDistanceSq(posStart) > 160 * 160)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.areatoofar"), true);
        return;
    }

    if (this.isAreaWithinSizeLimit(posStart.subtract(posEnd), stack, player) == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.areatoolarge"), true);
        return;
    }

    // Set all blocks to air
    for (BlockPos.MutableBlockPos posMutable : BlockPos.getAllInBoxMutable(posStart, posEnd))
    {
        if (world.isAirBlock(posMutable) == false)
        {
            BlockUtils.setBlockToAirWithoutSpillingContents(world, posMutable, 2);
        }
    }

    // Remove pending block updates from within the area
    BlockPos posMin = PositionUtils.getMinCorner(posStart, posEnd);
    BlockPos posMax = PositionUtils.getMaxCorner(posStart, posEnd).add(1, 1, 1);
    StructureBoundingBox sbb = StructureBoundingBox.createProper(posMin.getX(), posMin.getY(), posMin.getZ(), posMax.getX(), posMax.getY(), posMax.getZ());
    world.getPendingBlockUpdates(sbb, true); // The boolean parameter indicates whether the entries will be removed

    // Remove all entities within the area
    int count = 0;

    if (removeEntities)
    {
        int x1 = Math.min(posStart.getX(), posEnd.getX());
        int y1 = Math.min(posStart.getY(), posEnd.getY());
        int z1 = Math.min(posStart.getZ(), posEnd.getZ());
        int x2 = Math.max(posStart.getX(), posEnd.getX());
        int y2 = Math.max(posStart.getY(), posEnd.getY());
        int z2 = Math.max(posStart.getZ(), posEnd.getZ());

        AxisAlignedBB bb = new AxisAlignedBB(x1, y1, z1, x2 + 1, y2 + 1, z2 + 1);
        List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, bb);

        for (Entity entity : entities)
        {
            if ((entity instanceof EntityPlayer) == false || entity instanceof FakePlayer)
            {
                entity.setDead();
                count++;
            }
        }

        if (count > 0)
        {
            player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.killedentitieswithcount", count), true);
        }
    }
}
 
Example 20
Source File: TemplateEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void addEntitiesToWorld(World world, BlockPos posStart)
{
    if (this.placement.getIgnoreEntities())
    {
        return;
    }

    Mirror mirror = this.placement.getMirror();
    Rotation rotation = this.placement.getRotation();

    BlockPos posEnd = posStart.add(PositionUtils.getRelativeEndPositionFromAreaSize(this.size));
    BlockPos pos1 = PositionUtils.getMinCorner(posStart, posEnd);
    BlockPos pos2 = PositionUtils.getMaxCorner(posStart, posEnd).add(1, 1, 1);
    List<Entity> existingEntities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos1, pos2));

    for (TemplateEnderUtilities.TemplateEntityInfo entityInfo : this.entities)
    {
        BlockPos pos = transformedBlockPos(this.placement, entityInfo.blockPos).add(posStart);

        NBTTagCompound nbt = entityInfo.entityData;
        UUID uuidOriginal = nbt.getUniqueId("UUID");
        Vec3d vec3d = PositionUtils.transformedVec3d(entityInfo.pos, mirror, rotation);
        Vec3d vec3d1 = vec3d.add((double)posStart.getX(), (double)posStart.getY(), (double)posStart.getZ());
        NBTTagList tagList = new NBTTagList();
        tagList.appendTag(new NBTTagDouble(vec3d1.x));
        tagList.appendTag(new NBTTagDouble(vec3d1.y));
        tagList.appendTag(new NBTTagDouble(vec3d1.z));
        nbt.setTag("Pos", tagList);
        nbt.setUniqueId("UUID", UUID.randomUUID());
        Entity entity;

        try
        {
            entity = EntityList.createEntityFromNBT(nbt, world);
        }
        catch (Exception e)
        {
            entity = null;
        }

        if (entity != null)
        {
            if (entity instanceof EntityPainting)
            {
                entity.getMirroredYaw(mirror);
                entity.getRotatedYaw(rotation);
                entity.setPosition(pos.getX(), pos.getY(), pos.getZ());
                entity.setLocationAndAngles(vec3d1.x, vec3d1.y, vec3d1.z, entity.rotationYaw, entity.rotationPitch);
            }
            else
            {
                float f = entity.getMirroredYaw(mirror);
                f = f + (entity.rotationYaw - entity.getRotatedYaw(rotation));
                entity.setLocationAndAngles(vec3d1.x, vec3d1.y, vec3d1.z, f, entity.rotationPitch);
                // FIXME should call updateFacingWithBoundingBox(EnumFacing) for EntityHanging, otherwise a world reload is needed
                // for ItemFrames for example to visually update to the correct facing
            }

            // Use the original UUID if possible. If there is an entity with the same UUID within the pasted area,
            // then the old one will be killed. Otherwise if there is no entity currently in the world with
            // the same UUID, then the original UUID will be used.
            Entity existing = EntityUtils.findEntityByUUID(existingEntities, uuidOriginal);
            if (existing != null)
            {
                world.removeEntityDangerously(existing);
                entity.setUniqueId(uuidOriginal);
            }
            else if (world instanceof WorldServer && ((WorldServer) world).getEntityFromUuid(uuidOriginal) == null)
            {
                entity.setUniqueId(uuidOriginal);
            }

            world.spawnEntity(entity);
        }
    }
}