Search in sources :

Example 81 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Waystones by blay09.

the class BlockWaystone method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (player.isSneaking() && (player.capabilities.isCreativeMode || !WaystoneConfig.general.creativeModeOnly)) {
        if (!world.isRemote) {
            TileWaystone tileWaystone = getTileWaystone(world, pos);
            if (tileWaystone == null) {
                return true;
            }
            if (WaystoneConfig.general.restrictRenameToOwner && !tileWaystone.isOwner(player)) {
                player.sendStatusMessage(new TextComponentTranslation("waystones:notTheOwner"), true);
                return true;
            }
            if (tileWaystone.isGlobal() && !player.capabilities.isCreativeMode && !WaystoneConfig.general.allowEveryoneGlobal) {
                player.sendStatusMessage(new TextComponentTranslation("waystones:creativeRequired"), true);
                return true;
            }
            player.openGui(Waystones.instance, 1, world, pos.getX(), pos.getY(), pos.getZ());
        }
        return true;
    }
    TileWaystone tileWaystone = getTileWaystone(world, pos);
    if (tileWaystone == null) {
        return true;
    }
    WaystoneEntry knownWaystone = world.isRemote ? ClientWaystones.getKnownWaystone(tileWaystone.getWaystoneName()) : null;
    if (knownWaystone != null) {
        Waystones.proxy.openWaystoneSelection(WarpMode.WAYSTONE, EnumHand.MAIN_HAND, knownWaystone);
    } else if (!world.isRemote) {
        WaystoneEntry waystone = new WaystoneEntry(tileWaystone);
        if (!WaystoneManager.checkAndUpdateWaystone(player, waystone)) {
            TextComponentString nameComponent = new TextComponentString(tileWaystone.getWaystoneName());
            nameComponent.getStyle().setColor(TextFormatting.WHITE);
            TextComponentTranslation chatComponent = new TextComponentTranslation("waystones:activatedWaystone", nameComponent);
            chatComponent.getStyle().setColor(TextFormatting.YELLOW);
            player.sendMessage(chatComponent);
            player.addStat(WAYSTONE_ACTIVATED);
            WaystoneManager.addPlayerWaystone(player, waystone);
            WaystoneManager.sendPlayerWaystones(player);
        }
        if (WaystoneConfig.general.setSpawnPoint) {
            EnumFacing blockFacing = state.getValue(FACING);
            player.setSpawnPoint(new BlockPos(tileWaystone.getPos().offset(blockFacing)), true);
        }
    } else {
        Waystones.proxy.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, pos, 1f);
        for (int i = 0; i < 32; i++) {
            world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, pos.getX() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, pos.getY() + 3, pos.getZ() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, 0, -5, 0);
            world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, pos.getX() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, pos.getY() + 4, pos.getZ() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, 0, -5, 0);
        }
    }
    return true;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 82 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project OreSpawn by MinecraftModDevelopmentMods.

the class ClearChunkCommand method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (!(sender instanceof EntityPlayer)) {
        throw new CommandException("Only players can use this command");
    }
    EntityPlayer player = (EntityPlayer) sender;
    Chunk chunk = player.getEntityWorld().getChunkFromBlockCoords(player.getPosition());
    ChunkPos chunkPos = chunk.getPos();
    List<IBlockState> blocks;
    boolean flagClassic = args.length > 0 ? args[0].toLowerCase().equalsIgnoreCase("classic") : false;
    List<String> blockNames = new LinkedList<>();
    getBlocks(args, blockNames);
    blocks = blockNames.stream().map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).map(block -> block.getDefaultState()).collect(Collectors.toList());
    blocks.addAll(OreSpawn.API.getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()).stream().collect(Collectors.toList()));
    List<IBlockState> overburden = Arrays.asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", "minecraft:sandstone", "minecraft:red_sandstone").stream().map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).map(bl -> bl.getDefaultState()).collect(Collectors.toList());
    clearBlocks(chunkPos, blocks, overburden, flagClassic, player);
    player.sendStatusMessage(new TextComponentString("chunk " + chunkPos.toString() + " cleared"), true);
}
Also used : Arrays(java.util.Arrays) Blocks(net.minecraft.init.Blocks) OreSpawn(com.mcmoddev.orespawn.OreSpawn) ChunkPos(net.minecraft.util.math.ChunkPos) CommandBase(net.minecraft.command.CommandBase) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) ICommand(net.minecraft.command.ICommand) TextComponentString(net.minecraft.util.text.TextComponentString) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Block(net.minecraft.block.Block) ICommandSender(net.minecraft.command.ICommandSender) OreDictionary(net.minecraftforge.oredict.OreDictionary) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) Chunk(net.minecraft.world.chunk.Chunk) LinkedList(java.util.LinkedList) IBlockState(net.minecraft.block.state.IBlockState) CommandException(net.minecraft.command.CommandException) TextComponentString(net.minecraft.util.text.TextComponentString) Chunk(net.minecraft.world.chunk.Chunk) LinkedList(java.util.LinkedList) TextComponentString(net.minecraft.util.text.TextComponentString) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 83 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project YABBA by LatvianModder.

