public static String getLocalizedControlName(String guiName, String controlName) { String unlocalizedName = "inventory." + LibModInfo.ID.toLowerCase() + ":" + guiName + "." + controlName; String localizedName = StatCollector.translateToLocal(unlocalizedName); if (!unlocalizedName.equals(localizedName)) { return localizedName; } return unlocalizedName; }
public static void renderLocalizedGuiName( FontRenderer fontRenderer, int xSize, String name, String append, int colour) { String unlocalizedName = "inventory." + LibModInfo.ID.toLowerCase() + ":" + name + ".name"; String localizedName = StatCollector.translateToLocal(unlocalizedName); String renderText = unlocalizedName; if (!unlocalizedName.equals(localizedName)) { renderText = localizedName; } if (append != null) { renderText = renderText + " - " + append; } int xPos = xSize / 2 - fontRenderer.getStringWidth(renderText) / 2; fontRenderer.drawString(renderText, xPos, 6, colour); }
@SideOnly(Side.CLIENT) public class GuiList extends Gui { private static final ResourceLocation texture = new ResourceLocation(LibModInfo.ID.toLowerCase(), "textures/gui/controls/list.png"); /** Local copy of Minecraft */ protected final Minecraft mc; /** Local copy of the font renderer */ protected final FontRenderer fontRenderer; protected final int x; protected final int y; protected final int width; protected final int height; protected final int slotHeight; public final boolean enabled; public boolean visible; protected int scrollAmount; protected int selectedIndex; protected List<IGuiListItem> listItems; public GuiList(int x, int y, int width, int height, int slotHeight) { mc = Minecraft.getMinecraft(); fontRenderer = mc.fontRenderer; this.x = x; this.y = y; this.width = width; this.height = height; this.slotHeight = slotHeight; listItems = new ArrayList<IGuiListItem>(); this.enabled = true; this.visible = true; selectedIndex = -1; } public void clearList() { listItems.clear(); } public void addListItem(IGuiListItem item) { listItems.add(item); } public void drawList(int mouseX, int mouseY, float tickTime) { if (!this.visible) { return; } GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(texture); GuiUtils.drawContinuousTexturedBox( texture, this.x, this.y, 0, 0, width, height, 11, 11, 1, this.zLevel); // this.drawTexturedModalRect(x, y, 0, 0, width, height); ScaledResolution reso = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); double scaleWidth = (double) mc.displayWidth / reso.getScaledWidth_double(); double scaleHeight = (double) mc.displayHeight / reso.getScaledHeight_double(); GL11.glEnable(GL11.GL_SCISSOR_TEST); GL11.glScissor( (int) ((x + 1) * scaleWidth), (mc.displayHeight) - (int) ((y + height - 1) * scaleHeight), (int) ((width - 2) * scaleWidth), (int) ((height - 2) * scaleHeight)); for (int i = 0; i < listItems.size(); i++) { int yLocation = y - scrollAmount + 2 + i * slotHeight; if (yLocation + 6 >= y & yLocation <= y + height + 1) { listItems .get(i) .drawListItem( fontRenderer, x + 2, yLocation, mouseX, mouseY, i == selectedIndex, width); } } GL11.glDisable(GL11.GL_SCISSOR_TEST); } public boolean mouseClicked(int mouseX, int mouseY, int button) { if (!this.visible) { return false; } for (int i = 0; i < listItems.size(); i++) { int yLocation = y - scrollAmount + 2 + i * slotHeight; if (mouseY >= y & mouseY <= y + height - 2) { if (listItems .get(i) .mousePressed(fontRenderer, x + 2, yLocation, mouseX, mouseY, button, width)) { SoundHandler sh = mc.getSoundHandler(); sh.playSound( PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); selectedIndex = i; return true; } } } return false; } public void mouseMovedOrUp(int mouseX, int mouseY, int button) { if (!this.visible) { return; } for (int i = 0; i < listItems.size(); i++) { listItems.get(i).mouseReleased(fontRenderer, x, y, mouseX, mouseY, button, width); } } public IGuiListItem getSelectedListEntry() { if (selectedIndex >= 0 && selectedIndex < listItems.size()) { return this.listItems.get(selectedIndex); } return null; } public IGuiListItem getListEntry(int index) { return this.listItems.get(index); } public int getSelectedIndex() { return selectedIndex; } public void setSelectedIndex(int selectedIndex) { this.selectedIndex = selectedIndex; } public void setScrollPercentage(int amount) { int listHeight = this.listItems.size() * this.slotHeight; int scrollRange = listHeight - this.height; if (scrollRange <= 0) { scrollAmount = 0; return; } scrollAmount = (int) (scrollRange / (float) 100 * amount); } public int getSize() { return this.listItems.size(); } }
@Mod( modid = LibModInfo.ID, name = LibModInfo.NAME, version = LibModInfo.VERSION, guiFactory = LibModInfo.GUI_FACTORY_CLASS) public class ArmourersWorkshop { @Mod.Instance(LibModInfo.ID) public static ArmourersWorkshop instance; @SidedProxy( clientSide = LibModInfo.PROXY_CLIENT_CLASS, serverSide = LibModInfo.PROXY_COMMNON_CLASS) public static CommonProxy proxy; public static ModCreativeTab creativeTabArmorersWorkshop = new ModCreativeTab(LibModInfo.ID); public static CreativeTabArmourersWorkshop tabArmorersWorkshop = new CreativeTabArmourersWorkshop(CreativeTabs.getNextID(), LibModInfo.ID.toLowerCase()); public static ModItems modItems; public static ModBlocks modBlocks; @Mod.EventHandler public void perInit(FMLPreInitializationEvent event) { ModLogger.log("Loading " + LibModInfo.NAME + " " + LibModInfo.VERSION); creativeTabArmorersWorkshop.setMinecraftCreativeTab(tabArmorersWorkshop); ConfigHandler.init(event.getSuggestedConfigurationFile()); Addons.preInit(); proxy.preInit(); SkinIOUtils.makeLibraryDirectory(); UpdateCheck.checkForUpdates(); SkinExtractor.extractSkins(); modItems = new ModItems(); modBlocks = new ModBlocks(); SkinTypeRegistry.init(); CubeRegistry.init(); proxy.initLibraryManager(); } @Mod.EventHandler public void load(FMLInitializationEvent event) { CraftingManager.init(); modBlocks.registerTileEntities(); new GuiHandler(); new ConfigSynchronizeHandler(); PacketHandler.init(); EntityEquipmentDataManager.init(); EntitySkinHandler.init(); proxy.init(); proxy.registerKeyBindings(); proxy.initRenderers(); Addons.init(); } @Mod.EventHandler public void postInit(FMLPostInitializationEvent event) { proxy.postInit(); Addons.postInit(); proxy.libraryManager.reloadLibrary(); } @Mod.EventHandler public void serverStart(FMLServerStartingEvent event) { event.registerServerCommand(new CommandArmourers()); SkinDataCache.INSTANCE.serverStarted(); } @Mod.EventHandler public void serverStopped(FMLServerStoppedEvent event) { SkinDataCache.INSTANCE.serverStopped(); } @Mod.EventHandler public void processIMC(FMLInterModComms.IMCEvent event) { for (IMCMessage imcMessage : event.getMessages()) { if (!imcMessage.isStringMessage()) continue; if (imcMessage.key.equalsIgnoreCase("register")) { ModLogger.log( String.format( "Receiving registration request from %s for class %s", imcMessage.getSender(), imcMessage.getStringValue())); ApiRegistrar.INSTANCE.addApiRequest(imcMessage.getSender(), imcMessage.getStringValue()); } } } public static boolean isDedicated() { return proxy.getClass() == CommonProxy.class; } }