Search in sources :

Example 71 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Galacticraft by micdoodle8.

the class AsteroidsTickHandlerServer method onServerTick.

@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    // Prevent issues when clients switch to LAN servers
    if (server == null) {
        return;
    }
    if (event.phase == TickEvent.Phase.START) {
        TileEntityMinerBase.checkNewMinerBases();
        if (AsteroidsTickHandlerServer.spaceRaceData == null) {
            World world = server.getWorld(0);
            AsteroidsTickHandlerServer.spaceRaceData = (ShortRangeTelepadHandler) world.getMapStorage().getOrLoadData(ShortRangeTelepadHandler.class, ShortRangeTelepadHandler.saveDataID);
            if (AsteroidsTickHandlerServer.spaceRaceData == null) {
                AsteroidsTickHandlerServer.spaceRaceData = new ShortRangeTelepadHandler(ShortRangeTelepadHandler.saveDataID);
                world.getMapStorage().setData(ShortRangeTelepadHandler.saveDataID, AsteroidsTickHandlerServer.spaceRaceData);
            }
        }
        int index = -1;
        for (EntityAstroMiner miner : activeMiners) {
            index++;
            if (miner.isDead) {
                // minerIt.remove();  Don't remove it, we want the index number to be static for the others
                continue;
            }
            if (miner.playerMP != null) {
                GCPlayerStats stats = GCPlayerStats.get(miner.playerMP);
                if (stats != null) {
                    List<BlockVec3> list = stats.getActiveAstroMinerChunks();
                    boolean inListAlready = false;
                    Iterator<BlockVec3> it = list.iterator();
                    while (it.hasNext()) {
                        BlockVec3 data = it.next();
                        if (// SideDoneBits won't be saved to NBT, but during an active server session we can use it as a cross-reference to the index here - it's a 4th data int hidden inside a BlockVec3
                        data.sideDoneBits == index) {
                            if (miner.isDead) {
                                // Player stats should not save position of dead AstroMiner entity (probably broken by player deliberately breaking it)
                                it.remove();
                            } else {
                                data.x = miner.chunkCoordX;
                                data.z = miner.chunkCoordZ;
                            }
                            inListAlready = true;
                            break;
                        }
                    }
                    if (!inListAlready) {
                        BlockVec3 data = new BlockVec3(miner.chunkCoordX, miner.dimension, miner.chunkCoordZ);
                        data.sideDoneBits = index;
                        list.add(data);
                    }
                }
            }
        }
    }
}
Also used : EntityAstroMiner(micdoodle8.mods.galacticraft.planets.asteroids.entities.EntityAstroMiner) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) ShortRangeTelepadHandler(micdoodle8.mods.galacticraft.planets.asteroids.dimension.ShortRangeTelepadHandler) World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 72 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Wizardry by TeamWizardry.

the class BlockFluidMana method onEntityUpdate.

