Skip to content

Commit

Permalink
Fix panda watcher don't merge custom NBTs
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Dec 15, 2023
1 parent fa2d796 commit 3d422e1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public void mergeCompound(CompoundTag compoundTag)
@Override
public CompoundTag getCompound()
{
if (bindingWatcher != null)
instance.compoundTag.merge(WatcherUtils.buildCompoundFromWatcher(bindingWatcher));

return instance.compoundTag.copy();
}

Expand Down Expand Up @@ -308,6 +311,7 @@ private void refreshRegistry()
return;
}

//先和watcher同步一下我们的NBT
bindingWatcher.mergeFromCompound(getCompound());

//todo: 激活刷新时也刷新到玩家
Expand All @@ -321,6 +325,8 @@ private void refreshRegistry()
if (bindingWatcher.getEntityType() == EntityType.GHAST)
bindingWatcher.write(ValueIndex.GHAST.CHARGING, aggressive);

//然后从watcher拉取他们的NBT。
//如果watcher有存在会随机的值,此举会将随机的值同步给我们
this.instance.compoundTag.merge(WatcherUtils.buildCompoundFromWatcher(bindingWatcher));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types;

import net.minecraft.nbt.CompoundTag;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Panda;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -47,4 +48,31 @@ protected void initValues()
write(ValueIndex.PANDA.MAIN_GENE, (byte)mainGene.ordinal());
write(ValueIndex.PANDA.HIDDEN_GENE, (byte)hiddenGene.ordinal());
}

@Override
public void mergeFromCompound(CompoundTag nbt)
{
super.mergeFromCompound(nbt);

if (nbt.contains("MainGene"))
write(ValueIndex.PANDA.MAIN_GENE, (byte)getGeneFromName(nbt.getString("MainGene")).ordinal());

if (nbt.contains("HiddenGene"))
write(ValueIndex.PANDA.HIDDEN_GENE, (byte)getGeneFromName(nbt.getString("HiddenGene")).ordinal());
}

private Panda.Gene getGeneFromName(String name)
{
var gene = Panda.Gene.values();
var match = Arrays.stream(gene).filter(g -> g.name().equalsIgnoreCase(name))
.findFirst().orElse(null);

if (match == null)
{
logger.warn("Null Gene for name " + name + "?!");
match = Panda.Gene.NORMAL;
}

return match;
}
}

0 comments on commit 3d422e1

Please sign in to comment.