Skip to content
2 changes: 2 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
compileOnly("curse.maven:journeymap-32274:5172461") // Journeymap 5.7.1p3
compileOnly("curse.maven:voxelmap-225179:3029445") // VoxelMap 1.9.28
compileOnly("curse.maven:xaeros-263420:5394758") // Xaero's Minimap 24.2.0
devOnlyNonPublishable rfg.deobf("curse.maven:ftb-library-legacy-forge-237167:2985811") // FTB Library 5.4.7.2
devOnlyNonPublishable rfg.deobf("curse.maven:ftb-utilities-forge-237102:3157548") // FTB Utilities 5.4.1.131
compileOnly rfg.deobf("curse.maven:opencomputers-223008:5274236") // OpenComputers 1.8.5+179e1c3
compileOnly rfg.deobf("curse.maven:hwyla-253449:2568751") // HWYLA 1.8.26-B41
compileOnly rfg.deobf("curse.maven:baubles-227083:2518667") // Baubles 1.5.2
Expand Down
43 changes: 31 additions & 12 deletions src/main/java/gregtech/api/util/GregFakePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,51 @@
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.common.util.ITeleporter;
import net.minecraftforge.fml.common.FMLCommonHandler;

import com.mojang.authlib.GameProfile;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.ref.WeakReference;
import java.util.Map;
import java.util.UUID;

public class GregFakePlayer extends EntityPlayer {

private static final GameProfile GREGTECH = new GameProfile(UUID.fromString("518FDF18-EC2A-4322-832A-58ED1721309B"),
"[GregTech]");
private static WeakReference<FakePlayer> GREGTECH_PLAYER = null;
private static final String FAKE_NAME = "[GregTech]";
private static final UUID FAKE_UUID = UUID.fromString("518FDF18-EC2A-4322-832A-58ED1721309B");
private static final GameProfile FAKE_PROFILE = new GameProfile(FAKE_UUID, FAKE_NAME);
private static final Map<UUID, GameProfile> PROFILE_CACHE = new Object2ObjectOpenHashMap<>();
private static final Map<UUID, WeakReference<FakePlayer>> GREGTECH_PLAYERS = new Object2ObjectOpenHashMap<>();

public static FakePlayer get(WorldServer world) {
FakePlayer ret = GREGTECH_PLAYER != null ? GREGTECH_PLAYER.get() : null;
if (ret == null) {
ret = FakePlayerFactory.get(world, GREGTECH);
GREGTECH_PLAYER = new WeakReference<>(ret);
public static @NotNull FakePlayer get(@NotNull WorldServer world) {
return get(world, FAKE_PROFILE);
}

public static @NotNull FakePlayer get(@NotNull WorldServer world, @Nullable UUID fakePlayerUUID) {
return get(world, fakePlayerUUID == null ? FAKE_PROFILE :
PROFILE_CACHE.computeIfAbsent(fakePlayerUUID, id -> new GameProfile(id, FAKE_NAME)));
}

public static @NotNull FakePlayer get(@NotNull WorldServer world, @NotNull GameProfile fakePlayerProfile) {
UUID id = fakePlayerProfile.getId();
if (GREGTECH_PLAYERS.containsKey(id)) {
FakePlayer fakePlayer = GREGTECH_PLAYERS.get(id).get();
if (fakePlayer != null) {
return fakePlayer;
}
}
return ret;

FakePlayer fakePlayer = new FakePlayer(world, fakePlayerProfile);
GREGTECH_PLAYERS.put(id, new WeakReference<>(fakePlayer));
return fakePlayer;
}

public GregFakePlayer(World worldIn) {
super(worldIn, GREGTECH);
public GregFakePlayer(@NotNull World worldIn) {
super(worldIn, FAKE_PROFILE);
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/gregtech/api/util/Mods.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public enum Mods {
ForestryApiculture(Names.FORESTRY, forestryModule(Names.FORESTRY_APICULTURE)),
ForestryArboriculture(Names.FORESTRY, forestryModule(Names.FORESTRY_ARBORICULTURE)),
ForestryLepidopterology(Names.FORESTRY, forestryModule(Names.FORESTRY_LEPIDOPTEROLOGY)),
FTB_LIB(Names.FTB_LIB),
// FTB Utilities hard deps on ftb lib so you don't have to check if both are loaded
FTB_UTILITIES(Names.FTB_UTILITIES),
GalacticraftCore(Names.GALACTICRAFT_CORE),
Genetics(Names.GENETICS),
GregTech(Names.GREGTECH),
Expand Down Expand Up @@ -118,6 +121,8 @@ public static class Names {
public static final String FORESTRY_APICULTURE = "apiculture";
public static final String FORESTRY_ARBORICULTURE = "arboriculture";
public static final String FORESTRY_LEPIDOPTEROLOGY = "lepidopterology";
public static final String FTB_LIB = "ftblib";
public static final String FTB_UTILITIES = "ftbutilities";
public static final String GALACTICRAFT_CORE = "galacticraftcore";
public static final String GENETICS = "genetics";
public static final String GREGTECH = GTValues.MODID;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/gregtech/api/util/function/TriPredicate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gregtech.api.util.function;

@FunctionalInterface
public interface TriPredicate<A, B, C> {

boolean test(A a, B b, C c);
}
Loading
Loading