net.minecraft.util.text.TextComponentTranslation Java Examples

The following examples show how to use net.minecraft.util.text.TextComponentTranslation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 8 votes vote down vote up
private static ITextComponent stripEvents(ITextComponent c) {
    Style modi = c.getStyle();
    if (modi != null) {
        modi.setClickEvent(null);
        modi.setHoverEvent(null);
    }
    c.setStyle(modi);
    if (c instanceof TextComponentTranslation) {
        TextComponentTranslation cm = (TextComponentTranslation) c;
        Object[] oo = cm.getFormatArgs();
        for (int i = 0; i < oo.length; i++) {
            Object o = oo[i];
            if (o instanceof ITextComponent) {
                oo[i] = stripEvents((ITextComponent) o);
            }
        }
    }
    List<ITextComponent> ls = c.getSiblings();
    if (ls != null) {
        for (int i = 0; i < ls.size(); i++) {
            ls.set(i, stripEvents(ls.get(i)));
        }
    }
    return c;
}
 
Example #2
Source File: MultiblockWithDisplayBase.java    From GregTech with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
 * Called serverside to obtain text displayed in GUI
 * each element of list is displayed on new line
 * to use translation, use TextComponentTranslation
 */
protected void addDisplayText(List<ITextComponent> textList) {
    if (!isStructureFormed()) {
        ITextComponent tooltip = new TextComponentTranslation("gregtech.multiblock.invalid_structure.tooltip");
        tooltip.setStyle(new Style().setColor(TextFormatting.GRAY));
        textList.add(new TextComponentTranslation("gregtech.multiblock.invalid_structure")
            .setStyle(new Style().setColor(TextFormatting.RED)
                .setHoverEvent(new HoverEvent(Action.SHOW_TEXT, tooltip))));
    }
}
 
Example #3
Source File: ItemTofuSlimeRadar.java    From TofuCraftReload with MIT License 7 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
	 boolean flag = playerIn.capabilities.isCreativeMode;

        if (flag || playerIn.getHeldItem(handIn).getItemDamage() <= playerIn.getHeldItem(handIn).getMaxDamage())
        {
            if (!worldIn.isRemote)
            {
                boolean isSpawnChunk = playerIn.dimension == TofuMain.TOFU_DIMENSION.getId() || EntityTofuSlime.isSpawnChunk(playerIn.world, playerIn.posX, playerIn.posZ);
            
                if(isSpawnChunk) playerIn.sendMessage(new TextComponentTranslation("tofucraft.radar.result.success", new Object()));
                else playerIn.sendMessage(new TextComponentTranslation("tofucraft.radar.result.failed", new Object()));
            }

            if (!playerIn.capabilities.isCreativeMode && playerIn.getHeldItem(handIn).isItemStackDamageable())
            {
            	playerIn.getHeldItem(handIn).damageItem(1, playerIn);
            }
            playerIn.playSound(SoundEvents.UI_BUTTON_CLICK, 0.5F, 1.0F);
        }
	return super.onItemRightClick(worldIn, playerIn, handIn);
}
 
Example #4
Source File: NEIServerUtils.java    From NotEnoughItems with MIT License 6 votes vote down vote up
public static void sendNotice(ICommandSender sender, ITextComponent msg, String permission) {
    TextComponentTranslation notice = new TextComponentTranslation("chat.type.admin", sender.getName(), msg.createCopy());
    notice.getStyle().setColor(TextFormatting.GRAY).setItalic(true);

    if (NEIServerConfig.canPlayerPerformAction("CONSOLE", permission)) {
        ServerUtils.mc().sendMessage(notice);
    }

    for (EntityPlayer p : ServerUtils.getPlayers()) {
        if (p == sender) {
            p.sendMessage(msg);
        } else if (NEIServerConfig.canPlayerPerformAction(p.getName(), permission)) {
            p.sendMessage(notice);
        }
    }
}
 
Example #5
Source File: SimpleMachineMetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) {
    if(facing == getOutputFacing()) {
        if(!getWorld().isRemote) {
            if(allowInputFromOutputSide) {
                setAllowInputFromOutputSide(false);
                playerIn.sendMessage(new TextComponentTranslation("gregtech.machine.basic.input_from_output_side.disallow"));
            } else {
                setAllowInputFromOutputSide(true);
                playerIn.sendMessage(new TextComponentTranslation("gregtech.machine.basic.input_from_output_side.allow"));
            }
        }
        return true;
    }
    return super.onScrewdriverClick(playerIn, hand, facing, hitResult);
}
 
