Search in sources :

Example 1 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project Engine by VoltzEngine-Project.

the class CommandThreadClear method handleConsoleCommand.

@Override
public boolean handleConsoleCommand(ICommandSender sender, String[] args) {
    for (IWorkerThread thread : VoltzEngineAPI.WORKER_THREADS.values()) {
        if (thread != null) {
            int process = thread.containedProcesses();
            thread.clearProcesses();
            sender.addChatMessage(new ChatComponentText("Cleared " + process + " process from thread " + thread.toString()));
        }
    }
    return true;
}
Also used : IWorkerThread(com.builtbroken.mc.api.process.IWorkerThread) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 2 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project Engine by VoltzEngine-Project.

the class AbstractCommand method printHelp.

/**
     * Added the help output to the player's chat
     *
     * @param sender - user running the command
     * @param p      - page number to output
     */
protected void printHelp(ICommandSender sender, int p) {
    List<String> items = new ArrayList();
    getHelpOutput(sender, items);
    sender.addChatMessage(new ChatComponentText("====== help -" + getPrefix().replace("/", "") + "- page " + p + " ======"));
    for (int i = 0 + (p * 10); i < 10 + (p * 10) && i < items.size(); i++) {
        sender.addChatMessage(new ChatComponentText(getPrefix() + " " + items.get(i)));
    }
    sender.addChatMessage(new ChatComponentText(""));
}
Also used : ArrayList(java.util.ArrayList) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 3 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project Engine by VoltzEngine-Project.

the class CommandJsonRecipe method handleConsoleCommand.

