use of net.minecraft.world.WorldServer in project Engine by VoltzEngine-Project.
the class MassRegistry method getMass.
@Override
public double getMass(World world, int x, int y, int z) {
double mass;
if (world != null) {
//Checks if the chunk is loaded
if (world instanceof WorldServer) {
ChunkProviderServer providerServer = ((WorldServer) world).theChunkProviderServer;
if (!providerServer.chunkExists(x >> 4, z >> 4)) {
return -1;
}
}
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof IHasMass) {
mass = ((IHasMass) tile).getMass();
if (mass >= 0) {
return mass;
}
}
mass = getMass(block, meta);
return mass >= 0 ? mass : getMass(block);
}
return -1;
}
use of net.minecraft.world.WorldServer in project VanillaTeleporter by dyeo.
the class TeleporterUtility method transferPlayerToDimension.
/**
* Transfers a player to a different dimension and location, as if they were being teleported by a dimension portal
*/
private static boolean transferPlayerToDimension(EntityPlayerMP player, double posX, double posY, double posZ, float yaw, float pitch, int dimension) {
MinecraftServer minecraftServer = FMLCommonHandler.instance().getMinecraftServerInstance();
WorldServer srcWorld = minecraftServer.worldServerForDimension(player.dimension);
WorldServer dstWorld = minecraftServer.worldServerForDimension(dimension);
if (dstWorld != null) {
// fire player change dimension event and check that action is valid before continuing
if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(player, dimension))
return false;
// (hard) set the player's dimension to the destination dimension
player.dimension = dimension;
// send a player respawn packet to the destination dimension so the player respawns there
player.connection.sendPacket(new SPacketRespawn(player.dimension, player.world.getDifficulty(), player.world.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
// remove the original player entity
srcWorld.removeEntity(player);
// make sure the player isn't dead (removeEntity sets player as dead)
player.isDead = false;
PlayerList playerList = player.mcServer.getPlayerList();
// set player's location (net server handler)
setPlayerPosition(player, posX, posY, posZ, yaw, pitch);
// spawn the player in the new world
dstWorld.spawnEntity(player);
// update the entity (do not force)
dstWorld.updateEntityWithOptionalForce(player, false);
// set the player's world to the new world
player.setWorld(dstWorld);
// add the player into the appropriate player list
playerList.preparePlayer(player, srcWorld);
// set item in world manager's world to the same as the player
player.interactionManager.setWorld(dstWorld);
// update time and weather for the player so that it's the same as the world
playerList.updateTimeAndWeatherForPlayer(player, dstWorld);
// sync the player's inventory
playerList.syncPlayerInventory(player);
// add no experience (syncs experience)
player.addExperience(0);
// update player's health
player.setPlayerHealthUpdated();
// fire the dimension changed event so that minecraft swithces dimensions properly
FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, srcWorld.provider.getDimension(), dstWorld.provider.getDimension());
return true;
} else {
return false;
}
}
Aggregations