@SubscribeEvent
public static void onEntityUpdate(EntityUpdateEvent event) {
    Entity entityIn = event.getEntity();
    BlockPos pos = entityIn.getPosition();
    World world = entityIn.world;
    IBlockState state = world.getBlockState(pos);
    if (state.getBlock() == ModFluids.MANA.getActualBlock()) {
        // Fizz all entities in the pool
        if (world.isRemote)
            run(world, pos, state.getBlock(), entityIn, entity -> true, entity -> LibParticles.FIZZING_AMBIENT(world, entityIn.getPositionVector()));
        // Nullify gravity of player
        if (!world.isRemote)
            run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityLivingBase, entity -> {
                ((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(ModPotions.NULLIFY_GRAVITY, 100, 0, true, false));
                if (RandUtil.nextInt(50) == 0)
                    entity.attackEntityFrom(DamageSourceMana.INSTANCE, 0.1f);
            });
        run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityLivingBase, entity -> entityIn.motionY += 0.003);
        // Subtract player food
        run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityPlayer, entity -> {
            if (!world.isRemote) {
                MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
                Advancement advancement = server.getAdvancementManager().getAdvancement(new ResourceLocation(Wizardry.MODID, "advancements/advancement_crunch.json"));
                if (advancement == null)
                    return;
                AdvancementProgress progress = ((EntityPlayerMP) entity).getAdvancements().getProgress(advancement);
                for (String s : progress.getRemaningCriteria()) {
                    ((EntityPlayerMP) entity).getAdvancements().grantCriterion(advancement, s);
                }
            }
            if (!((EntityPlayer) entity).capabilities.isCreativeMode && RandUtil.nextInt(50) == 0)
                ((EntityPlayer) entity).getFoodStats().addExhaustion(1f);
        });
        // Explode explodable items
        run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityItem && ((EntityItem) entity).getItem().getItem() instanceof IPotionEffectExplodable, entity -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), new ManaRecipes.ExplodableCrafter()));
    }
    run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityItem && ManaRecipes.RECIPES.keySet().stream().anyMatch(item -> item.apply(((EntityItem) entity).getItem())), entity -> {
        List<Map.Entry<Ingredient, FluidRecipeBuilder.FluidCrafter>> allEntries = ManaRecipes.RECIPES.entries().stream().filter(entry -> entry.getValue().getFluid().getBlock() == state.getBlock() && entry.getKey().apply(((EntityItem) entity).getItem())).collect(Collectors.toList());
        allEntries.forEach(crafter -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), crafter.getValue().build()));
    });
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumHand(net.minecraft.util.EnumHand) ManaRecipes(com.teamwizardry.wizardry.crafting.mana.ManaRecipes) FMLCommonHandler(net.minecraftforge.fml.common.FMLCommonHandler) Random(java.util.Random) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PotionEffect(net.minecraft.potion.PotionEffect) BlockModFluid(com.teamwizardry.librarianlib.features.base.fluid.BlockModFluid) ModFluid(com.teamwizardry.librarianlib.features.base.fluid.ModFluid) MinecraftServer(net.minecraft.server.MinecraftServer) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Map(java.util.Map) FluidRecipeBuilder(com.teamwizardry.wizardry.crafting.mana.FluidRecipeBuilder) Nonnull(javax.annotation.Nonnull) EntityItem(net.minecraft.entity.item.EntityItem) MapColor(net.minecraft.block.material.MapColor) Entity(net.minecraft.entity.Entity) AdvancementProgress(net.minecraft.advancements.AdvancementProgress) Predicate(java.util.function.Predicate) World(net.minecraft.world.World) Wizardry(com.teamwizardry.wizardry.Wizardry) ModPotions(com.teamwizardry.wizardry.init.ModPotions) Advancement(net.minecraft.advancements.Advancement) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) DamageSourceMana(com.teamwizardry.wizardry.common.core.DamageSourceMana) EntityUpdateEvent(com.teamwizardry.librarianlib.features.forgeevents.EntityUpdateEvent) Consumer(java.util.function.Consumer) FluidTracker(com.teamwizardry.wizardry.api.block.FluidTracker) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityLivingBase(net.minecraft.entity.EntityLivingBase) LibParticles(com.teamwizardry.wizardry.client.fx.LibParticles) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) IPotionEffectExplodable(com.teamwizardry.wizardry.api.item.IPotionEffectExplodable) Entity(net.minecraft.entity.Entity) AdvancementProgress(net.minecraft.advancements.AdvancementProgress) IBlockState(net.minecraft.block.state.IBlockState) PotionEffect(net.minecraft.potion.PotionEffect) World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer) ResourceLocation(net.minecraft.util.ResourceLocation) EntityLivingBase(net.minecraft.entity.EntityLivingBase) FluidRecipeBuilder(com.teamwizardry.wizardry.crafting.mana.FluidRecipeBuilder) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) Advancement(net.minecraft.advancements.Advancement) EntityItem(net.minecraft.entity.item.EntityItem) IPotionEffectExplodable(com.teamwizardry.wizardry.api.item.IPotionEffectExplodable) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 73 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project malmo by Microsoft.

the class DefaultWorldGeneratorImplementation method shouldCreateWorld.

