~williewillus/violet-moon

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH botania] Move Brew registry source of truth out of BotaniaBrews

Details
Message ID
<20230519045228.530126-1-vincent@vincent-lee.net>
DKIM signature
missing
Download raw message
Patch: +22 -10
Closes #4264
---
Dependency order is now:
BotaniaAPI/BotaniaBrews -> XplatAbstractions -> internal RegistryHolder

 .../botania/fabric/xplat/FabricXplatImpl.java       | 11 +++++++++--
 .../vazkii/botania/forge/xplat/ForgeXplatImpl.java  | 13 +++++++++----
 .../vazkii/botania/common/brew/BotaniaBrews.java    |  2 +-
 .../vazkii/botania/common/impl/BotaniaAPIImpl.java  |  4 ++--
 .../vazkii/botania/xplat/XplatAbstractions.java     |  2 +-
 5 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/Fabric/src/main/java/vazkii/botania/fabric/xplat/FabricXplatImpl.java b/Fabric/src/main/java/vazkii/botania/fabric/xplat/FabricXplatImpl.java
index 2d27174bc..d5c1d40f0 100644
--- a/Fabric/src/main/java/vazkii/botania/fabric/xplat/FabricXplatImpl.java
+++ b/Fabric/src/main/java/vazkii/botania/fabric/xplat/FabricXplatImpl.java
@@ -500,8 +500,15 @@ public <T extends AbstractContainerMenu> MenuType<T> createMenuType(TriFunction<
	}

	@Override
	public Registry<Brew> createBrewRegistry() {
		return FabricRegistryBuilder.createDefaulted(Brew.class, prefix("brews"), prefix("fallback")).buildAndRegister();
	public Registry<Brew> getOrCreateBrewRegistry() {
		return RegistryHolder.BREW;
	}

	// static final field of an inner class provides:
	// - at most once initialization
	// - synchronization/serialization of concurrent accesses
	private static class RegistryHolder {
		public static final Registry<Brew> BREW = FabricRegistryBuilder.createDefaulted(Brew.class, prefix("brews"), prefix("fallback")).buildAndRegister();
	}

	@Nullable
diff --git a/Forge/src/main/java/vazkii/botania/forge/xplat/ForgeXplatImpl.java b/Forge/src/main/java/vazkii/botania/forge/xplat/ForgeXplatImpl.java
index 74c1590fc..c2622c7db 100644
--- a/Forge/src/main/java/vazkii/botania/forge/xplat/ForgeXplatImpl.java
+++ b/Forge/src/main/java/vazkii/botania/forge/xplat/ForgeXplatImpl.java
@@ -501,10 +501,15 @@ public <T extends AbstractContainerMenu> MenuType<T> createMenuType(TriFunction<
	}

	@Override
	public Registry<Brew> createBrewRegistry() {
		// The registryKey really belongs on BotaniaBrews, but this method is called from there,
		// so we'd like to avoid the circular dependency.
		return RegistryForgeAccessor.callRegisterDefaulted(ResourceKey.createRegistryKey(prefix("brews")),
	public Registry<Brew> getOrCreateBrewRegistry() {
		return RegistryHolder.BREW;
	}

	// static final field of an inner class provides:
	// - at most once initialization
	// - synchronization/serialization of concurrent accesses
	private static class RegistryHolder {
		public static final Registry<Brew> BREW = RegistryForgeAccessor.callRegisterDefaulted(ResourceKey.createRegistryKey(prefix("brews")),
				LibMisc.MOD_ID + ":fallback", registry -> BotaniaBrews.fallbackBrew);
	}

diff --git a/Xplat/src/main/java/vazkii/botania/common/brew/BotaniaBrews.java b/Xplat/src/main/java/vazkii/botania/common/brew/BotaniaBrews.java
index 0a4d86f2c..bd0b5ddcd 100644
--- a/Xplat/src/main/java/vazkii/botania/common/brew/BotaniaBrews.java
+++ b/Xplat/src/main/java/vazkii/botania/common/brew/BotaniaBrews.java
@@ -25,7 +25,6 @@

public class BotaniaBrews {

	public static final Registry<Brew> registry = XplatAbstractions.INSTANCE.createBrewRegistry();
	public static final Brew fallbackBrew = new Brew(0, 0).setNotBloodPendantInfusable().setNotIncenseInfusable();
	public static final Brew speed = new Brew(0x59B7FF, 4000, new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 1800, 1));
	public static final Brew strength = new Brew(0xEE3F3F, 4000, new MobEffectInstance(MobEffects.DAMAGE_BOOST, 1800, 1));
@@ -50,6 +49,7 @@ public class BotaniaBrews {
	public static final Brew clear = make(4000, new MobEffectInstance(BotaniaMobEffects.clear, 0, 0));

	public static void registerBrews() {
		Registry<Brew> registry = XplatAbstractions.INSTANCE.getOrCreateBrewRegistry();
		BiConsumer<Brew, ResourceLocation> r = (b, id) -> Registry.register(registry, id, b);
		r.accept(fallbackBrew, prefix("fallback"));
		r.accept(speed, prefix(LibBrewNames.SPEED));
diff --git a/Xplat/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java b/Xplat/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java
index d58182cdc..2cac1c6e3 100644
--- a/Xplat/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java
+++ b/Xplat/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java
@@ -36,13 +36,13 @@
import vazkii.botania.api.internal.ManaNetwork;
import vazkii.botania.client.fx.SparkleParticleData;
import vazkii.botania.common.block.flower.functional.SolegnoliaBlockEntity;
import vazkii.botania.common.brew.BotaniaBrews;
import vazkii.botania.common.handler.BotaniaSounds;
import vazkii.botania.common.handler.EquipmentHandler;
import vazkii.botania.common.handler.ManaNetworkHandler;
import vazkii.botania.common.integration.corporea.CorporeaNodeDetectors;
import vazkii.botania.common.item.BotaniaItems;
import vazkii.botania.common.item.relic.RingOfLokiItem;
import vazkii.botania.xplat.XplatAbstractions;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@@ -181,7 +181,7 @@ public int apiVersion() {

	@Override
	public Registry<Brew> getBrewRegistry() {
		return BotaniaBrews.registry;
		return XplatAbstractions.INSTANCE.getOrCreateBrewRegistry();
	}

	@Override
diff --git a/Xplat/src/main/java/vazkii/botania/xplat/XplatAbstractions.java b/Xplat/src/main/java/vazkii/botania/xplat/XplatAbstractions.java
index 4342d097a..56f715a5c 100644
--- a/Xplat/src/main/java/vazkii/botania/xplat/XplatAbstractions.java
+++ b/Xplat/src/main/java/vazkii/botania/xplat/XplatAbstractions.java
@@ -184,7 +184,7 @@ default Item.Properties noRepairOnForge(Item.Properties builder) {
	}

	<T extends AbstractContainerMenu> MenuType<T> createMenuType(TriFunction<Integer, Inventory, FriendlyByteBuf, T> constructor);
	Registry<Brew> createBrewRegistry();
	Registry<Brew> getOrCreateBrewRegistry();
	@Nullable
	EquipmentHandler tryCreateEquipmentHandler();

-- 
2.40.1

[botania/patches/linux.yml] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CSPZTHWJ3PDP.1ZE1OA3IX8XEJ@cirno2>
In-Reply-To
<20230519045228.530126-1-vincent@vincent-lee.net> (view parent)
DKIM signature
missing
Download raw message
botania/patches/linux.yml: SUCCESS in 16m19s

[Move Brew registry source of truth out of BotaniaBrews][0] from [Vincent Lee][1]

[0]: https://lists.sr.ht/~williewillus/violet-moon/patches/41267
[1]: vincent@vincent-lee.net

✓ #992271 SUCCESS botania/patches/linux.yml https://builds.sr.ht/~williewillus/job/992271
Details
Message ID
<aygpbi2ovky6kwdktv3cpynon4qtfoqck3lmjpxhx3rhg3pz5c@pzwpq7dvovfa>
In-Reply-To
<20230519045228.530126-1-vincent@vincent-lee.net> (view parent)
DKIM signature
missing
Download raw message
lgtm
Reply to thread Export thread (mbox)