Search in sources :

Example 81 with WorldServer

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();
        }
    }
}
Also used : IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) WorldServer(net.minecraft.world.WorldServer) IMixinMinecraftServer(org.spongepowered.common.interfaces.IMixinMinecraftServer) MinecraftServer(net.minecraft.server.MinecraftServer) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 82 with WorldServer

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)));
            }
        }
    }
}
Also used : TakumiExplosion(com.tntmodders.takumi.world.TakumiExplosion) SPacketExplosion(net.minecraft.network.play.server.SPacketExplosion) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer)

Example 83 with WorldServer

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);
        }
    }
}
Also used : Teleporter(net.minecraft.world.Teleporter) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer)

Example 84 with WorldServer

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());
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) BlockSand(net.minecraft.block.BlockSand) EntityLiving(net.minecraft.entity.EntityLiving) EnumFacing(net.minecraft.util.EnumFacing) WorldServer(net.minecraft.world.WorldServer) Biome(net.minecraft.world.biome.Biome) BlockInfo(lumien.randomthings.util.BlockPattern.BlockInfo) IGrowable(net.minecraft.block.IGrowable) BlockPos(net.minecraft.util.math.BlockPos) EntityAnimal(net.minecraft.entity.passive.EntityAnimal)

Example 85 with WorldServer

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();
        }
    }
}
Also used : Field(java.lang.reflect.Field) WorldServer(net.minecraft.world.WorldServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

WorldServer (net.minecraft.world.WorldServer)338 BlockPos (net.minecraft.util.math.BlockPos)101 EntityPlayer (net.minecraft.entity.player.EntityPlayer)63 ItemStack (net.minecraft.item.ItemStack)55 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)51 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)47 Entity (net.minecraft.entity.Entity)44 TileEntity (net.minecraft.tileentity.TileEntity)42 IBlockState (net.minecraft.block.state.IBlockState)39 MinecraftServer (net.minecraft.server.MinecraftServer)36 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)32 World (net.minecraft.world.World)29 Block (net.minecraft.block.Block)28 EntityLivingBase (net.minecraft.entity.EntityLivingBase)28 ArrayList (java.util.ArrayList)20 PotionEffect (net.minecraft.potion.PotionEffect)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)19 Nullable (javax.annotation.Nullable)17 Chunk (net.minecraft.world.chunk.Chunk)16 World (org.spongepowered.api.world.World)14