Skip to content

Commit

Permalink
misc: 调整流程,尝试修复盔甲架显示手臂的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Jul 6, 2024
1 parent 47cbe38 commit d6aadc8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/xiamomc/morph/MorphManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ private void postBuildDisguise(DisguiseBuildResult result,
var state = result.state();

// 初始化nbt
var wrapperCompound = provider.getNbtCompound(state, targetEntity, false);
var wrapperCompound = provider.getInitialNbtCompound(state, targetEntity, false);

if (wrapperCompound != null)
state.getDisguiseWrapper().mergeCompound(wrapperCompound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public void mergeCompound(CompoundTag compoundTag)
if (bindingWatcher instanceof AgeableMobWatcher)
bindingWatcher.write(ValueIndex.AGEABLE_MOB.IS_BABY, instance.isBaby);

instance.armorStandSmall = compoundTag.getBoolean("Small");
instance.armorStandNoBasePlate = compoundTag.getBoolean("NoBasePlate");
instance.armorStandShowArms = compoundTag.getBoolean("ShowArms");
if (compoundTag.contains("Small")) instance.armorStandSmall = compoundTag.getBoolean("Small");
if (compoundTag.contains("NoBasePlate")) instance.armorStandNoBasePlate = compoundTag.getBoolean("NoBasePlate");
if (compoundTag.contains("ShowArms")) instance.armorStandShowArms = compoundTag.getBoolean("ShowArms");
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/xiamomc/morph/providers/DisguiseProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,15 @@ public boolean validForClient(DisguiseState state)
return false;
}

/**
* 获取此伪装的初始NBT(如果有),如果有目标实体则尝试复制目标实体的NBT
* @param state
* @param targetEntity
* @param enableCulling 是否要隐藏一些信息防止被客户端获取?
* @return
*/
@Nullable
public CompoundTag getNbtCompound(DisguiseState state, Entity targetEntity, boolean enableCulling)
public CompoundTag getInitialNbtCompound(DisguiseState state, Entity targetEntity, boolean enableCulling)
{
if (targetEntity instanceof CraftLivingEntity
&& canConstruct(getMorphManager().getDisguiseMeta(state.getDisguiseIdentifier()), targetEntity, null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ public boolean validForClient(DisguiseState state)
}

@Override
public @Nullable CompoundTag getNbtCompound(DisguiseState state, Entity targetEntity, boolean enableCulling)
public @Nullable CompoundTag getInitialNbtCompound(DisguiseState state, Entity targetEntity, boolean enableCulling)
{
if (!(targetEntity instanceof Player targetPlayer)) return null;

if (!targetPlayer.getName().equals(DisguiseTypes.PLAYER.toStrippedId(state.getDisguiseIdentifier()))) return null;

return super.getNbtCompound(state, targetEntity, enableCulling);
return super.getInitialNbtCompound(state, targetEntity, enableCulling);
}

@Override
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/xiamomc/morph/providers/VanillaDisguiseProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,29 +375,32 @@ public boolean unMorph(Player player, DisguiseState state)
}

@Override
public @Nullable CompoundTag getNbtCompound(DisguiseState state, Entity targetEntity, boolean enableCulling)
public @Nullable CompoundTag getInitialNbtCompound(DisguiseState state, Entity targetEntity, boolean enableCulling)
{
var info = getMorphManager().getDisguiseMeta(state.getDisguiseIdentifier());

var rawCompound = targetEntity != null && canConstruct(info, targetEntity, null)
? NbtUtils.getRawTagCompound(targetEntity)
: NbtUtils.toCompoundTag(state.getFullNbtString());

if (rawCompound == null) rawCompound = new CompoundTag();
: new CompoundTag();

var theirDisguise = getMorphManager().getDisguiseStateFor(targetEntity);

if (theirDisguise != null)
{
rawCompound = theirDisguise.getDisguiseWrapper().getCompound();

if (state.getEntityType().equals(EntityType.ARMOR_STAND)
&& rawCompound.get("ShowArms") == null)
}
else
{
rawCompound.putBoolean("ShowArms", armorStandShowArms.get());
if (state.getEntityType().equals(EntityType.ARMOR_STAND)
&& rawCompound.get("ShowArms") == null)
{
rawCompound.putBoolean("ShowArms", armorStandShowArms.get());
}
}

if (targetEntity == null || targetEntity.getType() != state.getEntityType())
rawCompound.merge(state.getDisguiseWrapper().getCompound());
// ???
// if (targetEntity == null || targetEntity.getType() != state.getEntityType())
// rawCompound.merge(state.getDisguiseWrapper().getCompound());

return enableCulling ? cullNBT(rawCompound) : rawCompound;
}
Expand Down

0 comments on commit d6aadc8

Please sign in to comment.