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() });
}
}
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;
}
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!"));
}
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!"));
}
}
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);
}
}
Aggregations