Search in sources :

Example 36 with MinecraftServer

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

the class VenusTickHandlerServer 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 == Phase.END) {
        for (SolarModuleNetwork network : new ArrayList<>(solarModuleNetworks)) {
            if (!network.getTransmitters().isEmpty()) {
            // network.tickEnd();
            } else {
                solarModuleNetworks.remove(network);
            }
        }
        int maxPasses = 10;
        while (!solarTransmitterUpdates.isEmpty()) {
            LinkedList<TileEntitySolarTransmitter> pass = new LinkedList<>();
            pass.addAll(solarTransmitterUpdates);
            solarTransmitterUpdates.clear();
            for (TileEntitySolarTransmitter newTile : pass) {
                if (!newTile.isInvalid()) {
                    newTile.refresh();
                }
            }
            if (--maxPasses <= 0) {
                break;
            }
        }
    }
}
Also used : TileEntitySolarTransmitter(micdoodle8.mods.galacticraft.planets.venus.tile.TileEntitySolarTransmitter) SolarModuleNetwork(micdoodle8.mods.galacticraft.planets.venus.tile.SolarModuleNetwork) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 37 with MinecraftServer

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

the class EntityTieredRocket method onUpdate.

@Override
public void onUpdate() {
    if (this.getWaitForPlayer()) {
        if (!this.getPassengers().isEmpty()) {
            Entity passenger = this.getPassengers().get(0);
            if (this.ticks >= 40) {
                if (!this.world.isRemote) {
                    this.removePassengers();
                    passenger.startRiding(this, true);
                    GCLog.debug("Remounting player in rocket.");
                }
                this.setWaitForPlayer(false);
                this.motionY = -0.5D;
            } else {
                this.motionX = this.motionY = this.motionZ = 0.0D;
                passenger.motionX = passenger.motionY = passenger.motionZ = 0;
            }
        } else {
            this.motionX = this.motionY = this.motionZ = 0.0D;
        }
    }
    super.onUpdate();
    if (!this.world.isRemote) {
        if (this.launchCooldown > 0) {
            this.launchCooldown--;
        }
        if (this.preGenIterator != null) {
            if (this.preGenIterator.hasNext()) {
                MinecraftServer mcserver;
                if (this.world instanceof WorldServer) {
                    mcserver = ((WorldServer) this.world).getMinecraftServer();
                    BlockVec3 coords = this.preGenIterator.next();
                    World w = mcserver.getWorld(coords.y);
                    if (w != null) {
                        w.getChunkFromChunkCoords(coords.x, coords.z);
                        // Pregen a second chunk if still on launchpad (low strain on server)
                        if (this.launchPhase < EnumLaunchPhase.LAUNCHED.ordinal() && this.preGenIterator.hasNext()) {
                            coords = this.preGenIterator.next();
                            w = mcserver.getWorld(coords.y);
                            w.getChunkFromChunkCoords(coords.x, coords.z);
                        }
                    }
                }
            } else {
                this.preGenIterator = null;
                EntityTieredRocket.preGenInProgress = false;
            }
        }
    }
    if (this.rumble > 0) {
        this.rumble--;
    } else if (this.rumble < 0) {
        this.rumble++;
    }
    final double rumbleAmount = this.rumble / (double) (37 - 5 * Math.max(this.getRocketTier(), 5));
    for (Entity passenger : this.getPassengers()) {
        passenger.posX += rumbleAmount;
        passenger.posZ += rumbleAmount;
    }
    if (this.launchPhase >= EnumLaunchPhase.IGNITED.ordinal()) {
        this.performHurtAnimation();
        this.rumble = (float) this.rand.nextInt(3) - 3;
    }
    if (!this.world.isRemote) {
        this.lastLastMotionY = this.lastMotionY;
        this.lastMotionY = this.motionY;
    }
}
Also used : ICameraZoomEntity(micdoodle8.mods.galacticraft.api.entity.ICameraZoomEntity) Entity(net.minecraft.entity.Entity) WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 38 with MinecraftServer

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

the class WorldUtil method transferEntityToDimension.

/**
 * It is not necessary to use entity.setDead() following calling this method.
 * If the entity left the old world it was in, it will now automatically be removed from that old world before the next update tick.
 * (See WorldUtil.removeEntityFromWorld())
 */
public static Entity transferEntityToDimension(Entity entity, int dimensionID, WorldServer world, boolean transferInv, EntityAutoRocket ridingRocket) {
    if (!world.isRemote) {
        // GalacticraftCore.packetPipeline.sendToAll(new PacketSimple(EnumSimplePacket.C_UPDATE_PLANETS_LIST, WorldUtil.getPlanetList()));
        MinecraftServer mcServer = world.getMinecraftServer();
        if (mcServer != null) {
            final WorldServer var6 = mcServer.getWorld(dimensionID);
            if (var6 == null) {
                System.err.println("Cannot Transfer Entity to Dimension: Could not get World for Dimension " + dimensionID);
                return null;
            }
            final ITeleportType type = GalacticraftRegistry.getTeleportTypeForDimension(var6.provider.getClass());
            if (type != null) {
                return WorldUtil.teleportEntity(var6, entity, dimensionID, type, transferInv, ridingRocket);
            }
        }
    }
    return null;
}
Also used : ITeleportType(micdoodle8.mods.galacticraft.api.world.ITeleportType) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 39 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 40 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)

Aggregations

MinecraftServer (net.minecraft.server.MinecraftServer)186 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)42 WorldServer (net.minecraft.world.WorldServer)35 BlockPos (net.minecraft.util.math.BlockPos)34 Player (org.spongepowered.api.entity.living.player.Player)30 PlayerConnection (org.spongepowered.api.network.PlayerConnection)30 CommandException (net.minecraft.command.CommandException)19 TextComponentString (net.minecraft.util.text.TextComponentString)18 World (net.minecraft.world.World)18 Template (net.minecraft.world.gen.structure.template.Template)18 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 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)13 Rotation (net.minecraft.util.Rotation)12 RCConfig (ivorius.reccomplex.RCConfig)11 TileEntity (net.minecraft.tileentity.TileEntity)11