Example #6
Source File: TileEntityTeleportRail.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Only allow destination positions when:
 * 1. The position is similar to a portal position (it can't be used to cheese long distance travel)
 * 2. The receiving end has a teleport rail, to specify the destination direction.
 */
@Override
protected boolean isDestinationValid(MCPos destination, EntityPlayer player){
    if(getWorld().provider.getDimension() == destination.getDimID()) {
        player.sendMessage(new TextComponentTranslation("signals.message.teleport_rail_failed_same_dimension", destination.getX(), destination.getY(), destination.getZ()));
        return false;
    }

    Pair<MCPos, MCPos> allowedDestinationRange = getAllowedDestinationRange(destination.getWorld());
    if(allowedDestinationRange == null) {
        player.sendMessage(new TextComponentTranslation("signals.message.teleport_rail_failed_unloaded_destination_dimension", destination.getX(), destination.getY(), destination.getZ()));
        return false;
    } else if(destination.isInAABB(allowedDestinationRange.getLeft(), allowedDestinationRange.getRight())) {
        return true;
    } else {
        player.sendMessage(new TextComponentTranslation("signals.message.teleport_rail_failed_invalid_location", destination.getX(), destination.getY(), destination.getZ(), allowedDestinationRange.getLeft().getX(), allowedDestinationRange.getRight().getX(), allowedDestinationRange.getLeft().getZ(), allowedDestinationRange.getRight().getZ()));
        return false;
    }
}
 
Example #7
Source File: CmdGetLangpack.java    From I18nUpdateMod with MIT License 6 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
    // 参数为空,警告
    if (args.length == 0) {
        Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("message.i18nmod.cmd_get_langpack.empty"));
        return;
    }

    // 参数存在,进行下一步判定
    if (Minecraft.getMinecraft().getResourceManager().getResourceDomains().contains(args[0])) {
        Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("message.i18nmod.cmd_get_langpack.right_start", args[0]));

        // 同名资源包存在,直接返回
        if (!cerateTempLangpack(args[0])) {
            Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("message.i18nmod.cmd_get_langpack.error_create_folder"));
            return;
        }

        // 主下载功能
        langFileDownloader(args[0]);
    }
    // 参数不存在,警告
    else {
        Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("message.i18nmod.cmd_get_langpack.not_found", args[0]));
    }
}
 
Example #8
Source File: MetaTileEntityLargeTurbine.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void addDisplayText(List<ITextComponent> textList) {
    if (isStructureFormed()) {
        MetaTileEntityRotorHolder rotorHolder = getAbilities(ABILITY_ROTOR_HOLDER).get(0);
        FluidStack fuelStack = ((LargeTurbineWorkableHandler) workableHandler).getFuelStack();
        int fuelAmount = fuelStack == null ? 0 : fuelStack.amount;

        ITextComponent fuelName = new TextComponentTranslation(fuelAmount == 0 ? "gregtech.fluid.empty" : fuelStack.getUnlocalizedName());
        textList.add(new TextComponentTranslation("gregtech.multiblock.turbine.fuel_amount", fuelAmount, fuelName));

        if (rotorHolder.getRotorEfficiency() > 0.0) {
            textList.add(new TextComponentTranslation("gregtech.multiblock.turbine.rotor_speed", rotorHolder.getCurrentRotorSpeed(), rotorHolder.getMaxRotorSpeed()));
            textList.add(new TextComponentTranslation("gregtech.multiblock.turbine.rotor_efficiency", (int) (rotorHolder.getRotorEfficiency() * 100)));
            int rotorDurability = (int) (rotorHolder.getRotorDurability() * 100);
            if (rotorDurability > MIN_DURABILITY_TO_WARN) {
                textList.add(new TextComponentTranslation("gregtech.multiblock.turbine.rotor_durability", rotorDurability));
            } else {
                textList.add(new TextComponentTranslation("gregtech.multiblock.turbine.low_rotor_durability",
                    MIN_DURABILITY_TO_WARN, rotorDurability).setStyle(new Style().setColor(TextFormatting.RED)));
            }
        }
    }
    super.addDisplayText(textList);
}
 
Example #9
Source File: ModAdvancements.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void init() {
		MANAPOOL = new Advancement(
				new ResourceLocation(Wizardry.MODID, "advancement.manapool"),
				null,
				new DisplayInfo(
						new ItemStack(ModItems.ORB),
						new TextComponentTranslation("wizardry.advancement.begin.name"),
						new TextComponentTranslation("wizardry.advancement.begin.desc"),
						null, FrameType.GOAL, true, true, false),
				AdvancementRewards.EMPTY, new HashMap<>(), new String[0][0]);

		//	ModAdvancement("manapool", 1, -2, ModItems.ORB, null);
		//	BOOK = new ModAdvancement("book", 3, 0, ModItems.BOOK, MANAPOOL);
		//	DEVILDUST = new ModAdvancement("devildust", -1, 0, ModItems.DEVIL_DUST, null);
		//	CRUNCH = new ModAdvancement("crunch", 1, 2, Blocks.BEDROCK, null);
//
		//	PAGE = new AchievementPage(Wizardry.MODNAME, ModAdvancement.achievements.toArray(new Achievement[ModAdvancement.achievements.size()]));
		//	AchievementPage.registerAchievementPage(PAGE);
//
	}
 
Example #10
Source File: MetaTileEntityDieselEngine.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void addDisplayText(List<ITextComponent> textList) {
    if (isStructureFormed()) {
        FluidStack lubricantStack = importFluidHandler.drain(Materials.Lubricant.getFluid(Integer.MAX_VALUE), false);
        FluidStack oxygenStack = importFluidHandler.drain(Materials.Oxygen.getFluid(Integer.MAX_VALUE), false);
        FluidStack fuelStack = ((DieselEngineWorkableHandler) workableHandler).getFuelStack();
        int lubricantAmount = lubricantStack == null ? 0 : lubricantStack.amount;
        int oxygenAmount = oxygenStack == null ? 0 : oxygenStack.amount;
        int fuelAmount = fuelStack == null ? 0 : fuelStack.amount;

        ITextComponent fuelName = new TextComponentTranslation(fuelAmount == 0 ? "gregtech.fluid.empty" : fuelStack.getUnlocalizedName());
        textList.add(new TextComponentTranslation("gregtech.multiblock.diesel_engine.lubricant_amount", lubricantAmount));
        textList.add(new TextComponentTranslation("gregtech.multiblock.diesel_engine.fuel_amount", fuelAmount, fuelName));
        textList.add(new TextComponentTranslation("gregtech.multiblock.diesel_engine.oxygen_amount", oxygenAmount));
        textList.add(new TextComponentTranslation(oxygenAmount >= 2 ? "gregtech.multiblock.diesel_engine.oxygen_boosted" : "gregtech.multiblock.diesel_engine.supply_oxygen_to_boost"));
    }
    super.addDisplayText(textList);
}
 
Example #11
Source File: ItemTicket.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand){
    ItemStack stack = player.getHeldItem(hand);
    if(!world.isRemote) {
        TileEntity te = world.getTileEntity(pos);
        if(te instanceof TileEntityStationMarker) {
            TileEntityStationMarker stationMarker = (TileEntityStationMarker)te;
            String stationName = stationMarker.getStationName();

            appendDestination(stack, stationName);

            String concatDestinations = getConcattedDestinations(stack);
            player.sendMessage(new TextComponentTranslation("signals.message.added_destination", TextFormatting.GOLD + stationName + TextFormatting.WHITE, TextFormatting.GOLD + concatDestinations + TextFormatting.WHITE));

            return EnumActionResult.SUCCESS;
        }
    }
    return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
}
 
Example #12
Source File: ItemThatMakesYouSayDab.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
	if(!world.isRemote) {
		String text = Math.random() >= 0.01 ? "Dab" : "Neat (is a mod by Vazkii)";
		world.getMinecraftServer().getPlayerList().sendMessage(new TextComponentTranslation("chat.type.text", player.getName(), text));
		
		if(Dabbbbb.whenUBoppin) {
			for(int i = 0; i < 10; i++) {
				world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS, 1, (i / 10f) + 0.5f);
			}
			player.motionY += 10;
			player.velocityChanged = true;
		}
	}
	return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
 
