Added shoulder property for Player
This commit is contained in:
parent
e4ff39bc79
commit
9be27f0748
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.manager.server.ServerVersion;
|
||||
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 lol.pyr.znpcsplus.api.entity.EntityProperty;
|
||||
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
|
||||
|
||||
// Player
|
||||
registerType("shoulder_entity_left", ParrotVariant.NONE);
|
||||
registerType("shoulder_entity_right", ParrotVariant.NONE);
|
||||
|
||||
// End Crystal
|
||||
registerType("beam_target", null); // TODO: Make a block pos class for this
|
||||
registerType("show_base", true); // TODO
|
||||
|
@ -368,6 +367,17 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
|||
else parrotIndex = 15;
|
||||
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;
|
||||
// Pose
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue