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

The following examples show how to use net.minecraft.entity.Entity#setPosition() . 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: EntityDabSquirrel.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void updatePassenger(Entity passenger) {
    super.updatePassenger(passenger);

    if (passenger instanceof EntityLiving) {
        EntityLiving entityliving = (EntityLiving) passenger;
        this.renderYawOffset = entityliving.renderYawOffset;
    }

    if (this.prevRearingAmount > 0.0F) {
        float f3 = MathHelper.sin(this.renderYawOffset * 0.017453292F);
        float f = MathHelper.cos(this.renderYawOffset * 0.017453292F);
        float f1 = 0.7F * this.prevRearingAmount;
        float f2 = 0.15F * this.prevRearingAmount;
        passenger.setPosition(this.posX + f1 * f3, this.posY + this.getMountedYOffset() + passenger.getYOffset() + f2 - 2F, this.posZ - f1 * f);

        if (passenger instanceof EntityLivingBase) {
            ((EntityLivingBase) passenger).renderYawOffset = this.renderYawOffset;
        }
    }
    this.stepHeight = 4F;
}
 
Example 2
Source File: EntityRocket.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@Override
public void updatePassenger(Entity entity)
{
	if (entity != null )
	{
		//Bind player to the seat
		if(this.storage != null) {
			//Conditional b/c for some reason client/server positions do not match
			float xOffset = this.storage.getSizeX() % 2 == 0 ? 0.5f : 0f;
			float zOffset = this.storage.getSizeZ() % 2 == 0 ? 0.5f : 0f;
			entity.setPosition(this.posX  + stats.getSeatX() + xOffset, this.posY + stats.getSeatY() - 0.5f, this.posZ + stats.getSeatZ() + zOffset );
		}
		else
			entity.setPosition(this.posX , this.posY , this.posZ );
	}

	for(int i = 0; i < this.stats.getNumPassengerSeats(); i++) {
		HashedBlockPosition pos = this.stats.getPassengerSeat(i);
		if(mountedEntities[i] != null && mountedEntities[i].get() != null) {
			mountedEntities[i].get().setPosition(this.posX + pos.x, this.posY + pos.y, this.posZ + pos.z); 
			System.out.println("Additional: " + mountedEntities[i].get());
		}
	}
}
 
Example 3
Source File: DimTransfer.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void placeInPortal(Entity entityIn, float rotationYaw) {
    entityIn.setPosition(posX, posY, posZ);
    entityIn.motionX = 0.0D;
    entityIn.motionY = 0.0D;
    entityIn.motionZ = 0.0D;
}
 
Example 4
Source File: BaseVehicleEntity.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void updatePassenger(Entity passenger) {
	if (this.isPassenger(passenger) && getPassengers().indexOf(passenger) < seatOffsets.size()) {
		passenger.setPosition(
				this.posX + seatOffsets.get(getPassengers().indexOf(passenger)).getX() + 0.5, this.posY
						+ seatOffsets.get(getPassengers().indexOf(passenger)).getY() + passenger.getYOffset() + 0.6,
				this.posZ + seatOffsets.get(getPassengers().indexOf(passenger)).getZ() + 0.5);
		passenger.motionX = motionX;
		passenger.motionY = motionY;
		passenger.motionZ = motionZ;
		passenger.velocityChanged = true;
	}
}
 
Example 5
Source File: EntityExplodingChicken.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void updatePassenger(Entity passenger)
{
    super.updatePassenger(passenger);
    float f = MathHelper.sin(this.renderYawOffset * 0.017453292F);
    float f1 = MathHelper.cos(this.renderYawOffset * 0.017453292F);
    passenger.setPosition(this.posX + (double)(0.1F * f), this.posY + (double)(this.height * 0.5F) + passenger.getYOffset() + 0.0D, this.posZ - (double)(0.1F * f1));

    if (passenger instanceof EntityLivingBase)
    {
        ((EntityLivingBase)passenger).renderYawOffset = this.renderYawOffset;
    }
}
 
Example 6
Source File: GTCommandTeleporter.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void placeInPortal(@Nonnull Entity entity, float rotationYaw) {
	this.worldServer.getBlockState(new BlockPos((int) this.x, (int) this.y, (int) this.z));
	entity.setPosition(this.x, this.y, this.z);
	entity.motionX = 0.0f;
	entity.motionY = 0.0f;
	entity.motionZ = 0.0f;
}
 
