Search in sources :

Example 96 with MinecraftServer

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

the class SubCommandOp method processSubCommand.

@Override
public void processSubCommand(ICommandSender sender, String[] args) throws CommandException {
    MinecraftServer server = sender.getServer();
    if (server == null) {
        throw new CommandException("No server!");
    } else {
        server.getPlayerList().addOp(BuildCraftCore.gameProfile);
        CommandHelpers.sendLocalizedChatMessage(sender, "commands.op.success", "[BuildCraft]");
    }
}
Also used : CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 97 with MinecraftServer

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

the class CommandTropicsMisc method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    EntityPlayerMP player = this.getCommandSenderAsPlayer(commandSender);
    if (args.length > 0) {
        if (args[0].equals("village_coord")) {
            int x = 8452;
            int z = 5921;
            int relX = x - player.getPosition().getX();
            int relZ = z - player.getPosition().getZ();
            // x and z swapped on purpose
            System.out.println("pos: " + relZ + ", " + 0 + ", " + relX);
        } else if (args[0].equals("village_new")) {
            int x = MathHelper.floor(player.posX);
            int z = MathHelper.floor(player.posZ);
            int y = player.world.getHeight(x, z);
            if (y < WorldProviderTropicraft.MID_HEIGHT)
                y = WorldProviderTropicraft.MID_HEIGHT + 1;
            WorldDataInstance storage = player.world.getCapability(Tropicraft.WORLD_DATA_INSTANCE, null);
            if (storage != null) {
                TownKoaVillage village = new TownKoaVillage();
                int newID = storage.getAndIncrementKoaIDVillage();
                village.initData(newID, player.world.provider.getDimension(), new BlockPos(x, y, z));
                // TEMP!?
                village.direction = 0;
                village.initFirstTime();
                // wd.addTickingLocation(village);
                storage.addTickingLocation(village);
            }
        } else if (args[0].equals("village_try")) {
            int x = MathHelper.floor(player.posX);
            int z = MathHelper.floor(player.posZ);
            int y = player.world.getTopSolidOrLiquidBlock(new BlockPos(x, 0, z)).getY();
            if (y < WorldProviderTropicraft.MID_HEIGHT)
                y = WorldProviderTropicraft.MID_HEIGHT + 1;
            boolean result = TownKoaVillageGenHelper.hookTryGenVillage(new BlockPos(x, y, z), player.world);
            if (!result) {
                System.out.println("failed to gen village");
            }
        } else if (args[0].equals("schematic_save")) {
            try {
                String name = args[1];
                // Minecraft.getMinecraft().mouseHelper.ungrabMouseCursor();
                Vec3d vec = commandSender.getPositionVector();
                // Integer.parseInt(args[2]);
                int sx = MathHelper.floor(parseCoordinate(vec.x, args[2], false).getResult());
                // Integer.parseInt(args[3]);
                int sy = MathHelper.floor(parseCoordinate(vec.y, args[3], false).getResult());
                // Integer.parseInt(args[4]);
                int sz = MathHelper.floor(parseCoordinate(vec.z, args[4], false).getResult());
                // Integer.parseInt(args[5]);
                int ex = MathHelper.floor(parseCoordinate(vec.x, args[5], false).getResult());
                // Integer.parseInt(args[6]);
                int ey = MathHelper.floor(parseCoordinate(vec.y, args[6], false).getResult());
                // Integer.parseInt(args[7]);
                int ez = MathHelper.floor(parseCoordinate(vec.z, args[7], false).getResult());
                Build clipboardData = new Build(0, 0, 0, name, true);
                clipboardData.newFormat = true;
                clipboardData.recalculateLevelSize(sx, sy, sz, ex, ey, ez, true);
                clipboardData.scanLevelToData(player.world);
                clipboardData.writeNBT();
                commandSender.sendMessage(new TextComponentString("schematic saved to " + name + ".schematic"));
            } catch (Exception ex) {
                ex.printStackTrace();
                commandSender.sendMessage(new TextComponentString("command usage: tc_village schematic_save <filename> <start coords> <end coords>"));
                commandSender.sendMessage(new TextComponentString("eg: tc_village schematic_save myfile 0 0 0 5 5 5"));
                commandSender.sendMessage(new TextComponentString("start and end coords are inclusive"));
            }
        } else if (args[0].equals("schematic_print")) {
            try {
                Vec3d vec = commandSender.getPositionVector();
                String name = args[1];
                CoordinateArg sx = parseCoordinate(vec.x, args[2], false);
                CoordinateArg sy = parseCoordinate(vec.y, args[3], false);
                CoordinateArg sz = parseCoordinate(vec.z, args[4], false);
                int x = MathHelper.floor(sx.getResult());
                int y = MathHelper.floor(sy.getResult());
                int z = MathHelper.floor(sz.getResult());
                int direction = 0;
                if (args.length > 5) {
                    direction = Integer.parseInt(args[5]);
                }
                Build buildData = new Build(x, y, z, name, false);
                BuildJob bj = new BuildJob(-99, x, y, z, buildData);
                bj.build.dim = player.world.provider.getDimension();
                // skip air setting pass
                bj.useFirstPass = false;
                bj.useRotationBuild = true;
                bj.build_rate = 10000;
                bj.notifyFlag = 2;
                bj.setDirection(direction);
                // bj.customGenCallback = this;
                // bj.blockIDsNoBuildOver.add(HostileWorlds.blockSourceStructure);
                BuildServerTicks.buildMan.addBuild(bj);
                commandSender.sendMessage(new TextComponentString("printing schematic"));
            } catch (Exception ex) {
                ex.printStackTrace();
                commandSender.sendMessage(new TextComponentString("command usage: tc_village schematic_print <filename> <start coords>"));
                commandSender.sendMessage(new TextComponentString("eg: tc_village schematic_print myfile 5 5 5"));
            }
        } else if (args[0].equals("entities")) {
            HashMap<ResourceLocation, Integer> lookupCounts = new HashMap<>();
            for (Entity ent : player.world.loadedEntityList) {
                if (ent instanceof EntityLivingBase) {
                    ResourceLocation key = EntityList.getKey(ent.getClass());
                    lookupCounts.merge(key, 1, (a, b) -> a + b);
                }
            }
            player.sendMessage(new TextComponentString("Entity counts: "));
            int count = 0;
            for (Map.Entry<ResourceLocation, Integer> entry : lookupCounts.entrySet()) {
                ResourceLocation name = entry.getKey();
                player.sendMessage(new TextComponentString(name + ": " + entry.getValue()));
                count += entry.getValue();
            }
            player.sendMessage(new TextComponentString("total: " + count));
        } else if (args[0].equals("mount")) {
            float clDist = 99999;
            Entity clEntity = null;
            String name = args[1];
            boolean reverse = false;
            boolean playerMode = false;
            Class clazz = EntityList.getClass(new ResourceLocation(name));
            if (clazz == null) {
                clazz = EntityPlayer.class;
                playerMode = true;
            }
            if (args.length > 2) {
                reverse = args[2].equals("reverse");
                // no greifing
                if (reverse) {
                    playerMode = false;
                }
            }
            if (clazz != null) {
                List<Entity> listEnts = player.world.getEntitiesWithinAABB(clazz, player.getEntityBoundingBox().grow(15, 15, 15));
                for (Entity ent : listEnts) {
                    float dist = player.getDistance(ent);
                    if (dist < clDist) {
                        if (!playerMode) {
                            clDist = dist;
                            clEntity = ent;
                        } else {
                            if (player.getName().equals(name)) {
                                clEntity = ent;
                                break;
                            }
                        }
                    }
                }
            }
            if (clEntity != null) {
                if (reverse) {
                    clEntity.startRiding(player);
                } else {
                    player.startRiding(clEntity);
                }
            }
        } else if (args[0].equals("enc_unlock")) {
            for (int i = 0; i < Tropicraft.encyclopedia.getPageCount(); i++) {
                Tropicraft.encyclopedia.markPageAsNewlyVisible(i);
            }
        }
    }
}
Also used : WorldDataInstance(net.tropicraft.core.common.capability.WorldDataInstance) WorldProviderTropicraft(net.tropicraft.core.common.dimension.WorldProviderTropicraft) HashMap(java.util.HashMap) TownKoaVillage(net.tropicraft.core.common.worldgen.village.TownKoaVillage) BuildJob(net.tropicraft.core.common.build.world.BuildJob) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Vec3d(net.minecraft.util.math.Vec3d) Map(java.util.Map) Entity(net.minecraft.entity.Entity) BuildServerTicks(net.tropicraft.core.common.build.BuildServerTicks) TownKoaVillageGenHelper(net.tropicraft.core.common.worldgen.village.TownKoaVillageGenHelper) EntityList(net.minecraft.entity.EntityList) CommandBase(net.minecraft.command.CommandBase) BlockPos(net.minecraft.util.math.BlockPos) Tropicraft(net.tropicraft.Tropicraft) Build(net.tropicraft.core.common.build.world.Build) TextComponentString(net.minecraft.util.text.TextComponentString) List(java.util.List) ICommandSender(net.minecraft.command.ICommandSender) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MathHelper(net.minecraft.util.math.MathHelper) ResourceLocation(net.minecraft.util.ResourceLocation) Entity(net.minecraft.entity.Entity) HashMap(java.util.HashMap) TextComponentString(net.minecraft.util.text.TextComponentString) Vec3d(net.minecraft.util.math.Vec3d) CommandException(net.minecraft.command.CommandException) TextComponentString(net.minecraft.util.text.TextComponentString) Build(net.tropicraft.core.common.build.world.Build) ResourceLocation(net.minecraft.util.ResourceLocation) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) TownKoaVillage(net.tropicraft.core.common.worldgen.village.TownKoaVillage) BuildJob(net.tropicraft.core.common.build.world.BuildJob) WorldDataInstance(net.tropicraft.core.common.capability.WorldDataInstance)

