Skip to content

Commit

Permalink
Chemical Structure Material Texture (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
tekcay authored Nov 27, 2024
1 parent 7fd118e commit 418de60
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/java/gregtech/api/unification/material/Material.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class PropertyKey<T extends IMaterialProperty> {
public static final PropertyKey<WoodProperty> WOOD = new PropertyKey<>("wood", WoodProperty.class);
public static final PropertyKey<PhysicalProperties> PHYSICAL_PROPERTIES = new PropertyKey<>(
"physical_properties", PhysicalProperties.class);
public static final PropertyKey<ChemicalStructureProperty> 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<EmptyProperty> EMPTY = new PropertyKey<>("empty", EmptyProperty.class);
Expand Down
Empty file.

0 comments on commit 418de60

Please sign in to comment.