Skip to content

Commit 45a2956

Browse files
authored
Block breaker improvements (#2778)
1 parent 99d244a commit 45a2956

File tree

6 files changed

+228
-77
lines changed

6 files changed

+228
-77
lines changed

dependencies.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ dependencies {
5252
compileOnly("curse.maven:journeymap-32274:5172461") // Journeymap 5.7.1p3
5353
compileOnly("curse.maven:voxelmap-225179:3029445") // VoxelMap 1.9.28
5454
compileOnly("curse.maven:xaeros-263420:5394758") // Xaero's Minimap 24.2.0
55+
devOnlyNonPublishable rfg.deobf("curse.maven:ftb-library-legacy-forge-237167:2985811") // FTB Library 5.4.7.2
56+
devOnlyNonPublishable rfg.deobf("curse.maven:ftb-utilities-forge-237102:3157548") // FTB Utilities 5.4.1.131
5557
compileOnly rfg.deobf("curse.maven:opencomputers-223008:5274236") // OpenComputers 1.8.5+179e1c3
5658
compileOnly rfg.deobf("curse.maven:hwyla-253449:2568751") // HWYLA 1.8.26-B41
5759
compileOnly rfg.deobf("curse.maven:baubles-227083:2518667") // Baubles 1.5.2

src/main/java/gregtech/api/util/GregFakePlayer.java

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,51 @@
1111
import net.minecraft.world.World;
1212
import net.minecraft.world.WorldServer;
1313
import net.minecraftforge.common.util.FakePlayer;
14-
import net.minecraftforge.common.util.FakePlayerFactory;
1514
import net.minecraftforge.common.util.ITeleporter;
1615
import net.minecraftforge.fml.common.FMLCommonHandler;
1716

1817
import com.mojang.authlib.GameProfile;
18+
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
19+
import org.jetbrains.annotations.NotNull;
20+
import org.jetbrains.annotations.Nullable;
1921

2022
import java.lang.ref.WeakReference;
23+
import java.util.Map;
2124
import java.util.UUID;
2225

2326
public class GregFakePlayer extends EntityPlayer {
2427

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

29-
public static FakePlayer get(WorldServer world) {
30-
FakePlayer ret = GREGTECH_PLAYER != null ? GREGTECH_PLAYER.get() : null;
31-
if (ret == null) {
32-
ret = FakePlayerFactory.get(world, GREGTECH);
33-
GREGTECH_PLAYER = new WeakReference<>(ret);
34+
public static @NotNull FakePlayer get(@NotNull WorldServer world) {
35+
return get(world, FAKE_PROFILE);
36+
}
37+
38+
public static @NotNull FakePlayer get(@NotNull WorldServer world, @Nullable UUID fakePlayerUUID) {
39+
return get(world, fakePlayerUUID == null ? FAKE_PROFILE :
40+
PROFILE_CACHE.computeIfAbsent(fakePlayerUUID, id -> new GameProfile(id, FAKE_NAME)));
41+
}
42+
43+
public static @NotNull FakePlayer get(@NotNull WorldServer world, @NotNull GameProfile fakePlayerProfile) {
44+
UUID id = fakePlayerProfile.getId();
45+
if (GREGTECH_PLAYERS.containsKey(id)) {
46+
FakePlayer fakePlayer = GREGTECH_PLAYERS.get(id).get();
47+
if (fakePlayer != null) {
48+
return fakePlayer;
49+
}
3450
}
35-
return ret;
51+
52+
FakePlayer fakePlayer = new FakePlayer(world, fakePlayerProfile);
53+
GREGTECH_PLAYERS.put(id, new WeakReference<>(fakePlayer));
54+
return fakePlayer;
3655
}
3756

38-
public GregFakePlayer(World worldIn) {
39-
super(worldIn, GREGTECH);
57+
public GregFakePlayer(@NotNull World worldIn) {
58+
super(worldIn, FAKE_PROFILE);
4059
}
4160

4261
@Override

src/main/java/gregtech/api/util/Mods.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public enum Mods {
4646
ForestryApiculture(Names.FORESTRY, forestryModule(Names.FORESTRY_APICULTURE)),
4747
ForestryArboriculture(Names.FORESTRY, forestryModule(Names.FORESTRY_ARBORICULTURE)),
4848
ForestryLepidopterology(Names.FORESTRY, forestryModule(Names.FORESTRY_LEPIDOPTEROLOGY)),
49+
FTB_LIB(Names.FTB_LIB),
50+
// FTB Utilities hard deps on ftb lib so you don't have to check if both are loaded
51+
FTB_UTILITIES(Names.FTB_UTILITIES),
4952
GalacticraftCore(Names.GALACTICRAFT_CORE),
5053
Genetics(Names.GENETICS),
5154
GregTech(Names.GREGTECH),
@@ -118,6 +121,8 @@ public static class Names {
118121
public static final String FORESTRY_APICULTURE = "apiculture";
119122
public static final String FORESTRY_ARBORICULTURE = "arboriculture";
120123
public static final String FORESTRY_LEPIDOPTEROLOGY = "lepidopterology";
124+
public static final String FTB_LIB = "ftblib";
125+
public static final String FTB_UTILITIES = "ftbutilities";
121126
public static final String GALACTICRAFT_CORE = "galacticraftcore";
122127
public static final String GENETICS = "genetics";
123128
public static final String GREGTECH = GTValues.MODID;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package gregtech.api.util.function;
2+
3+
@FunctionalInterface
4+
public interface TriPredicate<A, B, C> {
5+
6+
boolean test(A a, B b, C c);
7+
}

0 commit comments

Comments
 (0)