use of net.minecraft.world.WorldServer in project SpongeVanilla by SpongePowered.
the class MixinMinecraftServer method stopServer.
/**
* @author Zidane - Chris Sanders
*/
@Overwrite
public void stopServer() {
// stopServer is called from both the shutdown hook AND the finally statement in the main game loop, no reason to do this twice..
if (skipServerStop) {
return;
}
skipServerStop = true;
LOGGER.info("Stopping server");
spongeVanilla.onServerStopping();
final MinecraftServer server = (MinecraftServer) (Object) this;
// Sponge Start - Force player profile cache save
server.getPlayerProfileCache().save();
if (this.getNetworkSystem() != null) {
this.getNetworkSystem().terminateEndpoints();
}
if (this.playerList != null) {
LOGGER.info("Saving players");
this.playerList.saveAllPlayerData();
this.playerList.removeAllPlayers();
}
if (server.worlds != null) {
LOGGER.info("Saving worlds");
for (WorldServer worldserver : server.worlds) {
if (worldserver != null) {
worldserver.disableLevelSaving = false;
}
}
server.saveAllWorlds(false);
for (WorldServer worldserver1 : server.worlds) {
if (worldserver1 != null) {
// Turn off Async Lighting
if (SpongeImpl.getGlobalConfig().getConfig().getModules().useOptimizations() && SpongeImpl.getGlobalConfig().getConfig().getOptimizations().useAsyncLighting()) {
((IMixinWorldServer) worldserver1).getLightingExecutor().shutdown();
try {
((IMixinWorldServer) worldserver1).getLightingExecutor().awaitTermination(1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
((IMixinWorldServer) worldserver1).getLightingExecutor().shutdownNow();
}
}
WorldManager.unloadWorld(worldserver1, false);
}
}
if (this.usageSnooper.isSnooperRunning()) {
this.usageSnooper.stopSnooper();
}
}
}
use of net.minecraft.world.WorldServer in project takumicraft by TNTModders.
the class TakumiUtils method takumiCreateExplosion.
public static void takumiCreateExplosion(World world, Entity entity, double x, double y, double z, float power, boolean fire, boolean destroy, double amp) {
boolean flg = world instanceof WorldServer;
TakumiExplosion explosion = new TakumiExplosion(world, entity, x, y, z, power, fire, destroy, amp);
if (ForgeEventFactory.onExplosionStart(world, explosion)) {
return;
}
explosion.doExplosionA();
explosion.doExplosionB(!flg);
if (flg) {
if (!fire) {
explosion.clearAffectedBlockPositions();
}
for (EntityPlayer entityplayer : world.playerEntities) {
if (entityplayer.getDistanceSq(x, y, z) < 4096.0D) {
((EntityPlayerMP) entityplayer).connection.sendPacket(new SPacketExplosion(x, y, z, power, explosion.getAffectedBlockPositions(), explosion.getPlayerKnockbackMap().get(entityplayer)));
}
}
}
}
use of net.minecraft.world.WorldServer in project Random-Things by lumien231.
the class EntityReviveCircle method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
age++;
if (!world.isRemote) {
if (this.reviver == null || this.reviver.isDead || this.reviver.getDistanceSq(this.getPosition()) > 25 || this.reviver.dimension != this.dimension || toRevive == null || toRevive.isDead) {
this.setDead();
}
if (this.world.getTotalWorldTime() % 20 == 0) {
EntityPlayerMP player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(toRevive.playerName);
if (player == null) {
this.setDead();
}
}
if (this.age >= 220 && this.world.getTotalWorldTime() % 10 == 0) {
reviver.attackEntityFrom(DamageSource.MAGIC, 1f);
}
if (this.age >= 400) {
toRevive.setDead();
this.setDead();
EntityPlayerMP player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(toRevive.playerName);
if (player != null) {
if (player.getHealth() <= 0) {
EntityPlayerMP revived = player.connection.player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().recreatePlayerEntity(player, 0, false);
if (revived.world.provider.getDimension() != this.dimension) {
FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().transferPlayerToDimension(revived, this.world.provider.getDimension(), new Teleporter((WorldServer) this.world));
}
revived.connection.setPlayerLocation(posX, posY, posZ, revived.rotationYaw, revived.rotationPitch);
revived.setPositionAndUpdate(posX, posY, posZ);
}
}
}
} else {
if (this.age >= 200) {
world.spawnParticle(EnumParticleTypes.REDSTONE, this.posX + Math.random() - 0.5f, this.posY + Math.random(), this.posZ + Math.random() - 0.5f, 0, 0, 0, 1);
}
}
}
use of net.minecraft.world.WorldServer in project Random-Things by lumien231.
the class TileEntityNatureCore method update.
@Override
public void update() {
if (!world.isRemote) {
// Replace Sand
if (rand.nextInt(40) == 0) {
int rX = this.pos.getX() + rand.nextInt(11) - 5;
int rY = this.pos.getY() + rand.nextInt(4) - 3;
int rZ = this.pos.getZ() + rand.nextInt(11) - 5;
BlockPos target = new BlockPos(rX, rY, rZ);
IBlockState state = world.getBlockState(target);
if (state.getBlock() instanceof BlockSand) {
if (this.world.isAirBlock(target.up())) {
this.world.setBlockState(target, Blocks.GRASS.getDefaultState());
} else {
this.world.setBlockState(target, Blocks.DIRT.getDefaultState());
}
}
}
// Animal Spawning
if (rand.nextInt(400) == 0) {
List<EntityAnimal> closeAnimals = world.getEntitiesWithinAABB(EntityAnimal.class, new AxisAlignedBB(this.pos, this.pos).grow(5, 5, 5));
if (closeAnimals.size() < 2) {
int rX = this.pos.getX() + rand.nextInt(11) - 5;
int rY = this.pos.getY() + rand.nextInt(5) - 2;
int rZ = this.pos.getZ() + rand.nextInt(11) - 5;
Biome.SpawnListEntry entry = ((WorldServer) world).getSpawnListEntryForTypeAt(EnumCreatureType.CREATURE, new BlockPos(rX, rY, rZ));
if (entry != null) {
EntityLiving entityliving = null;
try {
entityliving = entry.entityClass.getConstructor(new Class[] { World.class }).newInstance(new Object[] { world });
} catch (Exception exception) {
exception.printStackTrace();
}
if (entityliving != null) {
entityliving.setLocationAndAngles(rX, rY, rZ, rand.nextFloat() * 360.0F, 0.0F);
if (entityliving.getCanSpawnHere() && entityliving.isNotColliding()) {
world.spawnEntity(entityliving);
}
}
}
}
}
// Bonemealing
if (rand.nextInt(100) == 0) {
int rX = this.pos.getX() + rand.nextInt(11) - 5;
int rY = this.pos.getY() + rand.nextInt(4) - 3;
int rZ = this.pos.getZ() + rand.nextInt(11) - 5;
BlockPos target = new BlockPos(rX, rY, rZ);
IBlockState state = world.getBlockState(target);
if (state.getBlock() instanceof IGrowable) {
IGrowable growable = (IGrowable) state.getBlock();
if (growable.canGrow(world, target, state, world.isRemote)) {
world.playEvent(2005, target, 0);
growable.grow(world, rand, target, state);
}
}
}
// Trees
if (rand.nextInt(600) == 0) {
double radius = rand.nextInt(20) + 10;
double angle = Math.random() * Math.PI * 2;
int x = (int) Math.floor(this.pos.getX() + radius * Math.cos(angle));
int z = (int) Math.floor(this.pos.getZ() + radius * Math.sin(angle));
int y = this.pos.getY() + rand.nextInt(4) - 3;
BlockPos target = new BlockPos(x, y, z);
IBlockState state = world.getBlockState(target);
boolean space = true;
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
BlockPos log = target.up().offset(facing);
IBlockState there = world.getBlockState(log);
if (!(world.isAirBlock(log) || there.getBlock().isReplaceable(world, log))) {
space = false;
break;
}
}
if (space && Blocks.SAPLING.canPlaceBlockAt(world, target.up())) {
world.playEvent(2005, target, 0);
world.setBlockState(target.up(), Blocks.SAPLING.getDefaultState());
}
}
// Rebuild
if (rand.nextInt(600) == 0) {
ArrayList<BlockInfo> patternInfo = WorldGenCores.natureCore.getBlockInfo();
BlockInfo randomInfo = patternInfo.get(rand.nextInt(patternInfo.size()));
if (randomInfo.getState().getBlock() != ModBlocks.natureCore) {
BlockPos targetPlace = this.pos.add(randomInfo.getMod().down());
IBlockState original = world.getBlockState(targetPlace);
if (world.isAirBlock(this.pos.add(randomInfo.getMod().down())) || original.getBlock().isReplaceable(world, targetPlace)) {
world.setBlockState(this.pos.add(randomInfo.getMod().down()), randomInfo.getState());
}
}
}
}
}
use of net.minecraft.world.WorldServer in project FoamFix by asiekierka.
the class GhostBusterEventHandler method onWorldLoad.
@SubscribeEvent
public void onWorldLoad(WorldEvent.Load event) {
if (event.getWorld() instanceof WorldServer) {
FoamFix.logger.info("Overriding ChunkProviderServer in dimension " + event.getWorld().provider.getDimension() + "!");
ChunkProviderServerWrapped wrapped = new ChunkProviderServerWrapped((WorldServer) event.getWorld());
try {
Field f = ReflectionHelper.findField(World.class, "chunkProvider", "field_73020_y");
f.setAccessible(true);
f.set(event.getWorld(), wrapped);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations