Skip to content

Commit

Permalink
Remove some disguiselib dependant code
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Jun 4, 2022
1 parent 5b97a68 commit ef95e55
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.samo_lego.taterzens.compatibility;

import com.mojang.authlib.GameProfile;
import net.minecraft.world.entity.Entity;
import org.samo_lego.taterzens.npc.TaterzenNPC;
import xyz.nucleoid.disguiselib.api.EntityDisguise;
Expand All @@ -16,15 +15,7 @@ public static void disguiseAs(TaterzenNPC taterzen, Entity entity) {
((EntityDisguise) taterzen).disguiseAs(entity);
}

public static void setGameProfile(TaterzenNPC taterzen, GameProfile gameProfile) {
((EntityDisguise) taterzen).setGameProfile(gameProfile);
}

public static void clearDisguise(TaterzenNPC taterzen) {
((EntityDisguise) taterzen).removeDisguise();
}

public static boolean isDisguised(Entity entity) {
return ((EntityDisguise) entity).isDisguised();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
import org.samo_lego.taterzens.compatibility.DisguiseLibCompatibility;
import org.samo_lego.taterzens.interfaces.ITaterzenEditor;
import org.samo_lego.taterzens.mixin.accessors.ClientboundAddPlayerPacketAccessor;
import org.samo_lego.taterzens.mixin.accessors.ClientboundPlayerInfoPacketAccessor;
Expand All @@ -43,7 +41,6 @@
import static net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket.Action.ADD_PLAYER;
import static net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER;
import static org.samo_lego.taterzens.Taterzens.config;
import static org.samo_lego.taterzens.compatibility.ModDiscovery.DISGUISELIB_LOADED;

/**
* Used to "fake" the TaterzenNPC entity type.
Expand Down Expand Up @@ -85,7 +82,7 @@ private void changeEntityType(Packet<?> packet, GenericFutureListener<? extends
if(packet instanceof ClientboundAddPlayerPacket && !this.taterzens$skipCheck) {
Entity entity = world.getEntity(((ClientboundAddPlayerPacketAccessor) packet).getId());

if(!(entity instanceof TaterzenNPC npc) || (DISGUISELIB_LOADED && DisguiseLibCompatibility.isDisguised(entity)))
if(!(entity instanceof TaterzenNPC npc))
return;

GameProfile profile = npc.getGameProfile();
Expand Down Expand Up @@ -136,20 +133,11 @@ private void changeEntityType(Packet<?> packet, GenericFutureListener<? extends
}

((ClientboundSetEntityDataPacketAccessor) packet).setPackedItems(trackedValues);
} else if(packet instanceof ClientboundPlayerInfoPacket && !this.taterzens$skipCheck) {
((ClientboundPlayerInfoPacketAccessor) packet).getEntries().forEach(entry -> {
if(entry.getProfile().getName().equals("-" + config.defaults.name + "-")) {
// Fixes unloaded taterzens showing in tablist (disguiselib)
var uuid = entry.getProfile().getId();
taterzens$tablistQueue.remove(uuid);
taterzens$tablistQueue.put(uuid, new NpcPlayerUpdate(entry.getProfile(), entry.getDisplayName(), taterzens$queueTick + config.taterzenTablistTimeout));
}
});
}
}

@Inject(method = "handleMovePlayer(Lnet/minecraft/network/protocol/game/ServerboundMovePlayerPacket;)V", at = @At("RETURN"))
private void removeTaterzenFromTablist(ServerboundMovePlayerPacket packet, CallbackInfo ci) {
@Inject(method = "tick", at = @At("RETURN"))
private void removeTaterzenFromTablist(CallbackInfo ci) {
if(taterzens$tablistQueue.isEmpty()) return;

taterzens$queueTick++;
Expand Down
22 changes: 5 additions & 17 deletions common/src/main/java/org/samo_lego/taterzens/npc/TaterzenNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
import org.samo_lego.taterzens.api.TaterzensAPI;
import org.samo_lego.taterzens.api.professions.TaterzenProfession;
import org.samo_lego.taterzens.compatibility.BungeeCompatibility;
import org.samo_lego.taterzens.compatibility.DisguiseLibCompatibility;
import org.samo_lego.taterzens.interfaces.ITaterzenEditor;
import org.samo_lego.taterzens.interfaces.ITaterzenPlayer;
import org.samo_lego.taterzens.mixin.accessors.ChunkMapAccessor;
Expand Down Expand Up @@ -112,7 +111,6 @@
import static org.samo_lego.taterzens.Taterzens.PROFESSION_TYPES;
import static org.samo_lego.taterzens.Taterzens.TATERZEN_NPCS;
import static org.samo_lego.taterzens.Taterzens.config;
import static org.samo_lego.taterzens.compatibility.ModDiscovery.DISGUISELIB_LOADED;
import static org.samo_lego.taterzens.mixin.accessors.PlayerAccessor.getPLAYER_MODE_CUSTOMISATION;
import static org.samo_lego.taterzens.util.TextUtil.errorText;
import static org.samo_lego.taterzens.util.TextUtil.successText;
Expand Down Expand Up @@ -200,9 +198,6 @@ public TaterzenNPC(EntityType<? extends PathfinderMob> entityType, Level world)
this.setSpeed(0.4F);

this.gameProfile = new GameProfile(this.getUUID(), this.getName().getString());
if(DISGUISELIB_LOADED) {
DisguiseLibCompatibility.setGameProfile(this, this.gameProfile);
}
this.server = world.getServer();

// Null check due top gravity changer incompatibility
Expand Down Expand Up @@ -649,15 +644,11 @@ public void setCustomName(Component name) {
public void sendProfileUpdates() {
if (this.level.isClientSide()) return;

if(DISGUISELIB_LOADED)
DisguiseLibCompatibility.setGameProfile(this, this.gameProfile);
else {
ServerChunkCache manager = (ServerChunkCache) this.level.getChunkSource();
ChunkMap storage = manager.chunkMap;
EntityTrackerEntryAccessor trackerEntry = ((ChunkMapAccessor) storage).getEntityMap().get(this.getId());
if(trackerEntry != null)
trackerEntry.getSeenBy().forEach(tracking -> trackerEntry.getPlayer().addPairing(tracking.getPlayer()));
}
ServerChunkCache manager = (ServerChunkCache) this.level.getChunkSource();
ChunkMap storage = manager.chunkMap;
EntityTrackerEntryAccessor trackerEntry = ((ChunkMapAccessor) storage).getEntityMap().get(this.getId());
if(trackerEntry != null)
trackerEntry.getSeenBy().forEach(tracking -> trackerEntry.getPlayer().addPairing(tracking.getPlayer()));
}


Expand Down Expand Up @@ -822,9 +813,6 @@ public void readAdditionalSaveData(CompoundTag tag) {
}

this.gameProfile = new GameProfile(this.getUUID(), profileName);
if(DISGUISELIB_LOADED) {
DisguiseLibCompatibility.setGameProfile(this, this.gameProfile);
}

// Skin is cached
CompoundTag skinTag = npcTag.getCompound("skin");
Expand Down

0 comments on commit ef95e55

Please sign in to comment.