@Override
public boolean shouldCreateWorld(MissionInit missionInit) {
    if (this.dwparams != null && this.dwparams.isForceReset())
        return true;
    World world = null;
    MinecraftServer server = MinecraftServer.getServer();
    if (server.worldServers != null && server.worldServers.length != 0)
        world = server.getEntityWorld();
    if (Minecraft.getMinecraft().theWorld == null || world == null)
        // Definitely need to create a world if there isn't one in existence!
        return true;
    String genOptions = world.getWorldInfo().getGeneratorOptions();
    if (genOptions != null && !genOptions.isEmpty())
        // Default world has no generator options.
        return true;
    return false;
}
Also used : World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 74 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project MinecraftForge by MinecraftForge.

the class DimensionManager method initDimension.

public static void initDimension(int dim) {
    WorldServer overworld = getWorld(0);
    if (overworld == null) {
        throw new RuntimeException("Cannot Hotload Dim: Overworld is not Loaded!");
    }
    try {
        DimensionManager.getProviderType(dim);
    } catch (Exception e) {
        System.err.println("Cannot Hotload Dim: " + e.getMessage());
        // If a provider hasn't been registered then we can't hotload the dim
        return;
    }
    MinecraftServer mcServer = overworld.getMinecraftServer();
    ISaveHandler savehandler = overworld.getSaveHandler();
    //WorldSettings worldSettings = new WorldSettings(overworld.getWorldInfo());
    WorldServer world = (dim == 0 ? overworld : (WorldServer) (new WorldServerMulti(mcServer, savehandler, dim, overworld, mcServer.theProfiler).init()));
    world.addEventListener(new ServerWorldEventHandler(mcServer, world));
    MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(world));
    if (!mcServer.isSinglePlayer()) {
        world.getWorldInfo().setGameType(mcServer.getGameType());
    }
    mcServer.setDifficultyForAllWorlds(mcServer.getDifficulty());
}
Also used : ISaveHandler(net.minecraft.world.storage.ISaveHandler) WorldEvent(net.minecraftforge.event.world.WorldEvent) WorldServer(net.minecraft.world.WorldServer) ServerWorldEventHandler(net.minecraft.world.ServerWorldEventHandler) MinecraftException(net.minecraft.world.MinecraftException) WorldServerMulti(net.minecraft.world.WorldServerMulti) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 75 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project MinecraftForge by MinecraftForge.

the class FMLCommonHandler method handleServerStopped.

public void handleServerStopped() {
    sidedDelegate.serverStopped();
    MinecraftServer server = getMinecraftServerInstance();
    Loader.instance().serverStopped();
    // FORCE the internal server to stop: hello optifine workaround!
    if (server != null)
        ObfuscationReflectionHelper.setPrivateValue(MinecraftServer.class, server, false, "field_71316" + "_v", "u", "serverStopped");
    // allow any pending exit to continue, clear exitLatch
    CountDownLatch latch = exitLatch;
    if (latch != null) {
        latch.countDown();
        exitLatch = null;
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

MinecraftServer (net.minecraft.server.MinecraftServer)166 WorldServer (net.minecraft.world.WorldServer)35 BlockPos (net.minecraft.util.math.BlockPos)34 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)31 Player (org.spongepowered.api.entity.living.player.Player)30 PlayerConnection (org.spongepowered.api.network.PlayerConnection)30 CommandException (net.minecraft.command.CommandException)19 World (net.minecraft.world.World)18 Template (net.minecraft.world.gen.structure.template.Template)18 TextComponentString (net.minecraft.util.text.TextComponentString)16 ICommandSender (net.minecraft.command.ICommandSender)15 Entity (net.minecraft.entity.Entity)15 PlacementSettings (net.minecraft.world.gen.structure.template.PlacementSettings)15 TemplateManager (net.minecraft.world.gen.structure.template.TemplateManager)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 ResourceLocation (net.minecraft.util.ResourceLocation)14 Rotation (net.minecraft.util.Rotation)12 RCConfig (ivorius.reccomplex.RCConfig)11 TileEntity (net.minecraft.tileentity.TileEntity)11 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)10