From 2327746e5a0ddbfe460b1dd0d5392b94d7f106a2 Mon Sep 17 00:00:00 2001 From: Boblet Date: Tue, 14 Mar 2023 11:00:25 +0100 Subject: [PATCH] holy FUCK --- .../java/com/hbm/inventory/material/Mats.java | 26 +++--- .../hbm/inventory/material/NTMMaterial.java | 8 +- .../com/hbm/items/special/ItemAutogen.java | 26 +++--- ...RGBMutatorInterpolatedComponentRemap.java} | 26 +++--- .../icon/TextureAtlasSpriteMutatable.java | 88 +++++++++++++++++++ 5 files changed, 134 insertions(+), 40 deletions(-) rename src/main/java/com/hbm/render/icon/{RGBMutatorMultiplicative.java => RGBMutatorInterpolatedComponentRemap.java} (76%) diff --git a/src/main/java/com/hbm/inventory/material/Mats.java b/src/main/java/com/hbm/inventory/material/Mats.java index 86f375d34..14da42aa4 100644 --- a/src/main/java/com/hbm/inventory/material/Mats.java +++ b/src/main/java/com/hbm/inventory/material/Mats.java @@ -47,7 +47,7 @@ public class Mats { public static final int _AS = 30; //Vanilla and vanilla-like - public static final NTMMaterial MAT_STONE = makeSmeltable(_VS + 00, df("Stone"), 0x808080, 0x4D2F23); + public static final NTMMaterial MAT_STONE = makeSmeltable(_VS + 00, df("Stone"), 0x7F7F7F, 0x353535, 0x4D2F23); public static final NTMMaterial MAT_CARBON = makeAdditive( 1499, df("Carbon"), 0x404040); public static final NTMMaterial MAT_COAL = make( 1400, COAL) .setConversion(MAT_CARBON, 2, 1); public static final NTMMaterial MAT_LIGNITE = make( 1401, LIGNITE) .setConversion(MAT_CARBON, 3, 1); @@ -55,7 +55,7 @@ public class Mats { public static final NTMMaterial MAT_PETCOKE = make( 1411, PETCOKE) .setConversion(MAT_CARBON, 4, 3); public static final NTMMaterial MAT_LIGCOKE = make( 1412, LIGCOKE) .setConversion(MAT_CARBON, 4, 3); public static final NTMMaterial MAT_GRAPHITE = make( 1420, GRAPHITE) .setConversion(MAT_CARBON, 1, 1); - public static final NTMMaterial MAT_IRON = makeSmeltable(2600, IRON, 0xFFFFFF, 0xFFA259).setShapes(CASTPLATE); + public static final NTMMaterial MAT_IRON = makeSmeltable(2600, IRON, 0xFFFFFF, 0x353535, 0xFFA259).setShapes(CASTPLATE); public static final NTMMaterial MAT_GOLD = makeSmeltable(7900, GOLD, 0xE8D754).setShapes(CASTPLATE); public static final NTMMaterial MAT_REDSTONE = makeSmeltable(_VS + 01, REDSTONE, 0xFF1000); public static final NTMMaterial MAT_OBSIDIAN = makeSmeltable(_VS + 02, df("Obsidian"), 0x3D234D); @@ -85,7 +85,7 @@ public class Mats { public static final NTMMaterial MAT_TECHNIETIUM = makeSmeltable(4399, TC99, 0xCADFDF).setShapes(NUGGET, BILLET, INGOT, BLOCK); public static final NTMMaterial MAT_RADIUM = makeSmeltable(8826, RA226, 0xE9FAF6).setShapes(NUGGET, BILLET, INGOT, DUST, BLOCK); public static final NTMMaterial MAT_ACTINIUM = makeSmeltable(8927, AC227, 0x958989).setShapes(NUGGET, BILLET, INGOT); - public static final NTMMaterial MAT_CO60 = makeSmeltable(2760, CO60, 0x92A1C0, 0x8F72AE).setShapes(NUGGET, BILLET, INGOT, DUST); + public static final NTMMaterial MAT_CO60 = makeSmeltable(2760, CO60, 0xC2D1EE, 0x353554, 0x8F72AE).setShapes(NUGGET, BILLET, INGOT, DUST); public static final NTMMaterial MAT_AU198 = makeSmeltable(7998, AU198, 0xE8D754).setShapes(NUGGET, BILLET, INGOT, DUST); public static final NTMMaterial MAT_PB209 = makeSmeltable(8209, PB209, 0x7B535D).setShapes(NUGGET, BILLET, INGOT, DUST); public static final NTMMaterial MAT_SCHRABIDIUM = makeSmeltable(12626, SA326, 0x32FFFF).setShapes(NUGGET, WIRE, BILLET, INGOT, DUST, PLATE, CASTPLATE, BLOCK); @@ -97,16 +97,16 @@ public class Mats { //Base metals public static final NTMMaterial MAT_TITANIUM = makeSmeltable(2200, TI, 0xA99E79).setShapes(INGOT, DUST, PLATE, CASTPLATE, BLOCK); public static final NTMMaterial MAT_COPPER = makeSmeltable(2900, CU, 0xC18336).setShapes(WIRE, INGOT, DUST, PLATE, CASTPLATE, BLOCK); - public static final NTMMaterial MAT_TUNGSTEN = makeSmeltable(7400, W, 0x565656, 0x977474).setShapes(WIRE, INGOT, DUST, BLOCK); - public static final NTMMaterial MAT_ALUMINIUM = makeSmeltable(1300, AL, 0xE8F2F9, 0xD0B8EB).setShapes(WIRE, INGOT, DUST, PLATE, CASTPLATE, BLOCK); + public static final NTMMaterial MAT_TUNGSTEN = makeSmeltable(7400, W, 0x868686, 0x000000, 0x977474).setShapes(WIRE, INGOT, DUST, BLOCK); + public static final NTMMaterial MAT_ALUMINIUM = makeSmeltable(1300, AL, 0xFFFFFF, 0x344550, 0xD0B8EB).setShapes(WIRE, INGOT, DUST, PLATE, CASTPLATE, BLOCK); public static final NTMMaterial MAT_LEAD = makeSmeltable(8200, PB, 0x646470).setShapes(NUGGET, INGOT, DUST, PLATE, CASTPLATE, BLOCK); public static final NTMMaterial MAT_BISMUTH = makeSmeltable(8300, df("Bismuth"), 0xB200FF).setShapes(NUGGET, BILLET, INGOT, DUST, BLOCK); public static final NTMMaterial MAT_ARSENIC = makeSmeltable(3300, AS, 0x558080).setShapes(NUGGET, INGOT); public static final NTMMaterial MAT_TANTALIUM = makeSmeltable(7300, TA, 0xA89B74).setShapes(NUGGET, INGOT, DUST, BLOCK); public static final NTMMaterial MAT_NIOBIUM = makeSmeltable(4100, NB, 0xD576B1).setShapes(NUGGET, DUSTTINY, INGOT, DUST, BLOCK); public static final NTMMaterial MAT_BERYLLIUM = makeSmeltable(400, BE, 0xAE9572).setShapes(NUGGET, INGOT, DUST, BLOCK); - public static final NTMMaterial MAT_COBALT = makeSmeltable(2700, CO, 0x92A1C0, 0x8F72AE).setShapes(NUGGET, DUSTTINY, BILLET, INGOT, DUST, BLOCK); - public static final NTMMaterial MAT_BORON = makeSmeltable(500, B, 0x8D98A2, 0xAD72AE).setShapes(DUSTTINY, INGOT, DUST, BLOCK); + public static final NTMMaterial MAT_COBALT = makeSmeltable(2700, CO, 0xC2D1EE, 0x353554, 0x8F72AE).setShapes(NUGGET, DUSTTINY, BILLET, INGOT, DUST, BLOCK); + public static final NTMMaterial MAT_BORON = makeSmeltable(500, B, 0xBDC8D2, 0x29343E, 0xAD72AE).setShapes(DUSTTINY, INGOT, DUST, BLOCK); //Alloys public static final NTMMaterial MAT_STEEL = makeSmeltable(_AS + 0, STEEL, 0x4A4A4A).setShapes(DUSTTINY, INGOT, DUST, PLATE, CASTPLATE, BLOCK); @@ -122,19 +122,19 @@ public class Mats { public static final NTMMaterial MAT_FLUX = makeAdditive(_AS + 10, df("Flux"), 0xDECCAD).setShapes(DUST); public static final NTMMaterial MAT_SLAG = makeSmeltable(_AS + 11, SLAG, 0x6C6562).setShapes(BLOCK); - public static NTMMaterial makeSmeltable(int id, DictFrame dict, int color) { return makeSmeltable(id, dict, color, color); } - public static NTMMaterial makeAdditive(int id, DictFrame dict, int color) { return makeAdditive(id, dict, color, color); } + @Deprecated public static NTMMaterial makeSmeltable(int id, DictFrame dict, int color) { return makeSmeltable(id, dict, color, color, color); } + @Deprecated public static NTMMaterial makeAdditive(int id, DictFrame dict, int color) { return makeAdditive(id, dict, color, color, color); } public static NTMMaterial make(int id, DictFrame dict) { return new NTMMaterial(id, dict); } - public static NTMMaterial makeSmeltable(int id, DictFrame dict, int solidColor, int moltenColor) { - return new NTMMaterial(id, dict).smeltable(SmeltingBehavior.SMELTABLE).setSolidColor(solidColor).setMoltenColor(moltenColor); + public static NTMMaterial makeSmeltable(int id, DictFrame dict, int solidColorLight, int solidColorDark, int moltenColor) { + return new NTMMaterial(id, dict).smeltable(SmeltingBehavior.SMELTABLE).setSolidColor(solidColorLight, solidColorDark).setMoltenColor(moltenColor); } - public static NTMMaterial makeAdditive(int id, DictFrame dict, int solidColor, int moltenColor) { - return new NTMMaterial(id, dict).smeltable(SmeltingBehavior.ADDITIVE).setSolidColor(solidColor).setMoltenColor(moltenColor); + public static NTMMaterial makeAdditive(int id, DictFrame dict, int solidColorLight, int solidColorDark, int moltenColor) { + return new NTMMaterial(id, dict).smeltable(SmeltingBehavior.ADDITIVE).setSolidColor(solidColorLight, solidColorDark).setMoltenColor(moltenColor); } public static DictFrame df(String string) { diff --git a/src/main/java/com/hbm/inventory/material/NTMMaterial.java b/src/main/java/com/hbm/inventory/material/NTMMaterial.java index 60cf49fa5..354052e5b 100644 --- a/src/main/java/com/hbm/inventory/material/NTMMaterial.java +++ b/src/main/java/com/hbm/inventory/material/NTMMaterial.java @@ -16,7 +16,8 @@ public class NTMMaterial { public String[] names; public Set shapes = new HashSet(); public SmeltingBehavior smeltable = SmeltingBehavior.NOT_SMELTABLE; - public int solidColor = 0xFF4A00; + public int solidColorLight = 0xFF4A00; + public int solidColorDark = 0x802000; public int moltenColor = 0xFF4A00; public NTMMaterial smeltsInto; @@ -63,8 +64,9 @@ public class NTMMaterial { return this; } - public NTMMaterial setSolidColor(int color) { - this.solidColor = color; + public NTMMaterial setSolidColor(int colorLight, int colorDark) { + this.solidColorLight = colorLight; + this.solidColorDark = colorDark; return this; } diff --git a/src/main/java/com/hbm/items/special/ItemAutogen.java b/src/main/java/com/hbm/items/special/ItemAutogen.java index 8646e201a..2afb8a974 100644 --- a/src/main/java/com/hbm/items/special/ItemAutogen.java +++ b/src/main/java/com/hbm/items/special/ItemAutogen.java @@ -9,7 +9,7 @@ import com.hbm.inventory.material.Mats; import com.hbm.inventory.material.NTMMaterial; import com.hbm.items.tool.ItemColtanCompass.TextureColtass; import com.hbm.lib.RefStrings; -import com.hbm.render.icon.RGBMutatorMultiplicative; +import com.hbm.render.icon.RGBMutatorInterpolatedComponentRemap; import com.hbm.render.icon.TextureAtlasSpriteMutatable; import com.hbm.util.I18nUtil; @@ -28,7 +28,7 @@ public class ItemAutogen extends Item { MaterialShapes shape; private HashMap textureOverrides = new HashMap(); - private HashMap iconOverrides = new HashMap(); + private HashMap iconMap = new HashMap(); public ItemAutogen(MaterialShapes shape) { this.setHasSubtypes(true); @@ -45,17 +45,21 @@ public class ItemAutogen extends Item { public void registerIcons(IIconRegister reg) { super.registerIcons(reg); - /*if(reg instanceof TextureMap) { + if(reg instanceof TextureMap) { TextureMap map = (TextureMap) reg; - TextureAtlasSpriteMutatable jumpstart_my_shart = new TextureAtlasSpriteMutatable(this.getIconString(), new RGBMutatorMultiplicative(0xff0000)); - map.setTextureEntry(this.getIconString(), jumpstart_my_shart); - this.itemIcon = jumpstart_my_shart; - } else { - this.itemIcon = reg.registerIcon(this.getIconString()); - }*/ + + for(NTMMaterial mat : Mats.orderedList) { + if(!textureOverrides.containsKey(mat)) { + String placeholderName = this.getIconString() + "-" + mat.names[0]; //the part after the dash is discarded - the name only has to be unique so that the hashmap which holds all the icon definitions can hold multiple references + TextureAtlasSpriteMutatable mutableIcon = new TextureAtlasSpriteMutatable(placeholderName, new RGBMutatorInterpolatedComponentRemap(0xFFFFFF, 0x565656, mat.solidColorLight, mat.solidColorDark)); + map.setTextureEntry(placeholderName, mutableIcon); + iconMap.put(mat, mutableIcon); + } + } + } for(Entry tex : textureOverrides.entrySet()) { - iconOverrides.put(tex.getKey(), reg.registerIcon(RefStrings.MODID + ":" + tex.getValue())); + iconMap.put(tex.getKey(), reg.registerIcon(RefStrings.MODID + ":" + tex.getValue())); } } @@ -77,7 +81,7 @@ public class ItemAutogen extends Item { NTMMaterial mat = Mats.matById.get(meta); if(mat != null) { - IIcon override = iconOverrides.get(mat); + IIcon override = iconMap.get(mat); if(override != null) { return override; } diff --git a/src/main/java/com/hbm/render/icon/RGBMutatorMultiplicative.java b/src/main/java/com/hbm/render/icon/RGBMutatorInterpolatedComponentRemap.java similarity index 76% rename from src/main/java/com/hbm/render/icon/RGBMutatorMultiplicative.java rename to src/main/java/com/hbm/render/icon/RGBMutatorInterpolatedComponentRemap.java index 4a111bd45..527456655 100644 --- a/src/main/java/com/hbm/render/icon/RGBMutatorMultiplicative.java +++ b/src/main/java/com/hbm/render/icon/RGBMutatorInterpolatedComponentRemap.java @@ -2,12 +2,18 @@ package com.hbm.render.icon; import java.awt.image.BufferedImage; -public class RGBMutatorMultiplicative implements RGBMutator { +public class RGBMutatorInterpolatedComponentRemap implements RGBMutator { + + int sourceLight; + int sourceDark; + int targetLight; + int targetDark; - int color; - - public RGBMutatorMultiplicative(int color) { - this.color = color; + public RGBMutatorInterpolatedComponentRemap(int sourceLight, int sourceDark, int targetLight, int targetDark) { + this.sourceLight = sourceLight; + this.sourceDark = sourceDark; + this.targetLight = targetLight; + this.targetDark = targetDark; } @Override @@ -17,12 +23,7 @@ public class RGBMutatorMultiplicative implements RGBMutator { for(int y = 0; y < image.getHeight(); y++) { int pix = image.getRGB(x, y); - int boundLighter = 0xffffff; - int lighter = 0xFFEE3F; - int boundDarker = 0x505050; - int darker = 0xC0471F; - - int rgb = shiftColor(boundLighter, boundDarker, lighter, darker, pix); + int rgb = shiftColor(sourceLight, sourceDark, targetLight, targetDark, pix); image.setRGB(x, y, rgb); } } @@ -48,8 +49,7 @@ public class RGBMutatorMultiplicative implements RGBMutator { private static double shiftComponent(int lighter, int darker, int boundLighter, int boundDarker, int component) { double scaledComponent = getPosFromComp(boundLighter, boundDarker, component); - double newComp = getCompFromFunc(lighter, darker, scaledComponent); - return newComp; + return getCompFromFunc(lighter, darker, scaledComponent); } private static double getCompFromFunc(int lower, int upper, double interp) { diff --git a/src/main/java/com/hbm/render/icon/TextureAtlasSpriteMutatable.java b/src/main/java/com/hbm/render/icon/TextureAtlasSpriteMutatable.java index 76e2ae9cb..61a30509e 100644 --- a/src/main/java/com/hbm/render/icon/TextureAtlasSpriteMutatable.java +++ b/src/main/java/com/hbm/render/icon/TextureAtlasSpriteMutatable.java @@ -1,16 +1,31 @@ package com.hbm.render.icon; import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; + +import javax.imageio.ImageIO; + +import com.hbm.main.MainRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.IResource; +import net.minecraft.client.resources.IResourceManager; import net.minecraft.client.resources.data.AnimationMetadataSection; +import net.minecraft.client.resources.data.TextureMetadataSection; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; @SideOnly(Side.CLIENT) public class TextureAtlasSpriteMutatable extends TextureAtlasSprite { + //private boolean multiTexture; private RGBMutator mutator; + public String basePath = "textures/items"; public TextureAtlasSpriteMutatable(String iconName, RGBMutator mutator) { super(iconName); @@ -29,4 +44,77 @@ public class TextureAtlasSpriteMutatable extends TextureAtlasSprite { super.loadSprite(frames, animMeta, anisotropicFiltering); } + + @Override + public boolean hasCustomLoader(IResourceManager manager, ResourceLocation location) { + return true; //YES! + } + + @Override + public boolean load(IResourceManager man, ResourceLocation resourcelocation) { + + //the system is currently only applicable to items - mipmaps and whatnot aren't needed + int mipmap = 0;//Minecraft.getMinecraft().gameSettings.mipmapLevels; + int anisotropic = 0;//Minecraft.getMinecraft().gameSettings.anisotropicFiltering; + + String pathName = resourcelocation.getResourcePath(); + String tunkatedPath = pathName.substring(0, pathName.indexOf('-')); //fuck regex + //so basically we remove the dash and everything trailing it (see ItemAutogen.java), this allows us to have unique icon names for what is actually the same icon file + resourcelocation = new ResourceLocation(resourcelocation.getResourceDomain(), tunkatedPath); + ResourceLocation resourcelocation1 = this.completeResourceLocation(resourcelocation, 0); + + //garbage vanilla code, copy pasted because there's no proper hooks for this + try { + + IResource iresource = man.getResource(resourcelocation1); + BufferedImage[] abufferedimage = new BufferedImage[1 + mipmap]; + abufferedimage[0] = ImageIO.read(iresource.getInputStream()); + TextureMetadataSection texturemetadatasection = (TextureMetadataSection) iresource.getMetadata("texture"); + + if(texturemetadatasection != null) { + List list = texturemetadatasection.getListMipmaps(); + int l; + + if(!list.isEmpty()) { + int k = abufferedimage[0].getWidth(); + l = abufferedimage[0].getHeight(); + + if(MathHelper.roundUpToPowerOfTwo(k) != k || MathHelper.roundUpToPowerOfTwo(l) != l) { + throw new RuntimeException("Unable to load extra miplevels, source-texture is not power of two"); + } + } + + Iterator iterator3 = list.iterator(); + + while(iterator3.hasNext()) { + l = ((Integer) iterator3.next()).intValue(); + + if(l > 0 && l < abufferedimage.length - 1 && abufferedimage[l] == null) { + ResourceLocation resourcelocation2 = this.completeResourceLocation(resourcelocation, l); + + try { + abufferedimage[l] = ImageIO.read(man.getResource(resourcelocation2).getInputStream()); + } catch(IOException ioexception) { + MainRegistry.logger.error("Unable to load miplevel {} from: {}", new Object[] { Integer.valueOf(l), resourcelocation2, ioexception }); + } + } + } + } + + AnimationMetadataSection animationmetadatasection = (AnimationMetadataSection) iresource.getMetadata("animation"); + loadSprite(abufferedimage, animationmetadatasection, (float) anisotropic > 1.0F); + } catch(RuntimeException runtimeexception) { + cpw.mods.fml.client.FMLClientHandler.instance().trackBrokenTexture(resourcelocation1, runtimeexception.getMessage()); + } catch(IOException ioexception1) { + cpw.mods.fml.client.FMLClientHandler.instance().trackMissingTexture(resourcelocation1); + } + + return false; //FALSE! prevents vanilla loading (we just did that ourselves) + } + + //whatever the fuck this is + private ResourceLocation completeResourceLocation(ResourceLocation loc, int mipmap) { + return mipmap == 0 ? new ResourceLocation(loc.getResourceDomain(), String.format("%s/%s%s", new Object[] { this.basePath, loc.getResourcePath(), ".png" })) + : new ResourceLocation(loc.getResourceDomain(), String.format("%s/mipmaps/%s.%d%s", new Object[] { this.basePath, loc.getResourcePath(), Integer.valueOf(mipmap), ".png" })); + } }