Skip to content

Commit

Permalink
create NamedRegistry, move some logic to be INamed-based (#144)
Browse files Browse the repository at this point in the history
* move a number of things to INamed instead of IScriptReloadable

* move name logic to NamedRegistry

* remove now redundant info for ForgeRegistryWrapper

* simplify NamedRegistry

* make Thaumcraft Arcane Workbench use NR instead of VR

* make Vanilla stuff used NamedRegistry

* make reloading only happen once instead of every alias

* fix oredict

* make empty onReload instead use NamedRegistry

* avoid that one turkish casing bug for reviewer
  • Loading branch information
WaitingIdly authored Mar 25, 2024
1 parent 4f9916d commit 0aaec99
Show file tree
Hide file tree
Showing 36 changed files with 132 additions and 155 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/cleanroommc/groovyscript/api/INamed.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ default String getName() {
}
return aliases.iterator().next();
}

@GroovyBlacklist
default boolean isEnabled() {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,4 @@ public interface IScriptReloadable extends INamed {
@ApiStatus.OverrideOnly
void afterScriptLoad();

@GroovyBlacklist
default boolean isEnabled() {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cleanroommc.groovyscript.GroovyScript;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.registry.NamedRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
Expand All @@ -13,7 +14,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class Content {
public class Content extends NamedRegistry {

public CreativeTabs defaultTab;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.IScriptReloadable;
import com.cleanroommc.groovyscript.registry.NamedRegistry;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.util.Collection;
import java.util.Collections;

public class InWorldCrafting implements IScriptReloadable {
public class InWorldCrafting extends NamedRegistry implements IScriptReloadable {

public final FluidToFluid fluidToFluid = new FluidToFluid();
public final FluidToItem fluidToItem = new FluidToItem();
Expand Down Expand Up @@ -41,11 +39,6 @@ public void afterScriptLoad() {
this.pistonPush.afterScriptLoad();
}

@Override
public Collection<String> getAliases() {
return Collections.emptyList();
}

public static EntityItem spawnItem(World world, BlockPos pos, ItemStack item) {
EntityItem entityItem = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, item);
world.spawnEntity(entityItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.IScriptReloadable;
import com.cleanroommc.groovyscript.registry.NamedRegistry;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ResourceLocation;
Expand All @@ -10,11 +11,9 @@
import net.minecraftforge.fml.common.FMLCommonHandler;
import org.jetbrains.annotations.ApiStatus;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

public class Loot implements IScriptReloadable {
public class Loot extends NamedRegistry implements IScriptReloadable {

public Map<ResourceLocation, LootTable> tables = new Object2ObjectOpenHashMap<>();

Expand Down Expand Up @@ -43,8 +42,4 @@ public void afterScriptLoad() {
}
}

@Override
public Collection<String> getAliases() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@

public class ModPropertyContainer implements IDynamicGroovyProperty {

private final Map<String, IScriptReloadable> registries;
private final Map<String, INamed> registries;

public ModPropertyContainer() {
this.registries = new Object2ObjectOpenHashMap<>();
((IVirtualizedRegistrar) this::addRegistry).addFieldsOf(this);
}

protected void addRegistry(IScriptReloadable registry) {
protected void addRegistry(INamed registry) {
for (String alias : registry.getAliases()) {
this.registries.put(alias, registry);
}
}

public Collection<IScriptReloadable> getRegistries() {
public Collection<INamed> getRegistries() {
return registries.values();
}

@Override
public @Nullable Object getProperty(String name) {
IScriptReloadable registry = registries.get(name);
INamed registry = registries.get(name);
if (registry == null) {
GroovyLog.get().error("Attempted to access registry {}, but could not find a registry with that name", name);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.helper.EnumHelper;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
Expand All @@ -19,7 +18,7 @@
public class Accessory extends ForgeRegistryWrapper<AetherAccessory> {

public Accessory() {
super(GameRegistry.findRegistry(AetherAccessory.class), Alias.generateOfClass(Accessory.class));
super(GameRegistry.findRegistry(AetherAccessory.class));
}

@MethodDescription(type = MethodDescription.Type.ADDITION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
import com.gildedgames.the_aether.api.enchantments.AetherEnchantment;
Expand All @@ -15,7 +14,7 @@
public class Enchanter extends ForgeRegistryWrapper<AetherEnchantment> {

public Enchanter() {
super(GameRegistry.findRegistry(AetherEnchantment.class), Alias.generateOfClass(Enchanter.class));
super(GameRegistry.findRegistry(AetherEnchantment.class));
}

@RecipeBuilderDescription(example = @Example(".input(item('minecraft:clay')).output(item('minecraft:diamond')).time(200)"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.cleanroommc.groovyscript.api.documentation.annotations.Example;
import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
import com.gildedgames.the_aether.api.enchantments.AetherEnchantmentFuel;
import net.minecraft.item.ItemStack;
Expand All @@ -14,7 +13,7 @@
public class EnchanterFuel extends ForgeRegistryWrapper<AetherEnchantmentFuel> {

public EnchanterFuel() {
super(GameRegistry.findRegistry(AetherEnchantmentFuel.class), Alias.generateOfClass(EnchanterFuel.class));
super(GameRegistry.findRegistry(AetherEnchantmentFuel.class));
}

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("item('minecraft:blaze_rod'), 1000"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
import com.gildedgames.the_aether.api.freezables.AetherFreezable;
Expand All @@ -15,7 +14,7 @@
public class Freezer extends ForgeRegistryWrapper<AetherFreezable> {

public Freezer() {
super(GameRegistry.findRegistry(AetherFreezable.class), Alias.generateOfClass(Freezer.class));
super(GameRegistry.findRegistry(AetherFreezable.class));
}

@RecipeBuilderDescription(example = @Example(".input(item('minecraft:clay')).output(item('minecraft:dirt')).time(200)"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.cleanroommc.groovyscript.api.documentation.annotations.Example;
import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
import com.gildedgames.the_aether.api.freezables.AetherFreezableFuel;
import net.minecraft.item.ItemStack;
Expand All @@ -14,7 +13,7 @@
public class FreezerFuel extends ForgeRegistryWrapper<AetherFreezableFuel> {

public FreezerFuel() {
super(GameRegistry.findRegistry(AetherFreezableFuel.class), Alias.generateOfClass(FreezerFuel.class));
super(GameRegistry.findRegistry(AetherFreezableFuel.class));
}

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("item('minecraft:packed_ice'), 1000"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.helper.EnumHelper;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
Expand All @@ -19,7 +18,7 @@
public class Anvil extends ForgeRegistryWrapper<AnvilRecipe> {

public Anvil() {
super(ModuleTechBasic.Registries.ANVIL_RECIPE, Alias.generateOfClass(Anvil.class));
super(ModuleTechBasic.Registries.ANVIL_RECIPE);
}

@RecipeBuilderDescription(example = {
Expand All @@ -31,7 +30,7 @@ public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example(value = "'iron_to_clay', ore('ingotIron') * 5, item('minecraft:clay_ball') * 20, 9, 'granite', 'hammer'"))
@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("'iron_to_clay', ore('ingotIron') * 5, item('minecraft:clay_ball') * 20, 9, 'granite', 'hammer'"))
public AnvilRecipe add(String name, IIngredient input, ItemStack output, int hits, String tier, String type) {
AnvilRecipe.EnumTier enumTier = EnumHelper.valueOfNullable(AnvilRecipe.EnumTier.class, tier, false);
AnvilRecipe.EnumType enumType = EnumHelper.valueOfNullable(AnvilRecipe.EnumType.class, type, false);
Expand Down Expand Up @@ -66,7 +65,6 @@ public void removeByOutput(ItemStack output) {
remove(recipe);
}
}
;
}

@Property(property = "input", valid = @Comp("1"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
Expand All @@ -17,7 +16,7 @@
public class Barrel extends ForgeRegistryWrapper<BarrelRecipe> {

public Barrel() {
super(ModuleTechBasic.Registries.BARREL_RECIPE, Alias.generateOfClass(Barrel.class));
super(ModuleTechBasic.Registries.BARREL_RECIPE);
}

@RecipeBuilderDescription(example = @Example(
Expand All @@ -27,7 +26,7 @@ public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example(value = "'iron_dirt_water_to_lava', ore('ingotIron'), ore('ingotIron'), item('minecraft:dirt'), item('minecraft:dirt'), fluid('water'), fluid('lava'), 1000"))
@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("'iron_dirt_water_to_lava', ore('ingotIron'), ore('ingotIron'), item('minecraft:dirt'), item('minecraft:dirt'), fluid('water'), fluid('lava'), 1000"))
public BarrelRecipe add(String name, IIngredient input1, IIngredient input2, IIngredient input3, IIngredient input4, FluidStack fInput, FluidStack fOutput, int duration) {
return recipeBuilder()
.duration(duration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
Expand All @@ -16,15 +15,15 @@
public class Campfire extends ForgeRegistryWrapper<CampfireRecipe> {

public Campfire() {
super(ModuleTechBasic.Registries.CAMPFIRE_RECIPE, Alias.generateOfClass(Campfire.class));
super(ModuleTechBasic.Registries.CAMPFIRE_RECIPE);
}

@RecipeBuilderDescription(example = @Example(".input(item('minecraft:diamond')).output(item('minecraft:emerald')).duration(400).name('diamond_campfire_to_emerald')"))
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example(value = "'apple_to_dirt', item('minecraft:apple'), item('minecraft:dirt'), 1000"))
@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("'apple_to_dirt', item('minecraft:apple'), item('minecraft:dirt'), 1000"))
public CampfireRecipe add(String name, IIngredient input, ItemStack output, int duration) {
return recipeBuilder()
.duration(duration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
Expand All @@ -18,7 +17,7 @@
public class ChoppingBlock extends ForgeRegistryWrapper<ChoppingBlockRecipe> {

public ChoppingBlock() {
super(ModuleTechBasic.Registries.CHOPPING_BLOCK_RECIPE, Alias.generateOfClass(ChoppingBlock.class));
super(ModuleTechBasic.Registries.CHOPPING_BLOCK_RECIPE);
}


Expand Down Expand Up @@ -55,7 +54,6 @@ public void removeByOutput(IIngredient output) {
remove(recipe);
}
}
;
}

@Property(property = "input", valid = @Comp("1"))
Expand All @@ -67,7 +65,7 @@ public static class RecipeBuilder extends AbstractRecipeBuilder<ChoppingBlockRec
private final IntList chops = new IntArrayList();
private final IntList quantities = new IntArrayList();

@RecipeBuilderMethodDescription(field = {"chops, quantities"})
@RecipeBuilderMethodDescription(field = "chops, quantities")
public RecipeBuilder chops(int chops, int quantities) {
this.chops.add(chops);
this.quantities.add(quantities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
Expand All @@ -17,15 +16,15 @@ public class CompactingBin extends ForgeRegistryWrapper<CompactingBinRecipe> {


public CompactingBin() {
super(ModuleTechBasic.Registries.COMPACTING_BIN_RECIPE, Alias.generateOfClass(CompactingBin.class));
super(ModuleTechBasic.Registries.COMPACTING_BIN_RECIPE);
}

@RecipeBuilderDescription(example = @Example(".input(item('minecraft:diamond')).output(item('minecraft:emerald')).toolUses(5).name('diamond_to_emerald_compacting_bin')"))
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example(value = "'iron_to_clay', ore('ingotIron') * 5, item('minecraft:clay_ball') * 20, 9"))
@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("'iron_to_clay', ore('ingotIron') * 5, item('minecraft:clay_ball') * 20, 9"))
public CompactingBinRecipe add(String name, IIngredient input, ItemStack output, int hits) {
return recipeBuilder()
.toolUses(hits)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
Expand All @@ -18,15 +17,15 @@ public class CompostBin extends ForgeRegistryWrapper<CompostBinRecipe> {


public CompostBin() {
super(ModuleTechBasic.Registries.COMPOST_BIN_RECIPE, Alias.generateOfClass(CompostBin.class));
super(ModuleTechBasic.Registries.COMPOST_BIN_RECIPE);
}

@RecipeBuilderDescription(example = @Example(".input(item('minecraft:diamond')).output(item('minecraft:emerald') * 4).compostValue(25).name('diamond_to_emerald_compost_bin')"))
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example(value = "'iron_to_clay2', ore('ingotIron') * 5, item('minecraft:clay_ball') * 20, 2"))
@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("'iron_to_clay2', ore('ingotIron') * 5, item('minecraft:clay_ball') * 20, 2"))
public CompostBinRecipe add(String name, IIngredient input, ItemStack output, int compostValue) {
return recipeBuilder()
.compostValue(compostValue)
Expand Down Expand Up @@ -64,7 +63,6 @@ public void removeByOutput(IIngredient output) {
remove(recipe);
}
}
;
}

@Property(property = "input", valid = @Comp("1"))
Expand Down
Loading

0 comments on commit 0aaec99

Please sign in to comment.