Example #13
Source File: CmdReport.java    From I18nUpdateMod with MIT License 6 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
    ItemStack stack = Minecraft.getMinecraft().player.inventory.getCurrentItem();
    if (!stack.isEmpty()) {
        String text = String.format("模组ID:%s\n非本地化名称:%s\n显示名称:%s", stack.getItem().getCreatorModId(stack), stack.getItem().getUnlocalizedName(), stack.getDisplayName());
        String url = I18nConfig.key.reportURL;
        try {
            GuiScreen.setClipboardString(text);
            Desktop.getDesktop().browse(new URI(url));
        } catch (Exception urlException) {
            urlException.printStackTrace();
        }
    } else {
        Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("message.i18nmod.cmd_report.empty"));
    }
}
 
Example #14
Source File: MetaTileEntityLargeBoiler.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void addDisplayText(List<ITextComponent> textList) {
    super.addDisplayText(textList);
    if (isStructureFormed()) {
        textList.add(new TextComponentTranslation("gregtech.multiblock.large_boiler.temperature", currentTemperature, boilerType.maxTemperature));
        textList.add(new TextComponentTranslation("gregtech.multiblock.large_boiler.steam_output", lastTickSteamOutput, boilerType.baseSteamOutput));

        ITextComponent heatEffText = new TextComponentTranslation("gregtech.multiblock.large_boiler.heat_efficiency", (int) (getHeatEfficiencyMultiplier() * 100));
        withHoverTextTranslate(heatEffText, "gregtech.multiblock.large_boiler.heat_efficiency.tooltip");
        textList.add(heatEffText);

        ITextComponent throttleText = new TextComponentTranslation("gregtech.multiblock.large_boiler.throttle", throttlePercentage, (int)(getThrottleEfficiency() * 100));
        withHoverTextTranslate(throttleText, "gregtech.multiblock.large_boiler.throttle.tooltip");
        textList.add(throttleText);

        ITextComponent buttonText = new TextComponentTranslation("gregtech.multiblock.large_boiler.throttle_modify");
        buttonText.appendText(" ");
        buttonText.appendSibling(withButton(new TextComponentString("[-]"), "sub"));
        buttonText.appendText(" ");
        buttonText.appendSibling(withButton(new TextComponentString("[+]"), "add"));
        textList.add(buttonText);
    }
}
 
Example #15
Source File: CommandSignals.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException{
    if(args.length == 0) throw new WrongUsageException("command.signals.noArgs");
    String subCommand = args[0];
    if(subCommand.equals("rebuildNetwork")) {
        RailNetworkManager.getServerInstance().rebuildNetwork();
        sender.sendMessage(new TextComponentTranslation("command.signals.networkCleared"));
    } else if(subCommand.equals("debug") && sender.getName().startsWith("Player" /* Playerx */)) {
        if(debug(server, sender, args)) {
            sender.sendMessage(new TextComponentString("DEBUG EXECUTED"));
        } else {
            sender.sendMessage(new TextComponentString("Could not execute debug!"));
        }
    } else {
        throw new WrongUsageException("command.signals.invalidSubCommand", subCommand);
    }
}
 
Example #16
Source File: NEIClientPacketHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
/**
 * Handles the servers ServerSideCheck.
 * Checks both local and remote protocol versions for a mismatch.
 * If no mismatch is found it does the following:
 * Notifies ClientHandler of a world change.
 * Resets all local data of that dimension.
 * Requests the server for a LoginState.
 * Finally it sets the availability of a ServerSide counterpart as true.
 *
 * @param serverProtocol The servers protocol version.
 * @param worldName      The dimension data to load.
 * @param world          The clients current world object.
 */
private void handleServerSideCheck(int serverProtocol, String worldName, World world) {
    if (serverProtocol > NEIActions.protocol) {
        NEIClientUtils.printChatMessage(new TextComponentTranslation("nei.chat.mismatch.client"));
    } else if (serverProtocol < NEIActions.protocol) {
        NEIClientUtils.printChatMessage(new TextComponentTranslation("nei.chat.mismatch.server"));
    } else {
        try {
            ClientHandler.INSTANCE.loadWorld(world);
            NEIClientConfig.loadWorld(getSaveName(worldName));
            NEIClientConfig.setHasSMPCounterPart(true);
            sendRequestLoginInfo();
        } catch (Exception e) {
            LogHelper.errorError("Error handling SMP Check", e);
        }
    }
}
 
