Search in sources :

Example 86 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project RFTools by McJty.

the class StorageTerminalBlock method createServerContainer.

@Override
public Container createServerContainer(EntityPlayer entityPlayer, TileEntity tileEntity) {
    if (!entityPlayer.isSneaking()) {
        if (tileEntity instanceof StorageTerminalTileEntity) {
            StorageTerminalTileEntity terminalTileEntity = (StorageTerminalTileEntity) tileEntity;
            ItemStack module = terminalTileEntity.getStackInSlot(StorageTerminalContainer.SLOT_MODULE);
            if (!module.isEmpty()) {
                int dimension = RFToolsTools.getDimensionFromModule(module);
                BlockPos pos = RFToolsTools.getPositionFromModule(module);
                WorldServer world = DimensionManager.getWorld(dimension);
                if (!RFToolsTools.chunkLoaded(world, pos)) {
                    entityPlayer.sendStatusMessage(new TextComponentString(TextFormatting.YELLOW + "Storage scanner out of range!"), false);
                    return null;
                }
                TileEntity scannerTE = world.getTileEntity(pos);
                if (!(scannerTE instanceof StorageScannerTileEntity)) {
                    entityPlayer.sendStatusMessage(new TextComponentString(TextFormatting.YELLOW + "Storage scanner is missing!"), false);
                    return null;
                }
                return new StorageScannerContainer(entityPlayer, (IInventory) scannerTE, terminalTileEntity);
            }
        }
    }
    return super.createServerContainer(entityPlayer, tileEntity);
}
Also used : StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) StorageScannerContainer(mcjty.rftools.blocks.storagemonitor.StorageScannerContainer) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 87 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project RFTools by McJty.

the class StorageTerminalBlock method wrenchUse.

@Override
protected boolean wrenchUse(World world, BlockPos pos, EnumFacing side, EntityPlayer player) {
    if (!world.isRemote) {
        TileEntity te = world.getTileEntity(pos);
        if (te instanceof StorageTerminalTileEntity) {
            StorageTerminalTileEntity storageTerminalTileEntity = (StorageTerminalTileEntity) te;
            ItemStack module = storageTerminalTileEntity.getStackInSlot(StorageTerminalContainer.SLOT_MODULE);
            if (!module.isEmpty()) {
                storageTerminalTileEntity.setInventorySlotContents(StorageTerminalContainer.SLOT_MODULE, ItemStack.EMPTY);
                storageTerminalTileEntity.markDirtyClient();
                if (!player.inventory.addItemStackToInventory(module)) {
                    player.entityDropItem(module, 1.05f);
                }
                player.sendStatusMessage(new TextComponentString("Removed module"), false);
            }
        }
    }
    return true;
}
Also used : StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 88 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Wurst-MC-1.12 by Wurst-Imperium.

the class TemplateToolMod method saveFile.

private void saveFile() {
    step = Step.values()[step.ordinal() + 1];
    new Thread(() -> {
        JsonObject json = new JsonObject();
        // get facings
        EnumFacing front = EnumFacing.getHorizontal(4 - WMinecraft.getPlayer().getHorizontalFacing().getHorizontalIndex());
        EnumFacing left = front.rotateYCCW();
        // add sorted blocks
        JsonArray jsonBlocks = new JsonArray();
        for (BlockPos pos : template.sortedBlocks) {
            // translate
            pos = pos.subtract(Step.FIRST_BLOCK.pos);
            // rotate
            pos = new BlockPos(0, pos.getY(), 0).offset(front, pos.getZ()).offset(left, pos.getX());
            // add to json
            jsonBlocks.add(JsonUtils.gson.toJsonTree(new int[] { pos.getX(), pos.getY(), pos.getZ() }, int[].class));
        }
        json.add("blocks", jsonBlocks);
        try (PrintWriter save = new PrintWriter(new FileWriter(file))) {
            // save file
            save.print(JsonUtils.prettyGson.toJson(json));
            // show success message
            TextComponentString message = new TextComponentString("Saved template as ");
            TextComponentString link = new TextComponentString(file.getName());
            ClickEvent event = new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getParentFile().getAbsolutePath());
            link.getStyle().setUnderlined(true).setClickEvent(event);
            message.appendSibling(link);
            ChatUtils.component(message);
        } catch (IOException e) {
            e.printStackTrace();
            // show error message
            ChatUtils.error("File could not be saved.");
        }
        // update AutoBuild
        wurst.mods.autoBuildMod.loadTemplates();
        // disable TemplateTool
        setEnabled(false);
    }, "TemplateTool").start();
}
Also used : JsonArray(com.google.gson.JsonArray) EnumFacing(net.minecraft.util.EnumFacing) FileWriter(java.io.FileWriter) ClickEvent(net.minecraft.util.text.event.ClickEvent) JsonObject(com.google.gson.JsonObject) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 89 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Wurst-MC-1.12 by Wurst-Imperium.

