Added shoulder property for Player

This commit is contained in:
D3v1s0m 2023-09-13 00:53:25 +05:30
parent e4ff39bc79
commit 9be27f0748
No known key found for this signature in database
GPG Key ID: FA1F770C7B1D40C1
2 changed files with 63 additions and 4 deletions

@ -3,6 +3,9 @@ package lol.pyr.znpcsplus.entity;
import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.nbt.NBTInt;
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
import com.github.retrooper.packetevents.protocol.player.EquipmentSlot; import com.github.retrooper.packetevents.protocol.player.EquipmentSlot;
import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry;
@ -72,10 +75,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
/* /*
registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation
// Player
registerType("shoulder_entity_left", ParrotVariant.NONE);
registerType("shoulder_entity_right", ParrotVariant.NONE);
// End Crystal // End Crystal
registerType("beam_target", null); // TODO: Make a block pos class for this registerType("beam_target", null); // TODO: Make a block pos class for this
registerType("show_base", true); // TODO registerType("show_base", true); // TODO
@ -368,6 +367,17 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
else parrotIndex = 15; else parrotIndex = 15;
register(new EncodedIntegerProperty<>("parrot_variant", ParrotVariant.RED_BLUE, parrotIndex, Enum::ordinal)); register(new EncodedIntegerProperty<>("parrot_variant", ParrotVariant.RED_BLUE, parrotIndex, Enum::ordinal));
// Player
NBTProperty.NBTDecoder<ParrotVariant> parrotVariantDecoder = (variant) -> {
NBTCompound compound = new NBTCompound();
compound.setTag("id", new NBTString("minecraft:parrot"));
compound.setTag("Variant", new NBTInt(variant.ordinal()));
return compound;
};
int shoulderIndex = skinLayersIndex+2;
register(new NBTProperty<>("shoulder_entity_left", ParrotVariant.class, shoulderIndex++, parrotVariantDecoder));
register(new NBTProperty<>("shoulder_entity_right", ParrotVariant.class, shoulderIndex, parrotVariantDecoder));
if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return;
// Pose // Pose
register(new NpcPoseProperty()); register(new NpcPoseProperty());

@ -0,0 +1,49 @@
package lol.pyr.znpcsplus.entity.properties;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataType;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
import lol.pyr.znpcsplus.entity.PacketEntity;
import org.bukkit.entity.Player;
import java.util.Map;
public class NBTProperty<T> extends EntityPropertyImpl<T> {
private final EntityDataType<NBTCompound> type;
private final NBTDecoder<T> decoder;
private final int index;
public NBTProperty(String name, T defaultValue, Class<T> clazz, int index, NBTDecoder<T> decoder, EntityDataType<NBTCompound> type) {
super(name, defaultValue, clazz);
this.decoder = decoder;
this.index = index;
this.type = type;
}
@SuppressWarnings("unchecked")
public NBTProperty(String name, T defaultValue, int index, NBTDecoder<T> decoder) {
this(name, defaultValue, (Class<T>) defaultValue.getClass(), index, decoder, EntityDataTypes.NBT);
}
@SuppressWarnings("unchecked")
public NBTProperty(String name, T defaultValue, int index, NBTDecoder<T> decoder, EntityDataType<NBTCompound> type) {
this(name, defaultValue, (Class<T>) defaultValue.getClass(), index, decoder, type);
}
public NBTProperty(String name, Class<T> clazz, int index, NBTDecoder<T> decoder) {
this(name, null, clazz, index, decoder, EntityDataTypes.NBT);
}
@Override
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
T value = entity.getProperty(this);
if (value == null) return;
properties.put(index, newEntityData(index, type, decoder.decode(value)));
}
public interface NBTDecoder<T> {
NBTCompound decode(T obj);
}
}