Example #17
Source File: NEIServerUtils.java    From NotEnoughItems with MIT License 6 votes vote down vote up
public static void givePlayerItem(EntityPlayerMP player, ItemStack stack, boolean infinite, boolean doGive) {
    if (stack.getItem() == null) {
        player.sendMessage(setColour(new TextComponentTranslation("nei.chat.give.noitem"), TextFormatting.WHITE));
        return;
    }

    int given = stack.getCount();
    if (doGive) {
        if (infinite) {
            player.inventory.addItemStackToInventory(stack);
        } else {
            given -= InventoryUtils.insertItem(player.inventory, stack, false);
        }
    }

    sendNotice(player, new TextComponentTranslation("commands.give.success", stack.getTextComponent(), infinite ? "\u221E" : Integer.toString(given), player.getName()), "notify-item");
    player.openContainer.detectAndSendChanges();
}
 
Example #18
Source File: BlockSurfaceRockNew.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<ITextComponent> getMagnifyResults(IBlockAccess world, BlockPos pos, IBlockState blockState, EntityPlayer player) {
    TileEntitySurfaceRock tileEntity = getTileEntity(world, pos);
    if (tileEntity == null) {
        return Collections.emptyList();
    }
    List<Material> materials = tileEntity.getUndergroundMaterials();
    ITextComponent materialComponent = new TextComponentTranslation(tileEntity.getMaterial().getUnlocalizedName());
    materialComponent.getStyle().setColor(TextFormatting.GREEN);
    ITextComponent baseComponent = new TextComponentString("");
    ITextComponent separator = new TextComponentString(", ");
    separator.getStyle().setColor(TextFormatting.GRAY);
    for (int i = 0; i < materials.size(); i++) {
        ITextComponent extraComponent = new TextComponentTranslation(materials.get(i).getUnlocalizedName());
        extraComponent.getStyle().setColor(TextFormatting.YELLOW);
        baseComponent.appendSibling(extraComponent);
        if (i + 1 != materials.size()) baseComponent.appendSibling(separator);
    }
    ArrayList<ITextComponent> result = new ArrayList<>();
    result.add(new TextComponentTranslation("gregtech.block.surface_rock.material", materialComponent));
    result.add(new TextComponentTranslation("gregtech.block.surface_rock.underground_materials", baseComponent));
    return result;
}
 
Example #19
Source File: ItemShinai.java    From Sakura_mod with MIT License 6 votes vote down vote up
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
	super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
	if(worldIn.isRemote) return;
	if(entityIn instanceof EntityPlayer){
		EntityPlayer player = (EntityPlayer) entityIn;
		ItemStack mainhand =player.getHeldItem(EnumHand.MAIN_HAND);
		ItemStack offhand =player.getHeldItem(EnumHand.OFF_HAND);
		boolean flag1 =!(mainhand.isEmpty())&&!(offhand.isEmpty()),
				flag2 = mainhand.getItem() instanceof ItemShinai||offhand.getItem() instanceof ItemShinai;
		if(flag1&&flag2) {
            player.setItemStackToSlot((mainhand.getItem() instanceof ItemShinai)?EntityEquipmentSlot.OFFHAND:EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
            player.dropItem((mainhand.getItem() instanceof ItemShinai)?offhand:mainhand, false);
            player.sendStatusMessage(new TextComponentTranslation("sakura.katana.wrong_duel_shinai", new Object()), false);
		}
	}
}
 
Example #20
Source File: ItemKotachi.java    From Sakura_mod with MIT License 6 votes vote down vote up
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
	super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
	if(worldIn.isRemote) return;
	if(entityIn instanceof EntityPlayer){
		EntityPlayer player = (EntityPlayer) entityIn;
		ItemStack mainhand =player.getHeldItem(EnumHand.MAIN_HAND);
		ItemStack offhand =player.getHeldItem(EnumHand.OFF_HAND);
		boolean flag1 =!(mainhand.isEmpty())&&!(offhand.isEmpty()),
				flag2 = mainhand.getItem() instanceof ItemKotachi && offhand.getItem() instanceof ItemKotachi;
		if(flag1&&flag2) {
            player.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, ItemStack.EMPTY);
            player.dropItem(offhand, false);
            player.sendStatusMessage(new TextComponentTranslation("sakura.katana.wrong_duel", new Object()), false);
		}
	}
}
 