the class TileItemBarrel method createConfig.

@Override
public void createConfig(YabbaConfigEvent event) {
    super.createConfig(event);
    String group = Yabba.MOD_ID;
    event.getConfig().setGroupName(group, new TextComponentString(Yabba.MOD_NAME));
    if (!tier.creative()) {
        event.getConfig().add(group, "locked", isLocked);
    }
}
Also used : TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 84 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Cavern2 by kegare.

the class RegenerationMessage method process.

@Override
public IMessage process() {
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    File rootDir = DimensionManager.getCurrentSaveRootDirectory();
    if (rootDir == null || !rootDir.exists()) {
        return new RegenerationGuiMessage(EnumType.FAILED);
    }
    server.getPlayerList().saveAllPlayerData();
    for (DimensionType type : dimensions) {
        WorldServer world = DimensionManager.getWorld(type.getId());
        if (world != null) {
            for (EntityPlayer player : world.playerEntities) {
                if (player != null && player instanceof EntityPlayerMP) {
                    EntityPlayerMP playerMP = (EntityPlayerMP) player;
                    if (playerMP.connection != null) {
                        playerMP.connection.disconnect(new TextComponentTranslation("cavern.message.disconnect.unload"));
                    }
                }
            }
            try {
                world.saveAllChunks(true, null);
            } catch (MinecraftException e) {
                return new RegenerationGuiMessage(EnumType.FAILED);
            }
            world.flush();
            MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(world));
            DimensionManager.setWorld(world.provider.getDimension(), null, server);
            world.getWorldInfo().setDimensionData(world.provider.getDimension(), null);
        }
        for (EntityPlayerMP player : server.getPlayerList().getPlayers()) {
            if (player != null) {
                PortalCache.get(player).clearLastPos(null, type);
            }
        }
        File dimDir = new File(rootDir, "DIM" + type.getId());
        if (!dimDir.exists()) {
            return new RegenerationGuiMessage(EnumType.FAILED);
        }
        ITextComponent name = new TextComponentString(CaveDimensions.getLocalizedName(type));
        name.getStyle().setBold(true);
        sendProgress(EnumType.START);
        ITextComponent message = new TextComponentTranslation("cavern.regeneration.regenerating", name);
        message.getStyle().setColor(TextFormatting.GRAY);
        server.getPlayerList().sendMessage(message);
        if (backup) {
            message = new TextComponentTranslation("cavern.regeneration.backup", name);
            message.getStyle().setColor(TextFormatting.GRAY);
            server.getPlayerList().sendMessage(message);
            sendProgress(EnumType.BACKUP);
            Calendar calendar = Calendar.getInstance();
            String year = Integer.toString(calendar.get(Calendar.YEAR));
            String month = String.format("%02d", calendar.get(Calendar.MONTH) + 1);
            String day = String.format("%02d", calendar.get(Calendar.DATE));
            String hour = String.format("%02d", calendar.get(Calendar.HOUR_OF_DAY));
            String minute = String.format("%02d", calendar.get(Calendar.MINUTE));
            String second = String.format("%02d", calendar.get(Calendar.SECOND));
            File bak = new File(rootDir, type.getName() + "_bak-" + String.join("", year, month, day) + "-" + String.join("", hour, minute, second) + ".zip");
            if (CaveUtils.archiveDirectory(dimDir, bak)) {
                message = new TextComponentTranslation("cavern.regeneration.backup.success", name);
                message.getStyle().setColor(TextFormatting.GRAY);
                server.getPlayerList().sendMessage(message);
            } else {
                message = new TextComponentTranslation("cavern.regeneration.backup.failed", name);
                message.getStyle().setColor(TextFormatting.RED);
                server.getPlayerList().sendMessage(message);
                return new RegenerationGuiMessage(EnumType.FAILED);
            }
        }
        try {
            FileUtils.deleteDirectory(dimDir);
        } catch (IOException e) {
            return new RegenerationGuiMessage(EnumType.FAILED);
        }
        message = new TextComponentTranslation("cavern.regeneration.regenerated", name);
        message.getStyle().setColor(TextFormatting.GRAY);
        server.getPlayerList().sendMessage(message);
        if (type.shouldLoadSpawn()) {
            world = server.getWorld(type.getId());
            try {
                world.saveAllChunks(true, null);
            } catch (MinecraftException e) {
            }
            world.flush();
        }
    }
    return new RegenerationGuiMessage(EnumType.REGENERATED);
}
Also used : DimensionType(net.minecraft.world.DimensionType) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MinecraftException(net.minecraft.world.MinecraftException) Calendar(java.util.Calendar) ITextComponent(net.minecraft.util.text.ITextComponent) WorldServer(net.minecraft.world.WorldServer) RegenerationGuiMessage(cavern.network.client.RegenerationGuiMessage) TextComponentString(net.minecraft.util.text.TextComponentString) IOException(java.io.IOException) MinecraftServer(net.minecraft.server.MinecraftServer) TextComponentString(net.minecraft.util.text.TextComponentString) WorldEvent(net.minecraftforge.event.world.WorldEvent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) File(java.io.File)