the class Updater method checkForUpdate.

public void checkForUpdate() {
    Version currentVersion = new Version(WurstClient.VERSION);
    Version latestVersion = null;
    try {
        JsonArray json = fetchJson("https://api.github.com/repos/Wurst-Imperium/Wurst-MCX2/releases").getAsJsonArray();
        for (JsonElement element : json) {
            JsonObject release = element.getAsJsonObject();
            if (!currentVersion.isPreRelease() && release.get("prerelease").getAsBoolean())
                continue;
            if (!containsCompatibleAsset(release.get("assets").getAsJsonArray()))
                continue;
            latestVersionString = release.get("tag_name").getAsString().substring(1);
            latestVersion = new Version(latestVersionString);
            break;
        }
        if (latestVersion == null)
            throw new NullPointerException("Latest version is missing!");
        System.out.println("[Updater] Current version: " + currentVersion);
        System.out.println("[Updater] Latest version: " + latestVersion);
        outdated = currentVersion.shouldUpdateTo(latestVersion);
    } catch (Exception e) {
        System.err.println("[Updater] An error occurred!");
        e.printStackTrace();
    }
    if (latestVersion == null || latestVersion.isInvalid()) {
        component = new TextComponentString("An error occurred while checking for updates." + " Click \u00a7nhere\u00a7r to check manually.");
        ClickEvent event = new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.wurstclient.net/download/");
        component.getStyle().setClickEvent(event);
        WurstClient.INSTANCE.events.add(UpdateListener.class, this);
        return;
    }
    if (!latestVersion.isHigherThan(WurstClient.VERSION))
        return;
    component = new TextComponentString("Wurst " + latestVersion + " is now available." + " Click \u00a7nhere\u00a7r to download the update.");
    ClickEvent event = new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.wurstclient.net/download/");
    component.getStyle().setClickEvent(event);
    WurstClient.INSTANCE.events.add(UpdateListener.class, this);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) ClickEvent(net.minecraft.util.text.event.ClickEvent) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 90 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class InputHandler method commandEnter.

