use of net.minecraft.client.renderer.texture.DynamicTexture in project Hyperium by HyperiumClient.
the class DisplayElementConfig method regenImage.
private void regenImage() {
int dim = 256;
BufferedImage image = new BufferedImage(dim, dim, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < dim; x++) {
for (int y = 0; y < dim; y++) {
image.setRGB(x, y, Color.HSBtoRGB(x / 256F, 1.0F - y / 256F, 1F));
}
}
texture = new DynamicTexture(image);
if (hue != -1 && saturation != -1) {
BufferedImage image1 = new BufferedImage(1, dim, BufferedImage.TYPE_INT_RGB);
for (int y = 0; y < dim; y++) {
float hue = this.hue / 256F;
float saturation = this.saturation / 256F;
image1.setRGB(0, y, Color.HSBtoRGB(hue, saturation, 1.0F - y / 256F));
}
texture2 = new DynamicTexture(image1);
}
}
use of net.minecraft.client.renderer.texture.DynamicTexture in project Hyperium by HyperiumClient.
the class CapesGui method drawScreen.
// 22x17
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
try {
if (!texturesImage.isEmpty()) {
texturesImage.forEach((s, value) -> {
if (!textures.containsKey(s))
textures.put(s, new DynamicTexture(value));
});
}
super.drawScreen(mouseX, mouseY, partialTicks);
int oldScale = mc.gameSettings.guiScale;
mc.gameSettings.guiScale = 2;
ScaledResolution current = new ScaledResolution(Minecraft.getMinecraft());
mc.gameSettings.guiScale = oldScale;
float v = 2F / (oldScale);
GlStateManager.scale(v, v, v);
int blockWidth = 128;
int blockHeight = 256;
int blocksPerLine = (int) (current.getScaledWidth() / (1.5D * blockWidth));
if (blocksPerLine % 2 == 1)
blocksPerLine--;
JsonHolder capeAtlas = PurchaseApi.getInstance().getCapeAtlas();
int totalRows = (capeAtlas.getKeys().size() / blocksPerLine + (capeAtlas.getKeys().size() % blocksPerLine == 0 ? 0 : 1));
int row = 0;
int pos = 1;
int printY = 15 - offset;
GlStateManager.scale(2F, 2F, 2F);
fontRendererObj.drawString("Capes", (current.getScaledWidth() / 2F - fontRendererObj.getStringWidth("Capes")) / 2, printY / 2F, new Color(249, 99, 0).getRGB(), true);
String s1;
try {
s1 = PurchaseApi.getInstance().getSelf().getPurchaseSettings().optJSONObject("cape").optString("type");
} catch (NullPointerException ignored) {
return;
}
String s2 = capeAtlas.optJSONObject(s1).optString("name");
if (s2.isEmpty())
s2 = "NONE";
String text = "Active Cape: " + s2;
fontRendererObj.drawString(text, (current.getScaledWidth() / 2F - fontRendererObj.getStringWidth(text)) / 2, (printY + 20) / 2F, new Color(249, 99, 0).getRGB(), true);
text = "Need more credits? Click here";
int stringWidth1 = fontRendererObj.getStringWidth(text);
int i2 = current.getScaledWidth() / 2 - stringWidth1;
int i3 = printY + 40;
fontRendererObj.drawString(text, i2 / 2F, i3 / 2F, new Color(97, 132, 249).getRGB(), true);
GuiBlock block1 = new GuiBlock(i2, i2 + stringWidth1 * 2, i3, i3 + 15);
GlStateManager.scale(.5F, .5F, .5F);
actions.put(block1, () -> {
Desktop desktop = Desktop.getDesktop();
if (desktop != null) {
try {
desktop.browse(new URL("https://purchase.sk1er.club/category/1125808").toURI());
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
});
printY += 25;
printY += 35;
int scaledWidth = current.getScaledWidth();
RenderUtils.drawSmoothRect(scaledWidth / 2 - (blockWidth + 16) * blocksPerLine / 2, printY - 4, scaledWidth / 2 + (blockWidth + 16) * blocksPerLine / 2, printY + (blockHeight + 16) * totalRows + 4, new Color(53, 106, 110).getRGB());
for (String s : capeAtlas.getKeys()) {
JsonHolder cape = capeAtlas.optJSONObject(s);
if (cape.optBoolean("private"))
continue;
if (pos > blocksPerLine) {
pos = 1;
row++;
}
int thisBlocksCenter = (int) (scaledWidth / 2 - ((blocksPerLine / 2) - pos + .5) * (blockWidth + 16));
int thisTopY = printY + row * (16 + blockHeight);
RenderUtils.drawSmoothRect(thisBlocksCenter - blockWidth / 2, thisTopY, (thisBlocksCenter + blockWidth / 2), thisTopY + blockHeight, -1);
DynamicTexture dynamicTexture = textures.get(s);
if (dynamicTexture != null) {
int imgW = 120;
int imgH = 128;
GlStateManager.bindTexture(dynamicTexture.getGlTextureId());
float capeScale = .75F;
int topLeftX = (int) (thisBlocksCenter - imgW / (2F / capeScale));
int topLeftY = thisTopY + 4;
GlStateManager.translate(topLeftX, topLeftY, 0);
GlStateManager.scale(capeScale, capeScale, capeScale);
drawTexturedModalRect(0, 0, imgW / 12, 0, imgW, imgH * 2);
GlStateManager.scale(1F / capeScale, 1F / capeScale, 1F / capeScale);
GlStateManager.translate(-topLeftX, -topLeftY, 0);
}
String nameCape = cape.optString("name");
GlStateManager.scale(2F, 2F, 2F);
int x = thisBlocksCenter - fontRendererObj.getStringWidth(nameCape);
fontRendererObj.drawString(nameCape, x / 2F, (thisTopY - 8 + blockHeight / 2F + 64 + 16) / 2, new Color(249, 99, 0).getRGB(), true);
GlStateManager.scale(.5F, .5F, .5F);
if (cosmeticCallback.getKeys().size() == 0 || purchasing) {
String string = "Loading";
fontRendererObj.drawString(string, thisBlocksCenter - fontRendererObj.getStringWidth(string), (thisTopY - 8 + (blockHeight >> 1) + 64 + 48), new Color(91, 102, 249).getRGB(), true);
return;
}
JsonHolder jsonHolder = cosmeticCallback.optJSONObject(s);
boolean purchased = jsonHolder.optBoolean("purchased");
if (purchased) {
String string = "Purchased";
int widthThing3 = fontRendererObj.getStringWidth(string) / 2;
int leftThing3 = thisBlocksCenter - widthThing3;
int topThing3 = thisTopY - 8 + blockHeight / 2 + 64 + 36;
fontRendererObj.drawString(string, leftThing3, topThing3, new Color(41, 249, 18).getRGB(), true);
if (s.equalsIgnoreCase(s1)) {
string = "Active";
int stringWidth = fontRendererObj.getStringWidth(string);
int i = thisBlocksCenter - stringWidth;
int i1 = thisTopY - 8 + blockHeight / 2 + 64 + 48;
GlStateManager.scale(2F, 2F, 2F);
fontRendererObj.drawString(string, i / 2F, i1 / 2F, new Color(249, 55, 241).getRGB(), true);
} else {
int stringWidth = fontRendererObj.getStringWidth(string);
int i = thisBlocksCenter - stringWidth;
int i1 = thisTopY - 8 + blockHeight / 2 + 64 + 48;
string = "Make Active";
GuiBlock block = new GuiBlock(i, i + stringWidth * 2, i1, i1 + 20);
actions.put(block, () -> {
JsonHolder purchaseSettings = PurchaseApi.getInstance().getSelf().getPurchaseSettings();
if (!purchaseSettings.has("cape")) {
purchaseSettings.put("cape", new JsonHolder());
}
purchaseSettings.optJSONObject("cape").put("type", s);
NettyClient client = NettyClient.getClient();
if (client != null) {
client.write(ServerCrossDataPacket.build(new JsonHolder().put("internal", true).put("set_cape", true).put("value", s)));
}
Hyperium.INSTANCE.getHandlers().getGeneralChatHandler().sendMessage("You may need to switch worlds to update your cape.");
});
GlStateManager.scale(2F, 2F, 2F);
fontRendererObj.drawString(string, i / 2F, i1 / 2F, new Color(249, 55, 241).getRGB(), true);
}
GlStateManager.scale(.5F, .5F, .5F);
} else {
if (jsonHolder.optBoolean("enough")) {
String string = "Click to purchase";
int stringWidth = fontRendererObj.getStringWidth(string);
int left = thisBlocksCenter - stringWidth / 2;
int i = thisTopY - 8 + blockHeight / 2 + 64 + 48;
fontRendererObj.drawString(string, left, i, new Color(249, 76, 238).getRGB(), true);
GuiBlock block = new GuiBlock(left, left + stringWidth, i, i + 10);
actions.put(block, () -> {
Hyperium.LOGGER.debug("Attempting to purchase " + s);
purchasing = true;
Integer integer = intMap.computeIfAbsent(s, s3 -> ++purchaseIds);
GuiYesNo gui = new GuiYesNo(this, "Purchase " + s, "", integer);
Hyperium.INSTANCE.getHandlers().getGuiDisplayHandler().setDisplayNextTick(gui);
ids.put(integer, () -> {
GeneralChatHandler.instance().sendMessage("Attempting to purchase " + s);
NettyClient client = NettyClient.getClient();
if (client != null) {
client.write(ServerCrossDataPacket.build(new JsonHolder().put("internal", true).put("cosmetic_purchase", true).put("value", s)));
}
});
});
} else {
String string = "Insufficient Credits";
int stringWidth = fontRendererObj.getStringWidth(string);
int left = thisBlocksCenter - stringWidth / 2;
int i = thisTopY - 8 + blockHeight / 2 + 64 + 48;
fontRendererObj.drawString(string, left, i, new Color(249, 9, 0).getRGB(), true);
}
}
pos++;
}
GlStateManager.scale(1F / v, 1F / v, 1F / v);
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.minecraft.client.renderer.texture.DynamicTexture in project Galacticraft by micdoodle8.
the class MapUtil method resetClientBody.
@SideOnly(Side.CLIENT)
public static void resetClientBody() {
ClientProxyCore.overworldTexturesValid = false;
clientRequests.clear();
overworldImageBytesPart = null;
File baseFolder = new File(FMLClientHandler.instance().getClient().mcDataDir, "assets/galacticraftMaps");
if (baseFolder.exists() && baseFolder.isDirectory()) {
for (File f : baseFolder.listFiles()) {
if (f.isFile()) {
f.delete();
}
}
}
GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(PacketSimple.EnumSimplePacket.S_REQUEST_OVERWORLD_IMAGE, GCCoreUtil.getDimensionID(FMLClientHandler.instance().getClient().theWorld), new Object[] {}));
ClientProxyCore.overworldTextureRequestSent = true;
DrawGameScreen.reusableMap = new DynamicTexture(MapUtil.SIZE_STD2, MapUtil.SIZE_STD2);
MapUtil.biomeColours.clear();
setupColours();
}
use of net.minecraft.client.renderer.texture.DynamicTexture in project MinecraftForge by MinecraftForge.
the class ModListScreen method updateCache.
private void updateCache() {
if (selected == null) {
this.configButton.active = false;
this.modInfo.clearInfo();
return;
}
IModInfo selectedMod = selected.getInfo();
this.configButton.active = ConfigGuiHandler.getGuiFactoryFor(selectedMod).isPresent();
List<String> lines = new ArrayList<>();
VersionChecker.CheckResult vercheck = VersionChecker.getResult(selectedMod);
@SuppressWarnings("resource") Pair<ResourceLocation, Size2i> logoData = selectedMod.getLogoFile().map(logoFile -> {
TextureManager tm = this.minecraft.getTextureManager();
final PathResourcePack resourcePack = ResourcePackLoader.getPackFor(selectedMod.getModId()).orElse(ResourcePackLoader.getPackFor("forge").orElseThrow(() -> new RuntimeException("Can't find forge, WHAT!")));
try {
NativeImage logo = null;
InputStream logoResource = resourcePack.getRootResource(logoFile);
if (logoResource != null)
logo = NativeImage.read(logoResource);
if (logo != null) {
return Pair.of(tm.register("modlogo", new DynamicTexture(logo) {
@Override
public void upload() {
this.bind();
NativeImage td = this.getPixels();
// Use custom "blur" value which controls texture filtering (nearest-neighbor vs linear)
this.getPixels().upload(0, 0, 0, 0, 0, td.getWidth(), td.getHeight(), selectedMod.getLogoBlur(), false, false, false);
}
}), new Size2i(logo.getWidth(), logo.getHeight()));
}
} catch (IOException e) {
}
return Pair.<ResourceLocation, Size2i>of(null, new Size2i(0, 0));
}).orElse(Pair.of(null, new Size2i(0, 0)));
lines.add(selectedMod.getDisplayName());
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.version", MavenVersionStringHelper.artifactVersionToString(selectedMod.getVersion())));
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.idstate", selectedMod.getModId(), ModList.get().getModContainerById(selectedMod.getModId()).map(ModContainer::getCurrentState).map(Object::toString).orElse("NONE")));
selectedMod.getConfig().getConfigElement("credits").ifPresent(credits -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.credits", credits)));
selectedMod.getConfig().getConfigElement("authors").ifPresent(authors -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.authors", authors)));
selectedMod.getConfig().getConfigElement("displayURL").ifPresent(displayURL -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.displayurl", displayURL)));
if (selectedMod.getOwningFile() == null || selectedMod.getOwningFile().getMods().size() == 1)
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.nochildmods"));
else
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.childmods", selectedMod.getOwningFile().getMods().stream().map(IModInfo::getDisplayName).collect(Collectors.joining(","))));
if (vercheck.status() == VersionChecker.Status.OUTDATED || vercheck.status() == VersionChecker.Status.BETA_OUTDATED)
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.updateavailable", vercheck.url() == null ? "" : vercheck.url()));
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.license", selectedMod.getOwningFile().getLicense()));
lines.add(null);
lines.add(selectedMod.getDescription());
if ((vercheck.status() == VersionChecker.Status.OUTDATED || vercheck.status() == VersionChecker.Status.BETA_OUTDATED) && vercheck.changes().size() > 0) {
lines.add(null);
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.changelogheader"));
for (Entry<ComparableVersion, String> entry : vercheck.changes().entrySet()) {
lines.add(" " + entry.getKey() + ":");
lines.add(entry.getValue());
lines.add(null);
}
}
modInfo.setInfo(lines, logoData.getLeft(), logoData.getRight());
}
use of net.minecraft.client.renderer.texture.DynamicTexture in project MinecraftForge by MinecraftForge.
the class GuiModList method updateCache.
private void updateCache() {
configModButton.visible = false;
disableModButton.visible = false;
modInfo = null;
if (selectedMod == null)
return;
ResourceLocation logoPath = null;
Dimension logoDims = new Dimension(0, 0);
List<String> lines = new ArrayList<String>();
CheckResult vercheck = ForgeVersion.getResult(selectedMod);
String logoFile = selectedMod.getMetadata().logoFile;
if (!logoFile.isEmpty()) {
TextureManager tm = mc.getTextureManager();
IResourcePack pack = FMLClientHandler.instance().getResourcePackFor(selectedMod.getModId());
try {
BufferedImage logo = null;
if (pack != null) {
logo = pack.getPackImage();
} else {
InputStream logoResource = getClass().getResourceAsStream(logoFile);
if (logoResource != null)
logo = ImageIO.read(logoResource);
}
if (logo != null) {
logoPath = tm.getDynamicTextureLocation("modlogo", new DynamicTexture(logo));
logoDims = new Dimension(logo.getWidth(), logo.getHeight());
}
} catch (IOException e) {
}
}
if (!selectedMod.getMetadata().autogenerated) {
disableModButton.visible = true;
disableModButton.enabled = true;
disableModButton.packedFGColour = 0;
Disableable disableable = selectedMod.canBeDisabled();
if (disableable == Disableable.RESTART) {
disableModButton.packedFGColour = 0xFF3377;
} else if (disableable != Disableable.YES) {
disableModButton.enabled = false;
}
IModGuiFactory guiFactory = FMLClientHandler.instance().getGuiFactoryFor(selectedMod);
configModButton.visible = true;
configModButton.enabled = guiFactory != null && guiFactory.mainConfigGuiClass() != null;
lines.add(selectedMod.getMetadata().name);
lines.add(String.format("Version: %s (%s)", selectedMod.getDisplayVersion(), selectedMod.getVersion()));
lines.add(String.format("Mod ID: '%s' Mod State: %s", selectedMod.getModId(), Loader.instance().getModState(selectedMod)));
if (!selectedMod.getMetadata().credits.isEmpty()) {
lines.add("Credits: " + selectedMod.getMetadata().credits);
}
lines.add("Authors: " + selectedMod.getMetadata().getAuthorList());
lines.add("URL: " + selectedMod.getMetadata().url);
if (selectedMod.getMetadata().childMods.isEmpty())
lines.add("No child mods for this mod");
else
lines.add("Child mods: " + selectedMod.getMetadata().getChildModList());
if (vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED)
lines.add("Update Available: " + (vercheck.url == null ? "" : vercheck.url));
lines.add(null);
lines.add(selectedMod.getMetadata().description);
} else {
lines.add(WHITE + selectedMod.getName());
lines.add(WHITE + "Version: " + selectedMod.getVersion());
lines.add(WHITE + "Mod State: " + Loader.instance().getModState(selectedMod));
if (vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED)
lines.add("Update Available: " + (vercheck.url == null ? "" : vercheck.url));
lines.add(null);
lines.add(RED + "No mod information found");
lines.add(RED + "Ask your mod author to provide a mod mcmod.info file");
}
if ((vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED) && vercheck.changes.size() > 0) {
lines.add(null);
lines.add("Changes:");
for (Entry<ComparableVersion, String> entry : vercheck.changes.entrySet()) {
lines.add(" " + entry.getKey() + ":");
lines.add(entry.getValue());
lines.add(null);
}
}
modInfo = new Info(this.width - this.listWidth - 30, lines, logoPath, logoDims);
}
Aggregations