Skip to content
Open
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
2 changes: 1 addition & 1 deletion api/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tasks.named('test') {
}

group = 'gregtech'
version = '1.8.0'
version = '1.9.0'
base { archivesName = 'gt6ce-api' }

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
*/
public final class GregTechAddons {
private static final int API_MAJOR = 1;
private static final int API_MINOR = 8;
private static final int API_MINOR = 9;

/**
* Monotonic version code of the independent API artifact: {@code major * 1000 + minor}.
* The current 1.8 release reports 1008. Development builds still need a matching SDK and host
* The current 1.9 release reports 1009. Development builds still need a matching SDK and host
* runtime; this number alone does not check the installed mod or Minecraft version.
*
* <p>Not a compile-time constant. A {@code static final} primitive set to a literal is copied into
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ default MaterialFormsView formBindings() {
default MaterialProcessesView processes() {
throw new UnsupportedOperationException("This material catalog does not expose process views");
}
/** Immutable special-process method declarations captured with this definition view. */
default SpecialProcessesView specialProcesses() {
throw new UnsupportedOperationException("This material catalog does not expose special processes");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ public interface Registrar {

Registrar registerGroup(MaterialGroupDeclaration declaration);

/** Declares one special process method; target and reagent rules use its typed process key. */
default Registrar registerSpecialProcess(SpecialProcessMethod method) {
throw new UnsupportedOperationException("This material info host does not expose special processes");
}

/**
* Registers a typed process rule. The rule value must be treated as immutable after this call.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */

package gregtech.api.addon.material;

import java.util.Objects;

/**
* One special process method. Target and reagent materials attach {@link SpecialProcessValue}
* rules through the same {@link MaterialProcessKey}.
*/
public record SpecialProcessMethod(
MaterialProcessKey<SpecialProcessValue> process,
String recipeMap,
String displayNameKey) {
public SpecialProcessMethod {
Objects.requireNonNull(process, "process");
if (process.type() != SpecialProcessValue.class)
throw new IllegalArgumentException("Special process method has the wrong process value type");
if (recipeMap == null || recipeMap.isBlank())
throw new IllegalArgumentException("Special process method has no recipe map");
if (displayNameKey == null || displayNameKey.isBlank())
throw new IllegalArgumentException("Special process method has no display name key");
}

/** Material classification tag assigned to every processable material. */
public DataKey targetTag() {
return new DataKey(process.id().namespace(), process.id().path() + "/target");
}

/** Material classification tag assigned to every processing reagent. */
public DataKey reagentTag() {
return new DataKey(process.id().namespace(), process.id().path() + "/reagent");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */

package gregtech.api.addon.material;

import java.util.List;
import java.util.Objects;

/**
* A target or reagent rule for one declared special process method. Values are caller-owned and
* must be treated as immutable after registration.
*/
public sealed interface SpecialProcessValue permits SpecialProcessValue.Target, SpecialProcessValue.Reagent {
/**
* One processable material's recipe plan. The process rule's form set names accepted inputs;
* {@link #inputCounts()} supplies the exact item count for every accepted form.
*/
record Target(
java.util.Map<FormKey, Integer> inputCounts,
List<ItemOutput> itemOutputs,
List<FluidOutput> fluidOutputs,
long reagentAmount,
long duration,
long euPerTick)
implements SpecialProcessValue {
public Target {
inputCounts = java.util.Map.copyOf(inputCounts);
if (inputCounts.isEmpty()) throw new IllegalArgumentException("Special process target has no input form");
for (var entry : inputCounts.entrySet()) {
Objects.requireNonNull(entry.getKey(), "input form");
if (entry.getValue() < 1) throw new IllegalArgumentException("Invalid special process input count");
}
itemOutputs = List.copyOf(itemOutputs);
fluidOutputs = List.copyOf(fluidOutputs);
if (itemOutputs.isEmpty() && fluidOutputs.isEmpty())
throw new IllegalArgumentException("Special process target has no output");
if (reagentAmount < 1 || duration < 1 || euPerTick < 0)
throw new IllegalArgumentException("Invalid special process target quantities");
}
}

/** Marks one reagent material and its accepted forms through the enclosing process rule. */
record Reagent() implements SpecialProcessValue {}

/** One output material and ordered form alternatives. The first available form wins. */
record ItemOutput(MaterialKey material, List<FormCount> forms, int chance) {
public ItemOutput {
Objects.requireNonNull(material, "output material");
forms = List.copyOf(forms);
if (forms.isEmpty()) throw new IllegalArgumentException("Item output has no form");
if (chance < 1 || chance > 10_000) throw new IllegalArgumentException("Invalid output chance");
}
}

/** One certain fluid output and ordered phase/form alternatives. */
record FluidOutput(MaterialKey material, List<FormCount> forms, int millibuckets) {
public FluidOutput {
Objects.requireNonNull(material, "output material");
forms = List.copyOf(forms);
if (forms.isEmpty() || millibuckets < 1)
throw new IllegalArgumentException("Invalid fluid output");
}
}

/** A form and the concrete item count or millibucket amount emitted in that form. */
record FormCount(FormKey form, int count) {
public FormCount {
Objects.requireNonNull(form, "form");
if (count < 1) throw new IllegalArgumentException("Form count must be positive");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */

package gregtech.api.addon.material;

import java.util.List;
import java.util.Optional;

/** Immutable special-process method declarations from the current material publication. */
public interface SpecialProcessesView {
List<SpecialProcessMethod> methods();

Optional<SpecialProcessMethod> find(DataKey id);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */

/** Addon material, prefix, composition, metadata, tag, group and process declarations. */
/** Addon material, prefix, composition, metadata, tag, group, process and special-process declarations. */
@NullMarked
package gregtech.api.addon.material;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ void reset() {
void apiVersionCodeMatchesTheMajorAndMinorParts() {
assertEquals(GregTechAddons.apiMajor() * 1000 + GregTechAddons.apiMinor(), GregTechAddons.apiVersion());
assertEquals(1, GregTechAddons.apiMajor());
assertEquals(8, GregTechAddons.apiMinor());
assertEquals(1008, GregTechAddons.apiVersion());
assertEquals(9, GregTechAddons.apiMinor());
assertEquals(1009, GregTechAddons.apiVersion());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package gregtech.api.addon.material;

import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

final class SpecialProcessValueTest {
@Test
void methodDerivesStableMaterialTags() {
var method = new SpecialProcessMethod(
MaterialProcessKey.multiple(
new DataKey("example", "special_process/wash"), SpecialProcessValue.class),
"gt.recipe.bath",
"example.special_process.wash");

assertEquals(new DataKey("example", "special_process/wash/target"), method.targetTag());
assertEquals(new DataKey("example", "special_process/wash/reagent"), method.reagentTag());
}

@Test
void targetRejectsIncompleteRecipePlans() {
var output = new SpecialProcessValue.ItemOutput(
new MaterialKey("Iron"),
List.of(new SpecialProcessValue.FormCount(new FormKey("dust"), 1)),
10_000);

assertThrows(
IllegalArgumentException.class,
() -> new SpecialProcessValue.Target(
Map.of(), List.of(output), List.of(), 1, 1, 0));
assertThrows(
IllegalArgumentException.class,
() -> new SpecialProcessValue.Target(
Map.of(new FormKey("dust"), 1), List.of(), List.of(), 1, 1, 0));
}

@Test
void unsupportedCatalogFailsExplicitly() {
MaterialCatalogView catalog = new MaterialCatalogView() {
@Override
public long revision() {
return 0;
}

@Override
public Optional<MaterialKey> resolve(String name) {
return Optional.empty();
}

@Override
public MaterialTagsView tags() {
throw new UnsupportedOperationException();
}

@Override
public Optional<MaterialView> find(MaterialKey key) {
return Optional.empty();
}

@Override
public List<MaterialView> materials() {
return List.of();
}
};

assertThrows(UnsupportedOperationException.class, catalog::specialProcesses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package gregtech.api.contracts;

import gregtech.api.addon.material.*;

import java.util.List;

/** Only the delivered API JAR participates in this consumer. */
Expand Down Expand Up @@ -41,6 +42,20 @@ public List<MaterialProcessDeclaration<?>> processes() {
|| contributor.materialGroups().size() != 1
|| contributor.processes().size() != 1)
throw new AssertionError("tag, group and process SPI");
var specialKey = MaterialProcessKey.multiple(
new DataKey("consumer", "special_process/wash"), SpecialProcessValue.class);
var method = new SpecialProcessMethod(specialKey, "gt.recipe.bath", "consumer.special.wash");
var target = new SpecialProcessValue.Target(
java.util.Map.of(new FormKey("dust"), 1),
List.of(new SpecialProcessValue.ItemOutput(
key, List.of(new SpecialProcessValue.FormCount(new FormKey("dust"), 1)), 10_000)),
List.of(),
1,
1,
0);
if (!method.targetTag().equals(new DataKey("consumer", "special_process/wash/target"))
|| !(target.itemOutputs().get(0).material().equals(key)))
throw new AssertionError("special process contract");
try { GregTechMaterials.catalog(); throw new AssertionError("unbound host must fail"); }
catch (IllegalStateException expected) { }
}
Expand Down
Loading
Loading