Skip to content

Commit

Permalink
misc: Fix bed pos and custom name
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Dec 13, 2023
1 parent 814e51d commit 6889c3b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.core.BlockPos;
import xiamomc.morph.MorphPlugin;
import xiamomc.morph.backends.server.renderer.utilties.ProtocolRegistryUtils;

import java.util.List;

Expand All @@ -24,7 +26,7 @@ protected void registerSingle(SingleValue<?> value)

try
{
WrappedDataWatcher.Registry.get(value.type());
ProtocolRegistryUtils.getSerializer(value.defaultValue());
}
catch (Throwable t)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types;

import com.destroystokyo.paper.ClientOption;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex;

import java.util.Optional;

public class PlayerWatcher extends LivingEntityWatcher
{
public PlayerWatcher(Player bindingPlayer, EntityType entityType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.SingleWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.Watchers;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.PlayerWatcher;
import xiamomc.morph.backends.server.renderer.utilties.ProtocolRegistryUtils;
import xiamomc.morph.misc.MorphGameProfile;
import xiamomc.morph.misc.NmsRecord;
import xiamomc.morph.utilities.EntityTypeUtils;
Expand Down Expand Up @@ -237,7 +238,7 @@ private PacketContainer getMetaPackets(Player player, SingleWatcher watcher)

try
{
serializer = WrappedDataWatcher.Registry.get(single.type());
serializer = ProtocolRegistryUtils.getSerializer(single.defaultValue());
}
catch (Throwable t)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package xiamomc.morph.backends.server.renderer.utilties;

import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;

import java.util.Optional;

public class ProtocolRegistryUtils
{
public static WrappedDataWatcher.Serializer getSerializer(Object instance)
{
var clazz = instance.getClass();

if (instance instanceof Optional<?> optional)
{
if (optional.isEmpty())
throw new IllegalArgumentException("An empty Optional is given");

clazz = optional.get().getClass();
instance = optional.get();
}

if (clazz == BlockPos.class)
return WrappedDataWatcher.Registry.getBlockPositionSerializer(true);

if (instance instanceof Component)
return WrappedDataWatcher.Registry.getChatComponentSerializer(true);

return WrappedDataWatcher.Registry.get(clazz);
}
}

0 comments on commit 6889c3b

Please sign in to comment.