From 2bac81d313f5d32da52c67fef230b36dfcc4e9f7 Mon Sep 17 00:00:00 2001 From: omergunr100 Date: Mon, 30 Dec 2024 11:01:09 +0200 Subject: [PATCH] capitalized properly mod names. replace xei loaded checks in jei loaded check with just the isModLoaded check. moved frozen registry shenanigans to GTRegistries and an event listener to replace the mixin (seems to be working fine). --- .../java/com/gregtechceu/gtceu/GTCEu.java | 34 +++-------------- .../gtceu/api/gui/misc/IGhostFluidTarget.java | 6 +-- .../gtceu/api/gui/misc/IGhostItemTarget.java | 4 +- .../api/gui/widget/PatternPreviewWidget.java | 4 +- .../api/gui/widget/PhantomFluidWidget.java | 10 ++--- .../api/gui/widget/PhantomSlotWidget.java | 8 ++-- .../gtceu/api/gui/widget/SlotWidget.java | 36 +++++++++--------- .../gtceu/api/gui/widget/TankWidget.java | 38 +++++++++---------- .../recipe/content/IContentSerializer.java | 5 ++- .../gtceu/api/recipe/ui/GTRecipeTypeUI.java | 8 ++-- .../gtceu/api/registry/GTRegistries.java | 23 ++++++++++- .../packets/SPacketSyncBedrockOreVeins.java | 5 ++- .../packets/SPacketSyncFluidVeins.java | 5 ++- .../network/packets/SPacketSyncOreVeins.java | 5 ++- .../gtceu/core/mixins/WorldLoaderMixin.java | 31 --------------- .../gtceu/forge/ForgeCommonEventListener.java | 5 +++ .../gtceu/integration/jei/GTJEIPlugin.java | 8 ++-- .../xei/widgets/GTRecipeWidget.java | 2 +- src/main/resources/gtceu.mixins.json | 1 - 19 files changed, 106 insertions(+), 132 deletions(-) delete mode 100644 src/main/java/com/gregtechceu/gtceu/core/mixins/WorldLoaderMixin.java diff --git a/src/main/java/com/gregtechceu/gtceu/GTCEu.java b/src/main/java/com/gregtechceu/gtceu/GTCEu.java index e843756b2e..09fd3c85c3 100644 --- a/src/main/java/com/gregtechceu/gtceu/GTCEu.java +++ b/src/main/java/com/gregtechceu/gtceu/GTCEu.java @@ -7,8 +7,6 @@ import com.gregtechceu.gtceu.utils.FormattingUtil; import net.minecraft.client.Minecraft; -import net.minecraft.core.RegistryAccess; -import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraftforge.fml.DistExecutor; @@ -21,7 +19,6 @@ import dev.emi.emi.config.EmiConfig; import me.shedaniel.rei.api.client.REIRuntime; -import org.jetbrains.annotations.ApiStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,9 +31,6 @@ public class GTCEu { public static final String NAME = "GregTechCEu"; public static final Logger LOGGER = LoggerFactory.getLogger(NAME); - private static final RegistryAccess BLANK = RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY); - private static RegistryAccess FROZEN = BLANK; - public GTCEu() { GTCEu.init(); GTCEuAPI.instance = this; @@ -67,25 +61,6 @@ public static ResourceLocation appendId(String id) { return new ResourceLocation(strings[0], strings[1]); } - /** - * You shouldn't call it, you should probably not even look at it just to be extra safe - * - * @param registryAccess the new value to set to the frozen registry access - */ - @ApiStatus.Internal - public static void updateFrozenRegistry(RegistryAccess registryAccess) { - FROZEN = registryAccess; - } - - public static RegistryAccess getFrozenRegistry() { - if (FROZEN == BLANK && isClientThread()) { - if (Minecraft.getInstance().getConnection() != null) { - return Minecraft.getInstance().getConnection().registryAccess(); - } - } - return FROZEN; - } - /** * @return if we're running in a production environment */ @@ -164,15 +139,16 @@ public static Path getGameDir() { public static class Mods { - public static boolean isJeiLoaded() { - return !(isEmiLoaded() || isReiLoaded()) && isModLoaded(GTValues.MODID_JEI); + public static boolean isJEILoaded() { + return !(isModLoaded(GTValues.MODID_EMI) || isModLoaded(GTValues.MODID_REI)) && + isModLoaded(GTValues.MODID_JEI); } - public static boolean isReiLoaded() { + public static boolean isREILoaded() { return isModLoaded(GTValues.MODID_REI) && !(isClientSide() || REIRuntime.getInstance().isOverlayVisible()); } - public static boolean isEmiLoaded() { + public static boolean isEMILoaded() { return isModLoaded(GTValues.MODID_EMI) && !(isClientSide() || EmiConfig.enabled); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java index 634f0a6815..3324b34e81 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java @@ -62,17 +62,17 @@ public void accept(@NotNull Object ingredient) { } default Object convertIngredient(Object ingredient) { - if (GTCEu.Mods.isReiLoaded() && ingredient instanceof dev.architectury.fluid.FluidStack fluidStack) { + if (GTCEu.Mods.isREILoaded() && ingredient instanceof dev.architectury.fluid.FluidStack fluidStack) { ingredient = new FluidStack(fluidStack.getFluid(), (int) fluidStack.getAmount(), fluidStack.getTag()); } - if (GTCEu.Mods.isEmiLoaded() && ingredient instanceof EmiStack fluidEmiStack) { + if (GTCEu.Mods.isEMILoaded() && ingredient instanceof EmiStack fluidEmiStack) { Fluid fluid = fluidEmiStack.getKeyOfType(Fluid.class); ingredient = fluid == null ? FluidStack.EMPTY : new FluidStack(fluid, (int) fluidEmiStack.getAmount(), fluidEmiStack.getNbt()); } - if (GTCEu.Mods.isJeiLoaded() && ingredient instanceof net.minecraftforge.fluids.FluidStack fluidStack) { + if (GTCEu.Mods.isJEILoaded() && ingredient instanceof net.minecraftforge.fluids.FluidStack fluidStack) { ingredient = new FluidStack(fluidStack.getFluid(), fluidStack.getAmount(), fluidStack.getTag()); } return ingredient; diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostItemTarget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostItemTarget.java index 13c67de926..e26f1e3052 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostItemTarget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostItemTarget.java @@ -53,7 +53,7 @@ public void accept(@NotNull Object ingredient) { } default Object convertIngredient(Object ingredient) { - if (GTCEu.Mods.isEmiLoaded() && ingredient instanceof EmiStack itemEmiStack) { + if (GTCEu.Mods.isEMILoaded() && ingredient instanceof EmiStack itemEmiStack) { Item item = itemEmiStack.getKeyOfType(Item.class); ItemStack itemStack = item == null ? ItemStack.EMPTY : new ItemStack(item, (int) itemEmiStack.getAmount()); if (!itemStack.isEmpty()) { @@ -62,7 +62,7 @@ default Object convertIngredient(Object ingredient) { ingredient = itemStack; } - if (GTCEu.Mods.isJeiLoaded() && ingredient instanceof ITypedIngredient itemJeiStack) { + if (GTCEu.Mods.isJEILoaded() && ingredient instanceof ITypedIngredient itemJeiStack) { return itemJeiStack.getItemStack().orElse(ItemStack.EMPTY); } return ingredient; diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PatternPreviewWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PatternPreviewWidget.java index 9f5e6d6172..54d1667b98 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PatternPreviewWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PatternPreviewWidget.java @@ -254,10 +254,10 @@ public static BlockPos locateNextRegion(int range) { public void updateScreen() { super.updateScreen(); // I can only think of this way - if (!isLoaded && GTCEu.Mods.isEmiLoaded() && Minecraft.getInstance().screen instanceof RecipeScreen) { + if (!isLoaded && GTCEu.Mods.isEMILoaded() && Minecraft.getInstance().screen instanceof RecipeScreen) { setPage(0); isLoaded = true; - } else if (!isLoaded && GTCEu.Mods.isReiLoaded() && + } else if (!isLoaded && GTCEu.Mods.isREILoaded() && Minecraft.getInstance().screen instanceof AbstractDisplayViewingScreen) { setPage(0); isLoaded = true; diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java index 861efb129c..d20076126d 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java @@ -101,9 +101,9 @@ public static FluidStack drainFrom(Object ingredient) { @Override @OnlyIn(Dist.CLIENT) public List getPhantomTargets(Object ingredient) { - if (GTCEu.Mods.isReiLoaded() && ingredient instanceof dev.architectury.fluid.FluidStack fluidStack) { + if (GTCEu.Mods.isREILoaded() && ingredient instanceof dev.architectury.fluid.FluidStack fluidStack) { ingredient = new FluidStack(fluidStack.getFluid(), (int) fluidStack.getAmount(), fluidStack.getTag()); - } else if (GTCEu.Mods.isEmiLoaded() && ingredient instanceof EmiStack emiStack) { + } else if (GTCEu.Mods.isEMILoaded() && ingredient instanceof EmiStack emiStack) { var key = emiStack.getKey(); if (key instanceof Fluid f) { int amount = emiStack.getAmount() == 0 ? 1000 : (int) emiStack.getAmount(); @@ -114,7 +114,7 @@ public List getPhantomTargets(Object ingredient) { } else { ingredient = null; } - } else if (GTCEu.Mods.isJeiLoaded() && ingredient instanceof ITypedIngredient jeiStack) { + } else if (GTCEu.Mods.isJEILoaded() && ingredient instanceof ITypedIngredient jeiStack) { ingredient = jeiStack.getIngredient(); } @@ -133,11 +133,11 @@ public Rect2i getArea() { @Override public void accept(@Nonnull Object ingredient) { - if (GTCEu.Mods.isReiLoaded() && ingredient instanceof dev.architectury.fluid.FluidStack fluidStack) { + if (GTCEu.Mods.isREILoaded() && ingredient instanceof dev.architectury.fluid.FluidStack fluidStack) { ingredient = new FluidStack(fluidStack.getFluid(), (int) fluidStack.getAmount(), fluidStack.getTag()); - } else if (GTCEu.Mods.isEmiLoaded() && ingredient instanceof EmiStack emiStack) { + } else if (GTCEu.Mods.isEMILoaded() && ingredient instanceof EmiStack emiStack) { var key = emiStack.getKey(); if (key instanceof Fluid f) { int amount = emiStack.getAmount() == 0 ? 1000 : (int) emiStack.getAmount(); diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomSlotWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomSlotWidget.java index ba0c01664d..3864a6e6e0 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomSlotWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomSlotWidget.java @@ -126,13 +126,13 @@ public boolean canPutStack(ItemStack stack) { @Override @OnlyIn(Dist.CLIENT) public List getPhantomTargets(Object ingredient) { - if (GTCEu.Mods.isEmiLoaded() && ingredient instanceof EmiStack emiStack) { + if (GTCEu.Mods.isEMILoaded() && ingredient instanceof EmiStack emiStack) { Item item = emiStack.getKeyOfType(Item.class); if (item != null) { ingredient = new ItemStack(item, (int) emiStack.getAmount()); ((ItemStack) ingredient).setTag(emiStack.getNbt()); } - } else if (GTCEu.Mods.isJeiLoaded() && ingredient instanceof ITypedIngredient jeiStack) { + } else if (GTCEu.Mods.isJEILoaded() && ingredient instanceof ITypedIngredient jeiStack) { ingredient = jeiStack.getItemStack().orElse(null); } if (!(ingredient instanceof ItemStack)) { @@ -150,13 +150,13 @@ public Rect2i getArea() { @Override public void accept(@Nonnull Object ingredient) { - if (GTCEu.Mods.isEmiLoaded() && ingredient instanceof EmiStack emiStack) { + if (GTCEu.Mods.isEMILoaded() && ingredient instanceof EmiStack emiStack) { Item item = emiStack.getKeyOfType(Item.class); if (item != null) { ingredient = new ItemStack(item, (int) emiStack.getAmount()); ((ItemStack) ingredient).setTag(emiStack.getNbt()); } - } else if (GTCEu.Mods.isJeiLoaded() && ingredient instanceof ITypedIngredient jeiStack) { + } else if (GTCEu.Mods.isJEILoaded() && ingredient instanceof ITypedIngredient jeiStack) { ingredient = jeiStack.getItemStack().orElse(null); } if (slotReference != null && ingredient instanceof ItemStack stack) { diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/SlotWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/SlotWidget.java index c5251128b8..6ef83ff9c4 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/SlotWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/SlotWidget.java @@ -204,11 +204,11 @@ public Object getXEIIngredientOverMouse(double mouseX, double mouseY) { } } - if (GTCEu.Mods.isJeiLoaded() && !realStack.isEmpty()) { + if (GTCEu.Mods.isJEILoaded() && !realStack.isEmpty()) { return JEICallWrapper.getJEIStackClickable(realStack, getPosition(), getSize()); - } else if (GTCEu.Mods.isReiLoaded()) { + } else if (GTCEu.Mods.isREILoaded()) { return EntryStacks.of(realStack); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { return EmiStack.of(realStack).setChance(getXEIChance()); } return realStack; @@ -230,11 +230,11 @@ public List getXEIIngredients() { } } - if (GTCEu.Mods.isJeiLoaded() && !realStack.isEmpty()) { + if (GTCEu.Mods.isJEILoaded() && !realStack.isEmpty()) { return List.of(JEICallWrapper.getJEIStackClickable(realStack, getPosition(), getSize())); - } else if (GTCEu.Mods.isReiLoaded()) { + } else if (GTCEu.Mods.isREILoaded()) { return List.of(EntryStacks.of(realStack)); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { return List.of(EmiStack.of(realStack).setChance(getXEIChance())); } return List.of(realStack); @@ -242,11 +242,11 @@ public List getXEIIngredients() { private List getXEIIngredients(CycleItemStackHandler handler, int index) { var stackList = handler.getStackList(index); - if (GTCEu.Mods.isJeiLoaded()) { + if (GTCEu.Mods.isJEILoaded()) { return JEICallWrapper.getJEIIngredients(stackList, this::getRealStack); - } else if (GTCEu.Mods.isReiLoaded()) { + } else if (GTCEu.Mods.isREILoaded()) { return REICallWrapper.getREIIngredients(stackList, this::getRealStack); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { return EMICallWrapper.getEMIIngredients(stackList, getXEIChance(), this::getRealStack); } return Collections.emptyList(); @@ -254,11 +254,11 @@ private List getXEIIngredients(CycleItemStackHandler handler, int index) private List getXEIIngredientsClickable(CycleItemStackHandler handler, int index) { var stackList = handler.getStackList(index); - if (GTCEu.Mods.isJeiLoaded()) { + if (GTCEu.Mods.isJEILoaded()) { return JEICallWrapper.getJEIIngredientsClickable(stackList, getPosition(), getSize(), this::getRealStack); - } else if (GTCEu.Mods.isReiLoaded()) { + } else if (GTCEu.Mods.isREILoaded()) { return REICallWrapper.getREIIngredients(stackList, this::getRealStack); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { return EMICallWrapper.getEMIIngredients(stackList, getXEIChance(), this::getRealStack); } return Collections.emptyList(); @@ -266,11 +266,11 @@ private List getXEIIngredientsClickable(CycleItemStackHandler handler, i private List getXEIIngredients(CycleItemEntryHandler handler, int index) { ItemEntryList entryList = handler.getEntry(index); - if (GTCEu.Mods.isJeiLoaded()) { + if (GTCEu.Mods.isJEILoaded()) { return JEICallWrapper.getJEIIngredients(entryList, this::getRealStack); - } else if (GTCEu.Mods.isReiLoaded()) { + } else if (GTCEu.Mods.isREILoaded()) { return REICallWrapper.getREIIngredients(entryList, this::getRealStack); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { return EMICallWrapper.getEMIIngredients(entryList, getXEIChance(), this::getRealStack); } return Collections.emptyList(); @@ -278,11 +278,11 @@ private List getXEIIngredients(CycleItemEntryHandler handler, int index) private List getXEIIngredientsClickable(CycleItemEntryHandler handler, int index) { ItemEntryList entryList = handler.getEntry(index); - if (GTCEu.Mods.isJeiLoaded()) { + if (GTCEu.Mods.isJEILoaded()) { return JEICallWrapper.getJEIIngredientsClickable(entryList, getPosition(), getSize(), this::getRealStack); - } else if (GTCEu.Mods.isReiLoaded()) { + } else if (GTCEu.Mods.isREILoaded()) { return REICallWrapper.getREIIngredients(entryList, this::getRealStack); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { return EMICallWrapper.getEMIIngredients(entryList, getXEIChance(), this::getRealStack); } return Collections.emptyList(); diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java index df0b4e63e1..660aa1cfc1 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java @@ -202,11 +202,11 @@ public Object getXEIIngredientOverMouse(double mouseX, double mouseY) { return getXEIIngredientsClickable(entryHandler, tank).get(0); } - if (GTCEu.Mods.isJeiLoaded()) { + if (GTCEu.Mods.isJEILoaded()) { return JEICallWrapper.getJEIFluidClickable(lastFluidInTank, getPosition(), getSize()); - } else if (GTCEu.Mods.isReiLoaded()) { + } else if (GTCEu.Mods.isREILoaded()) { return EntryStacks.of(REICallWrapper.toREIStack(lastFluidInTank)); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { return ForgeEmiStack.of(lastFluidInTank).setChance(XEIChance); } } @@ -223,11 +223,11 @@ public List getXEIIngredients() { return getXEIIngredientsClickable(entryHandler, tank); } - if (GTCEu.Mods.isJeiLoaded()) { + if (GTCEu.Mods.isJEILoaded()) { return List.of(JEICallWrapper.getJEIFluidClickable(lastFluidInTank, getPosition(), getSize())); - } else if (GTCEu.Mods.isReiLoaded()) { + } else if (GTCEu.Mods.isREILoaded()) { return List.of(EntryStacks.of(REICallWrapper.toREIStack(lastFluidInTank))); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { return List.of(ForgeEmiStack.of(lastFluidInTank).setChance(XEIChance)); } return List.of(lastFluidInTank); @@ -235,11 +235,11 @@ public List getXEIIngredients() { private List getXEIIngredients(CycleFluidStackHandler handler, int index) { FluidStackList stackList = handler.getStackList(index); - if (GTCEu.Mods.isJeiLoaded()) { + if (GTCEu.Mods.isJEILoaded()) { return JEICallWrapper.getJEIIngredients(stackList); - } else if (GTCEu.Mods.isReiLoaded()) { + } else if (GTCEu.Mods.isREILoaded()) { return REICallWrapper.getREIIngredients(stackList); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { return EMICallWrapper.getEMIIngredients(stackList, getXEIChance()); } return Collections.emptyList(); @@ -247,11 +247,11 @@ private List getXEIIngredients(CycleFluidStackHandler handler, int index private List getXEIIngredientsClickable(CycleFluidStackHandler handler, int index) { FluidStackList stackList = handler.getStackList(index); - if (GTCEu.Mods.isJeiLoaded()) { + if (GTCEu.Mods.isJEILoaded()) { return JEICallWrapper.getJEIIngredientsClickable(stackList, getPosition(), getSize()); - } else if (GTCEu.Mods.isReiLoaded()) { + } else if (GTCEu.Mods.isREILoaded()) { return REICallWrapper.getREIIngredients(stackList); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { return EMICallWrapper.getEMIIngredients(stackList, getXEIChance()); } return Collections.emptyList(); @@ -259,11 +259,11 @@ private List getXEIIngredientsClickable(CycleFluidStackHandler handler, private List getXEIIngredients(CycleFluidEntryHandler handler, int index) { FluidEntryList entryList = handler.getEntry(index); - if (GTCEu.Mods.isJeiLoaded()) { + if (GTCEu.Mods.isJEILoaded()) { return JEICallWrapper.getJEIIngredients(entryList); - } else if (GTCEu.Mods.isReiLoaded()) { + } else if (GTCEu.Mods.isREILoaded()) { return REICallWrapper.getREIIngredients(entryList); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { return EMICallWrapper.getEMIIngredients(entryList, getXEIChance()); } return Collections.emptyList(); @@ -271,11 +271,11 @@ private List getXEIIngredients(CycleFluidEntryHandler handler, int index private List getXEIIngredientsClickable(CycleFluidEntryHandler handler, int index) { FluidEntryList entryList = handler.getEntry(index); - if (GTCEu.Mods.isJeiLoaded()) { + if (GTCEu.Mods.isJEILoaded()) { return JEICallWrapper.getJEIIngredientsClickable(entryList, getPosition(), getSize()); - } else if (GTCEu.Mods.isReiLoaded()) { + } else if (GTCEu.Mods.isREILoaded()) { return REICallWrapper.getREIIngredients(entryList); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { return EMICallWrapper.getEMIIngredients(entryList, getXEIChance()); } return Collections.emptyList(); @@ -318,7 +318,7 @@ public List getFullTooltipTexts() { @Override public void setCurrentJEIRenderedIngredient(Object ingredient) { - if (GTCEu.Mods.isJeiLoaded()) { + if (GTCEu.Mods.isJEILoaded()) { currentJEIRenderedIngredient = ingredient instanceof FluidStack f ? f : null; } else { currentJEIRenderedIngredient = null; diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/content/IContentSerializer.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/content/IContentSerializer.java index 7b7f2bc761..fbae53fd2f 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/content/IContentSerializer.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/content/IContentSerializer.java @@ -2,6 +2,7 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.recipe.chance.logic.ChanceLogic; +import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.lowdragmc.lowdraglib.LDLib; @@ -19,12 +20,12 @@ public interface IContentSerializer { default void toNetwork(FriendlyByteBuf buf, T content) { - RegistryOps ops = RegistryOps.create(JsonOps.INSTANCE, GTCEu.getFrozenRegistry()); + RegistryOps ops = RegistryOps.create(JsonOps.INSTANCE, GTRegistries.builtinRegistry()); buf.writeUtf(codec().encodeStart(ops, content).getOrThrow(false, GTCEu.LOGGER::error).toString()); } default T fromNetwork(FriendlyByteBuf buf) { - RegistryOps ops = RegistryOps.create(JsonOps.INSTANCE, GTCEu.getFrozenRegistry()); + RegistryOps ops = RegistryOps.create(JsonOps.INSTANCE, GTRegistries.builtinRegistry()); return codec().parse(ops, LDLib.GSON.fromJson(buf.readUtf(), JsonElement.class)).getOrThrow(false, GTCEu.LOGGER::error); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java index 08abac76f4..bfb3d06797 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java @@ -238,25 +238,25 @@ public IEditableUI createEditableUITemplate(final boo progress.add(dualProgressWidget); }); // add recipe button - if (!isJEI && (GTCEu.Mods.isReiLoaded() || GTCEu.Mods.isJeiLoaded() || GTCEu.Mods.isEmiLoaded())) { + if (!isJEI && (GTCEu.Mods.isREILoaded() || GTCEu.Mods.isJEILoaded() || GTCEu.Mods.isEMILoaded())) { for (Widget widget : progress) { template.addWidget(new ButtonWidget(widget.getPosition().x, widget.getPosition().y, widget.getSize().width, widget.getSize().height, IGuiTexture.EMPTY, cd -> { if (cd.isRemote) { - if (GTCEu.Mods.isReiLoaded()) { + if (GTCEu.Mods.isREILoaded()) { ViewSearchBuilder.builder().addCategories( recipeType.getCategories().stream() .filter(GTRecipeCategory::isXEIVisible) .map(GTRecipeREICategory::machineCategory) .collect(Collectors.toList())) .open(); - } else if (GTCEu.Mods.isJeiLoaded()) { + } else if (GTCEu.Mods.isJEILoaded()) { JEIPlugin.jeiRuntime.getRecipesGui().showTypes( recipeType.getCategories().stream() .filter(GTRecipeCategory::isXEIVisible) .map(GTRecipeJEICategory::machineType) .collect(Collectors.toList())); - } else if (GTCEu.Mods.isEmiLoaded()) { + } else if (GTCEu.Mods.isEMILoaded()) { EmiApi.displayRecipeCategory( GTRecipeEMICategory.machineCategory(recipeType.getCategory())); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/registry/GTRegistries.java b/src/main/java/com/gregtechceu/gtceu/api/registry/GTRegistries.java index 9f2921cc1c..d99561ecd5 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/registry/GTRegistries.java +++ b/src/main/java/com/gregtechceu/gtceu/api/registry/GTRegistries.java @@ -15,8 +15,10 @@ import com.gregtechceu.gtceu.api.recipe.condition.RecipeConditionType; import com.gregtechceu.gtceu.api.sound.SoundEntry; +import net.minecraft.client.Minecraft; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; @@ -32,6 +34,7 @@ import net.minecraftforge.registries.ForgeRegistries; import com.mojang.serialization.Codec; +import org.jetbrains.annotations.ApiStatus; /** * @author KilaBash @@ -64,6 +67,9 @@ public final class GTRegistries { public static final GTRegistry.RL DIMENSION_MARKERS = new GTRegistry.RL<>( GTCEu.id("dimension_marker")); + private static final RegistryAccess BLANK = RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY); + private static RegistryAccess FROZEN = BLANK; + public static final DeferredRegister> TRUNK_PLACER_TYPE = DeferredRegister .create(Registries.TRUNK_PLACER_TYPE, GTCEu.MOD_ID); public static final DeferredRegister> PLACEMENT_MODIFIER = DeferredRegister @@ -99,7 +105,22 @@ public static void init(IEventBus eventBus) { GLOBAL_LOOT_MODIFIES.register(eventBus); } + /** + * You shouldn't call it, you should probably not even look at it just to be extra safe + * + * @param registryAccess the new value to set to the frozen registry access + */ + @ApiStatus.Internal + public static void updateFrozenRegistry(RegistryAccess registryAccess) { + FROZEN = registryAccess; + } + public static RegistryAccess builtinRegistry() { - return GTCEu.getFrozenRegistry(); + if (FROZEN == BLANK && GTCEu.isClientThread()) { + if (Minecraft.getInstance().getConnection() != null) { + return Minecraft.getInstance().getConnection().registryAccess(); + } + } + return FROZEN; } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncBedrockOreVeins.java b/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncBedrockOreVeins.java index 3a5a6623ef..d74d959617 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncBedrockOreVeins.java +++ b/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncBedrockOreVeins.java @@ -2,6 +2,7 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreDefinition; +import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.client.ClientProxy; import com.lowdragmc.lowdraglib.networking.IHandlerContext; @@ -31,7 +32,7 @@ public SPacketSyncBedrockOreVeins() { @Override public void encode(FriendlyByteBuf buf) { - RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTCEu.getFrozenRegistry()); + RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTRegistries.builtinRegistry()); int size = veins.size(); buf.writeVarInt(size); for (var entry : veins.entrySet()) { @@ -44,7 +45,7 @@ public void encode(FriendlyByteBuf buf) { @Override public void decode(FriendlyByteBuf buf) { - RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTCEu.getFrozenRegistry()); + RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTRegistries.builtinRegistry()); Stream.generate(() -> { ResourceLocation id = buf.readResourceLocation(); CompoundTag tag = buf.readAnySizeNbt(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncFluidVeins.java b/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncFluidVeins.java index 953b37a178..450006be88 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncFluidVeins.java +++ b/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncFluidVeins.java @@ -2,6 +2,7 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.data.worldgen.bedrockfluid.BedrockFluidDefinition; +import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.client.ClientProxy; import com.lowdragmc.lowdraglib.networking.IHandlerContext; @@ -31,7 +32,7 @@ public SPacketSyncFluidVeins() { @Override public void encode(FriendlyByteBuf buf) { - RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTCEu.getFrozenRegistry()); + RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTRegistries.builtinRegistry()); int size = veins.size(); buf.writeVarInt(size); for (var entry : veins.entrySet()) { @@ -44,7 +45,7 @@ public void encode(FriendlyByteBuf buf) { @Override public void decode(FriendlyByteBuf buf) { - RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTCEu.getFrozenRegistry()); + RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTRegistries.builtinRegistry()); Stream.generate(() -> { ResourceLocation id = buf.readResourceLocation(); CompoundTag tag = buf.readAnySizeNbt(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncOreVeins.java b/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncOreVeins.java index 80dac75920..522df81bab 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncOreVeins.java +++ b/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncOreVeins.java @@ -2,6 +2,7 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.data.worldgen.GTOreDefinition; +import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.client.ClientProxy; import com.gregtechceu.gtceu.integration.map.cache.client.GTClientCache; @@ -32,7 +33,7 @@ public SPacketSyncOreVeins() { @Override public void encode(FriendlyByteBuf buf) { - RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTCEu.getFrozenRegistry()); + RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTRegistries.builtinRegistry()); int size = veins.size(); buf.writeVarInt(size); for (var entry : veins.entrySet()) { @@ -45,7 +46,7 @@ public void encode(FriendlyByteBuf buf) { @Override public void decode(FriendlyByteBuf buf) { - RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTCEu.getFrozenRegistry()); + RegistryOps ops = RegistryOps.create(NbtOps.INSTANCE, GTRegistries.builtinRegistry()); Stream.generate(() -> { ResourceLocation id = buf.readResourceLocation(); CompoundTag tag = buf.readAnySizeNbt(); diff --git a/src/main/java/com/gregtechceu/gtceu/core/mixins/WorldLoaderMixin.java b/src/main/java/com/gregtechceu/gtceu/core/mixins/WorldLoaderMixin.java deleted file mode 100644 index 7a8a064b8a..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/core/mixins/WorldLoaderMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.gregtechceu.gtceu.core.mixins; - -import com.gregtechceu.gtceu.GTCEu; - -import net.minecraft.core.RegistryAccess; -import net.minecraft.server.WorldLoader; - -import com.llamalad7.mixinextras.sugar.Local; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -@Mixin(value = WorldLoader.class) -public class WorldLoaderMixin { - - @Inject(method = "load", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/server/ReloadableServerResources;loadResources(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/core/RegistryAccess$Frozen;Lnet/minecraft/world/flag/FeatureFlagSet;Lnet/minecraft/commands/Commands$CommandSelection;ILjava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;")) - private static void gtceu$injectLoad(WorldLoader.InitConfig initConfig, - WorldLoader.WorldDataSupplier loadContextSupplier, - WorldLoader.ResultFactory applierFactory, - Executor prepareExecutor, Executor applyExecutor, - CallbackInfoReturnable> cir, - @Local(ordinal = 2) RegistryAccess.Frozen frozen2) { - GTCEu.updateFrozenRegistry(frozen2); - } -} diff --git a/src/main/java/com/gregtechceu/gtceu/forge/ForgeCommonEventListener.java b/src/main/java/com/gregtechceu/gtceu/forge/ForgeCommonEventListener.java index 9fa56ceb83..36c11814f4 100644 --- a/src/main/java/com/gregtechceu/gtceu/forge/ForgeCommonEventListener.java +++ b/src/main/java/com/gregtechceu/gtceu/forge/ForgeCommonEventListener.java @@ -605,4 +605,9 @@ public static void remapIds(MissingMappingsEvent event) { }); } } + + @SubscribeEvent + public static void onAddReloadableServerResources(AddReloadListenerEvent event) { + GTRegistries.updateFrozenRegistry(event.getRegistryAccess()); + } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/jei/GTJEIPlugin.java b/src/main/java/com/gregtechceu/gtceu/integration/jei/GTJEIPlugin.java index 91087af80a..cd74ea5f99 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/jei/GTJEIPlugin.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/jei/GTJEIPlugin.java @@ -56,7 +56,7 @@ public ResourceLocation getPluginUid() { @Override public void registerCategories(@NotNull IRecipeCategoryRegistration registry) { - if (GTCEu.Mods.isReiLoaded() || GTCEu.Mods.isEmiLoaded()) return; + if (GTCEu.Mods.isREILoaded() || GTCEu.Mods.isEMILoaded()) return; GTCEu.LOGGER.info("JEI register categories"); IJeiHelpers jeiHelpers = registry.getJeiHelpers(); registry.addRecipeCategories(new MultiblockInfoCategory(jeiHelpers)); @@ -76,7 +76,7 @@ public void registerCategories(@NotNull IRecipeCategoryRegistration registry) { @Override public void registerRecipeCatalysts(@NotNull IRecipeCatalystRegistration registration) { - if (GTCEu.Mods.isReiLoaded() || GTCEu.Mods.isEmiLoaded()) return; + if (GTCEu.Mods.isREILoaded() || GTCEu.Mods.isEMILoaded()) return; GTRecipeJEICategory.registerRecipeCatalysts(registration); if (!ConfigHolder.INSTANCE.compat.hideOreProcessingDiagrams) GTOreProcessingInfoCategory.registerRecipeCatalysts(registration); @@ -91,7 +91,7 @@ public void registerRecipeCatalysts(@NotNull IRecipeCatalystRegistration registr @Override public void registerRecipes(@NotNull IRecipeRegistration registration) { - if (GTCEu.Mods.isReiLoaded() || GTCEu.Mods.isEmiLoaded()) return; + if (GTCEu.Mods.isREILoaded() || GTCEu.Mods.isEMILoaded()) return; GTCEu.LOGGER.info("JEI register"); MultiblockInfoCategory.registerRecipes(registration); GTRecipeJEICategory.registerRecipes(registration); @@ -107,7 +107,7 @@ public void registerRecipes(@NotNull IRecipeRegistration registration) { @Override public void registerIngredients(@NotNull IModIngredientRegistration registry) { - if (GTCEu.Mods.isReiLoaded() || GTCEu.Mods.isEmiLoaded()) return; + if (GTCEu.Mods.isREILoaded() || GTCEu.Mods.isEMILoaded()) return; GTCEu.LOGGER.info("JEI register ingredients"); } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/xei/widgets/GTRecipeWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/xei/widgets/GTRecipeWidget.java index 3c0f9f7bc2..10ca5b5c48 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/xei/widgets/GTRecipeWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/xei/widgets/GTRecipeWidget.java @@ -233,7 +233,7 @@ private int getVoltageXOffset() { case IV -> 12; default -> 14; }; - if (!GTCEu.Mods.isEmiLoaded()) { + if (!GTCEu.Mods.isEMILoaded()) { x -= 3; } return x; diff --git a/src/main/resources/gtceu.mixins.json b/src/main/resources/gtceu.mixins.json index dd2a3fd651..d9b0fff6ee 100644 --- a/src/main/resources/gtceu.mixins.json +++ b/src/main/resources/gtceu.mixins.json @@ -60,7 +60,6 @@ "TagLoaderMixin", "TagManagerMixin", "TagValueAccessor", - "WorldLoaderMixin", "ae2.GenericStackInvAccessor", "embeddium.BiomeColorCacheMixin", "embeddium.VanillaColorAdapterMixin",