Example #21
Source File: NEIServerUtils.java    From NotEnoughItems with MIT License 6 votes vote down vote up
public static void setGamemode(EntityPlayerMP player, int mode) {
    if (mode < 0 || mode >= NEIActions.gameModes.length || NEIActions.nameActionMap.containsKey(NEIActions.gameModes[mode]) && !NEIServerConfig.canPlayerPerformAction(player.getName(), NEIActions.gameModes[mode])) {
        return;
    }

    //creative+
    NEIServerConfig.getSaveForPlayer(player.getName()).changeActionState("creative+", mode == 2);
    if (mode == 2 && !(player.openContainer instanceof ContainerCreativeInv))//open the container immediately for the client
    {
        NEIServerPacketHandler.processCreativeInv(player, true);
    }

    //change it on the server
    player.interactionManager.setGameType(getGameType(mode));

    //tell the client to change it
    new PacketCustom(NEIServerPacketHandler.channel, 14).writeByte(mode).sendToPlayer(player);
    player.sendMessage(new TextComponentTranslation("nei.chat.gamemode." + mode));
}
 
Example #22
Source File: NoticeShower.java    From I18nUpdateMod with MIT License 5 votes vote down vote up
public NoticeShower() {
    new Thread(() -> {
        try {
            URL url = new URL(I18nConfig.notice.noticeURL);
            strings = IOUtils.readLines(url.openStream(), StandardCharsets.UTF_8);
            Minecraft.getMinecraft().addScheduledTask(() -> Minecraft.getMinecraft().displayGuiScreen(new NoticeGui(strings)));
        } catch (Throwable e) {
            Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("获取公告失败。"));
            I18nUpdateMod.logger.error("获取公告失败:", e);
        }
    }, "I18n_NOTICE_PENDING_THREAD").start();
}
 
Example #23
Source File: ModeSwitchBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack itemStack = player.getHeldItem(hand);
    if(player.isSneaking()) {
        T currentMode = getModeFromItemStack(itemStack);
        int currentModeIndex = ArrayUtils.indexOf(enumConstants, currentMode);
        T nextMode = enumConstants[(currentModeIndex + 1) % enumConstants.length];
        setModeForItemStack(itemStack, nextMode);
        ITextComponent newModeComponent = new TextComponentTranslation(nextMode.getUnlocalizedName());
        ITextComponent textComponent = new TextComponentTranslation("metaitem.behavior.mode_switch.mode_switched", newModeComponent);
        player.sendStatusMessage(textComponent, true);
        return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
    }
    return ActionResult.newResult(EnumActionResult.PASS, itemStack);
}
 
Example #24
Source File: RecipeMapMultiblockController.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void addDisplayText(List<ITextComponent> textList) {
    super.addDisplayText(textList);
    if (isStructureFormed()) {
        IEnergyContainer energyContainer = recipeMapWorkable.getEnergyContainer();
        if (energyContainer != null && energyContainer.getEnergyCapacity() > 0) {
            long maxVoltage = energyContainer.getInputVoltage();
            String voltageName = GTValues.VN[GTUtility.getTierByVoltage(maxVoltage)];
            textList.add(new TextComponentTranslation("gregtech.multiblock.max_energy_per_tick", maxVoltage, voltageName));
        }

        if (!recipeMapWorkable.isWorkingEnabled()) {
            textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused"));

        } else if (recipeMapWorkable.isActive()) {
            textList.add(new TextComponentTranslation("gregtech.multiblock.running"));
            int currentProgress = (int) (recipeMapWorkable.getProgressPercent() * 100);
            textList.add(new TextComponentTranslation("gregtech.multiblock.progress", currentProgress));
        } else {
            textList.add(new TextComponentTranslation("gregtech.multiblock.idling"));
        }

        if (recipeMapWorkable.isHasNotEnoughEnergy()) {
            textList.add(new TextComponentTranslation("gregtech.multiblock.not_enough_energy").setStyle(new Style().setColor(TextFormatting.RED)));
        }
    }
}
 
Example #25
Source File: CmdUpload.java    From I18nUpdateMod with MIT License 5 votes vote down vote up
/**
 * 将准备上传的语言文件进行处理
 *
 * @param modid 上传的模组资源 domain
 * @return 处理后的文件对象
 * @throws IOException 读取文件可能发生的 IO 错误
 */
