Skip to content

Commit

Permalink
Fix #52
Browse files Browse the repository at this point in the history
  • Loading branch information
Thelnfamous1 committed Feb 10, 2024
1 parent c0433e6 commit 7d119ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.infamous.dungeons_libraries.capabilities.minionmaster;

import com.infamous.dungeons_libraries.DungeonsLibraries;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceKey;
Expand Down Expand Up @@ -28,10 +29,15 @@ public class Follower implements INBTSerializable<CompoundTag>, Minion {
private boolean revertsOnExpiration = false;
private boolean goalsAdded = false;

@Nullable
public LivingEntity getLeader() {
if (this.leader == null && this.leaderUUID != null && this.levelOnLoad != null) {
ResourceKey<Level> registrykey1 = ResourceKey.create(Registry.DIMENSION_REGISTRY, this.levelOnLoad);
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
if(server == null){
DungeonsLibraries.LOGGER.debug("Tried and failed to query leader by UUID from a Follower with no MinecraftServer present");
return null;
}
ServerLevel world = server.getLevel(registrykey1);
if (world != null) {
Entity entity = world.getEntity(leaderUUID);
Expand All @@ -43,7 +49,7 @@ public LivingEntity getLeader() {
return this.leader;
}

public void setLeader(LivingEntity leader) {
public void setLeader(@Nullable LivingEntity leader) {
this.leader = leader;
if (leader != null) {
this.leaderUUID = leader.getUUID();
Expand Down Expand Up @@ -121,7 +127,7 @@ public CompoundTag serializeNBT() {
}
CompoundTag tag = new CompoundTag();
if (this.getLeader() != null) {
tag.putUUID(LEADER_KEY, this.getLeader().getUUID());
tag.putUUID(LEADER_KEY, this.leaderUUID);
ResourceLocation location = this.getLeader().level.dimension().location();
tag.putString(LEVEL_KEY, location.toString());
}
Expand Down Expand Up @@ -157,7 +163,7 @@ public void deserializeNBT(CompoundTag tag) {
// Methods deprectated after 1.20.0
@Deprecated(forRemoval = true)
@Override
public LivingEntity getMaster() {
public @Nullable LivingEntity getMaster() {
return getLeader();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.infamous.dungeons_libraries.capabilities.minionmaster;

import net.minecraft.world.entity.LivingEntity;
import org.jetbrains.annotations.Nullable;

/**
* @deprecated Use {@link FollowerLeaderHelper} instead.
* Removal in 1.20.0
*/
@Deprecated(forRemoval = true)
public interface Minion {
LivingEntity getMaster();
@Nullable LivingEntity getMaster();
void setMaster(LivingEntity master);
boolean isMinion();
boolean isSummon();
Expand Down

0 comments on commit 7d119ae

Please sign in to comment.