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

View File

@@ -13,13 +13,11 @@ import com.dfsek.terra.api.world.biome.TerraBiome;
import java.util.function.Supplier;
public class BiomeConfigType implements ConfigType<BiomeTemplate, TerraBiome> {
private final ConfigPack pack;
private final BiomeFactory factory;
public static final TypeKey<TerraBiome> BIOME_TYPE_TOKEN = new TypeKey<>() {};
public BiomeConfigType(ConfigPack pack) {
this.pack = pack;
this.factory = new BiomeFactory(pack);
}
@@ -40,7 +38,7 @@ public class BiomeConfigType implements ConfigType<BiomeTemplate, TerraBiome> {
@Override
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;
TerraBiome obj = registry.get((String) c);
if(obj == null)

View File

@@ -25,7 +25,7 @@ public class FloraAddon extends TerraAddon implements EventListener {
}
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);
}
}

View File

@@ -12,14 +12,9 @@ import java.util.function.Supplier;
public class FloraConfigType implements ConfigType<FloraTemplate, Flora> {
private final FloraFactory factory = new FloraFactory();
private final ConfigPack pack;
public static final TypeKey<Flora> FLORA_TYPE_TOKEN = new TypeKey<>(){};
public FloraConfigType(ConfigPack pack) {
this.pack = pack;
}
@Override
public FloraTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
return new FloraTemplate();
@@ -37,6 +32,6 @@ public class FloraConfigType implements ConfigType<FloraTemplate, Flora> {
@Override
public Supplier<OpenRegistry<Flora>> registrySupplier(ConfigPack pack) {
return this.pack.getRegistryFactory()::create;
return pack.getRegistryFactory()::create;
}
}

View File

@@ -25,7 +25,7 @@ public class OreAddon extends TerraAddon implements EventListener {
}
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));
}
}

View File

@@ -12,13 +12,8 @@ import java.util.function.Supplier;
public class OreConfigType implements ConfigType<OreTemplate, Ore> {
private final OreFactory factory = new OreFactory();
private final ConfigPack pack;
public static final TypeKey<Ore> ORE_TYPE_TOKEN = new TypeKey<>(){};
public OreConfigType(ConfigPack pack) {
this.pack = pack;
}
@Override
public OreTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
return new OreTemplate();
@@ -36,6 +31,6 @@ public class OreConfigType implements ConfigType<OreTemplate, Ore> {
@Override
public Supplier<OpenRegistry<Ore>> registrySupplier(ConfigPack pack) {
return this.pack.getRegistryFactory()::create;
return pack.getRegistryFactory()::create;
}
}

View File

@@ -24,7 +24,7 @@ public class PaletteAddon extends TerraAddon implements EventListener {
}
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());
}
}

View File

@@ -15,13 +15,11 @@ import java.util.function.Supplier;
public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> {
private final PaletteFactory factory = new PaletteFactory();
private final ConfigPack pack;
private final TerraPlugin main;
public static final TypeKey<Palette> PALETTE_TYPE_TOKEN = new TypeKey<>(){};
public PaletteConfigType(ConfigPack pack, TerraPlugin main) {
this.pack = pack;
public PaletteConfigType(TerraPlugin main) {
this.main = main;
}
@@ -42,7 +40,7 @@ public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> {
@Override
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:"))
return new PaletteImpl.Singleton(main.getWorldHandle().createBlockData(((String) c).substring(6))); // Return single palette for BLOCK: shortcut.
Palette obj = registry.get((String) c);

View File

@@ -23,6 +23,6 @@ public class TreeAddon extends TerraAddon implements EventListener {
}
public void onPackLoad(ConfigPackPreLoadEvent event) throws DuplicateEntryException {
event.getPack().registerConfigType(new TreeConfigType(event.getPack()), "TREE", 2);
event.getPack().registerConfigType(new TreeConfigType(), "TREE", 2);
}
}

View File

@@ -12,12 +12,8 @@ import java.util.function.Supplier;
public class TreeConfigType implements ConfigType<TreeTemplate, Tree> {
private final TreeFactory factory = new TreeFactory();
private final ConfigPack pack;
public static final TypeKey<Tree> TREE_TYPE_TOKEN = new TypeKey<>(){};
public TreeConfigType(ConfigPack pack) {
this.pack = pack;
}
@Override
public TreeTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
@@ -36,6 +32,6 @@ public class TreeConfigType implements ConfigType<TreeTemplate, Tree> {
@Override
public Supplier<OpenRegistry<Tree>> registrySupplier(ConfigPack pack) {
return this.pack.getRegistryFactory()::create;
return pack.getRegistryFactory()::create;
}
}

View File

@@ -191,7 +191,7 @@ public class ConfigPackImpl implements ConfigPack {
@SuppressWarnings("unchecked")
private ConfigTypeRegistry createRegistry() {
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.
registryMap.get(configType.getTypeClass().getType()).getLeft().forEach(((OpenRegistry<Object>) openRegistry)::register);
}