Example 98 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project SpongeForge by SpongePowered.

the class SpongeModGame method getServer.

@Override
public Server getServer() {
    final MinecraftServer server = FMLCommonHandler.instance().getSidedDelegate().getServer();
    checkState(server != null, "Server has not been initialized yet!");
    return (Server) server;
}
Also used : MinecraftServer(net.minecraft.server.MinecraftServer) Server(org.spongepowered.api.Server) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 99 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Cavern2 by kegare.

the class BlockPortalCavern method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
    if (world.isRemote || getDimension() == null || teleporting) {
        return;
    }
    if (entity.isDead || entity.isSneaking() || entity.isRiding() || entity.isBeingRidden() || !entity.isNonBoss() || entity instanceof IProjectile) {
        return;
    }
    if (entity.timeUntilPortal <= 0) {
        ResourceLocation key = getRegistryName();
        IPortalCache cache = PortalCache.get(entity);
        MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
        DimensionType dimOld = world.provider.getDimensionType();
        DimensionType dimNew = isEntityInCave(entity) ? cache.getLastDim(key) : getDimension();
        WorldServer worldNew = server.getWorld(dimNew.getId());
        Teleporter teleporter = getTeleporter(worldNew);
        BlockPos prevPos = entity.getPosition();
        entity.timeUntilPortal = Math.max(entity.getPortalCooldown(), 100);
        if (entity instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) entity;
            if (MinerStats.get(player).getRank() < getMinerRank().getRank()) {
                player.sendStatusMessage(new TextComponentTranslation("cavern.message.portal.rank", new TextComponentTranslation(getMinerRank().getUnlocalizedName())), true);
                return;
            }
        }
        teleporting = true;
        cache.setLastDim(key, dimOld);
        cache.setLastPos(key, dimOld, prevPos);
        PatternHelper pattern = createPatternHelper(world, pos);
        double d0 = pattern.getForwards().getAxis() == EnumFacing.Axis.X ? (double) pattern.getFrontTopLeft().getZ() : (double) pattern.getFrontTopLeft().getX();
        double d1 = pattern.getForwards().getAxis() == EnumFacing.Axis.X ? entity.posZ : entity.posX;
        d1 = Math.abs(MathHelper.pct(d1 - (pattern.getForwards().rotateY().getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ? 1 : 0), d0, d0 - pattern.getWidth()));
        double d2 = MathHelper.pct(entity.posY - 1.0D, pattern.getFrontTopLeft().getY(), pattern.getFrontTopLeft().getY() - pattern.getHeight());
        cache.setLastPortalVec(new Vec3d(d1, d2, 0.0D));
        cache.setTeleportDirection(pattern.getForwards());
        entity.changeDimension(dimNew.getId(), teleporter);
        teleporting = false;
    } else {
        entity.timeUntilPortal = Math.max(entity.getPortalCooldown(), 100);
    }
}
Also used : DimensionType(net.minecraft.world.DimensionType) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) PatternHelper(net.minecraft.block.state.pattern.BlockPattern.PatternHelper) Teleporter(net.minecraft.world.Teleporter) WorldServer(net.minecraft.world.WorldServer) Vec3d(net.minecraft.util.math.Vec3d) IProjectile(net.minecraft.entity.IProjectile) MinecraftServer(net.minecraft.server.MinecraftServer) IPortalCache(cavern.api.IPortalCache) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Example 100 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Cavern2 by kegare.

