Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor LDLib calls #2609

Merged
merged 27 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
af0d372
i didn't remember the axis methods when i wrote it ok
omergunr100 Dec 21, 2024
149ee42
get offset timer should now work on both client and server again
omergunr100 Dec 21, 2024
715240f
added the getTime thing back for client
omergunr100 Dec 21, 2024
3ff50e2
moved mod load checks to forge native method
omergunr100 Dec 21, 2024
8d6ebbc
doing the actual thing with the stuff
omergunr100 Dec 21, 2024
c66e3e0
CLIENT_TIME
omergunr100 Dec 21, 2024
8e9bc48
moved unsubscribe to onInvalid and removed check from subscriber runn…
omergunr100 Dec 21, 2024
433ba8f
getOffsetTimer in pbf
omergunr100 Dec 21, 2024
0dc659d
Here is my wisdom:
omergunr100 Dec 21, 2024
4e216cb
feck
omergunr100 Dec 21, 2024
aa1ddc2
thanks tom
omergunr100 Dec 21, 2024
579362d
Merge branch '1.20.1' into 1.20.1-rendering-cringe
omergunr100 Dec 22, 2024
577c6dd
back into the gtceu class
omergunr100 Dec 22, 2024
3a0615b
more GTCEu less ldlib/platform
omergunr100 Dec 22, 2024
9f53581
javadoc
omergunr100 Dec 22, 2024
5d340fb
Merge remote-tracking branch 'origin/1.20.1' into 1.20.1-rendering-cr…
omergunr100 Dec 28, 2024
daa6c7d
new one found
omergunr100 Dec 28, 2024
cd8c3aa
cursed
omergunr100 Dec 28, 2024
fe195e5
refactor is mod loaded into a subclass
omergunr100 Dec 28, 2024
ffee50b
removed all ldlib from main gtceu class
omergunr100 Dec 28, 2024
9bb896d
removed incorrect merge result
omergunr100 Dec 28, 2024
4860a51
rename
omergunr100 Dec 28, 2024
b57dd71
was working in runClient but not in production
omergunr100 Dec 28, 2024
2bac81d
capitalized properly mod names.
omergunr100 Dec 30, 2024
5d25735
what can I say, I guess I should take my adhd medicine more
omergunr100 Dec 30, 2024
dc66138
moved registry access closer to related functions
omergunr100 Dec 31, 2024
e5b2400
Merge branch '1.20.1' into fork/omergunr100/1.20.1-rendering-cringe
screret Jan 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/Development/General-Topics/Global-Data.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ When doing so, you need to ensure that remote and serverside instances don't get
To make working with this requirement easier, You can use `SideLocal<T>` to store your global data.
It is similar to Java's `ThreadLocal`, but operates on the game's sides instead.

