-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
142 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/slimeknights/tmechworks/common/entities/MechworksFakePlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package slimeknights.tmechworks.common.entities; | ||
|
||
import com.mojang.authlib.GameProfile; | ||
import net.minecraft.potion.EffectInstance; | ||
import net.minecraft.world.IWorld; | ||
import net.minecraft.world.server.ServerWorld; | ||
import net.minecraftforge.common.util.FakePlayer; | ||
import net.minecraftforge.event.world.WorldEvent; | ||
import slimeknights.tmechworks.TMechworks; | ||
|
||
import java.lang.ref.WeakReference; | ||
import java.util.UUID; | ||
|
||
@SuppressWarnings("EntityConstructor") | ||
public class MechworksFakePlayer extends FakePlayer { | ||
public static final String NAME = "MechworksWorker"; | ||
public static final UUID ID = UUID.nameUUIDFromBytes((TMechworks.modId + ".FakePlayer").getBytes()); | ||
public static final GameProfile PROFILE = new GameProfile(ID, NAME); | ||
|
||
private static MechworksFakePlayer instance; | ||
|
||
private MechworksFakePlayer(ServerWorld world, GameProfile name) { | ||
super(world, name); | ||
} | ||
|
||
public static WeakReference<FakePlayer> getInstance(ServerWorld world) { | ||
if (instance == null) { | ||
instance = new MechworksFakePlayer(world, PROFILE); | ||
} | ||
|
||
instance.world = world; | ||
return new WeakReference<>(instance); | ||
} | ||
|
||
private static void releaseInstance(IWorld world) { | ||
// If the fake player has a reference to the world getting unloaded, | ||
// null out the fake player so that the world can unload | ||
if (instance != null && instance.world == world) { | ||
instance = null; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isPotionApplicable(EffectInstance potioneffectIn) { | ||
return false; | ||
} | ||
|
||
public static void onWorldUnload(WorldEvent.Unload event) { | ||
if (event.getWorld() instanceof ServerWorld) { | ||
releaseInstance(event.getWorld()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters