Skip to content

Commit

Permalink
capitalized properly mod names.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
omergunr100 committed Dec 30, 2024
1 parent b57dd71 commit 2bac81d
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 132 deletions.
34 changes: 5 additions & 29 deletions src/main/java/com/gregtechceu/gtceu/GTCEu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public static FluidStack drainFrom(Object ingredient) {
@Override
@OnlyIn(Dist.CLIENT)
public List<Target> 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();
Expand All @@ -114,7 +114,7 @@ public List<Target> 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();
}

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ public boolean canPutStack(ItemStack stack) {
@Override
@OnlyIn(Dist.CLIENT)
public List<Target> 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)) {
Expand All @@ -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) {
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/com/gregtechceu/gtceu/api/gui/widget/SlotWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -230,59 +230,59 @@ public List<Object> 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);
}

private List<Object> 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();
}

private List<Object> 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();
}

private List<Object> 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();
}

private List<Object> 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();
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -223,59 +223,59 @@ public List<Object> 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);
}

private List<Object> 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();
}

private List<Object> 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();
}

private List<Object> 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();
}

private List<Object> 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();
Expand Down Expand Up @@ -318,7 +318,7 @@ public List<Component> 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;
Expand Down
Loading

0 comments on commit 2bac81d

Please sign in to comment.