Example 7
Source File: EntityUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void spawnEntityAndPassengersInWorld(Entity entity, World world)
{
    if (world.spawnEntity(entity) && entity.isBeingRidden())
    {
        for (Entity passenger : entity.getPassengers())
        {
            passenger.setPosition(entity.posX, entity.posY + entity.getMountedYOffset() + passenger.getYOffset(), entity.posZ);
            spawnEntityAndPassengersInWorld(passenger, world);
        }
    }
}
 
Example 8
Source File: TeleportUtil.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void placeInPortal(@Nonnull Entity entity, float rotationYaw) {
	worldServer.getBlockState(new BlockPos((int) x, (int) y, (int) z));

	entity.setPosition(x, y, z);
	entity.motionX = 0.0f;
	entity.motionY = 0.0f;
	entity.motionZ = 0.0f;
}
 
Example 9
Source File: EventHandlers.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void spawnToroWhenCowPackSpawns(EntityJoinWorldEvent event) {
	if (event.getWorld().isRemote) {
		return;
	}

	Entity entity = event.getEntity();
	if (entity == null || !(entity instanceof EntityCow)) {
		return;
	}

	if (entity.getEntityData().getBoolean("AddedToWorld")) {
		return;
	}

	entity.getEntityData().setBoolean("AddedToWorld", true);
	
	World world = event.getWorld();

	if (world.rand.nextInt(8) != 0) {
		return;
	}

	BlockPos spawnPoint = findSurface(world, entity.getPosition());

	if (spawnPoint == null) {
		return;
	}
	
	
	Entity toro = new EntityToro(world);

	toro.setPosition(spawnPoint.getX(), spawnPoint.getY() + 1, spawnPoint.getZ());
	world.spawnEntity(toro);
}
 
Example 10
Source File: BlockMethods.java    From pycode-minecraft with MIT License 5 votes vote down vote up
@Nullable
public MyBase spawn(String entityName) throws EntityNameError {
    if (this.world == null || this.world.isRemote) return null;
    Entity entity = EntityList.createEntityByName(entityName, this.world);
    if (entity == null) throw new EntityNameError(entityName);
    BlockPos pos = this.block.getPos().add(0.5, 1.0, 0.5);
    entity.setPosition(pos.getX(), pos.getY(), pos.getZ());
    world.spawnEntityInWorld(entity);
    return PyRegistry.myWrapper(world, entity);
}
 
Example 11
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 12
Source File: BlockElevatorFrame.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
 */
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity){
    //  float blockHeight = getElevatorBlockHeight(world, x, y, z);
    //   if(blockHeight > 0) {
    // if(entity.posY < y + blockHeight) {
    //     entity.setPosition(entity.posX, y + blockHeight + 2, entity.posZ);
    TileEntityElevatorBase te = getElevatorTE(world, x, y, z);
    if(te != null && te.oldExtension != te.extension) {
        entity.setPosition(entity.posX, te.yCoord + te.extension + (double)entity.yOffset + entity.ySize + 1, entity.posZ);
    }
    entity.fallDistance = 0;
    //}
    //   }
}
 
Example 13
Source File: EntityMountable.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Override
public void updatePassenger(Entity passenger) {
    if (this.isPassenger(passenger)) {
        passenger.setPosition(this.posX, this.posY, this.posZ);
    }
}
 
Example 14
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);
        }
    }
}
 
