Java Code Examples for net.minecraft.world.WorldServer#spawnEntity()
The following examples show how to use
net.minecraft.world.WorldServer#spawnEntity() .
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: GTCommandTeleporter.java From GT-Classic with GNU Lesser General Public License v3.0 | 6 votes |
public static void teleportToDimension(EntityPlayer player, int dimension, double x, double y, double z) { int oldDimension = player.getEntityWorld().provider.getDimension(); EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player; MinecraftServer server = player.getEntityWorld().getMinecraftServer(); WorldServer worldServer = server.getWorld(dimension); player.addExperienceLevel(0); if (worldServer == null || worldServer.getMinecraftServer() == null) { // Dimension doesn't exist throw new IllegalArgumentException("Dimension: " + dimension + " doesn't exist!"); } worldServer.getMinecraftServer().getPlayerList().transferPlayerToDimension(entityPlayerMP, dimension, new GTCommandTeleporter(worldServer, x, y, z)); player.setPositionAndUpdate(x, y, z); if (oldDimension == 1) { // For some reason teleporting out of the end does weird things. player.setPositionAndUpdate(x, y, z); worldServer.spawnEntity(player); worldServer.updateEntityWithOptionalForce(player, false); } }
Example 2
Source File: TeleportUtil.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
public static void teleportToDimension(EntityPlayer player, int dimension, double x, double y, double z) { if (!(player instanceof EntityPlayerMP)) return; int oldDimension = player.world.provider.getDimension(); EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player; MinecraftServer server = ((EntityPlayerMP) player).world.getMinecraftServer(); if (server == null) return; WorldServer worldServer = server.getWorld(dimension); player.addExperienceLevel(0); if (worldServer.getMinecraftServer() == null) return; worldServer.getMinecraftServer().getPlayerList().transferPlayerToDimension(entityPlayerMP, dimension, new CustomTeleporter(worldServer, x, y, z)); player.setPositionAndUpdate(x, y, z); if (oldDimension == 1) { // For some reason teleporting out of the end does weird things. player.setPositionAndUpdate(x, y, z); worldServer.spawnEntity(player); worldServer.updateEntityWithOptionalForce(player, false); } }
Example 3
Source File: CraftPainting.java From Kettle with GNU General Public License v3.0 | 5 votes |
private void update() { WorldServer world = ((CraftWorld) getWorld()).getHandle(); EntityPainting painting = new EntityPainting(world); painting.hangingPosition = getHandle().getHangingPosition(); painting.art = getHandle().art; painting.updateFacingWithBoundingBox(getHandle().facingDirection); getHandle().setDead(); getHandle().velocityChanged = true; // because this occurs when the painting is broken, so it might be important world.spawnEntity(painting); this.entity = painting; }
Example 4
Source File: CraftItemFrame.java From Kettle with GNU General Public License v3.0 | 5 votes |
private void update() { EntityItemFrame old = this.getHandle(); WorldServer world = ((CraftWorld) getWorld()).getHandle(); BlockPos position = old.getPosition(); EnumFacing direction = old.getHorizontalFacing(); ItemStack item = old.getDisplayedItem() != null ? old.getDisplayedItem().copy() : null; old.setDead(); EntityItemFrame frame = new EntityItemFrame(world, position, direction); frame.setDisplayedItem(item); world.spawnEntity(frame); this.entity = frame; }
Example 5
Source File: TeleporterNoPortal.java From AdvancedRocketry with MIT License | 5 votes |
public void teleport(Entity entity, WorldServer world) { if (entity.isEntityAlive()) { entity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch); world.spawnEntity(entity); world.updateEntityWithOptionalForce(entity, false); } entity.setWorld(world); }
Example 6
Source File: TeleporterNoPortalSeekBlock.java From AdvancedRocketry with MIT License | 5 votes |
public void teleport(Entity entity, WorldServer world) { if (entity.isEntityAlive()) { entity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch); world.spawnEntity(entity); world.updateEntityWithOptionalForce(entity, false); } entity.setWorld(world); }
Example 7
Source File: Nyan.java From CommunityMod with GNU Lesser General Public License v2.1 | 4 votes |
private static void updateNyanEntity(MinecraftServer server, WorldServer world, Entity entity, NBTTagCompound data) { Entity nyanEntity = null; if(data.hasUniqueId(NYAN_ENTITY_UUID_KEY)) { nyanEntity = server.getEntityFromUuid(data.getUniqueId(NYAN_ENTITY_UUID_KEY)); } boolean shouldSpawn = false; if(nyanEntity == null || nyanEntity.isDead) { nyanEntity = newNyanEntity(world); nyanEntity.getEntityData().setUniqueId(NYANED_ENTITY_UUID_KEY, entity.getUniqueID()); data.setUniqueId(NYAN_ENTITY_UUID_KEY, nyanEntity.getUniqueID()); shouldSpawn = true; } final BlockPos entityPos = entity.getPosition(); double entityHeightMultiplier = world.getTotalWorldTime() % 2 == 0 ? 3.5 : 4.0; //Account for dab particles if(entity instanceof EntityPlayer) { entityHeightMultiplier += 2.0; } //I *could* disable the AI, but this is more fun nyanEntity.setPositionAndRotation( entityPos.getX(), entityPos.getY() + entity.height * entityHeightMultiplier + nyanEntity.height, entityPos.getZ(), entity.rotationYaw, entity.rotationPitch ); nyanEntity.setRotationYawHead(entity.getRotationYawHead()); nyanEntity.setEntityInvulnerable(true); if(shouldSpawn) { world.spawnEntity(nyanEntity); } final BlockPos nyanPos = nyanEntity.getPosition(); final NyanDirection direction = NyanDirection.getDirectionFacing(nyanEntity, Rotation.CLOCKWISE_90); world.spawnParticle( //Wool EnumParticleTypes.REDSTONE, //Not long distance false, nyanPos.getX() + direction.getXDirection() * 12.0, nyanPos.getY() - 2.5, nyanPos.getZ() + direction.getZDirection() * 12.0, //Number of particles 10, direction.getXDirection() * 5.0, 0.0, direction.getZDirection() * 5.0, //Speed 10.0 ); }
Example 8
Source File: BlockTeleportRail.java From Signals with GNU General Public License v3.0 | 4 votes |
private void teleport(EntityMinecart cart, MCPos destination){ if(cart instanceof EntityMinecartContainer) { ((EntityMinecartContainer)cart).dropContentsWhenDead = false; } int dimensionIn = destination.getDimID(); BlockPos destPos = destination.getPos(); if(!ForgeHooks.onTravelToDimension(cart, destination.getDimID())) return; MinecraftServer minecraftserver = cart.getServer(); int i = cart.dimension; WorldServer worldserver = minecraftserver.getWorld(i); WorldServer worldserver1 = minecraftserver.getWorld(dimensionIn); cart.dimension = dimensionIn; /*if (i == 1 && dimensionIn == 1) { worldserver1 = minecraftserver.getWorld(0); this.dimension = 0; }*/ cart.world.removeEntity(cart); cart.isDead = false; BlockPos blockpos = destination.getPos(); /* double moveFactor = worldserver.provider.getMovementFactor() / worldserver1.provider.getMovementFactor(); double d0 = MathHelper.clamp(this.posX * moveFactor, worldserver1.getWorldBorder().minX() + 16.0D, worldserver1.getWorldBorder().maxX() - 16.0D); double d1 = MathHelper.clamp(this.posZ * moveFactor, worldserver1.getWorldBorder().minZ() + 16.0D, worldserver1.getWorldBorder().maxZ() - 16.0D); double d2 = 8.0D;*/ cart.moveToBlockPosAndAngles(destPos, 90.0F, 0.0F); /*Teleporter teleporter = worldserver1.getDefaultTeleporter(); teleporter.placeInExistingPortal(this, f); blockpos = new BlockPos(this);*/ worldserver.updateEntityWithOptionalForce(cart, false); Entity entity = EntityList.newEntity(cart.getClass(), worldserver1); if(entity != null) { copyDataFromOld(entity, cart); entity.moveToBlockPosAndAngles(blockpos, entity.rotationYaw, entity.rotationPitch); IBlockState state = destination.getLoadedBlockState(); if(state.getBlock() == ModBlocks.TELEPORT_RAIL) { //If the destination is a teleport track, use its rail direction to push the cart the right direction EnumFacing teleportDir = getTeleportDirection(state); double speed = 0.2; entity.motionX = teleportDir.getFrontOffsetX() * speed; entity.motionY = teleportDir.getFrontOffsetY() * speed; entity.motionZ = teleportDir.getFrontOffsetZ() * speed; } else { entity.motionX = entity.motionY = entity.motionZ = 0; } boolean flag = entity.forceSpawn; entity.forceSpawn = true; worldserver1.spawnEntity(entity); entity.forceSpawn = flag; worldserver1.updateEntityWithOptionalForce(entity, false); } cart.isDead = true; worldserver.resetUpdateEntityTick(); worldserver1.resetUpdateEntityTick(); }
Example 9
Source File: EntityElevatorCapsule.java From AdvancedRocketry with MIT License | 4 votes |
@Nullable public Entity changeDimension(int dimensionIn, double posX, double y, double posZ) { if (!this.world.isRemote && !this.isDead) { List<Entity> passengers = getPassengers(); if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(this, dimensionIn)) return null; this.world.profiler.startSection("changeDimension"); MinecraftServer minecraftserver = this.getServer(); int i = this.dimension; WorldServer worldserver = minecraftserver.getWorld(i); WorldServer worldserver1 = minecraftserver.getWorld(dimensionIn); this.dimension = dimensionIn; if (i == 1 && dimensionIn == 1) { worldserver1 = minecraftserver.getWorld(0); this.dimension = 0; } this.world.removeEntity(this); this.isDead = false; this.world.profiler.startSection("reposition"); BlockPos blockpos; double d0 = this.posX; double d1 = this.posZ; double d2 = 8.0D; d0 = MathHelper.clamp(d0 * 8.0D, worldserver1.getWorldBorder().minX() + 16.0D, worldserver1.getWorldBorder().maxX() - 16.0D); d1 = MathHelper.clamp(d1 * 8.0D, worldserver1.getWorldBorder().minZ() + 16.0D, worldserver1.getWorldBorder().maxZ() - 16.0D); d0 = (double)MathHelper.clamp((int)d0, -29999872, 29999872); d1 = (double)MathHelper.clamp((int)d1, -29999872, 29999872); float f = this.rotationYaw; this.setLocationAndAngles(d0, this.posY, d1, 90.0F, 0.0F); Teleporter teleporter = new TeleporterNoPortal(worldserver1); teleporter.placeInExistingPortal(this, f); worldserver.updateEntityWithOptionalForce(this, false); this.world.profiler.endStartSection("reloading"); Entity entity = EntityList.newEntity(this.getClass(), worldserver1); if (entity != null) { this.moveToBlockPosAndAngles(new BlockPos(posX, y, posZ), entity.rotationYaw, entity.rotationPitch); ((EntityElevatorCapsule)entity).copyDataFromOld(this); entity.forceSpawn = true; worldserver1.spawnEntity(entity); worldserver1.updateEntityWithOptionalForce(entity, true); int timeOffset = 1; for(Entity e : passengers) { //Fix that darn random crash? worldserver.resetUpdateEntityTick(); worldserver1.resetUpdateEntityTick(); //Transfer the player if applicable //Need to handle our own removal to avoid race condition where player is mounted on client on the old entity but is already mounted to the new one on server //PacketHandler.sendToPlayer(new PacketEntity(this, (byte)PacketType.DISMOUNTCLIENT.ordinal()), (EntityPlayer) e); PlanetEventHandler.addDelayedTransition(worldserver.getTotalWorldTime(), new TransitionEntity(worldserver.getTotalWorldTime(), e, dimensionIn, new BlockPos(posX + 16, y, posZ), entity)); //minecraftserver.getPlayerList().transferPlayerToDimension((EntityPlayerMP)e, dimensionIn, teleporter); //e.setLocationAndAngles(posX, Configuration.orbit, posZ, this.rotationYaw, this.rotationPitch); //e.startRiding(entity); //e.playerNetServerHandler.sendPacket(new SPacketRespawn(e.dimension, e.world.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), ((EntityPlayerMP)e).interactionManager.getGameType())); //((WorldServer)startWorld).getPlayerManager().removePlayer(player); } } this.isDead = true; this.world.profiler.endSection(); worldserver.resetUpdateEntityTick(); worldserver1.resetUpdateEntityTick(); this.world.profiler.endSection(); return entity; } else { return null; } }
Example 10
Source File: TeleportEntity.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
private static Entity teleportEntityToDimension(Entity entity, double x, double y, double z, int dimDst) { MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); WorldServer worldDst = server.getWorld(dimDst); teleportInProgress = true; if (worldDst == null || ForgeHooks.onTravelToDimension(entity, dimDst) == false) { teleportInProgress = false; return null; } teleportInProgress = false; // Load the chunk first int chunkX = (int) Math.floor(x / 16D); int chunkZ = (int) Math.floor(z / 16D); ChunkLoading.getInstance().loadChunkForcedWithModTicket(dimDst, chunkX, chunkZ, 10); if (entity instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) entity; World worldOld = player.getEntityWorld(); DummyTeleporter teleporter = new DummyTeleporter(worldDst); player.setLocationAndAngles(x, y, z, player.rotationYaw, player.rotationPitch); server.getPlayerList().transferPlayerToDimension(player, dimDst, teleporter); // Teleporting FROM The End, remove the boss bar that would otherwise get stuck on if (worldOld.provider instanceof WorldProviderEnd) { removeDragonBossBarHack(player, (WorldProviderEnd) worldOld.provider); } player.setPositionAndUpdate(x, y, z); worldDst.updateEntityWithOptionalForce(player, false); player.addExperienceLevel(0); player.setPlayerHealthUpdated(); // TODO update food level? } else { WorldServer worldSrc = (WorldServer) entity.getEntityWorld(); // FIXME ugly special case to prevent the chest minecart etc from duping items if (entity instanceof EntityMinecartContainer) { ((EntityMinecartContainer) entity).setDropItemsWhenDead(false); } Entity entityNew = EntityList.newEntity(entity.getClass(), worldDst); if (entityNew != null) { EntityUtils.copyDataFromOld(entityNew, entity); entityNew.setLocationAndAngles(x, y, z, entity.rotationYaw, entity.rotationPitch); boolean flag = entityNew.forceSpawn; entityNew.forceSpawn = true; worldDst.spawnEntity(entityNew); entityNew.forceSpawn = flag; worldDst.updateEntityWithOptionalForce(entityNew, false); entity.isDead = true; worldSrc.removeEntity(entity); worldSrc.updateEntityWithOptionalForce(entity, false); worldSrc.resetUpdateEntityTick(); worldDst.resetUpdateEntityTick(); } entity = entityNew; } return entity; }