下面列出了怎么用net.minecraft.util.ChatComponentTranslation的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if(!world.isRemote) {
if(player.isSneaking()) {
NBTTagCompound compound = NBTHelper.getData(stack);
if(compound.hasKey("networkId")) {
compound.removeTag("networkId");
if(compound.hasNoTags()) {
stack.setTagCompound(null);
}
player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.RemoteJar.clear"));
}
}
}
return super.onItemRightClick(stack, world, player);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
int meta = world.getBlockMetadata(x, y, z);
if (meta != 0 || player.isSneaking())
return false;
if (!world.isRemote) {
TileChunkLoader tile = (TileChunkLoader) world.getTileEntity(x, y, z);
if (tile.owner == null || tile.owner.equals(player.getCommandSenderName()) ||
ChunkLoaderManager.opInteract() && ServerUtils.isPlayerOP(player.getCommandSenderName())) {
PacketCustom packet = new PacketCustom(ChunkLoaderSPH.channel, 12);
packet.writeCoord(x, y, z);
packet.sendToPlayer(player);
} else
player.addChatMessage(new ChatComponentTranslation("chickenchunks.accessdenied"));
}
return true;
}
public static void givePlayerItem(EntityPlayerMP player, ItemStack stack, boolean infinite, boolean doGive) {
if (stack.getItem() == null) {
player.addChatComponentMessage(setColour(new ChatComponentTranslation("nei.chat.give.noitem"), EnumChatFormatting.WHITE));
return;
}
int given = stack.stackSize;
if(doGive) {
if (infinite)
player.inventory.addItemStackToInventory(stack);
else
given -= InventoryUtils.insertItem(player.inventory, stack, false);
}
sendNotice(player, new ChatComponentTranslation("commands.give.success", stack.getChatComponent(), infinite ? "\u221E" : Integer.toString(given), player.getCommandSenderName()), "notify-item");
player.openContainer.detectAndSendChanges();
}
public static void setGamemode(EntityPlayerMP player, int mode) {
if (mode < 0 || mode >= NEIActions.gameModes.length ||
NEIActions.nameActionMap.containsKey(NEIActions.gameModes[mode]) &&
!NEIServerConfig.canPlayerPerformAction(player.getCommandSenderName(), NEIActions.gameModes[mode]))
return;
//creative+
NEIServerConfig.forPlayer(player.getCommandSenderName()).enableAction("creative+", mode == 2);
if(mode == 2 && !(player.openContainer instanceof ContainerCreativeInv))//open the container immediately for the client
NEISPH.processCreativeInv(player, true);
//change it on the server
player.theItemInWorldManager.setGameType(getGameType(mode));
//tell the client to change it
new PacketCustom(NEISPH.channel, 14).writeByte(mode).sendToPlayer(player);
player.addChatMessage(new ChatComponentTranslation("nei.chat.gamemode." + mode));
}
private void handleSMPCheck(int serverprotocol, String worldName, World world) {
if (serverprotocol > NEIActions.protocol) {
NEIClientUtils.printChatMessage(new ChatComponentTranslation("nei.chat.mismatch.client"));
} else if (serverprotocol < NEIActions.protocol) {
NEIClientUtils.printChatMessage(new ChatComponentTranslation("nei.chat.mismatch.server"));
} else {
try {
ClientHandler.instance().loadWorld(world);
NEIClientConfig.setHasSMPCounterPart(true);
NEIClientConfig.loadWorld(getSaveName(worldName));
sendRequestLoginInfo();
} catch (Exception e) {
NEIClientConfig.logger.error("Error handling SMP Check", e);
}
}
}
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void init(File dir, EntityPlayer player) {
configDir = new File(dir, Reference.MOD_ID);
if (!configDir.exists()) {
try {
configDir.mkdir();
File defaultFile = new File(configDir, "default.json");
defaultFile.createNewFile();
LogHelper.info("Empty config created");
player.addChatMessage(new ChatComponentTranslation("wailanbt.info.CreateEmptyConfig"));
} catch (Exception e) {
LogHelper.info("Create config file failed");
player.addChatMessage(new ChatComponentTranslation("wailanbt.info.FailCreateEmptyConfig"));
e.printStackTrace();
}
}
loadConfig(player);
}
public void render(){
if(helmetModel == null) {
helmetModel = AdvancedModelLoader.loadModel(Models.PNEUMATIC_HELMET);
eyesModel = AdvancedModelLoader.loadModel(Models.PNEUMATIC_HELMET_EYES);
faceModel = AdvancedModelLoader.loadModel(Models.PNEUMATIC_HELMET_FACE);
if(!Config.useHelmetModel) {
PneumaticCraft.proxy.getPlayer().addChatComponentMessage(new ChatComponentTranslation("message.date.ironman"));
}
}
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glColor4d(1, 0.2, 0.2, 1);
helmetModel.renderAll();
GL11.glColor4d(1, 1, 0.7, 1);
faceModel.renderAll();
GL11.glColor4d(1, 1, 1, 1);
GL11.glDisable(GL11.GL_CULL_FACE);
eyesModel.renderAll();
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
@Override
public void handleServerSide(PacketAmadronTradeAdd message, EntityPlayer player){
AmadronOfferCustom offer = message.getOffer();
offer.updatePlayerId();
if(AmadronOfferManager.getInstance().hasOffer(offer.copy().invert())) {
player.addChatMessage(new ChatComponentTranslation("message.amadron.duplicateReversedOffer"));
} else if(AmadronOfferManager.getInstance().addStaticOffer(offer)) {
if(AmadronOfferSettings.notifyOfTradeAddition) NetworkHandler.sendToAll(message);
try {
AmadronOfferStaticConfig.INSTANCE.writeToFile();
} catch(IOException e) {
e.printStackTrace();
}
} else {
player.addChatMessage(new ChatComponentTranslation("message.amadron.duplicateOffer"));
}
}
@Override
public boolean onItemUse(ItemStack tablet, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10){
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof IFluidHandler) {
if(!world.isRemote) {
setLiquidProvidingLocation(tablet, x, y, z, world.provider.dimensionId);
player.addChatComponentMessage(new ChatComponentTranslation("message.amadronTable.setLiquidProvidingLocation", x, y, z, world.provider.dimensionId, world.provider.getDimensionName()));
}
} else if(te instanceof IInventory) {
if(!world.isRemote) {
setItemProvidingLocation(tablet, x, y, z, world.provider.dimensionId);
player.addChatComponentMessage(new ChatComponentTranslation("message.amadronTable.setItemProvidingLocation", x, y, z, world.provider.dimensionId, world.provider.getDimensionName()));
}
} else {
return false;
}
return true;
}
@Override
public boolean itemInteractionForEntity(ItemStack iStack, EntityPlayer player, EntityLivingBase entity){
if(!player.worldObj.isRemote) {
if(entity instanceof IManoMeasurable) {
if(((IPressurizable)iStack.getItem()).getPressure(iStack) > 0F) {
List<String> curInfo = new ArrayList<String>();
((IManoMeasurable)entity).printManometerMessage(player, curInfo);
if(curInfo.size() > 0) {
((IPressurizable)iStack.getItem()).addAir(iStack, -30);
for(String s : curInfo) {
player.addChatComponentMessage(new ChatComponentTranslation(s));
}
return true;
}
} else {
player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "The Manometer doesn't have any charge!"));
}
}
}
return false;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
if(player.isSneaking()) return false;
else {
if(!world.isRemote) {
TileEntitySecurityStation te = (TileEntitySecurityStation)world.getTileEntity(x, y, z);
if(te != null) {
if(te.isPlayerOnWhiteList(player)) {
player.openGui(PneumaticCraft.instance, EnumGuiId.SECURITY_STATION_INVENTORY.ordinal(), world, x, y, z);
} else if(!te.hasValidNetwork()) {
player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "This Security Station is out of order: Its network hasn't been properly configured."));
} else if(te.hasPlayerHacked(player)) {
player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "You've already hacked this Security Station!"));
} else if(getPlayerHackLevel(player) < te.getSecurityLevel()) {
player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "You can't access or hack this Security Station. To hack it you need at least a Pneumatic Helmet upgraded with " + te.getSecurityLevel() + " Security upgrade(s)."));
} else {
player.openGui(PneumaticCraft.instance, EnumGuiId.HACKING.ordinal(), world, x, y, z);
}
}
}
return true;
}
}
@Override
public void handleGUIButtonPress(int buttonID, EntityPlayer player){
if(buttonID == 0) {
redstoneMode++;
if(redstoneMode > 2) redstoneMode = 0;
updateNeighbours();
} else if(buttonID == 2) {
rebootStation();
} else if(buttonID == 3) {
if(!hasValidNetwork()) {
player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "This Security Station is out of order: Its network hasn't been properly configured."));
} else {
player.openGui(PneumaticCraft.instance, EnumGuiId.HACKING.ordinal(), worldObj, xCoord, yCoord, zCoord);
}
} else if(buttonID > 3 && buttonID - 4 < sharedUsers.size()) {
sharedUsers.remove(buttonID - 4);
}
sendDescriptionPacket();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) {
if(!world.isRemote) {
TileInfusionClaw tile = (TileInfusionClaw) world.getTileEntity(x, y, z);
if(tile.hasOwner()) {
player.openGui(Gadomancy.instance, 1, world, x, y, z);
} else if(tile.setOwner(player)) {
player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.InfusionClaw.owner"));
}
}
return true;
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
TileRemoteJar tile = BlockRemoteJar.getJarTile(world, x, y, z);
if (tile != null) {
if(!world.isRemote) {
NBTTagCompound compound = NBTHelper.getData(stack);
if(!player.isSneaking()) {
UUID networkId = null;
if(tile.networkId == null) {
player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.RemoteJar.new"));
networkId = UUID.randomUUID();
tile.networkId = networkId;
tile.markForUpdate();
} else {
UUID current = NBTHelper.getUUID(compound, "networkId");
if(current == null || !current.equals(tile.networkId)) {
player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.RemoteJar.connected"));
networkId = tile.networkId;
}
}
if(networkId != null) {
NBTHelper.setUUID(compound, "networkId", networkId);
}
}
return true;
} else {
if(player.isSneaking()) {
return true;
}
}
}
return false;
}
public static void toggleRaining(World world, boolean notify) {
boolean raining = !world.isRaining();
if (!raining)//turn off
((WorldServer) world).provider.resetRainAndThunder();
else
world.getWorldInfo().setRaining(!isRaining(world));
if (notify)
ServerUtils.sendChatToAll(new ChatComponentTranslation("nei.chat.rain." + (raining ? "on" : "off")));
}
public static void setHourForward(World world, int hour, boolean notify) {
long day = (getTime(world) / 24000L) * 24000L;
long newTime = day + 24000L + hour * 1000;
setTime(newTime, world);
if (notify)
ServerUtils.sendChatToAll(new ChatComponentTranslation("nei.chat.time", getTime(world) / 24000L, hour));
}
public static void sendNotice(ICommandSender sender, IChatComponent msg, String permission) {
ChatComponentTranslation notice = new ChatComponentTranslation("chat.type.admin", sender.getCommandSenderName(), msg.createCopy());
notice.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true);
if (NEIServerConfig.canPlayerPerformAction("CONSOLE", permission))
MinecraftServer.getServer().addChatMessage(notice);
for (EntityPlayer p : ServerUtils.getPlayers())
if(p == sender)
p.addChatComponentMessage(msg);
else if (NEIServerConfig.canPlayerPerformAction(p.getCommandSenderName(), permission))
p.addChatComponentMessage(notice);
}
@Override
protected void keyTyped(char c, int keycode) throws IOException {
if (keycode == Keyboard.KEY_ESCAPE || keycode == Keyboard.KEY_BACK) {
returnScreen(new ChatComponentTranslation(opt.fullName()+".icon.cancelled"));
return;
}
super.keyTyped(c, keycode);
}
private void exportItems() throws IOException {
BufferedImage img = screenshot();
int rows = img.getHeight() / boxSize;
int cols = img.getWidth() / boxSize;
int fit = rows*cols;
for(int i = 0; parseIndex < ItemPanel.items.size() && i < fit; parseIndex++, i++) {
int x = i%cols * boxSize;
int y = i/cols * boxSize;
exportImage(dir, img.getSubimage(x+borderSize, y+borderSize, iconSize, iconSize), ItemPanel.items.get(parseIndex));
}
if(parseIndex >= ItemPanel.items.size())
returnScreen(new ChatComponentTranslation(opt.fullName()+".icon.dumped", "dumps/itempanel_icons"));
}
@Override
public void processCommand(ICommandSender sender, String[] array) {
EntityPlayer player = (EntityPlayer) sender;
Minecraft minecraft = Minecraft.getMinecraft();
MovingObjectPosition objectMouseOver = minecraft.objectMouseOver;
if (objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
Class pointEntityClass = objectMouseOver.entityHit.getClass();
if (EntityList.classToStringMapping.containsKey(pointEntityClass)) {
player.addChatComponentMessage(new ChatComponentText(EntityList.getEntityString(objectMouseOver.entityHit)));
}
} else {
player.addChatComponentMessage(new ChatComponentTranslation("omniocular.info.NotPointing"));
}
}
@Override
public void processCommand(ICommandSender sender, String[] array) {
EntityPlayer player = (EntityPlayer) sender;
ItemStack holdItem = player.getHeldItem();
if (holdItem == null) {
player.addChatComponentMessage(new ChatComponentTranslation("omniocular.info.NotHolding"));
return;
}
player.addChatComponentMessage(new ChatComponentText(Item.itemRegistry.getNameForObject(holdItem.getItem())));
}
@Override
public void processCommand(ICommandSender sender, String[] array) {
EntityPlayer player = (EntityPlayer) sender;
Minecraft minecraft = Minecraft.getMinecraft();
MovingObjectPosition objectMouseOver = minecraft.objectMouseOver;
if (objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY){
Class pointEntityClass = objectMouseOver.entityHit.getClass();
if (EntityList.classToStringMapping.containsKey(pointEntityClass)){
player.addChatComponentMessage(new ChatComponentText(EntityList.getEntityString(objectMouseOver.entityHit)));
}
}else{
player.addChatComponentMessage(new ChatComponentTranslation("wailanbt.info.NotPointing"));
}
}
@Override
public void processCommand(ICommandSender sender, String[] array) {
EntityPlayer player = (EntityPlayer) sender;
ItemStack holdItem = player.getHeldItem();
if (holdItem == null) {
player.addChatComponentMessage(new ChatComponentTranslation("wailanbt.info.NotHolding"));
return;
}
player.addChatComponentMessage(new ChatComponentText(Item.itemRegistry.getNameForObject(holdItem.getItem())));
}
@Override
public void onSlotHack(int slot, boolean nuked){
if(!simulating && station.getStackInSlot(slot) != null && station.getStackInSlot(slot).getItemDamage() == ItemNetworkComponents.NETWORK_IO_PORT) {
FMLClientHandler.instance().getClient().thePlayer.closeScreen();
FMLClientHandler.instance().getClient().thePlayer.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "Hacking unsuccessful! The Diagnostic Subroutine traced to your location!"));
if(gui instanceof GuiSecurityStationHacking) ((GuiSecurityStationHacking)gui).removeUpdatesOnConnectionHandlers();
}
}
@Override
protected void onSlotHack(int slot, boolean nuked){
if(!nuked && gui instanceof GuiSecurityStationHacking) {
((GuiSecurityStationHacking)gui).onSlotHack(slot);
}
if(station.getStackInSlot(slot) != null && (station.getStackInSlot(slot).getItemDamage() == ItemNetworkComponents.NETWORK_REGISTRY || station.getStackInSlot(slot).getItemDamage() == ItemNetworkComponents.DIAGNOSTIC_SUBROUTINE)) {
hackedSuccessfully = true;
EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer;
NetworkHandler.sendToServer(new PacketSecurityStationAddHacker(station, player.getCommandSenderName()));
FMLClientHandler.instance().getClient().thePlayer.closeScreen();
player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "Hacking successful! This Security Station now doesn't protect the area any longer!"));
if(gui instanceof GuiSecurityStationHacking) ((GuiSecurityStationHacking)gui).removeUpdatesOnConnectionHandlers();
}
}
@Override
public void keyTyped(char ch, int key){
if(changingKeybinding) {
changingKeybinding = false;
updateKeybindingButtonText();
KeyHandler.getInstance().keybindOpenOptions.setKeyCode(key);
KeyBinding.resetKeyBindingArrayAndHash();
FMLClientHandler.instance().getClient().thePlayer.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "Bound the opening of this menu to the '" + Keyboard.getKeyName(key) + "' key."));
}
}
@Override
public void onDeath(DamageSource par1DamageSource){
for(int i = 0; i < inventory.getSizeInventory(); i++) {
if(inventory.getStackInSlot(i) != null) {
entityDropItem(inventory.getStackInSlot(i), 0);
inventory.setInventorySlotContents(i, null);
}
}
if(naturallySpawned) {
} else {
ItemStack drone = getDroppedStack();
if(hasCustomNameTag()) drone.setStackDisplayName(getCustomNameTag());
entityDropItem(drone, 0);
if(!worldObj.isRemote) {
EntityPlayer owner = getOwner();
if(owner != null) {
int x = (int)Math.floor(posX);
int y = (int)Math.floor(posY);
int z = (int)Math.floor(posZ);
if(hasCustomNameTag()) {
owner.addChatComponentMessage(new ChatComponentTranslation("death.drone.named", getCustomNameTag(), x, y, z));
} else {
owner.addChatComponentMessage(new ChatComponentTranslation("death.drone", x, y, z));
}
}
}
}
if(!worldObj.isRemote) ((FakePlayerItemInWorldManager)getFakePlayer().theItemInWorldManager).cancelDigging();
super.onDeath(par1DamageSource);
}
@Override
public void processCommand(ICommandSender sender, String[] args){
if(args.length != 4) throw new WrongUsageException("command.deliverAmazon.args");
String varName = args[0].startsWith("#") ? args[0].substring(1) : args[0];
ChunkPosition newPos = new ChunkPosition(parseInt(sender, args[1]), parseInt(sender, args[2]), parseInt(sender, args[3]));
GlobalVariableManager.getInstance().set(varName, newPos);
sender.addChatMessage(new ChatComponentTranslation("command.setGlobalVariable.output", varName, newPos.chunkPosX, newPos.chunkPosY, newPos.chunkPosZ));
}
/**
* Returns the message to be displayed on player death.
*/
@Override
public IChatComponent func_151519_b(EntityLivingBase par1EntityLivingBase){
String messageMeta = "";
int messageNumber = par1EntityLivingBase.getRNG().nextInt(deathMessages) + 1;
messageMeta = messageNumber + "";
EntityLivingBase entitylivingbase1 = par1EntityLivingBase.func_94060_bK();
String s = "death.attack." + damageType + messageMeta;
String s1 = s + ".player";
return entitylivingbase1 != null && StatCollector.canTranslate(s1) ? new ChatComponentTranslation(s1, new Object[]{par1EntityLivingBase.func_145748_c_(), entitylivingbase1.func_145748_c_()}) : new ChatComponentTranslation(s, new Object[]{par1EntityLivingBase.func_145748_c_()});
}
@Override
public boolean onItemUse(ItemStack IStack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10){
setGPSLocation(IStack, x, y, z);
if(!world.isRemote) player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "[GPS Tool] Set Coordinates to " + x + ", " + y + ", " + z + "."));
return true; // we don't want to use the item.
}