Skip to content

Commit

Permalink
change some things to be more addon dev-friendly (GregTechCEu#485)
Browse files Browse the repository at this point in the history
* fix: make modid filter in fabric registry generator not be hardcoded.

* fix: "a feature order cycle was found"
should close GregTechCEu#430, GregTechCEu#409, GregTechCEu#301

* feat: deprecate these. didn't work as planned.

* feat: add recipe removal event to IGTAddon

* feat: general tags for purified & refined ores

* fix: changed my mind, removíng these now

* fix: make SoundEntryProvider able to accept a filter for the mod id to run for.

* fix: make VanillaRecipeHelper use ResourceLocations for recipe ids, add methods to create from string for backwards compatibility.

* chore: bump version

* chore: changelog
  • Loading branch information
screret authored Oct 21, 2023
1 parent 8ab9f58 commit 84430f2
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 58 deletions.
15 changes: 3 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# ChangeLog

* fix fluid pipe throughput being too low
* fix super tank & quantum tank amount being displayed incorrectly on fabric
* fix wires not being colored
* fix large boiler not resuming work after being unloaded
* fix large distillery and some GCyM machines not forming
* fix some missing / unnecessary mixer recipes, glass vial material amount, melon maceration
* fix server crashes on multiblock recipe map modification
* fix distinct bus mode not working with circuits config
* fix placement issues when using the terminal to build a multiblock
* fix cherry and bamboo recipes not being affected by the harderWoodRecipes config
* fix spray cans being unable to color vanilla blocks
* add KubeJS bindings for GTFluidStorageKeys, GTFluidState, PropertyKey
* fix feature order cycle on fabric
* make some API methods more addon dev friendly
* add tags for all purified/refined ores
23 changes: 7 additions & 16 deletions common/src/main/java/com/gregtechceu/gtceu/api/addon/IGTAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import com.gregtechceu.gtceu.api.addon.events.KJSRecipeKeyEvent;
import com.gregtechceu.gtceu.api.addon.events.MaterialCasingCollectionEvent;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.resources.ResourceLocation;

import java.util.function.Consumer;

public interface IGTAddon {

/**
* You can freely initialize blocks/items/etc. here, this runs after GTCEu has setup it's content
* This runs after GTCEu has setup it's content.
*/
void initializeAddon();

Expand Down Expand Up @@ -54,20 +55,6 @@ default void registerCovers() {

}

/**
* Call init on your custom RecipeType class(es) here
*/
default void registerRecipeTypes() {

}

/**
* Call init on your custom Machine class(es) here
*/
default void registerMachines() {

}

/**
* Call init on your custom IWorldGenLayer class(es) here
*/
Expand All @@ -82,7 +69,11 @@ default void registerVeinGenerators() {

}

default void initializeRecipes(Consumer<FinishedRecipe> provider) {
default void addRecipes(Consumer<FinishedRecipe> provider) {

}

default void removeRecipes(Consumer<ResourceLocation> consumer) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ public static TagPrefix get(String name) {
public static final TagPrefix crushedRefined = new TagPrefix("refinedOre")
.defaultTagPath(FORGE, "refined_ores/%s")
.defaultTagPath(FABRIC, "%s_refined_ores")
.defaultTagPath(FORGE, "refined_ores")
.defaultTagPath(FABRIC, "refined_ores")
.langValue("Refined %s Ore")
.materialIconType(MaterialIconType.crushedRefined)
.unificationEnabled(true)
Expand All @@ -200,6 +202,8 @@ public static TagPrefix get(String name) {
public static final TagPrefix crushedPurified = new TagPrefix("purifiedOre")
.defaultTagPath(FORGE, "purified_ores/%s")
.defaultTagPath(FABRIC, "%s_purified_ores")
.defaultTagPath(FORGE, "purified_ores")
.defaultTagPath(FABRIC, "purified_ores")
.langValue("Purified %s Ore")
.materialIconType(MaterialIconType.crushedPurified)
.unificationEnabled(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ public class SoundEntryBuilder {

public static class SoundEntryProvider implements DataProvider {
private final PackOutput output;
private final String modId;

public SoundEntryProvider(PackOutput output) {
public SoundEntryProvider(PackOutput output, String modId) {
this.output = output;
this.modId = modId;
}

@Override
Expand All @@ -44,14 +46,14 @@ public CompletableFuture<?> run(CachedOutput cache) {

@Override
public String getName() {
return "GTCEU's Custom Sounds";
return modId + "'s Custom Sounds";
}

public CompletableFuture<?> generate(Path path, CachedOutput cache) {
JsonObject json = new JsonObject();
try {
for (SoundEntry sound : GTRegistries.SOUNDS) {
sound.write(json);
if (sound.getId().getNamespace().equals(modId)) sound.write(json);
}
} catch (Exception ignored) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ public static void init() {
GTRegistries.REGISTRATE.registerRegistrate();
WorldGenLayers.registerAll();
GTFeatures.init();
GTFeatures.register();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,6 @@ public static void init() {
.register(),
MV, HV, EV);
}
AddonFinder.getAddons().forEach(IGTAddon::registerMachines);
if (GTCEu.isKubeJSLoaded()) {
GTRegistryObjectBuilderTypes.registerFor(GTRegistries.MACHINES.getRegistryName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void bootstrap(BootstapContext<PlacedFeature> ctx) {
PlacementUtils.countExtra(0, ConfigHolder.INSTANCE.worldgen.rubberTreeSpawnChance, 1),
InSquarePlacement.spread(),
SurfaceWaterDepthFilter.forMaxDepth(0),
PlacementUtils.HEIGHTMAP_OCEAN_FLOOR,
PlacementUtils.HEIGHTMAP_TOP_SOLID,
BiomeFilter.biome(),
PlacementUtils.filteredByBlockSurvival(GTBlocks.RUBBER_SAPLING.get())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ public static void init() {
.save(provider);
});
}
AddonFinder.getAddons().forEach(IGTAddon::registerRecipeTypes);
if (GTCEu.isKubeJSLoaded()) {
GTRegistryObjectBuilderTypes.registerFor(GTRegistries.RECIPE_TYPES.getRegistryName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void recipeAddition(Consumer<FinishedRecipe> consumer) {
CreateRecipeLoader.init(consumer);
}

AddonFinder.getAddons().forEach(addon -> addon.initializeRecipes(consumer));
AddonFinder.getAddons().forEach(addon -> addon.addRecipes(consumer));
}

/*
Expand All @@ -80,5 +80,7 @@ public static void recipeAddition(Consumer<FinishedRecipe> consumer) {
*/
public static void recipeRemoval(Consumer<ResourceLocation> consumer) {
RecipeRemoval.init(consumer);

AddonFinder.getAddons().forEach(addon -> addon.removeRecipes(consumer));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public OreDataLoader() {
@Override
protected void apply(Map<ResourceLocation, JsonElement> resourceList, ResourceManager resourceManager, ProfilerFiller profiler) {
GTRegistries.ORE_VEINS.registry().clear();
GTFeatures.register();
GTOres.init();
if (GTCEu.isKubeJSLoaded()) {
RunKJSEventInSeparateClassBecauseForgeIsDumb.fireKJSEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand All @@ -36,27 +37,43 @@
public class VanillaRecipeHelper {

public static void addSmeltingRecipe(Consumer<FinishedRecipe> provider, @Nonnull String regName, TagKey<Item> input, ItemStack output) {
addSmeltingRecipe(provider, GTCEu.id(regName.toLowerCase(Locale.ROOT)), input, output);
}

public static void addSmeltingRecipe(Consumer<FinishedRecipe> provider, @Nonnull ResourceLocation regName, TagKey<Item> input, ItemStack output) {
addSmeltingRecipe(provider, regName, input, output, 0.0f);
}

public static void addSmeltingRecipe(Consumer<FinishedRecipe> provider, @Nonnull String regName, TagKey<Item> input, ItemStack output, float experience) {
new SmeltingRecipeBuilder(GTCEu.id(regName.toLowerCase(Locale.ROOT))).input(input).output(output).cookingTime(200).experience(experience).save(provider);
public static void addSmeltingRecipe(Consumer<FinishedRecipe> provider, @Nonnull ResourceLocation regName, TagKey<Item> input, ItemStack output, float experience) {
new SmeltingRecipeBuilder(regName).input(input).output(output).cookingTime(200).experience(experience).save(provider);
}

public static void addBlastingRecipe(Consumer<FinishedRecipe> provider, @Nonnull String regName, TagKey<Item> input, ItemStack output, float experience) {
new BlastingRecipeBuilder(GTCEu.id(regName.toLowerCase(Locale.ROOT))).input(input).output(output).cookingTime(100).experience(experience).save(provider);
addBlastingRecipe(provider, GTCEu.id(regName.toLowerCase(Locale.ROOT)), input, output, experience);
}

public static void addBlastingRecipe(Consumer<FinishedRecipe> provider, @Nonnull ResourceLocation regName, TagKey<Item> input, ItemStack output, float experience) {
new BlastingRecipeBuilder(regName).input(input).output(output).cookingTime(100).experience(experience).save(provider);
}

public static void addSmokingRecipe(Consumer<FinishedRecipe> provider, @Nonnull String regName, TagKey<Item> input, ItemStack output, float experience) {
new SmokingRecipeBuilder(GTCEu.id(regName.toLowerCase(Locale.ROOT))).input(input).output(output).cookingTime(100).experience(experience).save(provider);
addSmokingRecipe(provider, GTCEu.id(regName.toLowerCase(Locale.ROOT)), input, output, experience);
}

public static void addSmokingRecipe(Consumer<FinishedRecipe> provider, @Nonnull ResourceLocation regName, TagKey<Item> input, ItemStack output, float experience) {
new SmokingRecipeBuilder(regName).input(input).output(output).cookingTime(100).experience(experience).save(provider);
}

public static void addSmeltingRecipe(Consumer<FinishedRecipe> provider, @Nonnull String regName, ItemStack input, ItemStack output) {
addSmeltingRecipe(provider, regName, input, output, 0.0f);
addSmeltingRecipe(provider, GTCEu.id(regName.toLowerCase(Locale.ROOT)), input, output, 0.0f);
}

public static void addSmeltingRecipe(Consumer<FinishedRecipe> provider, @Nonnull String regName, ItemStack input, ItemStack output, float experience) {
new SmeltingRecipeBuilder(GTCEu.id(regName.toLowerCase(Locale.ROOT))).input(input).output(output).cookingTime(200).experience(experience).save(provider);
addSmeltingRecipe(provider, GTCEu.id(regName.toLowerCase(Locale.ROOT)), input, output, experience);
}

public static void addSmeltingRecipe(Consumer<FinishedRecipe> provider, @Nonnull ResourceLocation regName, ItemStack input, ItemStack output, float experience) {
new SmeltingRecipeBuilder(regName).input(input).output(output).cookingTime(200).experience(experience).save(provider);
}

private static final Char2ObjectMap<TagKey<Item>> TOOLS = new Char2ObjectArrayMap<>();
Expand All @@ -74,10 +91,18 @@ public static void addSmeltingRecipe(Consumer<FinishedRecipe> provider, @Nonnull
}

public static void addShapedRecipe(Consumer<FinishedRecipe> provider, @Nonnull String regName, @Nonnull ItemStack result, @Nonnull Object... recipe) {
addShapedRecipe(provider, GTCEu.id(regName.toLowerCase(Locale.ROOT)), result, recipe);
}

public static void addShapedRecipe(Consumer<FinishedRecipe> provider, @Nonnull ResourceLocation regName, @Nonnull ItemStack result, @Nonnull Object... recipe) {
addShapedRecipe(provider, false, regName, result, recipe);
}

public static void addStrictShapedRecipe(Consumer<FinishedRecipe> provider, @Nonnull String regName, @Nonnull ItemStack result, @Nonnull Object... recipe) {
addStrictShapedRecipe(provider, GTCEu.id(regName.toLowerCase(Locale.ROOT)), result, recipe);
}

public static void addStrictShapedRecipe(Consumer<FinishedRecipe> provider, @Nonnull ResourceLocation regName, @Nonnull ItemStack result, @Nonnull Object... recipe) {
addStrictShapedRecipe(provider, false, regName, result, recipe);
}

Expand Down Expand Up @@ -106,8 +131,8 @@ public static void addStrictShapedRecipe(Consumer<FinishedRecipe> provider, @Non
* @param result the output for the recipe
* @param recipe the contents of the recipe
*/
public static void addShapedRecipe(Consumer<FinishedRecipe> provider, boolean withUnificationData, boolean isStrict, @Nonnull String regName, @Nonnull ItemStack result, @Nonnull Object... recipe) {
var builder = new ShapedRecipeBuilder(GTCEu.id(regName.toLowerCase(Locale.ROOT))).output(result);
public static void addShapedRecipe(Consumer<FinishedRecipe> provider, boolean withUnificationData, boolean isStrict, @Nonnull ResourceLocation regName, @Nonnull ItemStack result, @Nonnull Object... recipe) {
var builder = new ShapedRecipeBuilder(regName).output(result);
builder.isStrict(isStrict);
CharSet set = new CharOpenHashSet();
for (int i = 0; i < recipe.length; i++) {
Expand Down Expand Up @@ -151,16 +176,20 @@ public static void addShapedRecipe(Consumer<FinishedRecipe> provider, boolean wi
}
}

public static void addShapedRecipe(Consumer<FinishedRecipe> provider, boolean withUnificationData, @Nonnull String regName, @Nonnull ItemStack result, @Nonnull Object... recipe) {
public static void addShapedRecipe(Consumer<FinishedRecipe> provider, boolean withUnificationData, @Nonnull ResourceLocation regName, @Nonnull ItemStack result, @Nonnull Object... recipe) {
addShapedRecipe(provider, withUnificationData, false, regName, result, recipe);
}

public static void addStrictShapedRecipe(Consumer<FinishedRecipe> provider, boolean withUnificationData, @Nonnull String regName, @Nonnull ItemStack result, @Nonnull Object... recipe) {
public static void addStrictShapedRecipe(Consumer<FinishedRecipe> provider, boolean withUnificationData, @Nonnull ResourceLocation regName, @Nonnull ItemStack result, @Nonnull Object... recipe) {
addShapedRecipe(provider, withUnificationData, true, regName, result, recipe);
}

public static void addShapelessRecipe(Consumer<FinishedRecipe> provider, @Nonnull String regName, @Nonnull ItemStack result, @Nonnull Object... recipe) {
var builder = new ShapelessRecipeBuilder(GTCEu.id(regName.toLowerCase(Locale.ROOT))).output(result);
addShapelessRecipe(provider, GTCEu.id(regName.toLowerCase(Locale.ROOT)), result, recipe);
}

public static void addShapelessRecipe(Consumer<FinishedRecipe> provider, @Nonnull ResourceLocation regName, @Nonnull ItemStack result, @Nonnull Object... recipe) {
var builder = new ShapelessRecipeBuilder(regName).output(result);
for (Object content : recipe) {
if (content instanceof Ingredient ingredient) {
builder.requires(ingredient);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.data.recipe.misc;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper;
import com.gregtechceu.gtceu.api.data.chemical.material.stack.UnificationEntry;
import com.gregtechceu.gtceu.api.recipe.FacadeCoverRecipe;
Expand Down Expand Up @@ -85,8 +86,8 @@ public static void init(Consumer<FinishedRecipe> provider) {

VanillaRecipeHelper.addShapedRecipe(provider, "blacklight", BLACKLIGHT.asStack(), "SPS", "GRG", "CPK", 'S', new UnificationEntry(screw, TungstenCarbide), 'P', new UnificationEntry(plate, TungstenCarbide), 'G', GTBlocks.CASING_LAMINATED_GLASS.asStack(), 'R', new UnificationEntry(spring, Europium), 'C', CustomTags.IV_CIRCUITS, 'K', new UnificationEntry(cableGtSingle, Platinum));

VanillaRecipeHelper.addShapedRecipe(provider, true, "filter_casing", GTBlocks.FILTER_CASING.asStack(), "BBB", "III", "MFR", 'B', new ItemStack(Blocks.IRON_BARS), 'I', ITEM_FILTER.asStack(), 'M', ELECTRIC_MOTOR_MV.asStack(), 'F', new UnificationEntry(frameGt, Steel), 'R', new UnificationEntry(rotor, Steel));
VanillaRecipeHelper.addShapedRecipe(provider, true, "filter_casing_sterile", GTBlocks.FILTER_CASING_STERILE.asStack(), "BEB", "ISI", "MFR", 'B', new UnificationEntry(pipeLargeFluid, Polybenzimidazole), 'E', EMITTER_ZPM.asStack(), 'I', ITEM_FILTER.asStack(), 'S', BLACKLIGHT.asStack(), 'M', ELECTRIC_MOTOR_ZPM.asStack(), 'F', new UnificationEntry(frameGt, Tritanium), 'R', new UnificationEntry(rotor, NaquadahAlloy));
VanillaRecipeHelper.addShapedRecipe(provider, true, GTCEu.id("filter_casing"), GTBlocks.FILTER_CASING.asStack(), "BBB", "III", "MFR", 'B', new ItemStack(Blocks.IRON_BARS), 'I', ITEM_FILTER.asStack(), 'M', ELECTRIC_MOTOR_MV.asStack(), 'F', new UnificationEntry(frameGt, Steel), 'R', new UnificationEntry(rotor, Steel));
VanillaRecipeHelper.addShapedRecipe(provider, true, GTCEu.id("filter_casing_sterile"), GTBlocks.FILTER_CASING_STERILE.asStack(), "BEB", "ISI", "MFR", 'B', new UnificationEntry(pipeLargeFluid, Polybenzimidazole), 'E', EMITTER_ZPM.asStack(), 'I', ITEM_FILTER.asStack(), 'S', BLACKLIGHT.asStack(), 'M', ELECTRIC_MOTOR_ZPM.asStack(), 'F', new UnificationEntry(frameGt, Tritanium), 'R', new UnificationEntry(rotor, NaquadahAlloy));

///////////////////////////////////////////////////
// Shapes and Molds //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ public class GTRegistriesDatapackGenerator extends RegistriesDatapackGenerator {
private final CompletableFuture<HolderLookup.Provider> registries;
private final java.util.function.Predicate<String> namespacePredicate;

private GTRegistriesDatapackGenerator(String name, PackOutput output, CompletableFuture<Provider> registries) {
private GTRegistriesDatapackGenerator(String name, PackOutput output, CompletableFuture<Provider> registries, Set<String> modIds) {
super(output, registries);
this.name = name;
this.namespacePredicate = Set.of(GTCEu.MOD_ID)::contains;
this.namespacePredicate = modIds::contains;
this.registries = registries;
this.output = output;
}

public GTRegistriesDatapackGenerator(PackOutput output, CompletableFuture<Provider> registries, RegistrySetBuilder builder, String name) {
this(name, output, registries.thenApply(r -> constructRegistries(r, builder)));
public GTRegistriesDatapackGenerator(PackOutput output, CompletableFuture<Provider> registries, RegistrySetBuilder builder, Set<String> modIds, String name) {
this(name, output, registries.thenApply(r -> constructRegistries(r, builder)), modIds);
}

/**
Expand Down
Loading

0 comments on commit 84430f2

Please sign in to comment.