Search in sources :

Example 61 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.

the class ServerboundSelectedTitlePacketHandler method handleMessage.

@Override
public void handleMessage(final ServerboundSelectedTitlePacket message, final RemoteConnection connection, final Platform.Type side) {
    if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
        final Player player = ((PlayerConnection) connection).getPlayer();
        this.titleManager.setSelectedTitleFor(player, message.titleId);
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PlayerConnection(org.spongepowered.api.network.PlayerConnection) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 62 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project MorePlanets by SteveKunG.

the class WorldGenGravityHarvester method generate.

@Override
public boolean generate(World world, Random rand, BlockPos pos) {
    Random random = world.getChunk(pos).getRandomWithSeed(987234911L);
    MinecraftServer server = world.getMinecraftServer();
    Rotation[] arotation = CachedEnum.rotationValues;
    Rotation rotation = arotation[random.nextInt(arotation.length)];
    int i = random.nextInt(GRAVITY_HARVESTERS.length);
    TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
    Template template = manager.getTemplate(server, GRAVITY_HARVESTERS[i]);
    ChunkPos chunkpos = new ChunkPos(pos);
    StructureBoundingBox box = new StructureBoundingBox(chunkpos.getXStart(), 0, chunkpos.getZStart(), chunkpos.getXEnd(), 256, chunkpos.getZEnd());
    PlacementSettings settings = new PlacementSettings().setRotation(rotation).setBoundingBox(box).setRandom(random);
    BlockPos blockpos = template.transformedSize(rotation);
    int x = random.nextInt(16 - blockpos.getX());
    int z = random.nextInt(16 - blockpos.getZ());
    BlockPos blockpos1 = template.getZeroPositionWithTransform(pos.add(x, 0, z), Mirror.NONE, rotation);
    Map<BlockPos, String> dataList = template.getDataBlocks(blockpos1, settings);
    for (Map.Entry<BlockPos, String> entry : dataList.entrySet()) {
        if ("extractor".equals(entry.getValue())) {
            BlockPos pos2 = entry.getKey();
            world.setBlockState(pos2, MPBlocks.GRAVITY_CREEP_EXTRACTOR.getDefaultState(), 3);
            TileEntity tile = world.getTileEntity(pos2);
            if (tile instanceof TileEntityGravityExtractor) {
                ((TileEntityGravityExtractor) tile).setLifeTime(6000 + rand.nextInt(6000));
            }
        } else if ("extractor_with_vines".equals(entry.getValue())) {
            BlockPos pos2 = entry.getKey();
            world.setBlockState(pos2, MPBlocks.GRAVITY_CREEP_EXTRACTOR.getDefaultState(), 3);
            world.setBlockState(pos2.down(), MPBlocks.GRAVITY_CREEP_VINES.getDefaultState(), 3);
            TileEntity tile = world.getTileEntity(pos2);
            if (tile instanceof TileEntityGravityExtractor) {
                ((TileEntityGravityExtractor) tile).setLifeTime(6000 + rand.nextInt(6000));
            }
        }
    }
    template.addBlocksToWorld(world, blockpos1, settings, 20);
    return true;
}
Also used : TileEntityGravityExtractor(stevekung.mods.moreplanets.moons.koentus.tileentity.TileEntityGravityExtractor) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Rotation(net.minecraft.util.Rotation) MinecraftServer(net.minecraft.server.MinecraftServer) Template(net.minecraft.world.gen.structure.template.Template) TileEntity(net.minecraft.tileentity.TileEntity) Random(java.util.Random) TemplateManager(net.minecraft.world.gen.structure.template.TemplateManager) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map)

Example 63 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project MorePlanets by SteveKunG.

the class StructureNibiruIglooPieces method addComponentParts.

@Override
public boolean addComponentParts(World world, Random rand, StructureBoundingBox structureBoundingBox) {
    if (!this.offsetToAverageGroundLevel(world, structureBoundingBox, -1)) {
        return false;
    } else {
        StructureBoundingBox box = this.getBoundingBox();
        BlockPos pos = new BlockPos(box.minX, box.minY, box.minZ);
        Rotation[] arotation = CachedEnum.rotationValues;
        MinecraftServer server = world.getMinecraftServer();
        TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
        PlacementSettings settings = new PlacementSettings().setRotation(arotation[rand.nextInt(arotation.length)]).setReplacedBlock(Blocks.STRUCTURE_VOID).setBoundingBox(box);
        Template template = manager.getTemplate(server, IGLOO_TOP_ID);
        template.addBlocksToWorldChunk(world, pos, settings);
        if (rand.nextDouble() < 0.5D) {
            Template template1 = manager.getTemplate(server, IGLOO_MIDDLE_ID);
            Template template2 = manager.getTemplate(server, IGLOO_BOTTOM_ID);
            int i = rand.nextInt(8) + 4;
            for (int j = 0; j < i; ++j) {
                BlockPos blockpos1 = template.calculateConnectedPos(settings, new BlockPos(3, -1 - j * 3, 5), settings, new BlockPos(1, 2, 1));
                template1.addBlocksToWorldChunk(world, pos.add(blockpos1), settings);
            }
            BlockPos blockpos4 = pos.add(template.calculateConnectedPos(settings, new BlockPos(3, -1 - i * 3, 5), settings, new BlockPos(3, 5, 7)));
            template2.addBlocksToWorldChunk(world, blockpos4, settings);
            Map<BlockPos, String> map = template2.getDataBlocks(blockpos4, settings);
            for (Entry<BlockPos, String> entry : map.entrySet()) {
                if ("chest".equals(entry.getValue())) {
                    BlockPos blockpos2 = entry.getKey();
                    world.setBlockState(blockpos2, Blocks.AIR.getDefaultState(), 3);
                    TileEntity tile = world.getTileEntity(blockpos2.down());
                    if (tile instanceof TileEntityChestMP) {
                        ((TileEntityChestMP) tile).setLootTable(MPLootTables.COMMON_SPACE_DUNGEON, rand.nextLong());
                    }
                }
            }
        } else {
            BlockPos blockpos3 = Template.transformedBlockPos(settings, new BlockPos(3, 0, 5));
            world.setBlockState(pos.add(blockpos3), MPBlocks.INFECTED_SNOW.getDefaultState(), 3);
        }
        return true;
    }
}
Also used : StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) TileEntityChestMP(stevekung.mods.moreplanets.utils.tileentity.TileEntityChestMP) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Rotation(net.minecraft.util.Rotation) MinecraftServer(net.minecraft.server.MinecraftServer) Template(net.minecraft.world.gen.structure.template.Template) TileEntity(net.minecraft.tileentity.TileEntity) TemplateManager(net.minecraft.world.gen.structure.template.TemplateManager) BlockPos(net.minecraft.util.math.BlockPos)

Example 64 with MinecraftServer

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

the class PrimaryLevelDataMixin method impl$updateWorldForDifficultyChange.

void impl$updateWorldForDifficultyChange(final ServerLevel world, final boolean isLocked) {
    if (world == null) {
        return;
    }
    final MinecraftServer server = world.getServer();
    final Difficulty difficulty = ((LevelData) this).getDifficulty();
    if (difficulty == Difficulty.HARD) {
        world.setSpawnSettings(true, true);
    } else if (server.isSingleplayer()) {
        world.setSpawnSettings(difficulty != Difficulty.PEACEFUL, true);
    } else {
        world.setSpawnSettings(((MinecraftServerAccessor) server).invoker$isSpawningMonsters(), server.isSpawningAnimals());
    }
    world.players().forEach(player -> player.connection.send(new ClientboundChangeDifficultyPacket(difficulty, isLocked)));
}
Also used : MinecraftServerAccessor(org.spongepowered.common.accessor.server.MinecraftServerAccessor) Difficulty(net.minecraft.world.Difficulty) ClientboundChangeDifficultyPacket(net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket) PrimaryLevelData(net.minecraft.world.level.storage.PrimaryLevelData) ServerLevelData(net.minecraft.world.level.storage.ServerLevelData) LevelData(net.minecraft.world.level.storage.LevelData) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 65 with MinecraftServer

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

the class PacketPhase method setupPacketToStateMapping.