Example 85 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project BetterQuesting by Funwayguy.

the class PktHandlerLineEdit method handleServer.

@Override
public void handleServer(NBTTagCompound data, EntityPlayerMP sender) {
    if (sender == null) {
        return;
    }
    boolean isOP = sender.world.getMinecraftServer().getPlayerList().canSendCommands(sender.getGameProfile());
    if (!isOP) {
        BetterQuesting.logger.log(Level.WARN, "Player " + sender.getName() + " (UUID:" + QuestingAPI.getQuestingUUID(sender) + ") tried to edit quest lines without OP permissions!");
        sender.sendStatusMessage(new TextComponentString(TextFormatting.RED + "You need to be OP to edit quests!"), false);
        // Player is not operator. Do nothing
        return;
    }
    int aID = !data.hasKey("action") ? -1 : data.getInteger("action");
    int lID = !data.hasKey("lineID") ? -1 : data.getInteger("lineID");
    int idx = !data.hasKey("order") ? -1 : data.getInteger("order");
    IQuestLine questLine = QuestLineDatabase.INSTANCE.getValue(lID);
    if (aID < 0 || aID >= EnumPacketAction.values().length) {
        return;
    }
    EnumPacketAction action = EnumPacketAction.values()[aID];
    if (action == EnumPacketAction.ADD) {
        IQuestLine nq = new QuestLine();
        int nID = QuestLineDatabase.INSTANCE.nextKey();
        if (data.hasKey("data") && lID >= 0) {
            nID = lID;
            NBTTagCompound base = data.getCompoundTag("data");
            nq.readFromNBT(base.getCompoundTag("line"), EnumSaveType.CONFIG);
        }
        QuestLineDatabase.INSTANCE.add(nq, nID);
        PacketSender.INSTANCE.sendToAll(nq.getSyncPacket());
        return;
    } else if (// Edit quest lines
    action == EnumPacketAction.EDIT && questLine != null) {
        questLine.readPacket(data);
        if (idx >= 0 && QuestLineDatabase.INSTANCE.getOrderIndex(lID) != idx) {
            QuestLineDatabase.INSTANCE.setOrderIndex(lID, idx);
            PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
        } else {
            PacketSender.INSTANCE.sendToAll(questLine.getSyncPacket());
        }
        return;
    } else if (action == EnumPacketAction.REMOVE && questLine != null) {
        QuestLineDatabase.INSTANCE.removeKey(lID);
        PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
        return;
    }
}
Also used : IQuestLine(betterquesting.api.questing.IQuestLine) EnumPacketAction(betterquesting.api.enums.EnumPacketAction) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) QuestLine(betterquesting.questing.QuestLine) IQuestLine(betterquesting.api.questing.IQuestLine) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

TextComponentString (net.minecraft.util.text.TextComponentString)343 EntityPlayer (net.minecraft.entity.player.EntityPlayer)79 ItemStack (net.minecraft.item.ItemStack)68 BlockPos (net.minecraft.util.math.BlockPos)60 ITextComponent (net.minecraft.util.text.ITextComponent)48 TileEntity (net.minecraft.tileentity.TileEntity)41 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)35 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)32 Colony (com.minecolonies.coremod.colony.Colony)26 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)26 IBlockState (net.minecraft.block.state.IBlockState)23 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)21 Style (net.minecraft.util.text.Style)21 IColony (com.minecolonies.api.colony.IColony)19 ClickEvent (net.minecraft.util.text.event.ClickEvent)19 Entity (net.minecraft.entity.Entity)18 Block (net.minecraft.block.Block)17 World (net.minecraft.world.World)17 ArrayList (java.util.ArrayList)16 ActionResult (net.minecraft.util.ActionResult)13