@Nullable
private File handleFile(String modid) throws IOException {
    // 英文,中文,临时文件
    File rawChineseFile = new File(String.format(Minecraft.getMinecraft().mcDataDir.toString() + File.separator + "resourcepacks" + File.separator + "%s_tmp_resource_pack" + File.separator + "assets" + File.separator + "%s" + File.separator + "lang" + File.separator + "zh_cn.lang", modid, modid));
    File rawEnglishFile = new File(String.format(Minecraft.getMinecraft().mcDataDir.toString() + File.separator + "resourcepacks" + File.separator + "%s_tmp_resource_pack" + File.separator + "assets" + File.separator + "%s" + File.separator + "lang" + File.separator + "en_us.lang", modid, modid));
    File handleChineseFile = new File(String.format(Minecraft.getMinecraft().mcDataDir.toString() + File.separator + "resourcepacks" + File.separator + "%s_tmp_resource_pack" + File.separator + "assets" + File.separator + "%s" + File.separator + "lang" + File.separator + "zh_cn_tmp.lang", modid, modid));

    // 文件存在,才进行处理
    if (rawEnglishFile.exists() && rawChineseFile.exists()) {
        // 读取处理成 HashMap
        Map<String, String> zh_cn = I18nUtils.listToMap(FileUtils.readLines(rawChineseFile, StandardCharsets.UTF_8));
        Map<String, String> en_us = I18nUtils.listToMap(FileUtils.readLines(rawEnglishFile, StandardCharsets.UTF_8));

        // 未翻译处进行剔除
        List<String> tmpFile = new ArrayList<>();
        for (String key : zh_cn.keySet()) {
            if (en_us.get(key) != null && !en_us.get(key).equals(zh_cn.get(key))) {
                tmpFile.add(key + '=' + zh_cn.get(key));
            }
        }

        // 文件写入
        FileUtils.writeLines(handleChineseFile, "UTF-8", tmpFile, "\n", false);
        Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("message.i18nmod.cmd_upload.handle_success"));
        return handleChineseFile;
    } else {
        return null; // 不存在返回 null
    }
}
 
Example #26
Source File: HotKeyHandler.java    From I18nUpdateMod with MIT License 5 votes vote down vote up
/**
 * 单独功能,快速重载语言文件
 *
 * @return 是否成功
 */
private boolean reloadLocalization() {
    if (keyCodeCheck(reportKey.getKeyCode()) && Keyboard.isKeyDown(mainKey.getKeyCode()) && Keyboard.getEventKey() == reloadKey.getKeyCode()) {
        Minecraft.getMinecraft().getLanguageManager().onResourceManagerReload(Minecraft.getMinecraft().getResourceManager());
        Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("message.i18nmod.cmd_reload.success"));
        return true;
    }
    return false;
}
 
Example #27
Source File: BlockSurfaceRockDeprecated.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<ITextComponent> getMagnifyResults(IBlockAccess world, BlockPos pos, IBlockState blockState, EntityPlayer player) {
    ArrayList<ITextComponent> result = new ArrayList<>();
    ITextComponent materialComponent = new TextComponentTranslation(getStoneMaterial(world, pos, blockState).getUnlocalizedName());
    materialComponent.getStyle().setColor(TextFormatting.GREEN);
    result.add(new TextComponentTranslation("gregtech.block.surface_rock.material", materialComponent));
    return result;
}
 
Example #28
Source File: MetaTileEntityDistillationTower.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void addDisplayText(List<ITextComponent> textList) {
    if (isStructureFormed()) {
        FluidStack stackInTank = importFluids.drain(Integer.MAX_VALUE, false);
        if (stackInTank != null && stackInTank.amount > 0) {
            TextComponentTranslation fluidName = new TextComponentTranslation(stackInTank.getFluid().getUnlocalizedName(stackInTank));
            textList.add(new TextComponentTranslation("gregtech.multiblock.distillation_tower.distilling_fluid", fluidName));
        }
    }
    super.addDisplayText(textList);
}
 
Example #29
Source File: RailNetworkManager.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
public void onPostServerTick(){
    if(!SignalsConfig.enableRailNetwork) return;
    validateOnServer();
    checkForNewNetwork(true);
    state.update(network);
    if(networkUpdater.didJustTurnBusy()) {
        notifyAllPlayers(new TextComponentTranslation("signals.message.signals_busy"));
    }
    if(networkUpdater.didJustTurnIdle()) {
        notifyAllPlayers(new TextComponentTranslation("signals.message.signals_idle"));
    }
}
 
Example #30
Source File: GuiItemIconDumper.java    From NotEnoughItems with MIT License 5 votes vote down vote up
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 TextComponentTranslation(opt.fullName() + ".icon.dumped", "dumps/itempanel_icons"));
    }
}