@Override
public boolean handleConsoleCommand(ICommandSender sender, String[] args) {
    if (args != null && args.length > 0 && !"help".equalsIgnoreCase(args[0])) {
        if (args[0].equals("generate") || args[0].equals("gen")) {
            if (args.length > 1) {
                String entryID = args[1];
                ItemStack stack = new JsonCraftingRecipeData(null, null, null, false, false).toStack(entryID);
                if (stack != null) {
                    List<IRecipe> recipes = entryID.contains("#") ? InventoryUtility.getRecipesWithOutput(stack) : InventoryUtility.getRecipesWithOutput(stack.getItem());
                    if (recipes != null) {
                        sender.addChatMessage(new ChatComponentText("Found " + recipes.size() + " for '" + entryID + "' saving to external json file"));
                        File writeFile = new File(JsonContentLoader.INSTANCE.externalContentFolder.getParent(), "json-gen/" + (entryID + "-recipes.json").replace(":", "_"));
                        if (!writeFile.getParentFile().exists()) {
                            writeFile.getParentFile().mkdirs();
                        }
                        try {
                            JsonObject object = new JsonObject();
                            int index = 0;
                            for (IRecipe recipe : recipes) {
                                try {
                                    if (recipe instanceof ShapedOreRecipe) {
                                        int width = 0;
                                        int height = 0;
                                        Object[] recipeItems = null;
                                        Field field = ShapedOreRecipe.class.getDeclaredField("input");
                                        field.setAccessible(true);
                                        recipeItems = (Object[]) field.get(recipe);
                                        field = ShapedOreRecipe.class.getDeclaredField("width");
                                        field.setAccessible(true);
                                        width = field.getInt(recipe);
                                        field = ShapedOreRecipe.class.getDeclaredField("height");
                                        field.setAccessible(true);
                                        height = field.getInt(recipe);
                                        Pair<String, HashMap<String, JsonElement>> itemSet = generateItemData(recipeItems, width, height);
                                        //Build data
                                        if (itemSet != null) {
                                            JsonObject recipeObject = new JsonObject();
                                            recipeObject.add("type", new JsonPrimitive("shaped"));
                                            recipeObject.add("output", toItemJson(recipe.getRecipeOutput()));
                                            recipeObject.add("grid", new JsonPrimitive(itemSet.left()));
                                            JsonObject itemEntry = new JsonObject();
                                            for (Map.Entry<String, JsonElement> entry : itemSet.right().entrySet()) {
                                                itemEntry.add(entry.getKey(), entry.getValue());
                                            }
                                            recipeObject.add("items", itemEntry);
                                            object.add("craftingGridRecipe:" + (index++), recipeObject);
                                        } else {
                                            sender.addChatMessage(new ChatComponentText("Failed to map recipe items for '" + recipe + "'"));
                                        }
                                    } else if (recipe instanceof ShapedRecipes) {
                                        Pair<String, HashMap<String, JsonElement>> itemSet = generateItemData(((ShapedRecipes) recipe).recipeItems, ((ShapedRecipes) recipe).recipeWidth, ((ShapedRecipes) recipe).recipeHeight);
                                        //Build data
                                        if (itemSet != null) {
                                            JsonObject recipeObject = new JsonObject();
                                            recipeObject.add("type", new JsonPrimitive("shaped"));
                                            recipeObject.add("output", toItemJson(recipe.getRecipeOutput()));
                                            recipeObject.add("grid", new JsonPrimitive(itemSet.left()));
                                            JsonObject itemEntry = new JsonObject();
                                            for (Map.Entry<String, JsonElement> entry : itemSet.right().entrySet()) {
                                                itemEntry.add(entry.getKey(), entry.getValue());
                                            }
                                            recipeObject.add("items", itemEntry);
                                            object.add("craftingGridRecipe:" + (index++), recipeObject);
                                        } else {
                                            sender.addChatMessage(new ChatComponentText("Failed to map recipe items for '" + recipe + "'"));
                                        }
                                    } else {
                                        sender.addChatMessage(new ChatComponentText("Failed to ID recipe type of '" + recipe + "'"));
                                    }
                                } catch (Exception e) {
                                    sender.addChatMessage(new ChatComponentText("Error processing recipe '" + recipe + "', see logs for details."));
                                    e.printStackTrace();
                                }
                            }
                            if (object.entrySet().size() > 0) {
                                Gson gson = new GsonBuilder().setPrettyPrinting().create();
                                try (FileWriter file = new FileWriter(writeFile)) {
                                    file.write(gson.toJson(object));
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {
                        sender.addChatMessage(new ChatComponentText("Failed to locate recipes for '" + entryID + "'"));
                    }
                } else {
                    sender.addChatMessage(new ChatComponentText("Failed to locate entry for '" + entryID + "'"));
                }
                return true;
            }
        }
    }
    return handleHelp(sender, args);
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) Field(java.lang.reflect.Field) JsonCraftingRecipeData(com.builtbroken.mc.lib.json.processors.recipe.crafting.JsonCraftingRecipeData) ChatComponentText(net.minecraft.util.ChatComponentText) Pair(com.builtbroken.jlib.type.Pair) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ItemStack(net.minecraft.item.ItemStack) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project Engine by VoltzEngine-Project.

the class CommandDebugMap method handleEntityPlayerCommand.

@Override
public boolean handleEntityPlayerCommand(EntityPlayer player, String[] args) {
    if (args != null && args.length > 0 && !"help".equalsIgnoreCase(args[0])) {
        if (args[0].equalsIgnoreCase("radar")) {
        } else if (args[0].equalsIgnoreCase("tile") && args.length > 1) {
            if (args[1].equalsIgnoreCase("enableDebug")) {
                if (args.length > 2) {
                    RadarMap map = TileMapRegistry.getRadarMapForWorld(player.worldObj);
                    if (args[2].equalsIgnoreCase("true") || args[2].equalsIgnoreCase("t")) {
                        map.setDebugEnabled(true);
                        player.addChatComponentMessage(new ChatComponentText("Debug enabled for tile map in your world."));
                    } else if (args[2].equalsIgnoreCase("false") || args[2].equalsIgnoreCase("f")) {
                        map.setDebugEnabled(false);
                        player.addChatComponentMessage(new ChatComponentText("Debug disabled for tile map in your world."));
                    } else {
                        player.addChatComponentMessage(new ChatComponentText("Could not parse [" + args[2] + "], enable status can only be true or false"));
                    }
                    return true;
                } else {
                    RadarMap map = TileMapRegistry.getRadarMapForWorld(player.worldObj);
                    if (!map.debugRadarMap) {
                        map.setDebugEnabled(true);
                        player.addChatComponentMessage(new ChatComponentText("Debug enabled for tile map in your world."));
                    } else {
                        map.setDebugEnabled(false);
                        player.addChatComponentMessage(new ChatComponentText("Debug disabled for tile map in your world."));
                    }
                    return true;
                }
            } else if (args[1].equalsIgnoreCase("objects")) {
                RadarMap map = TileMapRegistry.getRadarMapForWorld(player.worldObj);
                if (map.allEntities.size() > 0) {
                    player.addChatComponentMessage(new ChatComponentText("There are " + map.allEntities.size() + " tiles in the map."));
                } else {
                    player.addChatComponentMessage(new ChatComponentText("No tiles detected in global tile list."));
                }
                return true;
            } else if (args[1].equalsIgnoreCase("chunks")) {
                RadarMap map = TileMapRegistry.getRadarMapForWorld(player.worldObj);
                if (map.chunk_to_entities.size() > 0) {
                    player.addChatComponentMessage(new ChatComponentText("There are " + map.chunk_to_entities.size() + " chunk locations in the map."));
                } else {
                    player.addChatComponentMessage(new ChatComponentText("No chunks detected in map."));
                }
                return true;
            } else if (args[1].equalsIgnoreCase("around")) {
                int range = 100;
                if (args.length > 2) {
                    try {
                        range = Integer.parseInt(args[2]);
                    } catch (NumberFormatException e) {
                        player.addChatComponentMessage(new ChatComponentText("Invalid range number"));
                        return true;
                    }
                }
                RadarMap map = TileMapRegistry.getRadarMapForWorld(player.worldObj);
                List<RadarObject> list = map.getRadarObjects(player.posX, player.posZ, range);
                if (list.size() > 0) {
                    player.addChatComponentMessage(new ChatComponentText("There are " + list.size() + " tiles within " + range + " meters"));
                } else {
                    player.addChatComponentMessage(new ChatComponentText("No tiles detected in within " + range + " meters"));
                }
                return true;
            }
            return handleHelp(player, args);
        } else if (args[0].equalsIgnoreCase("heat")) {
        }
    }
    return handleHelp(player, args);
}
Also used : RadarMap(com.builtbroken.mc.lib.world.radar.RadarMap) RadarObject(com.builtbroken.mc.lib.world.radar.data.RadarObject) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 5 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project Engine by VoltzEngine-Project.

the class BlockBase method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    try {
        boolean activated = false;
        Object tile = getTile(world, x, y, z);
        if (WrenchUtility.isUsableWrench(player, player.inventory.getCurrentItem(), x, y, z)) {
            ListenerIterator it = new ListenerIterator(world, x, y, z, this, "wrench");
            while (it.hasNext()) {
                ITileEventListener next = it.next();
                if (next instanceof IWrenchListener && ((IWrenchListener) next).handlesWrenchRightClick() && ((IWrenchListener) next).onPlayerRightClickWrench(player, side, hitX, hitY, hitZ)) {
                    activated = true;
                }
            }
            if (activated) {
                WrenchUtility.damageWrench(player, player.inventory.getCurrentItem(), x, y, z);
            }
            if (activated) {
                return true;
            }
        }
        //TODO move to listener to prevent usage of IGuiTile in special cases
        if (tile instanceof IGuiTile && ((IGuiTile) tile).shouldOpenOnRightClick(player)) {
            int id = ((IGuiTile) tile).getDefaultGuiID(player);
            if (id >= 0) {
                Object o = ((IGuiTile) tile).getServerGuiElement(id, player);
                if (o != null) {
                    player.openGui(mod, id, world, x, y, z);
                    return true;
                }
            }
        }
        ListenerIterator it = new ListenerIterator(world, x, y, z, this, "activation");
        while (it.hasNext()) {
            ITileEventListener next = it.next();
            if (next instanceof IActivationListener) {
                if (((IActivationListener) next).onPlayerActivated(player, side, hitX, hitY, hitZ)) {
                    activated = true;
                }
            }
        }
        return activated;
    } catch (Exception e) {
        outputError(world, x, y, z, "while right click block on side " + side, e);
        player.addChatComponentMessage(new ChatComponentText(Colors.RED.code + LanguageUtility.getLocal("blockTile.error.onBlockActivated")));
    }
    return false;
}
Also used : ListenerIterator(com.builtbroken.mc.prefab.tile.listeners.ListenerIterator) IGuiTile(com.builtbroken.mc.api.tile.access.IGuiTile) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

ChatComponentText (net.minecraft.util.ChatComponentText)164 ItemStack (net.minecraft.item.ItemStack)27 EntityPlayer (net.minecraft.entity.player.EntityPlayer)24 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)16 TileEntity (net.minecraft.tileentity.TileEntity)13 Entity (net.minecraft.entity.Entity)12 ClickEvent (net.minecraft.event.ClickEvent)10 IChatComponent (net.minecraft.util.IChatComponent)10 ArrayList (java.util.ArrayList)9 ChatStyle (net.minecraft.util.ChatStyle)9 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)8 Block (net.minecraft.block.Block)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)8 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)7 File (java.io.File)7 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)7 WrongUsageException (net.minecraft.command.WrongUsageException)7 World (net.minecraft.world.World)6 AccessGroup (com.builtbroken.mc.lib.access.AccessGroup)5 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)5