public void commandEnter() {
    Minecraft mc = Minecraft.getMinecraft();
    EntityPlayer player = mc.player;
    World world = mc.world;
    PlayerStatsCapability.IPlayerStats STATS = player.getCapability(ModCapabilities.PLAYER_STATS, null);
    IDriveState DRIVE = player.getCapability(ModCapabilities.DRIVE_STATE, null);
    loadLists();
    switch(GuiCommandMenu.selected) {
        case GuiCommandMenu.ATTACK:
            player.swingArm(EnumHand.MAIN_HAND);
            if (player.getCapability(ModCapabilities.ORGANIZATION_XIII, null).getMember() != Utils.OrgMember.NONE) {
                // Submenu of the portals
                if (GuiCommandMenu.submenu == GuiCommandMenu.SUB_MAIN) {
                    if (!this.portalCommands.isEmpty() && !STATS.getRecharge()) {
                        GuiCommandMenu.submenu = GuiCommandMenu.SUB_PORTALS;
                        GuiCommandMenu.portalSelected = 0;
                        world.playSound(player, player.getPosition(), ModSounds.select, SoundCategory.MASTER, 1.0f, 1.0f);
                    } else {
                        GuiCommandMenu.selected = GuiCommandMenu.ATTACK;
                        world.playSound(player, player.getPosition(), ModSounds.error, SoundCategory.MASTER, 1.0f, 1.0f);
                    }
                    return;
                }
            }
            if (player.getCapability(ModCapabilities.DRIVE_STATE, null).getActiveDriveName().equals(Strings.Form_Wisdom)) {
                PacketDispatcher.sendToServer(new MagicWisdomShot());
            }
            break;
        case GuiCommandMenu.MAGIC:
            if (GuiCommandMenu.submenu == GuiCommandMenu.SUB_MAIN) {
                if (!STATS.getRecharge() && (!this.magicCommands.isEmpty() && !DRIVE.getActiveDriveName().equals(Strings.Form_Valor))) {
                    GuiCommandMenu.magicselected = 0;
                    GuiCommandMenu.submenu = GuiCommandMenu.SUB_MAGIC;
                    world.playSound(player, player.getPosition(), ModSounds.select, SoundCategory.MASTER, 1.0f, 1.0f);
                    return;
                } else {
                    GuiCommandMenu.selected = GuiCommandMenu.ATTACK;
                    world.playSound(player, player.getPosition(), ModSounds.error, SoundCategory.MASTER, 1.0f, 1.0f);
                }
            }
            break;
        case GuiCommandMenu.ITEMS:
            if (GuiCommandMenu.submenu == GuiCommandMenu.SUB_MAIN) {
                if (!this.itemsCommands.isEmpty()) {
                    GuiCommandMenu.submenu = GuiCommandMenu.SUB_ITEMS;
                    GuiCommandMenu.potionselected = 0;
                    world.playSound(player, player.getPosition(), ModSounds.select, SoundCategory.MASTER, 1.0f, 1.0f);
                } else {
                    GuiCommandMenu.selected = GuiCommandMenu.ATTACK;
                    world.playSound(player, player.getPosition(), ModSounds.error, SoundCategory.MASTER, 1.0f, 1.0f);
                }
                return;
            }
            break;
        case GuiCommandMenu.DRIVE:
            if (GuiCommandMenu.submenu == GuiCommandMenu.SUB_MAIN) {
                if (player.getCapability(ModCapabilities.ORGANIZATION_XIII, null).getMember() != Utils.OrgMember.NONE) {
                    // TODO Use Limit
                    player.sendMessage(new TextComponentString("Limits are not available yet"));
                    GuiCommandMenu.submenu = GuiCommandMenu.SUB_MAIN;
                    GuiCommandMenu.selected = GuiCommandMenu.ATTACK;
                    world.playSound(player, player.getPosition(), ModSounds.error, SoundCategory.MASTER, 1.0f, 1.0f);
                } else {
                    if (DRIVE.getInDrive()) {
                        // Revert
                        if (DRIVE.getActiveDriveName().equals(Strings.Form_Anti) && !player.getCapability(ModCapabilities.CHEAT_MODE, null).getCheatMode()) {
                            GuiCommandMenu.selected = GuiCommandMenu.ATTACK;
                            world.playSound(player, player.getPosition(), ModSounds.error, SoundCategory.MASTER, 1.0f, 1.0f);
                            player.sendMessage(new TextComponentTranslation("Cannot revert while in Anti form"));
                        } else {
                            PacketDispatcher.sendToServer(new DriveFormPacket(DRIVE.getActiveDriveName(), true));
                            if (DriveFormRegistry.isDriveFormRegistered(DRIVE.getActiveDriveName()))
                                DriveFormRegistry.get(DRIVE.getActiveDriveName()).endDrive(player);
                            GuiCommandMenu.submenu = GuiCommandMenu.SUB_MAIN;
                            GuiCommandMenu.selected = GuiCommandMenu.ATTACK;
                            world.playSound(player, player.getPosition(), ModSounds.select, SoundCategory.MASTER, 1.0f, 1.0f);
                        }
                    } else if (this.driveCommands.isEmpty() || DRIVE.getDP() <= 0) {
                        world.playSound(player, player.getPosition(), ModSounds.error, SoundCategory.MASTER, 1.0f, 1.0f);
                        GuiCommandMenu.selected = GuiCommandMenu.ATTACK;
                    } else {
                        GuiCommandMenu.driveselected = 0;
                        GuiCommandMenu.submenu = GuiCommandMenu.SUB_DRIVE;
                        world.playSound(player, player.getPosition(), ModSounds.select, SoundCategory.MASTER, 1.0f, 1.0f);
                        return;
                    }
                }
            }
            break;
    }
    // Portal Submenu
    if (GuiCommandMenu.selected == GuiCommandMenu.ATTACK && GuiCommandMenu.submenu == GuiCommandMenu.SUB_PORTALS) {
        if (this.portalCommands.isEmpty()) {
        } else {
            // ModDriveForms.getDriveForm(player, world, (String) this.driveCommands.get(GuiCommandMenu.driveselected));
            if (!player.getCapability(ModCapabilities.PLAYER_STATS, null).getRecharge()) {
                PortalCoords coords = this.portalCommands.get((byte) GuiCommandMenu.portalSelected);
                if (coords.getX() != 0 && coords.getY() != 0 && coords.getZ() != 0) {
                    // ValidPortal
                    summonPortal(player, coords);
                } else {
                    player.sendMessage(new TextComponentString(TextFormatting.RED + "You don't have any portal destination"));
                }
                GuiCommandMenu.selected = GuiCommandMenu.ATTACK;
                GuiCommandMenu.submenu = GuiCommandMenu.SUB_MAIN;
                world.playSound(player, player.getPosition(), ModSounds.select, SoundCategory.MASTER, 1.0f, 1.0f);
            }
        }
    }
    // Magic Submenu
    if (GuiCommandMenu.selected == GuiCommandMenu.MAGIC && GuiCommandMenu.submenu == GuiCommandMenu.SUB_MAGIC) {
        if (this.magicCommands.isEmpty()) {
        } else if (!STATS.getRecharge() || Constants.getCost((String) this.magicCommands.get(GuiCommandMenu.magicselected)) == -1 && STATS.getMP() > 0) {
            Magic.getMagic(player, world, (String) this.magicCommands.get(GuiCommandMenu.magicselected));
            GuiCommandMenu.selected = GuiCommandMenu.ATTACK;
            GuiCommandMenu.submenu = GuiCommandMenu.SUB_MAIN;
            world.playSound(player, player.getPosition(), ModSounds.select, SoundCategory.MASTER, 1.0f, 1.0f);
        }
    }
    if (GuiCommandMenu.selected == GuiCommandMenu.ITEMS && GuiCommandMenu.submenu == GuiCommandMenu.SUB_ITEMS) {
        if (this.itemsCommands.isEmpty()) {
        } else if (!this.itemsCommands.isEmpty()) {
            ItemKKPotion.getItem(player, world, (String) this.itemsCommands.get(GuiCommandMenu.potionselected), GuiCommandMenu.potionselected);
            GuiCommandMenu.selected = GuiCommandMenu.ATTACK;
            GuiCommandMenu.submenu = GuiCommandMenu.SUB_MAIN;
            world.playSound(player, player.getPosition(), ModSounds.select, SoundCategory.MASTER, 1.0f, 1.0f);
        }
    }
    if (GuiCommandMenu.selected == GuiCommandMenu.DRIVE && GuiCommandMenu.submenu == GuiCommandMenu.SUB_DRIVE) {
        if (this.driveCommands.isEmpty()) {
        } else if ((DRIVE.getDP() >= Constants.getCost((String) this.driveCommands.get(GuiCommandMenu.driveselected)))) {
            if (this.driveCommands.get(GuiCommandMenu.driveselected).equals(Strings.Form_Final)) {
                ModDriveForms.getDriveForm(player, world, (String) this.driveCommands.get(GuiCommandMenu.driveselected));
            } else {
                if (!antiFormCheck()) {
                    ModDriveForms.getDriveForm(player, world, (String) this.driveCommands.get(GuiCommandMenu.driveselected));
                }
            }
            GuiCommandMenu.selected = GuiCommandMenu.ATTACK;
            GuiCommandMenu.submenu = GuiCommandMenu.SUB_MAIN;
            world.playSound(player, player.getPosition(), ModSounds.select, SoundCategory.MASTER, 1.0f, 1.0f);
        }
    }
}
Also used : PortalCoords(uk.co.wehavecookies56.kk.common.util.PortalCoords) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MagicWisdomShot(uk.co.wehavecookies56.kk.common.network.packet.server.magics.MagicWisdomShot) PlayerStatsCapability(uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability) EntityPlayer(net.minecraft.entity.player.EntityPlayer) DriveFormPacket(uk.co.wehavecookies56.kk.common.network.packet.server.DriveFormPacket) TextComponentString(net.minecraft.util.text.TextComponentString) World(net.minecraft.world.World) Minecraft(net.minecraft.client.Minecraft) IDriveState(uk.co.wehavecookies56.kk.common.capability.DriveStateCapability.IDriveState) 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