Java Code Examples for net.minecraft.world.WorldServer#updateEntityWithOptionalForce()
The following examples show how to use
net.minecraft.world.WorldServer#updateEntityWithOptionalForce() .
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: ThermiteTeleportationHandler.java From Thermos with GNU General Public License v3.0 | 6 votes |
public static void transferEntityToWorld(Entity ent, WorldServer oldWorld, WorldServer newWorld) { WorldProvider pOld = oldWorld.provider; WorldProvider pNew = newWorld.provider; double moveFactor = pOld.getMovementFactor() / pNew.getMovementFactor(); double x = ent.posX * moveFactor; double z = ent.posZ * moveFactor; x = MathHelper.clamp_double(x, -29999872, 29999872); z = MathHelper.clamp_double(z, -29999872, 29999872); if (ent.isEntityAlive()) { ent.setLocationAndAngles(x, ent.posY, z, ent.rotationYaw, ent.rotationPitch); newWorld.spawnEntityInWorld(ent); newWorld.updateEntityWithOptionalForce(ent, false); } ent.setWorld(newWorld); }
Example 4
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 5
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 6
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 7
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 8
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; }