diff --git a/src/main/java/gregtech/api/unification/material/Material.java b/src/main/java/gregtech/api/unification/material/Material.java index b4147c1e5c0..d6d331b899a 100644 --- a/src/main/java/gregtech/api/unification/material/Material.java +++ b/src/main/java/gregtech/api/unification/material/Material.java @@ -5,6 +5,8 @@ import gregtech.api.fluids.FluidState; import gregtech.api.fluids.store.FluidStorageKey; import gregtech.api.fluids.store.FluidStorageKeys; +import gregtech.api.gui.resources.TextureArea; +import gregtech.api.gui.widgets.ImageWidget; import gregtech.api.unification.Element; import gregtech.api.unification.Elements; import gregtech.api.unification.material.info.MaterialFlag; @@ -451,6 +453,22 @@ public MaterialRegistry getRegistry() { return GregTechAPI.materialManager.getRegistry(getModid()); } + @Nullable + public TextureArea getChemicalStructureTextureArea() { + Preconditions.checkArgument(hasProperty(PropertyKey.CHEMICAL_STRUCTURE), + "does not have PropertyKey.CHEMICAL_STRUCTURE!"); + return ChemicalStructureProperty.getMoleculeTexture(this); + } + + @Nullable + public ImageWidget getChemicalStructureWidget(int x, int y) { + Preconditions.checkArgument(hasProperty(PropertyKey.CHEMICAL_STRUCTURE), + "does not have PropertyKey.CHEMICAL_STRUCTURE!"); + ChemicalStructureProperty property = this.getProperty(PropertyKey.CHEMICAL_STRUCTURE); + return ChemicalStructureProperty.getChemicalStructureWidget(this, x, y, property.textureHeight(), + property.textureWidth()); + } + /** * @since GTCEu 2.0.0 */ @@ -1105,6 +1123,14 @@ public Builder physicalProperties(PhysicalProperties.Builder builder) { return this; } + public Builder chemicalStructureTexture(int textureHeight, int textureWidth) { + Preconditions.checkArgument(textureHeight > 0 && textureWidth > 0, + "textureHeight and textureWidth must be > 0"); + properties.setProperty(PropertyKey.CHEMICAL_STRUCTURE, + new ChemicalStructureProperty(textureHeight, textureWidth)); + return this; + } + // TODO Clean this up post 2.5 release @Deprecated public Builder addDefaultEnchant(Enchantment enchant, int level) { diff --git a/src/main/java/gregtech/api/unification/material/properties/ChemicalStructureProperty.java b/src/main/java/gregtech/api/unification/material/properties/ChemicalStructureProperty.java new file mode 100644 index 00000000000..a0d82818786 --- /dev/null +++ b/src/main/java/gregtech/api/unification/material/properties/ChemicalStructureProperty.java @@ -0,0 +1,29 @@ +package gregtech.api.unification.material.properties; + +import gregtech.api.gui.resources.TextureArea; +import gregtech.api.gui.widgets.ImageWidget; +import gregtech.api.unification.material.Material; + +import com.github.bsideup.jabel.Desugar; +import org.jetbrains.annotations.NotNull; + +@Desugar +public record ChemicalStructureProperty(int textureHeight, int textureWidth) implements IMaterialProperty { + + @Override + public void verifyProperty(MaterialProperties properties) { + properties.ensureSet(PropertyKey.CHEMICAL_STRUCTURE, true); + } + + @NotNull + public static TextureArea getMoleculeTexture(Material material) { + return TextureArea.fullImage( + String.format("textures/chemicalstructure/%s.png", material.getResourceLocation().getPath())); + } + + @NotNull + public static ImageWidget getChemicalStructureWidget(Material material, int x, int y, int height, int width) { + TextureArea tx = getMoleculeTexture(material); + return new ImageWidget(x, y, width, height, tx); + } +} diff --git a/src/main/java/gregtech/api/unification/material/properties/PropertyKey.java b/src/main/java/gregtech/api/unification/material/properties/PropertyKey.java index 4c955611ebf..3825881e1f6 100644 --- a/src/main/java/gregtech/api/unification/material/properties/PropertyKey.java +++ b/src/main/java/gregtech/api/unification/material/properties/PropertyKey.java @@ -19,6 +19,8 @@ public class PropertyKey { public static final PropertyKey WOOD = new PropertyKey<>("wood", WoodProperty.class); public static final PropertyKey PHYSICAL_PROPERTIES = new PropertyKey<>( "physical_properties", PhysicalProperties.class); + public static final PropertyKey CHEMICAL_STRUCTURE = new PropertyKey<>( + "physical_properties", ChemicalStructureProperty.class); // Empty property used to allow property-less Materials without removing base type enforcement public static final PropertyKey EMPTY = new PropertyKey<>("empty", EmptyProperty.class); diff --git a/src/main/resources/assets/gregtech/textures/chemicalstructure/.gitignore b/src/main/resources/assets/gregtech/textures/chemicalstructure/.gitignore new file mode 100644 index 00000000000..e69de29bb2d