the class MinerStats method addPoint.

@Override
public void addPoint(int value, boolean adjust) {
    MinerStatsEvent.AddPoint event = new MinerStatsEvent.AddPoint(entityPlayer, this, value);
    if (MinecraftForge.EVENT_BUS.post(event)) {
        return;
    }
    setPoint(point + event.getNewPoint(), adjust);
    if (entityPlayer != null && value > 0 && point > 0 && point % 100 == 0) {
        entityPlayer.addExperience(entityPlayer.xpBarCap() / 2);
    }
    MinerRank current = MinerRank.get(rank);
    int max = MinerRank.values().length - 1;
    boolean promoted = false;
    while (current.getRank() < max) {
        MinerRank next = MinerRank.get(rank + 1);
        if (point >= next.getPhase()) {
            ++rank;
            promoted = true;
            current = next;
            setPoint(point - current.getPhase(), false);
        } else
            break;
    }
    if (promoted) {
        if (adjust) {
            adjustData();
        }
        if (entityPlayer != null && entityPlayer instanceof EntityPlayerMP) {
            EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
            MinecraftServer server = player.mcServer;
            ITextComponent name = new TextComponentTranslation(current.getUnlocalizedName());
            name.getStyle().setBold(true);
            ITextComponent component = new TextComponentTranslation("cavern.minerrank.promoted", player.getDisplayName(), name);
            component.getStyle().setColor(TextFormatting.GRAY).setItalic(true);
            server.getPlayerList().sendMessage(component);
            double x = player.posX;
            double y = player.posY + player.getEyeHeight();
            double z = player.posZ;
            player.getServerWorld().playSound(null, x, y, z, CaveSounds.RANK_PROMOTE, SoundCategory.MASTER, 0.85F, 1.0F);
            switch(current) {
                case IRON_MINER:
                    PlayerHelper.grantAdvancement(player, "iron_miner");
                    break;
                case GOLD_MINER:
                    PlayerHelper.grantAdvancement(player, "gold_miner");
                    break;
                case HEXCITE_MINER:
                    PlayerHelper.grantAdvancement(player, "hexcite_miner");
                    break;
                case DIAMOND_MINER:
                    PlayerHelper.grantAdvancement(player, "diamond_miner");
                    break;
                default:
            }
            if (current.getRank() >= MiningAssistConfig.minerRank.getValue()) {
                PlayerHelper.grantToast(player, "mining_assist");
            }
        }
        MinecraftForge.EVENT_BUS.post(new MinerStatsEvent.PromoteRank(entityPlayer, this));
    }
}
Also used : MinerStatsEvent(cavern.api.event.MinerStatsEvent) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) 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