Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methods for Chemical structure texture creation #14

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading