Skip to content

Commit

Permalink
Merge branch '1.20.2-server-renderer' into 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Dec 27, 2023
2 parents 8bcf3c8 + a046a89 commit 51073ad
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 48 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# FeatherMorph

[[English](./README_en.md)] [[Modrinth](https://modrinth.com/plugin/feathermorph)]
[[Modrinth](https://modrinth.com/plugin/feathermorph)]

一个适用于Paper的变形插件。

Expand All @@ -21,12 +21,12 @@
### 依赖关系
FeatherMorph至少需要下面这些依赖才能运行:
- 一个Paper或基于Paper的服务器
- [LibsDisguises](https://www.spigotmc.org/resources/libs-disguises-free.81/) >= 10.0.32 <!--[^ld]-->
- **[1.0.0+ / 0.13.10+]**: [ProtocolLib](https://ci.dmulloy2.net/job/ProtocolLib) >= 678
- **[0.x]** [LibsDisguises](https://www.spigotmc.org/resources/libs-disguises-free.81/) >= 10.0.32 <!--[^ld]-->

<!-- [^ld]: 我们建议使用Jenkins上版本至少为#1154的构建,Spigot页面上的最新版本并不支持1.19.3。-->

另外,我们还支持以下这些插件。这些插件不是必须的,但装上后能让我们提供一些额外功能:
- [GSit](https://www.spigotmc.org/resources/gsit-modern-sit-seat-and-chair-lay-and-crawl-plugin-1-13-x-1-19-x.62325/) - 提供与LibsDisguises之间的一些冲突修复
- [PlaceholderAPI](https://www.spigotmc.org/resources/placeholderapi.6245/) - 占位符可以在[Wiki](https://github.com/XiaMoZhiShi/MorphPlugin/wiki/PlaceholderAPI)中查询到

### 构建
Expand Down
42 changes: 0 additions & 42 deletions README_en.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.EntityEquipment;
import xiamomc.morph.MorphPluginObject;
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex;
import xiamomc.morph.backends.server.renderer.network.datawatcher.values.AbstractValues;
import xiamomc.morph.backends.server.renderer.network.datawatcher.values.SingleValue;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.SingleWatcher;
import xiamomc.morph.backends.server.renderer.network.registries.EntryIndex;
Expand Down Expand Up @@ -137,6 +139,38 @@ public List<PacketContainer> buildSpawnPackets(Player player, DisplayParameters
return packets;
}

/**
* 从给定的meta包中移除不属于给定AbstractValues的数据
* @return
*/
public PacketContainer removeNonLivingValues(AbstractValues av, PacketContainer originalPacket)
{
if (originalPacket.getType() != PacketType.Play.Server.ENTITY_METADATA)
throw new IllegalArgumentException("Original packet is not a valid metadata packet!");

var livingValues = av.getValues();
var modifier = originalPacket.getDataValueCollectionModifier();

//获取原Meta包中的数据
var wrappedData = modifier.read(0);

//剔除不属于BASE_LIVING的数据
wrappedData.removeIf(w ->
{
var rawValue = w.getRawValue();

var match = livingValues.stream().filter(sv ->
w.getIndex() == sv.index() && (rawValue == null || rawValue.getClass() == sv.defaultValue().getClass())
).findFirst().orElse(null);

return match == null;
});

modifier.write(0, wrappedData);

return originalPacket;
}

public PacketContainer buildDiffMetaPacket(Player player, SingleWatcher watcher)
{
var metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.GamePhase;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import xiamomc.morph.MorphPlugin;
import xiamomc.morph.backends.server.renderer.network.PacketFactory;
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex;
import xiamomc.morph.backends.server.renderer.network.registries.RenderRegistry;
import xiamomc.morph.utilities.NmsUtils;
import xiamomc.pluginbase.Annotations.Resolved;
Expand Down Expand Up @@ -64,12 +66,14 @@ private void onMetaPacket(ClientboundSetEntityDataPacket packet, PacketEvent pac
return;

//不要二次处理来自我们自己的包
//并且不要处理同为玩家的Meta包
var packetContainer = packetEvent.getPacket();
var meta = packetContainer.getMeta(PacketFactory.MORPH_PACKET_METAKEY);
if (meta.isEmpty())
if (meta.isEmpty() && watcher.getEntityType() != EntityType.PLAYER)
{
//取得来源玩家的伪装后的Meta,发送给目标玩家
packetEvent.setPacket(getFactory().buildFullMetaPacket(sourcePlayer, watcher));
//从包里移除玩家meta中不属于BASE_LIVING的部分
packetEvent.setPacket(getFactory().removeNonLivingValues(ValueIndex.BASE_LIVING, packetContainer));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.minecraft.world.level.GameType;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
Expand Down

0 comments on commit 51073ad

Please sign in to comment.