implement cat & tamed property
This commit is contained in:
parent
f2a4d51e28
commit
551b989240
9 changed files with 46 additions and 112 deletions
|
@ -1,25 +1,15 @@
|
|||
package lol.pyr.znpcsplus.util;
|
||||
|
||||
public enum CatVariant {
|
||||
TABBY(0),
|
||||
BLACK(1),
|
||||
RED(2),
|
||||
SIAMESE(3),
|
||||
BRITISH_SHORTHAIR(4),
|
||||
CALICO(5),
|
||||
PERSIAN(6),
|
||||
RAGDOLL(7),
|
||||
WHITE(8),
|
||||
JELLIE(9),
|
||||
ALL_BLACK(10);
|
||||
|
||||
private final int id;
|
||||
|
||||
CatVariant(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
TABBY,
|
||||
BLACK,
|
||||
RED,
|
||||
SIAMESE,
|
||||
BRITISH_SHORTHAIR,
|
||||
CALICO,
|
||||
PERSIAN,
|
||||
RAGDOLL,
|
||||
WHITE,
|
||||
JELLIE,
|
||||
ALL_BLACK
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ 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.player.EquipmentSlot;
|
||||
import lol.pyr.znpcsplus.api.entity.EntityProperty;
|
||||
import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry;
|
||||
|
@ -210,6 +211,15 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
|||
linkProperties("glow", "fire", "invisible");
|
||||
register(new BooleanProperty("silent", 4, false, legacyBooleans));
|
||||
|
||||
final int tamedIndex;
|
||||
if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) tamedIndex = 17;
|
||||
else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) tamedIndex = 16;
|
||||
else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) tamedIndex = 15;
|
||||
else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) tamedIndex = 13;
|
||||
else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) tamedIndex = 12;
|
||||
else tamedIndex = 16;
|
||||
register(new BitsetProperty("tamed", tamedIndex, 0x04));
|
||||
|
||||
int potionIndex;
|
||||
if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) potionIndex = 10;
|
||||
else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) potionIndex = 9;
|
||||
|
@ -276,6 +286,16 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
|||
|
||||
if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return;
|
||||
|
||||
// Cat
|
||||
int catIndex;
|
||||
if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) catIndex = 19;
|
||||
else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) catIndex = 18;
|
||||
else catIndex = 17;
|
||||
register(new EncodedIntegerProperty<>("cat_variant", CatVariant.BLACK, catIndex++, Enum::ordinal, EntityDataTypes.CAT_VARIANT));
|
||||
register(new BooleanProperty("cat_laying", catIndex++, false, legacyBooleans));
|
||||
register(new BooleanProperty("cat_relaxed", catIndex++, false, legacyBooleans));
|
||||
register(new EncodedIntegerProperty<>("cat_collar", DyeColor.RED, catIndex, Enum::ordinal));
|
||||
|
||||
// Fox
|
||||
int foxIndex;
|
||||
if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) foxIndex = 17;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
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 lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||
|
@ -9,29 +10,36 @@ import org.bukkit.entity.Player;
|
|||
import java.util.Map;
|
||||
|
||||
public class EncodedIntegerProperty<T> extends EntityPropertyImpl<T> {
|
||||
private final EntityDataType<Integer> type;
|
||||
private final IntegerDecoder<T> decoder;
|
||||
private final int index;
|
||||
|
||||
protected EncodedIntegerProperty(String name, T defaultValue, Class<T> clazz, int index, IntegerDecoder<T> decoder) {
|
||||
protected EncodedIntegerProperty(String name, T defaultValue, Class<T> clazz, int index, IntegerDecoder<T> decoder, EntityDataType<Integer> type) {
|
||||
super(name, defaultValue, clazz);
|
||||
this.decoder = decoder;
|
||||
this.index = index;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public EncodedIntegerProperty(String name, T defaultValue, int index, IntegerDecoder<T> decoder) {
|
||||
this(name, defaultValue, (Class<T>) defaultValue.getClass(), index, decoder);
|
||||
this(name, defaultValue, (Class<T>) defaultValue.getClass(), index, decoder, EntityDataTypes.INT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public EncodedIntegerProperty(String name, T defaultValue, int index, IntegerDecoder<T> decoder, EntityDataType<Integer> type) {
|
||||
this(name, defaultValue, (Class<T>) defaultValue.getClass(), index, decoder, type);
|
||||
}
|
||||
|
||||
public EncodedIntegerProperty(String name, Class<T> clazz, int index, IntegerDecoder<T> decoder) {
|
||||
this(name, null, clazz, index, decoder);
|
||||
this(name, null, clazz, index, decoder, EntityDataTypes.INT);
|
||||
}
|
||||
|
||||
@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, EntityDataTypes.INT, decoder.decode(value)));
|
||||
properties.put(index, newEntityData(index, type, decoder.decode(value)));
|
||||
}
|
||||
|
||||
public interface IntegerDecoder<T> {
|
||||
|
|
|
@ -2,10 +2,8 @@ package lol.pyr.znpcsplus.metadata;
|
|||
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
|
||||
import lol.pyr.znpcsplus.util.CatVariant;
|
||||
import lol.pyr.znpcsplus.util.CreeperState;
|
||||
import lol.pyr.znpcsplus.util.ParrotVariant;
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
/**
|
||||
* 1.8 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=7415">...</a>
|
||||
|
@ -38,12 +36,6 @@ public interface MetadataFactory {
|
|||
// Blaze
|
||||
EntityData blazeOnFire(boolean onFire);
|
||||
|
||||
// Cat
|
||||
EntityData catVariant(CatVariant variant);
|
||||
EntityData catLying(boolean lying);
|
||||
EntityData catTamed(boolean tamed);
|
||||
EntityData catCollarColor(DyeColor collarColor);
|
||||
|
||||
// Creeper
|
||||
EntityData creeperState(CreeperState state);
|
||||
EntityData creeperCharged(boolean charged);
|
||||
|
|
|
@ -4,10 +4,8 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
|||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
|
||||
import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
|
||||
import lol.pyr.znpcsplus.util.CatVariant;
|
||||
import lol.pyr.znpcsplus.util.CreeperState;
|
||||
import lol.pyr.znpcsplus.util.ParrotVariant;
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
@Deprecated
|
||||
public class V1_14MetadataFactory extends V1_13MetadataFactory {
|
||||
|
@ -37,21 +35,6 @@ public class V1_14MetadataFactory extends V1_13MetadataFactory {
|
|||
return newEntityData(14, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catVariant(CatVariant variant) {
|
||||
return newEntityData(17, EntityDataTypes.CAT_VARIANT, variant.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catLying(boolean lying) {
|
||||
throw new UnsupportedOperationException("The cat lying entity data isn't supported on this version");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catCollarColor(DyeColor collarColor) {
|
||||
return newEntityData(20, EntityDataTypes.INT, collarColor.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData creeperState(CreeperState state) {
|
||||
return newEntityData(14, EntityDataTypes.INT, state.getState());
|
||||
|
|
|
@ -3,10 +3,8 @@ package lol.pyr.znpcsplus.metadata;
|
|||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
|
||||
import lol.pyr.znpcsplus.util.CatVariant;
|
||||
import lol.pyr.znpcsplus.util.CreeperState;
|
||||
import lol.pyr.znpcsplus.util.ParrotVariant;
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
@Deprecated
|
||||
public class V1_15MetadataFactory extends V1_14MetadataFactory {
|
||||
|
@ -25,21 +23,6 @@ public class V1_15MetadataFactory extends V1_14MetadataFactory {
|
|||
return newEntityData(15, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catVariant(CatVariant variant) {
|
||||
return newEntityData(18, EntityDataTypes.CAT_VARIANT, variant.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catLying(boolean lying) {
|
||||
return newEntityData(19, EntityDataTypes.BOOLEAN, lying);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catCollarColor(DyeColor collarColor) {
|
||||
return newEntityData(21, EntityDataTypes.INT, collarColor.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData creeperState(CreeperState state) {
|
||||
return newEntityData(15, EntityDataTypes.INT, state.getState());
|
||||
|
|
|
@ -3,10 +3,8 @@ package lol.pyr.znpcsplus.metadata;
|
|||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
|
||||
import lol.pyr.znpcsplus.util.CatVariant;
|
||||
import lol.pyr.znpcsplus.util.CreeperState;
|
||||
import lol.pyr.znpcsplus.util.ParrotVariant;
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
@Deprecated
|
||||
public class V1_17MetadataFactory extends V1_16MetadataFactory {
|
||||
|
@ -41,26 +39,6 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory {
|
|||
return newEntityData(16, EntityDataTypes.BYTE, (byte) (onFire ? 0x01 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catVariant(CatVariant variant) {
|
||||
return newEntityData(19, EntityDataTypes.CAT_VARIANT, variant.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catLying(boolean lying) {
|
||||
return newEntityData(20, EntityDataTypes.BOOLEAN, lying);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catTamed(boolean tamed) {
|
||||
return newEntityData(17, EntityDataTypes.BYTE, (byte) (tamed ? 0x04 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catCollarColor(DyeColor collarColor) {
|
||||
return newEntityData(22, EntityDataTypes.INT, collarColor.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData creeperState(CreeperState state) {
|
||||
return newEntityData(16, EntityDataTypes.INT, state.getState());
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityDataType;
|
|||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
|
||||
import lol.pyr.znpcsplus.util.*;
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
@Deprecated
|
||||
public class V1_8MetadataFactory implements MetadataFactory {
|
||||
|
@ -45,26 +44,6 @@ public class V1_8MetadataFactory implements MetadataFactory {
|
|||
return newEntityData(16, EntityDataTypes.BYTE, (byte) (onFire ? 1 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catVariant(CatVariant variant) {
|
||||
throw new UnsupportedOperationException("The cat variant entity data isn't supported on this version");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catLying(boolean lying) {
|
||||
throw new UnsupportedOperationException("The cat lying entity data isn't supported on this version");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catTamed(boolean tamed) {
|
||||
throw new UnsupportedOperationException("The cat tamed entity data isn't supported on this version");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData catCollarColor(DyeColor collarColor) {
|
||||
throw new UnsupportedOperationException("The cat collar color entity data isn't supported on this version");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData creeperState(CreeperState state) {
|
||||
return newEntityData(16, EntityDataTypes.BYTE, (byte) state.getState());
|
||||
|
|
|
@ -143,7 +143,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
|
|||
.setHologramOffset(1.525));
|
||||
|
||||
register(builder(p, "wolf", EntityTypes.WOLF)
|
||||
.setHologramOffset(-1.125));
|
||||
.setHologramOffset(-1.125)
|
||||
.addProperties("tamed"));
|
||||
|
||||
register(builder(p, "zombie", EntityTypes.ZOMBIE)
|
||||
.setHologramOffset(-0.025)
|
||||
|
@ -250,7 +251,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
|
|||
|
||||
register(builder(p, "cat", EntityTypes.CAT)
|
||||
.setHologramOffset(-1.275)
|
||||
.addProperties("cat_variant", "cat_lying", "cat_collar_color"));
|
||||
.addProperties("cat_variant", "cat_laying", "cat_relaxed", "cat_collar", "tamed"));
|
||||
|
||||
register(builder(p, "fox", EntityTypes.FOX)
|
||||
.setHologramOffset(-1.275)
|
||||
|
|
Loading…
Reference in a new issue