Example 15
Source File: EntityShip.java    From archimedes-ships with MIT License 4 votes vote down vote up
public void updateRiderPosition(Entity entity, int seatx, int seaty, int seatz, int flags)
{
	if (entity != null)
	{
		float yaw = (float) Math.toRadians(rotationYaw);
		float pitch = (float) Math.toRadians(rotationPitch);
		
		int x1 = seatx, y1 = seaty, z1 = seatz;
		if ((flags & 1) == 1)
		{
			if (frontDirection == 0)
			{
				z1 -= 1;
			} else if (frontDirection == 1)
			{
				x1 += 1;
			} else if (frontDirection == 2)
			{
				z1 += 1;
			} else if (frontDirection == 3)
			{
				x1 -= 1;
			}
			
			Block block = shipChunk.getBlock(x1, MathHelper.floor_double(y1 + getMountedYOffset() + entity.getYOffset()), z1);
			if (block.isOpaqueCube())
			{
				x1 = seatx;
				y1 = seaty;
				z1 = seatz;
			}
		}
		
		double yoff = (flags & 2) == 2 ? 0d : getMountedYOffset();
		Vec3 vec = Vec3.createVectorHelper(x1 - shipChunk.getCenterX() + 0.5d, y1 - shipChunk.minY() + yoff, z1 - shipChunk.getCenterZ() + 0.5d);
		switch (frontDirection)
		{
		case 0:
			vec.rotateAroundZ(-pitch);
			break;
		case 1:
			vec.rotateAroundX(pitch);
			break;
		case 2:
			vec.rotateAroundZ(pitch);
			break;
		case 3:
			vec.rotateAroundX(-pitch);
			break;
		}
		vec.rotateAroundY(yaw);
		
		entity.setPosition(posX + vec.xCoord, posY + vec.yCoord + entity.getYOffset(), posZ + vec.zCoord);
	}
}
 
Example 16
Source File: TileEntityAirCannon.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
private synchronized boolean fire(){
    Entity itemShot = getCloseEntityIfUpgraded();
    if(getPressure(ForgeDirection.UNKNOWN) >= PneumaticValues.MIN_PRESSURE_AIR_CANNON && (itemShot != null || inventory[0] != null)) {
        double[] velocity = getVelocityVector(heightAngle, rotationAngle, getForce());
        addAir((int)(-500 * getForce()), ForgeDirection.UNKNOWN);
        boolean shootingInventory = false;
        if(itemShot == null) {
            shootingInventory = true;
            itemShot = getPayloadEntity();

            if(itemShot instanceof EntityItem) {
                inventory[0] = null;
                if(getUpgrades(ItemMachineUpgrade.UPGRADE_BLOCK_TRACKER) > 0) {
                    trackedItems.add((EntityItem)itemShot);
                }
            } else {
                inventory[0].stackSize--;
                if(inventory[0].stackSize <= 0) inventory[0] = null;
            }
        } else if(itemShot instanceof EntityPlayer) {
            EntityPlayerMP entityplayermp = (EntityPlayerMP)itemShot;
            if(entityplayermp.playerNetServerHandler.func_147362_b().isChannelOpen()) {
                entityplayermp.setPositionAndUpdate(xCoord + 0.5D, yCoord + 1.8D, zCoord + 0.5D);
            }
        }

        if(itemShot.isRiding()) {
            itemShot.mountEntity((Entity)null);
        }

        itemShot.setPosition(xCoord + 0.5D, yCoord + 1.8D, zCoord + 0.5D);
        NetworkHandler.sendToAllAround(new PacketSetEntityMotion(itemShot, velocity[0], velocity[1], velocity[2]), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 64));

        if(itemShot instanceof EntityFireball) {
            velocity[0] *= 0.05D;
            velocity[1] *= 0.05D;
            velocity[2] *= 0.05D;
        }

        itemShot.motionX = velocity[0];
        itemShot.motionY = velocity[1];
        itemShot.motionZ = velocity[2];

        itemShot.onGround = false;
        itemShot.isCollided = false;
        itemShot.isCollidedHorizontally = false;
        itemShot.isCollidedVertically = false;
        if(itemShot instanceof EntityLivingBase) ((EntityLivingBase)itemShot).setJumping(true);

        if(shootingInventory && !worldObj.isRemote) worldObj.spawnEntityInWorld(itemShot);

        for(int i = 0; i < 10; i++) {
            double velX = velocity[0] * 0.4D + (rand.nextGaussian() - 0.5D) * 0.05D;
            double velY = velocity[1] * 0.4D + (rand.nextGaussian() - 0.5D) * 0.05D;
            double velZ = velocity[2] * 0.4D + (rand.nextGaussian() - 0.5D) * 0.05D;
            NetworkHandler.sendToAllAround(new PacketSpawnParticle("largesmoke", xCoord + 0.5D, yCoord + 0.7D, zCoord + 0.5D, velX, velY, velZ), worldObj);
        }
        NetworkHandler.sendToAllAround(new PacketPlaySound(Sounds.CANNON_SOUND, xCoord, yCoord, zCoord, 1.0F, rand.nextFloat() / 4F + 0.75F, true), worldObj);
        return true;
    } else {
        return false;
    }
}