If you are currently on the remote side (`LDLib.isRemote()` / on the client's `main` thread), it will return the
If you are currently on the remote side (`GTCEuAPI.isClientThread()` / on the client's `main` thread), it will return the
remote side's instance of your data. Otherwise, you will get the server side's instance.

??? example "Example Usage"
Expand Down
141 changes: 124 additions & 17 deletions src/main/java/com/gregtechceu/gtceu/GTCEu.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,42 @@
import com.gregtechceu.gtceu.utils.FormattingUtil;

import com.lowdragmc.lowdraglib.LDLib;
import com.lowdragmc.lowdraglib.Platform;

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;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.loading.FMLEnvironment;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.FMLPaths;
import net.minecraftforge.server.ServerLifecycleHooks;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;

@Mod(GTCEu.MOD_ID)
public class GTCEu {

public static final String MOD_ID = "gtceu";
public static final String NAME = "GregTechCEu";
public static final Logger LOGGER = LoggerFactory.getLogger(NAME);

private static final RegistryAccess BLANK = RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY);

public GTCEu() {
GTCEu.init();
GTCEuAPI.instance = this;
DistExecutor.unsafeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new);
}

public static void init() {
LOGGER.info("{} is initializing on platform: {}", NAME, Platform.platformName());
LOGGER.info("{} is initializing...", NAME);
}

public static ResourceLocation id(String path) {
Expand All @@ -53,45 +65,140 @@ public static ResourceLocation appendId(String id) {
return new ResourceLocation(strings[0], strings[1]);
}

public static RegistryAccess getFrozenRegistry() {
// todo: see if this behaves correctly, the ldlib version just assigns it to a different var and returns it
if (BLANK == null && isClientThread()) {
if (Minecraft.getInstance().getConnection() != null) {
return Minecraft.getInstance().getConnection().registryAccess();
}
}
return BLANK;
}

/**
* @return if we're running in a production environment
*/
public static boolean isProd() {
return FMLLoader.isProduction();
}

/**
* @return if we're not running in a production environment
*/
public static boolean isDev() {
return !isProd();
}

/**
* @return if we're running data generation
*/
public static boolean isDataGen() {
return FMLLoader.getLaunchHandler().isData();
}

/**
* A friendly reminder that the server instance is populated on the server side only, so null/side check it!
*
* @return the current minecraft server instance
*/
public static MinecraftServer getMinecraftServer() {
return ServerLifecycleHooks.getCurrentServer();
}

/**
* @param modId the mod id to check for
* @return if the mod whose id is {@code modId} is loaded or not
*/
public static boolean isModLoaded(String modId) {
return ModList.get().isLoaded(modId);
}

/**
* For async stuff use this, otherwise use {@link GTCEu isClientSide}
*
* @return if the current thread is the client thread
*/
public static boolean isClientThread() {
return isClientSide() && Minecraft.getInstance().isSameThread();
}

/**
* @return if the FML environment is a client
*/
public static boolean isClientSide() {
return FMLEnvironment.dist.isClient();
}

/**
* This check isn't the same for client and server!
*
* @return if it's safe to access the current instance {@link net.minecraft.world.level.Level Level} on client or if
* it's safe to access any level on server.
*/
public static boolean canGetServerLevel() {
omergunr100 marked this conversation as resolved.
Show resolved Hide resolved
if (isClientSide()) {
return Minecraft.getInstance().level != null;
}
var server = getMinecraftServer();
return server != null &&
!(server.isStopped() || server.isShutdown() || !server.isRunning() || server.isCurrentlySaving());
}

/**
* @return the path to the minecraft instance directory
*/
public static Path getGameDir() {
return FMLPaths.GAMEDIR.get();
}

public static boolean isJeiLoaded() {
return !(isEmiLoaded() || isReiLoaded()) && isModLoaded(GTValues.MODID_JEI);
}

public static boolean isReiLoaded() {
// todo: convert to base check after ui rework
return LDLib.isReiLoaded();
}

public static boolean isEmiLoaded() {
// todo: convert to base check after ui rework
return LDLib.isEmiLoaded();
}

public static boolean isKubeJSLoaded() {
return LDLib.isModLoaded(GTValues.MODID_KUBEJS);
return isModLoaded(GTValues.MODID_KUBEJS);
}

public static boolean isIrisOculusLoaded() {
return LDLib.isModLoaded(GTValues.MODID_IRIS) || LDLib.isModLoaded(GTValues.MODID_OCULUS);
return isModLoaded(GTValues.MODID_IRIS) || isModLoaded(GTValues.MODID_OCULUS);
}

public static boolean isSodiumRubidiumEmbeddiumLoaded() {
return LDLib.isModLoaded(GTValues.MODID_SODIUM) || LDLib.isModLoaded(GTValues.MODID_RUBIDIUM) ||
LDLib.isModLoaded(GTValues.MODID_EMBEDDIUM);
return isModLoaded(GTValues.MODID_SODIUM) || isModLoaded(GTValues.MODID_RUBIDIUM) ||
isModLoaded(GTValues.MODID_EMBEDDIUM);
}

public static boolean isAE2Loaded() {
return LDLib.isModLoaded(GTValues.MODID_APPENG);
return isModLoaded(GTValues.MODID_APPENG);
}

public static boolean isCuriosLoaded() {
return LDLib.isModLoaded(GTValues.MODID_CURIOS);
return isModLoaded(GTValues.MODID_CURIOS);
}

public static boolean isShimmerLoaded() {
return LDLib.isModLoaded(GTValues.MODID_SHIMMER);
return isModLoaded(GTValues.MODID_SHIMMER);
}

public static boolean isJAVDLoaded() {
return LDLib.isModLoaded(GTValues.MODID_JAVD);
return isModLoaded(GTValues.MODID_JAVD);
}

public static boolean isFTBTeamsLoaded() {
return LDLib.isModLoaded(GTValues.MODID_FTB_TEAMS);
return isModLoaded(GTValues.MODID_FTB_TEAMS);
}

public static boolean isArgonautsLoaded() {
return LDLib.isModLoaded(GTValues.MODID_ARGONAUTS);
}

@Deprecated(forRemoval = true, since = "1.0.21")
public static boolean isHighTier() {
return GTCEuAPI.isHighTier();
return isModLoaded(GTValues.MODID_ARGONAUTS);
}
}
4 changes: 1 addition & 3 deletions src/main/java/com/gregtechceu/gtceu/api/GTCEuAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import com.gregtechceu.gtceu.common.block.CoilBlock;
import com.gregtechceu.gtceu.config.ConfigHolder;

import com.lowdragmc.lowdraglib.Platform;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.eventbus.api.GenericEvent;
Expand Down Expand Up @@ -49,7 +47,7 @@ public class GTCEuAPI {
public static void initializeHighTier() {
if (highTierInitialized) throw new IllegalStateException("High-Tier is already initialized.");
highTier = ConfigHolder.INSTANCE.machines.highTierContent ||
AddonFinder.getAddons().stream().anyMatch(IGTAddon::requiresHighTier) || Platform.isDevEnv();
AddonFinder.getAddons().stream().anyMatch(IGTAddon::requiresHighTier) || GTCEu.isDev();
highTierInitialized = true;

if (isHighTier()) GTCEu.LOGGER.info("High-Tier is Enabled.");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/api/GTValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public static int[] tiersBetween(int minInclusive, int maxInclusive) {

public static final String MODID_TOP = "theoneprobe",
MODID_JEI = "jei",
MODID_REI = "roughlyenoughitems",
MODID_EMI = "emi",
MODID_APPENG = "ae2",
MODID_KUBEJS = "kubejs",
MODID_IRIS = "iris",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.api.block;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.blockentity.PipeBlockEntity;
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
Expand All @@ -10,8 +11,6 @@
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.gregtechceu.gtceu.data.recipe.VanillaRecipeHelper;

import com.lowdragmc.lowdraglib.Platform;

import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -71,7 +70,7 @@ public MaterialBlock(Properties properties, TagPrefix tagPrefix, Material materi
super(properties);
this.material = material;
this.tagPrefix = tagPrefix;
if (registerModel && Platform.isClient()) {
if (registerModel && GTCEu.isClientSide()) {
MaterialBlockRenderer.create(this, tagPrefix.materialIconType(), material.getMaterialIconSet());
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/gregtechceu/gtceu/api/block/OreBlock.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.gregtechceu.gtceu.api.block;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.client.renderer.block.OreBlockRenderer;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.gregtechceu.gtceu.integration.map.cache.server.ServerCache;

import com.lowdragmc.lowdraglib.Platform;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
Expand All @@ -21,7 +20,7 @@ public class OreBlock extends MaterialBlock {

public OreBlock(Properties properties, TagPrefix tagPrefix, Material material, boolean registerModel) {
super(properties, tagPrefix, material, false);
if (registerModel && Platform.isClient()) {
if (registerModel && GTCEu.isClientSide()) {
OreBlockRenderer.create(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
* @author KilaBash
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.gregtechceu.gtceu.api.capability;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.block.IAppearance;
import com.gregtechceu.gtceu.api.blockentity.ITickSubscription;
import com.gregtechceu.gtceu.api.cover.CoverBehavior;
import com.gregtechceu.gtceu.api.cover.CoverDefinition;
import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable;
import com.gregtechceu.gtceu.utils.GTUtil;

import com.lowdragmc.lowdraglib.LDLib;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -169,7 +168,7 @@ default boolean hasCover(Direction facing) {
}

default boolean isRemote() {
return getLevel() == null ? LDLib.isRemote() : getLevel().isClientSide;
return getLevel() == null ? GTCEu.isClientThread() : getLevel().isClientSide;
}

default VoxelShape[] addCoverCollisionBoundingBox() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.gregtechceu.gtceu.api.cover.filter;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.cover.CoverBehavior;
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.gui.widget.SlotWidget;
import com.gregtechceu.gtceu.api.machine.MachineCoverContainer;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
import com.gregtechceu.gtceu.api.transfer.item.CustomItemStackHandler;

import com.lowdragmc.lowdraglib.LDLib;
import com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup;
import com.lowdragmc.lowdraglib.gui.widget.Widget;
import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;
Expand Down Expand Up @@ -128,7 +128,7 @@ private CustomItemStackHandler getFilterSlot() {
private void updateFilter() {
var filterContainer = getFilterSlot();

if (LDLib.isRemote()) {
if (GTCEu.isClientThread()) {
if (!filterContainer.getStackInSlot(0).isEmpty() && !this.filterItem.isEmpty()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.integration.kjs.GTRegistryInfo;

import com.lowdragmc.lowdraglib.Platform;
import com.lowdragmc.lowdraglib.utils.ResourceHelper;

import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -158,7 +157,7 @@ public ResourceLocation getBlockTexturePath(@NotNull MaterialIconSet materialIco

MaterialIconSet iconSet = materialIconSet;
// noinspection ConstantConditions
if (!Platform.isClient() || Minecraft.getInstance() == null ||
if (!GTCEu.isClientSide() || Minecraft.getInstance() == null ||
Minecraft.getInstance().getResourceManager() == null)
return null; // check minecraft for null for CI environments
if (!iconSet.isRootIconset) {
Expand Down Expand Up @@ -197,7 +196,7 @@ public ResourceLocation getBlockModelPath(@NotNull MaterialIconSet materialIconS

MaterialIconSet iconSet = materialIconSet;
// noinspection ConstantConditions
if (!iconSet.isRootIconset && Platform.isClient() && Minecraft.getInstance() != null &&
if (!iconSet.isRootIconset && GTCEu.isClientSide() && Minecraft.getInstance() != null &&
Minecraft.getInstance().getResourceManager() != null) { // check minecraft for null for CI environments
while (!iconSet.isRootIconset) {
ResourceLocation location = GTCEu
Expand All @@ -224,7 +223,7 @@ public ResourceLocation getItemModelPath(@NotNull MaterialIconSet materialIconSe

MaterialIconSet iconSet = materialIconSet;
// noinspection ConstantConditions
if (!iconSet.isRootIconset && Platform.isClient() && Minecraft.getInstance() != null &&
if (!iconSet.isRootIconset && GTCEu.isClientSide() && Minecraft.getInstance() != null &&
Minecraft.getInstance().getResourceManager() != null) { // check minecraft for null for CI environments
while (!iconSet.isRootIconset) {
ResourceLocation location = GTCEu
Expand Down Expand Up @@ -263,7 +262,7 @@ public ResourceLocation getItemTexturePath(@NotNull MaterialIconSet materialIcon

MaterialIconSet iconSet = materialIconSet;
// noinspection ConstantConditions
if (!iconSet.isRootIconset && Platform.isClient() && Minecraft.getInstance() != null &&
if (!iconSet.isRootIconset && GTCEu.isClientSide() && Minecraft.getInstance() != null &&
Minecraft.getInstance().getResourceManager() != null) { // check minecraft for null for CI environments
while (!iconSet.isRootIconset) {
ResourceLocation location = GTCEu
Expand Down
Loading
Loading