dont use pack instance where unneeded

This commit is contained in:
dfsek
2021-07-20 15:12:06 -07:00
parent d807abb165
commit 0ff6a9cce1
10 changed files with 11 additions and 29 deletions
@@ -13,13 +13,11 @@ import com.dfsek.terra.api.world.biome.TerraBiome;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BiomeConfigType implements ConfigType<BiomeTemplate, TerraBiome> { public class BiomeConfigType implements ConfigType<BiomeTemplate, TerraBiome> {
private final ConfigPack pack;
private final BiomeFactory factory; private final BiomeFactory factory;
public static final TypeKey<TerraBiome> BIOME_TYPE_TOKEN = new TypeKey<>() {}; public static final TypeKey<TerraBiome> BIOME_TYPE_TOKEN = new TypeKey<>() {};
public BiomeConfigType(ConfigPack pack) { public BiomeConfigType(ConfigPack pack) {
this.pack = pack;
this.factory = new BiomeFactory(pack); this.factory = new BiomeFactory(pack);
} }
@@ -40,7 +38,7 @@ public class BiomeConfigType implements ConfigType<BiomeTemplate, TerraBiome> {
@Override @Override
public Supplier<OpenRegistry<TerraBiome>> registrySupplier(ConfigPack pack) { public Supplier<OpenRegistry<TerraBiome>> registrySupplier(ConfigPack pack) {
return () -> this.pack.getRegistryFactory().create(registry -> (TypeLoader<TerraBiome>) (t, c, loader) -> { return () -> pack.getRegistryFactory().create(registry -> (TypeLoader<TerraBiome>) (t, c, loader) -> {
if(c.equals("SELF")) return null; if(c.equals("SELF")) return null;
TerraBiome obj = registry.get((String) c); TerraBiome obj = registry.get((String) c);
if(obj == null) if(obj == null)
@@ -25,7 +25,7 @@ public class FloraAddon extends TerraAddon implements EventListener {
} }
public void onPackLoad(ConfigPackPreLoadEvent event) throws DuplicateEntryException { public void onPackLoad(ConfigPackPreLoadEvent event) throws DuplicateEntryException {
event.getPack().registerConfigType(new FloraConfigType(event.getPack()), "FLORA", 2); event.getPack().registerConfigType(new FloraConfigType(), "FLORA", 2);
event.getPack().applyLoader(BlockLayer.class, BlockLayerTemplate::new); event.getPack().applyLoader(BlockLayer.class, BlockLayerTemplate::new);
} }
} }
@@ -12,14 +12,9 @@ import java.util.function.Supplier;
public class FloraConfigType implements ConfigType<FloraTemplate, Flora> { public class FloraConfigType implements ConfigType<FloraTemplate, Flora> {
private final FloraFactory factory = new FloraFactory(); private final FloraFactory factory = new FloraFactory();
private final ConfigPack pack;
public static final TypeKey<Flora> FLORA_TYPE_TOKEN = new TypeKey<>(){}; public static final TypeKey<Flora> FLORA_TYPE_TOKEN = new TypeKey<>(){};
public FloraConfigType(ConfigPack pack) {
this.pack = pack;
}
@Override @Override
public FloraTemplate getTemplate(ConfigPack pack, TerraPlugin main) { public FloraTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
return new FloraTemplate(); return new FloraTemplate();
@@ -37,6 +32,6 @@ public class FloraConfigType implements ConfigType<FloraTemplate, Flora> {
@Override @Override
public Supplier<OpenRegistry<Flora>> registrySupplier(ConfigPack pack) { public Supplier<OpenRegistry<Flora>> registrySupplier(ConfigPack pack) {
return this.pack.getRegistryFactory()::create; return pack.getRegistryFactory()::create;
} }
} }
@@ -25,7 +25,7 @@ public class OreAddon extends TerraAddon implements EventListener {
} }
public void onPackLoad(ConfigPackPreLoadEvent event) throws DuplicateEntryException { public void onPackLoad(ConfigPackPreLoadEvent event) throws DuplicateEntryException {
event.getPack().registerConfigType(new OreConfigType(event.getPack()), "ORE", 1); event.getPack().registerConfigType(new OreConfigType(), "ORE", 1);
event.getPack().getOrCreateRegistry(GenerationStageProvider.class).register("ORE", pack -> new OrePopulator(main)); event.getPack().getOrCreateRegistry(GenerationStageProvider.class).register("ORE", pack -> new OrePopulator(main));
} }
} }
@@ -12,13 +12,8 @@ import java.util.function.Supplier;
public class OreConfigType implements ConfigType<OreTemplate, Ore> { public class OreConfigType implements ConfigType<OreTemplate, Ore> {
private final OreFactory factory = new OreFactory(); private final OreFactory factory = new OreFactory();
private final ConfigPack pack;
public static final TypeKey<Ore> ORE_TYPE_TOKEN = new TypeKey<>(){}; public static final TypeKey<Ore> ORE_TYPE_TOKEN = new TypeKey<>(){};
public OreConfigType(ConfigPack pack) {
this.pack = pack;
}
@Override @Override
public OreTemplate getTemplate(ConfigPack pack, TerraPlugin main) { public OreTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
return new OreTemplate(); return new OreTemplate();
@@ -36,6 +31,6 @@ public class OreConfigType implements ConfigType<OreTemplate, Ore> {
@Override @Override
public Supplier<OpenRegistry<Ore>> registrySupplier(ConfigPack pack) { public Supplier<OpenRegistry<Ore>> registrySupplier(ConfigPack pack) {
return this.pack.getRegistryFactory()::create; return pack.getRegistryFactory()::create;
} }
} }
@@ -24,7 +24,7 @@ public class PaletteAddon extends TerraAddon implements EventListener {
} }
public void onPackLoad(ConfigPackPreLoadEvent event) { public void onPackLoad(ConfigPackPreLoadEvent event) {
event.getPack().registerConfigType(new PaletteConfigType(event.getPack(), main), "PALETTE", 2); event.getPack().registerConfigType(new PaletteConfigType(main), "PALETTE", 2);
event.getPack().applyLoader(PaletteLayerHolder.class, new PaletteLayerLoader()); event.getPack().applyLoader(PaletteLayerHolder.class, new PaletteLayerLoader());
} }
} }
@@ -15,13 +15,11 @@ import java.util.function.Supplier;
public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> { public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> {
private final PaletteFactory factory = new PaletteFactory(); private final PaletteFactory factory = new PaletteFactory();
private final ConfigPack pack;
private final TerraPlugin main; private final TerraPlugin main;
public static final TypeKey<Palette> PALETTE_TYPE_TOKEN = new TypeKey<>(){}; public static final TypeKey<Palette> PALETTE_TYPE_TOKEN = new TypeKey<>(){};
public PaletteConfigType(ConfigPack pack, TerraPlugin main) { public PaletteConfigType(TerraPlugin main) {
this.pack = pack;
this.main = main; this.main = main;
} }
@@ -42,7 +40,7 @@ public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> {
@Override @Override
public Supplier<OpenRegistry<Palette>> registrySupplier(ConfigPack pack) { public Supplier<OpenRegistry<Palette>> registrySupplier(ConfigPack pack) {
return () -> this.pack.getRegistryFactory().create(registry -> (TypeLoader<Palette>) (t, c, loader) -> { return () -> pack.getRegistryFactory().create(registry -> (TypeLoader<Palette>) (t, c, loader) -> {
if(((String) c).startsWith("BLOCK:")) if(((String) c).startsWith("BLOCK:"))
return new PaletteImpl.Singleton(main.getWorldHandle().createBlockData(((String) c).substring(6))); // Return single palette for BLOCK: shortcut. return new PaletteImpl.Singleton(main.getWorldHandle().createBlockData(((String) c).substring(6))); // Return single palette for BLOCK: shortcut.
Palette obj = registry.get((String) c); Palette obj = registry.get((String) c);
@@ -23,6 +23,6 @@ public class TreeAddon extends TerraAddon implements EventListener {
} }
public void onPackLoad(ConfigPackPreLoadEvent event) throws DuplicateEntryException { public void onPackLoad(ConfigPackPreLoadEvent event) throws DuplicateEntryException {
event.getPack().registerConfigType(new TreeConfigType(event.getPack()), "TREE", 2); event.getPack().registerConfigType(new TreeConfigType(), "TREE", 2);
} }
} }
@@ -12,12 +12,8 @@ import java.util.function.Supplier;
public class TreeConfigType implements ConfigType<TreeTemplate, Tree> { public class TreeConfigType implements ConfigType<TreeTemplate, Tree> {
private final TreeFactory factory = new TreeFactory(); private final TreeFactory factory = new TreeFactory();
private final ConfigPack pack;
public static final TypeKey<Tree> TREE_TYPE_TOKEN = new TypeKey<>(){}; public static final TypeKey<Tree> TREE_TYPE_TOKEN = new TypeKey<>(){};
public TreeConfigType(ConfigPack pack) {
this.pack = pack;
}
@Override @Override
public TreeTemplate getTemplate(ConfigPack pack, TerraPlugin main) { public TreeTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
@@ -36,6 +32,6 @@ public class TreeConfigType implements ConfigType<TreeTemplate, Tree> {
@Override @Override
public Supplier<OpenRegistry<Tree>> registrySupplier(ConfigPack pack) { public Supplier<OpenRegistry<Tree>> registrySupplier(ConfigPack pack) {
return this.pack.getRegistryFactory()::create; return pack.getRegistryFactory()::create;
} }
} }
@@ -191,7 +191,7 @@ public class ConfigPackImpl implements ConfigPack {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private ConfigTypeRegistry createRegistry() { private ConfigTypeRegistry createRegistry() {
return new ConfigTypeRegistry(main, (id, configType) -> { return new ConfigTypeRegistry(main, (id, configType) -> {
OpenRegistry<?> openRegistry = configType.registrySupplier().get(); OpenRegistry<?> openRegistry = configType.registrySupplier(this).get();
if(registryMap.containsKey(configType.getTypeClass().getType())) { // Someone already registered something; we need to copy things to the new registry. if(registryMap.containsKey(configType.getTypeClass().getType())) { // Someone already registered something; we need to copy things to the new registry.
registryMap.get(configType.getTypeClass().getType()).getLeft().forEach(((OpenRegistry<Object>) openRegistry)::register); registryMap.get(configType.getTypeClass().getType()).getLeft().forEach(((OpenRegistry<Object>) openRegistry)::register);
} }