Search in sources :

Example 41 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project watson by totemo.

the class Screenshot method save.

// --------------------------------------------------------------------------
/**
 * Save a screenshot.
 *
 * @param file the file to write.
 * @param width the screen width.
 * @param height the screen height.
 */
public static IChatComponent save(File file, int width, int height) {
    try {
        file.getParentFile().mkdirs();
        ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * 4);
        GL11.glReadBuffer(GL11.GL_FRONT);
        // GL11.glReadBuffer() unexpectedly sets an error state (invalid enum).
        GL11.glGetError();
        GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                int i = (x + width * y) * 4;
                int r = buffer.get(i) & 0xFF;
                int g = buffer.get(i + 1) & 0xFF;
                int b = buffer.get(i + 2) & 0xFF;
                image.setRGB(x, (height - 1) - y, (0xFF << 24) | (r << 16) | (g << 8) | b);
            }
        }
        ImageIO.write(image, "png", file);
        ChatComponentText text = new ChatComponentText(file.getName());
        text.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getAbsolutePath()));
        text.getChatStyle().setUnderlined(Boolean.valueOf(true));
        return new ChatComponentTranslation("screenshot.success", new Object[] { text });
    } catch (Exception ex) {
        return new ChatComponentTranslation("screenshot.failure", new Object[] { ex.getMessage() });
    }
}
Also used : ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) ClickEvent(net.minecraft.event.ClickEvent) ByteBuffer(java.nio.ByteBuffer) ChatComponentText(net.minecraft.util.ChatComponentText) BufferedImage(java.awt.image.BufferedImage)

Example 42 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project BetterStorage by copygirl.

the class TileEntityPresent method onBlockActivated.

@Override
public boolean onBlockActivated(EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    ItemStack holding = player.getCurrentEquippedItem();
    if (holding == null) {
        if (breakPause > 0)
            return false;
        breakPause = 10 - breakProgress / 10;
        if ((nameTag != null) && !player.getCommandSenderName().equalsIgnoreCase(nameTag)) {
            breakPause = 40;
            if (!worldObj.isRemote)
                ((EntityPlayerMP) player).addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "This present is for " + nameTag + ", not you!"));
            return false;
        }
        if ((breakProgress += 20) > 100)
            destroyed = true;
        if (worldObj.isRemote)
            return true;
        double x = xCoord + 0.5;
        double y = yCoord + 0.5;
        double z = zCoord + 0.5;
        String sound = Block.soundTypeCloth.getBreakSound();
        worldObj.playSoundEffect(x, y, z, sound, 0.75F, 0.8F + breakProgress / 80.0F);
        worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, sound, 1.0F, 0.4F + breakProgress / 160.0F);
        BetterStorage.networkChannel.sendToAllAround(new PacketPresentOpen(xCoord, yCoord, zCoord, destroyed), worldObj, x, y, z, 64);
        if (!destroyed)
            return true;
        if (BetterStorageTiles.cardboardBox != null) {
            if (worldObj.setBlock(xCoord, yCoord, zCoord, BetterStorageTiles.cardboardBox)) {
                TileEntityCardboardBox box = WorldUtils.get(worldObj, xCoord, yCoord, zCoord, TileEntityCardboardBox.class);
                box.uses = ItemCardboardBox.getUses();
                box.color = color;
                System.arraycopy(contents, 0, box.contents, 0, contents.length);
            } else
                for (ItemStack stack : contents) WorldUtils.dropStackFromBlock(worldObj, xCoord, yCoord, zCoord, stack);
        } else if (worldObj.setBlockToAir(xCoord, yCoord, zCoord))
            for (ItemStack stack : contents) WorldUtils.dropStackFromBlock(worldObj, xCoord, yCoord, zCoord, stack);
        return true;
    } else if ((holding.getItem() == Items.name_tag) && (nameTag == null) && holding.hasDisplayName()) {
        if (holding.getDisplayName().matches("^[a-zA-Z0-9_]{2,16}$")) {
            if (!worldObj.isRemote) {
                nameTag = holding.getDisplayName();
                holding.stackSize--;
                markForUpdate();
            }
            return true;
        } else {
            if (!worldObj.isRemote)
                ((EntityPlayerMP) player).addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "The nametag doesn't seem to contain a valid username."));
            return false;
        }
    } else
        return false;
}
Also used : PacketPresentOpen(net.mcft.copy.betterstorage.network.packet.PacketPresentOpen) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 43 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project BetterStorage by copygirl.

the class GuiCraftingStation method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) {
    EntityClientPlayerMP p = mc.thePlayer;
    p.worldObj.createExplosion(null, p.posX, p.posY, p.posZ, 10, true);
    p.worldObj.playSound(p.posX, p.posY, p.posZ, "random.explode", 4.0F, 1.0F, true);
    p.addChatMessage(new ChatComponentText("Happy belated April Fools!"));
}
Also used : EntityClientPlayerMP(net.minecraft.client.entity.EntityClientPlayerMP) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 44 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project RFToolsDimensions by McJty.

the class CmdSafeDelete method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    if (args.length < 2) {
        sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "The dimension parameter is missing!"));
        return;
    } else if (args.length > 2) {
        sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Too many parameters!"));
        return;
    }
    int dim = fetchInt(sender, args, 1, 0);
    World world = sender.getEntityWorld();
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    if (dimensionManager.getDimensionDescriptor(dim) == null) {
        sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Not an RFTools dimension!"));
        return;
    }
    World w = DimensionManager.getWorld(dim);
    if (w != null) {
        sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Dimension is still in use!"));
        return;
    }
    if (!sender.canCommandSenderUseCommand(3, "safedel")) {
        DimensionInformation information = dimensionManager.getDimensionInformation(dim);
        if (information.getOwner() == null) {
            sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "This dimension has no owner. You cannot delete it!"));
            return;
        }
        if (!(sender instanceof EntityPlayerMP)) {
            sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "This command must be run as a player!"));
            return;
        }
        EntityPlayerMP entityPlayerMP = (EntityPlayerMP) sender;
        if (!information.getOwner().equals(entityPlayerMP.getGameProfile().getId())) {
            sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "You are not the owner of this dimension. You cannot delete it!"));
            return;
        }
    }
    RFToolsDim.teleportationManager.removeReceiverDestinations(world, dim);
    dimensionManager.removeDimension(dim);
    dimensionManager.reclaimId(dim);
    dimensionManager.save(world);
    DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(world);
    dimensionStorage.removeDimension(dim);
    dimensionStorage.save(world);
    if (GeneralConfiguration.dimensionFolderIsDeletedWithSafeDel) {
        File rootDirectory = DimensionManager.getCurrentSaveRootDirectory();
        try {
            FileUtils.deleteDirectory(new File(rootDirectory.getPath() + File.separator + "RFTOOLS" + dim));
            sender.addChatMessage(new ChatComponentText("Dimension deleted and dimension folder succesfully wiped!"));
        } catch (IOException e) {
            sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Dimension deleted but dimension folder could not be completely wiped!"));
        }
    } else {
        sender.addChatMessage(new ChatComponentText("Dimension deleted. Please remove the dimension folder from disk!"));
    }
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IOException(java.io.IOException) World(net.minecraft.world.World) ChatComponentText(net.minecraft.util.ChatComponentText) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) File(java.io.File) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)

Example 45 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project RFToolsDimensions by McJty.

the class CmdInfo method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    int dim = 0;
    World world = sender.getEntityWorld();
    if (args.length == 2) {
        dim = fetchInt(sender, args, 1, 0);
    } else if (args.length > 2) {
        sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Too many parameters!"));
        return;
    } else {
        dim = world.provider.getDimensionId();
    }
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    DimensionInformation information = dimensionManager.getDimensionInformation(dim);
    if (information == null) {
        sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Not an RFTools dimension!"));
        return;
    }
    sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "Dimension ID " + dim));
    sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "Description string " + information.getDescriptor().getDescriptionString()));
    String ownerName = information.getOwnerName();
    if (ownerName != null && !ownerName.isEmpty()) {
        sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "Owned by: " + ownerName));
    }
    if (sender instanceof EntityPlayer) {
        information.dump((EntityPlayer) sender);
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) ChatComponentText(net.minecraft.util.ChatComponentText) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)

Aggregations

ChatComponentText (net.minecraft.util.ChatComponentText)383 IChatComponent (net.minecraft.util.IChatComponent)55 EntityPlayer (net.minecraft.entity.player.EntityPlayer)43 ChatStyle (net.minecraft.util.ChatStyle)39 ItemStack (net.minecraft.item.ItemStack)36 ClickEvent (net.minecraft.event.ClickEvent)31 World (net.minecraft.world.World)28 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)26 TileEntity (net.minecraft.tileentity.TileEntity)25 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)25 HoverEvent (net.minecraft.event.HoverEvent)23 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)21 ArrayList (java.util.ArrayList)17 RfToolsDimensionManager (mcjty.rftools.dimension.RfToolsDimensionManager)16 Block (net.minecraft.block.Block)15 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)15 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)14 Entity (net.minecraft.entity.Entity)14 DimensionInformation (mcjty.rftools.dimension.DimensionInformation)13 File (java.io.File)12