private void setupPacketToStateMapping() {
    this.packetTranslationMap.put(ServerboundKeepAlivePacket.class, packet -> PacketPhase.General.IGNORED);
    this.packetTranslationMap.put(ServerboundChatPacket.class, packet -> PacketPhase.General.CHAT_COMMAND);
    this.packetTranslationMap.put(ServerboundInteractPacket.class, packet -> {
        final ServerboundInteractPacket useEntityPacket = (ServerboundInteractPacket) packet;
        final ServerboundInteractPacket.Action action = useEntityPacket.getAction();
        if (action == ServerboundInteractPacket.Action.INTERACT) {
            return PacketPhase.General.INTERACT_ENTITY;
        } else if (action == ServerboundInteractPacket.Action.ATTACK) {
            return PacketPhase.General.ATTACK_ENTITY;
        } else if (action == ServerboundInteractPacket.Action.INTERACT_AT) {
            return PacketPhase.General.INTERACT_AT_ENTITY;
        } else {
            return PacketPhase.General.INVALID;
        }
    });
    this.packetTranslationMap.put(ServerboundMovePlayerPacket.class, packet -> PacketPhase.General.MOVEMENT);
    this.packetTranslationMap.put(ServerboundMovePlayerPacket.Pos.class, packet -> PacketPhase.General.MOVEMENT);
    this.packetTranslationMap.put(ServerboundMovePlayerPacket.Rot.class, packet -> PacketPhase.General.MOVEMENT);
    this.packetTranslationMap.put(ServerboundMovePlayerPacket.PosRot.class, packet -> PacketPhase.General.MOVEMENT);
    this.packetTranslationMap.put(ServerboundPlayerActionPacket.class, packet -> {
        final ServerboundPlayerActionPacket playerDigging = (ServerboundPlayerActionPacket) packet;
        final ServerboundPlayerActionPacket.Action action = playerDigging.getAction();
        final IPhaseState<? extends PacketContext<?>> state = PacketPhase.INTERACTION_ACTION_MAPPINGS.get(action);
        return state == null ? PacketPhase.General.UNKNOWN : state;
    });
    this.packetTranslationMap.put(ServerboundUseItemOnPacket.class, packet -> {
        // Note that CPacketPlayerTryUseItem is swapped with CPacketPlayerBlockPlacement
        final ServerboundUseItemOnPacket blockPlace = (ServerboundUseItemOnPacket) packet;
        final BlockPos blockPos = blockPlace.getHitResult().getBlockPos();
        final Direction front = blockPlace.getHitResult().getDirection();
        final MinecraftServer server = SpongeCommon.server();
        if (blockPos.getY() < server.getMaxBuildHeight() - 1 || front != Direction.UP && blockPos.getY() < server.getMaxBuildHeight()) {
            return PacketPhase.General.PLACE_BLOCK;
        }
        return PacketPhase.General.INVALID;
    });
    this.packetTranslationMap.put(ServerboundUseItemPacket.class, packet -> PacketPhase.General.USE_ITEM);
    this.packetTranslationMap.put(ServerboundSetCarriedItemPacket.class, packet -> PacketPhase.Inventory.SET_CARRIED_ITEM);
    this.packetTranslationMap.put(ServerboundSwingPacket.class, packet -> PacketPhase.General.ANIMATION);
    this.packetTranslationMap.put(ServerboundPlayerCommandPacket.class, packet -> {
        final ServerboundPlayerCommandPacket playerAction = (ServerboundPlayerCommandPacket) packet;
        final ServerboundPlayerCommandPacket.Action action = playerAction.getAction();
        return PacketPhase.PLAYER_ACTION_MAPPINGS.get(action);
    });
    this.packetTranslationMap.put(ServerboundPlayerInputPacket.class, packet -> PacketPhase.General.HANDLED_EXTERNALLY);
    this.packetTranslationMap.put(ServerboundContainerClosePacket.class, packet -> PacketPhase.General.CLOSE_WINDOW);
    this.packetTranslationMap.put(ServerboundContainerClickPacket.class, packet -> PacketPhase.fromWindowPacket((ServerboundContainerClickPacket) packet));
    this.packetTranslationMap.put(ServerboundContainerAckPacket.class, packet -> PacketPhase.General.UNKNOWN);
    this.packetTranslationMap.put(ServerboundSetCreativeModeSlotPacket.class, packet -> PacketPhase.General.CREATIVE_INVENTORY);
    this.packetTranslationMap.put(ServerboundContainerButtonClickPacket.class, packet -> PacketPhase.Inventory.ENCHANT_ITEM);
    this.packetTranslationMap.put(ServerboundSignUpdatePacket.class, packet -> PacketPhase.General.UPDATE_SIGN);
    this.packetTranslationMap.put(ServerboundPlayerAbilitiesPacket.class, packet -> PacketPhase.General.IGNORED);
    this.packetTranslationMap.put(ServerboundCommandSuggestionPacket.class, packet -> PacketPhase.General.TAB_COMPLETE);
    this.packetTranslationMap.put(ServerboundClientCommandPacket.class, packet -> {
        final ServerboundClientCommandPacket clientStatus = (ServerboundClientCommandPacket) packet;
        final ServerboundClientCommandPacket.Action status = clientStatus.getAction();
        if (status == ServerboundClientCommandPacket.Action.PERFORM_RESPAWN) {
            return PacketPhase.General.REQUEST_RESPAWN;
        }
        return PacketPhase.General.IGNORED;
    });
    this.packetTranslationMap.put(ServerboundCustomPayloadPacket.class, packet -> PacketPhase.General.HANDLED_EXTERNALLY);
    this.packetTranslationMap.put(ServerboundTeleportToEntityPacket.class, packet -> PacketPhase.General.IGNORED);
    this.packetTranslationMap.put(ServerboundResourcePackPacket.class, packet -> PacketPhase.General.RESOURCE_PACK);
    this.packetTranslationMap.put(ServerboundPlaceRecipePacket.class, packet -> PacketPhase.Inventory.PLACE_RECIPE);
}
Also used : Direction(net.minecraft.core.Direction) MinecraftServer(net.minecraft.server.MinecraftServer) ServerboundClientCommandPacket(net.minecraft.network.protocol.game.ServerboundClientCommandPacket) ServerboundUseItemOnPacket(net.minecraft.network.protocol.game.ServerboundUseItemOnPacket) ServerboundPlayerActionPacket(net.minecraft.network.protocol.game.ServerboundPlayerActionPacket) ServerboundMovePlayerPacket(net.minecraft.network.protocol.game.ServerboundMovePlayerPacket) BlockPos(net.minecraft.core.BlockPos) ServerboundInteractPacket(net.minecraft.network.protocol.game.ServerboundInteractPacket) ServerboundPlayerCommandPacket(net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket) ServerboundContainerClickPacket(net.minecraft.network.protocol.game.ServerboundContainerClickPacket)

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