Added mooshroom_variant property

This commit is contained in:
D3v1s0m 2023-09-10 18:49:05 +05:30
parent 55308d6a79
commit 0127af865b
No known key found for this signature in database
GPG Key ID: FA1F770C7B1D40C1
5 changed files with 68 additions and 4 deletions

@ -0,0 +1,10 @@
package lol.pyr.znpcsplus.util;
public enum MooshroomVariant {
RED,
BROWN;
public static String getVariantName(MooshroomVariant variant) {
return variant.name().toLowerCase();
}
}

@ -271,6 +271,7 @@ public class ZNpcsPlus extends JavaPlugin {
registerEnumParser(manager, HorseColor.class, incorrectUsageMessage); registerEnumParser(manager, HorseColor.class, incorrectUsageMessage);
registerEnumParser(manager, HorseArmor.class, incorrectUsageMessage); registerEnumParser(manager, HorseArmor.class, incorrectUsageMessage);
registerEnumParser(manager, LlamaVariant.class, incorrectUsageMessage); registerEnumParser(manager, LlamaVariant.class, incorrectUsageMessage);
registerEnumParser(manager, MooshroomVariant.class, incorrectUsageMessage);
manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root")) manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root"))
.addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry)) .addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry))

@ -65,6 +65,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
registerEnumSerializer(HorseStyle.class); registerEnumSerializer(HorseStyle.class);
registerEnumSerializer(HorseArmor.class); registerEnumSerializer(HorseArmor.class);
registerEnumSerializer(LlamaVariant.class); registerEnumSerializer(LlamaVariant.class);
registerEnumSerializer(MooshroomVariant.class);
/* /*
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
@ -147,9 +148,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
// Wither // Wither
registerType("invulnerable_time", 0); // TODO registerType("invulnerable_time", 0); // TODO
// Phantom
registerType("phantom_size", 0); // TODO
*/ */
} }
@ -384,6 +382,12 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
register(new BitsetProperty("fox_sleeping", foxIndex, 0x20)); register(new BitsetProperty("fox_sleeping", foxIndex, 0x20));
linkProperties("fox_sitting", "fox_crouching", "fox_sleeping"); linkProperties("fox_sitting", "fox_crouching", "fox_sleeping");
int mooshroomIndex;
if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) mooshroomIndex = 17;
else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) mooshroomIndex = 16;
else mooshroomIndex = 15;
register(new EncodedStringProperty<>("mooshroom_variant", MooshroomVariant.RED, mooshroomIndex, MooshroomVariant::getVariantName));
if (!ver.isNewerThanOrEquals(ServerVersion.V_1_15)) return; if (!ver.isNewerThanOrEquals(ServerVersion.V_1_15)) return;
register(new BitsetProperty("fox_faceplanted", foxIndex, 0x40)); register(new BitsetProperty("fox_faceplanted", foxIndex, 0x40));

@ -0,0 +1,48 @@
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;
import org.bukkit.entity.Player;
import java.util.Map;
public class EncodedStringProperty<T> extends EntityPropertyImpl<T> {
private final EntityDataType<String> type;
private final EncodedStringProperty.StringDecoder<T> decoder;
private final int index;
public EncodedStringProperty(String name, T defaultValue, Class<T> clazz, int index, StringDecoder<T> decoder, EntityDataType<String> type) {
super(name, defaultValue, clazz);
this.decoder = decoder;
this.index = index;
this.type = type;
}
@SuppressWarnings("unchecked")
public EncodedStringProperty(String name, T defaultValue, int index, StringDecoder<T> decoder) {
this(name, defaultValue, (Class<T>) defaultValue.getClass(), index, decoder, EntityDataTypes.STRING);
}
@SuppressWarnings("unchecked")
public EncodedStringProperty(String name, T defaultValue, int index, StringDecoder<T> decoder, EntityDataType<String> type) {
this(name, defaultValue, (Class<T>) defaultValue.getClass(), index, decoder, type);
}
public EncodedStringProperty(String name, Class<T> clazz, int index, StringDecoder<T> decoder) {
this(name, null, clazz, index, decoder, EntityDataTypes.STRING);
}
@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 StringDecoder<T> {
String decode(T obj);
}
}

@ -104,7 +104,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "magma_cube", EntityTypes.MAGMA_CUBE)); // TODO: Hologram offset scaling with size property register(builder(p, "magma_cube", EntityTypes.MAGMA_CUBE)); // TODO: Hologram offset scaling with size property
register(builder(p, "mooshroom", EntityTypes.MOOSHROOM) register(builder(p, "mooshroom", EntityTypes.MOOSHROOM)
.setHologramOffset(-0.575)); .setHologramOffset(-0.575)
.addProperties("mooshroom_variant"));
register(builder(p, "ocelot", EntityTypes.OCELOT) register(builder(p, "ocelot", EntityTypes.OCELOT)
.setHologramOffset(-1.275)); .setHologramOffset(-1.275));