3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Fixup legacy entity type hierarchy and namings (#3849)

Dieser Commit ist enthalten in:
EnZaXD 2024-05-14 14:43:34 +02:00 committet von Nassim Jahnke
Ursprung 0fc0259d8c
Commit 04b31d70b2
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
13 geänderte Dateien mit 1218 neuen und 588 gelöschten Zeilen

Datei anzeigen

@ -25,141 +25,160 @@ package com.viaversion.viaversion.api.minecraft.entities;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
// 1.10 Entity / Object ids
public class EntityTypes1_10 { public class EntityTypes1_10 {
public static EntityType getTypeFromId(int typeID, boolean isObject) { public static EntityType getTypeFromId(final int typeId, final boolean object) {
Optional<EntityType> type; EntityType type;
if (isObject) if (object) {
type = ObjectType.getPCEntity(typeID); type = ObjectType.getEntityType(typeId);
else } else {
type = EntityType.findById(typeID); type = EntityType.findById(typeId);
}
if (type.isEmpty()) { if (type == null) {
Via.getPlatform().getLogger().severe("Could not find 1.10 type id " + typeID + " isObject=" + isObject); Via.getPlatform().getLogger().severe("Could not find 1.10 type id " + typeId + " objectType=" + object);
return EntityType.ENTITY; // Fall back to the basic ENTITY return EntityType.ENTITY; // Fall back to the basic ENTITY
} }
return type;
return type.get();
} }
public enum EntityType implements com.viaversion.viaversion.api.minecraft.entities.EntityType { public enum EntityType implements com.viaversion.viaversion.api.minecraft.entities.EntityType {
ENTITY(-1),
DROPPED_ITEM(1, ENTITY), ENTITY,
AREA_EFFECT_CLOUD(3, ENTITY),
END_CRYSTAL(200, ENTITY),
EXPERIENCE_ORB(2, ENTITY), EXPERIENCE_ORB(2, ENTITY),
LEASH_HITCH(8, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata EYE_OF_ENDER(15, ENTITY),
PAINTING(9, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata
ARROW(10, ENTITY),
SNOWBALL(11, ENTITY), // Actually EntityProjectile
FIREBALL(12, ENTITY),
SMALL_FIREBALL(13, ENTITY),
ENDER_PEARL(14, ENTITY), // Actually EntityProjectile
ENDER_SIGNAL(15, ENTITY),
THROWN_EXP_BOTTLE(17, ENTITY),
ITEM_FRAME(18, ENTITY), // Actually EntityHanging
WITHER_SKULL(19, ENTITY),
PRIMED_TNT(20, ENTITY),
FALLING_BLOCK(21, ENTITY), FALLING_BLOCK(21, ENTITY),
FIREWORK(22, ENTITY), ITEM(1, ENTITY),
TIPPED_ARROW(23, ARROW), TNT(20, ENTITY),
SPECTRAL_ARROW(24, ARROW), LIGHTNING_BOLT(ENTITY), // Needed for entity (un)tracking
// Hanging entities
HANGING_ENTITY(ENTITY),
LEASH_KNOT(8, HANGING_ENTITY),
ITEM_FRAME(18, HANGING_ENTITY),
PAINTING(9, HANGING_ENTITY),
// Projectiles
PROJECTILE(ENTITY),
FIREWORK_ROCKET(22, ENTITY),
SHULKER_BULLET(25, ENTITY), SHULKER_BULLET(25, ENTITY),
DRAGON_FIREBALL(26, FIREBALL), SNOWBALL(11, PROJECTILE),
ENDER_PEARL(14, PROJECTILE),
EGG(7, PROJECTILE),
EXPERIENCE_BOTTLE(17, PROJECTILE),
POTION(16, PROJECTILE),
FISHING_HOOK(ENTITY),
ENTITY_LIVING(-1, ENTITY), ABSTRACT_ARROW(ENTITY),
ENTITY_INSENTIENT(-1, ENTITY_LIVING), ARROW(10, ABSTRACT_ARROW),
ENTITY_AGEABLE(-1, ENTITY_INSENTIENT), SPECTRAL_ARROW(24, ABSTRACT_ARROW),
ENTITY_TAMEABLE_ANIMAL(-1, ENTITY_AGEABLE),
ENTITY_HUMAN(-1, ENTITY_LIVING),
ARMOR_STAND(30, ENTITY_LIVING), HURTING_PROJECTILE(ENTITY),
DRAGON_FIREBALL(26, HURTING_PROJECTILE),
FIREBALL(12, HURTING_PROJECTILE),
SMALL_FIREBALL(13, HURTING_PROJECTILE),
WITHER_SKULL(19, HURTING_PROJECTILE),
// Vehicles // Vehicles
MINECART_ABSTRACT(-1, ENTITY),
MINECART_COMMAND(40, MINECART_ABSTRACT),
BOAT(41, ENTITY), BOAT(41, ENTITY),
MINECART_RIDEABLE(42, MINECART_ABSTRACT),
MINECART_CHEST(43, MINECART_ABSTRACT),
MINECART_FURNACE(44, MINECART_ABSTRACT),
MINECART_TNT(45, MINECART_ABSTRACT),
MINECART_HOPPER(46, MINECART_ABSTRACT),
MINECART_MOB_SPAWNER(47, MINECART_ABSTRACT),
CREEPER(50, ENTITY_INSENTIENT), ABSTRACT_MINECART(ENTITY),
SKELETON(51, ENTITY_INSENTIENT), MINECART(42, ABSTRACT_MINECART),
SPIDER(52, ENTITY_INSENTIENT), FURNACE_MINECART(44, ABSTRACT_MINECART),
GIANT(53, ENTITY_INSENTIENT), COMMAND_BLOCK_MINECART(40, ABSTRACT_MINECART),
ZOMBIE(54, ENTITY_INSENTIENT), TNT_MINECART(45, ABSTRACT_MINECART),
SLIME(55, ENTITY_INSENTIENT), SPAWNER_MINECART(47, ABSTRACT_MINECART),
GHAST(56, ENTITY_INSENTIENT),
PIG_ZOMBIE(57, ZOMBIE), ABSTRACT_MINECART_CONTAINER(ABSTRACT_MINECART),
ENDERMAN(58, ENTITY_INSENTIENT), CHEST_MINECART(43, ABSTRACT_MINECART_CONTAINER),
CAVE_SPIDER(59, SPIDER), HOPPER_MINECART(46, ABSTRACT_MINECART_CONTAINER),
SILVERFISH(60, ENTITY_INSENTIENT),
BLAZE(61, ENTITY_INSENTIENT), LIVING_ENTITY_BASE(ENTITY),
ARMOR_STAND(30, LIVING_ENTITY_BASE),
PLAYER(LIVING_ENTITY_BASE), // Needed for entity (un)tracking
// Living entities as a larger subclass
LIVING_ENTITY(48, LIVING_ENTITY_BASE),
ENDER_DRAGON(63, LIVING_ENTITY),
ABSTRACT_CREATURE(LIVING_ENTITY),
SLIME(55, LIVING_ENTITY),
MAGMA_CUBE(62, SLIME), MAGMA_CUBE(62, SLIME),
ENDER_DRAGON(63, ENTITY_INSENTIENT),
WITHER(64, ENTITY_INSENTIENT), // Flying entities
BAT(65, ENTITY_INSENTIENT), FLYING_MOB(LIVING_ENTITY),
WITCH(66, ENTITY_INSENTIENT), GHAST(56, FLYING_MOB),
ENDERMITE(67, ENTITY_INSENTIENT),
GUARDIAN(68, ENTITY_INSENTIENT), AMBIENT_CREATURE(LIVING_ENTITY),
IRON_GOLEM(99, ENTITY_INSENTIENT), // moved up to avoid illegal forward references BAT(65, AMBIENT_CREATURE),
SHULKER(69, IRON_GOLEM),
PIG(90, ENTITY_AGEABLE), ABSTRACT_GOLEM(ABSTRACT_CREATURE),
SHEEP(91, ENTITY_AGEABLE), SNOW_GOLEM(97, ABSTRACT_GOLEM),
COW(92, ENTITY_AGEABLE), IRON_GOLEM(99, ABSTRACT_GOLEM),
CHICKEN(93, ENTITY_AGEABLE), SHULKER(69, ABSTRACT_GOLEM),
SQUID(94, ENTITY_INSENTIENT),
WOLF(95, ENTITY_TAMEABLE_ANIMAL), WATER_ANIMAL(LIVING_ENTITY),
MUSHROOM_COW(96, COW), SQUID(94, WATER_ANIMAL),
SNOWMAN(97, IRON_GOLEM),
OCELOT(98, ENTITY_TAMEABLE_ANIMAL), // Ageable mobs and (tamable) animals
HORSE(100, ENTITY_AGEABLE), ABSTRACT_AGEABLE(ABSTRACT_CREATURE),
RABBIT(101, ENTITY_AGEABLE), VILLAGER(120, ABSTRACT_AGEABLE),
POLAR_BEAR(102, ENTITY_AGEABLE),
VILLAGER(120, ENTITY_AGEABLE), ABSTRACT_ANIMAL(ABSTRACT_AGEABLE),
ENDER_CRYSTAL(200, ENTITY), CHICKEN(93, ABSTRACT_ANIMAL),
SPLASH_POTION(-1, ENTITY), COW(92, ABSTRACT_ANIMAL),
LINGERING_POTION(-1, SPLASH_POTION), MOOSHROOM(96, COW),
AREA_EFFECT_CLOUD(-1, ENTITY), PIG(90, ABSTRACT_ANIMAL),
EGG(-1, ENTITY), POLAR_BEAR(102, ABSTRACT_ANIMAL),
FISHING_HOOK(-1, ENTITY), RABBIT(101, ABSTRACT_ANIMAL),
LIGHTNING(-1, ENTITY), SHEEP(91, ABSTRACT_ANIMAL),
WEATHER(-1, ENTITY), HORSE(100, ABSTRACT_ANIMAL),
PLAYER(-1, ENTITY_HUMAN),
COMPLEX_PART(-1, ENTITY); TAMABLE_ANIMAL(ABSTRACT_ANIMAL),
OCELOT(98, TAMABLE_ANIMAL),
WOLF(95, TAMABLE_ANIMAL),
// Monsters
ABSTRACT_MONSTER(49, ABSTRACT_CREATURE),
BLAZE(61, ABSTRACT_MONSTER),
CREEPER(50, ABSTRACT_MONSTER),
ENDERMITE(67, ABSTRACT_MONSTER),
ENDERMAN(58, ABSTRACT_MONSTER),
GIANT(53, ABSTRACT_MONSTER),
SILVERFISH(60, ABSTRACT_MONSTER),
WITCH(66, ABSTRACT_MONSTER),
WITHER(64, ABSTRACT_MONSTER),
SKELETON(51, ABSTRACT_MONSTER),
ZOMBIE(54, ABSTRACT_MONSTER),
ZOMBIE_PIGMEN(57, ZOMBIE),
GUARDIAN(68, ABSTRACT_MONSTER),
SPIDER(52, ABSTRACT_MONSTER),
CAVE_SPIDER(59, SPIDER);
private static final Map<Integer, EntityType> TYPES = new HashMap<>(); private static final Map<Integer, EntityType> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType parent; private final EntityType parent;
EntityType(int id) { EntityType() {
this.id = id; this.id = -1;
this.parent = null; this.parent = null;
} }
EntityType(EntityType parent) {
this.id = -1;
this.parent = parent;
}
EntityType(int id, EntityType parent) { EntityType(int id, EntityType parent) {
this.id = id; this.id = id;
this.parent = parent; this.parent = parent;
} }
static {
for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type);
}
}
public static Optional<EntityType> findById(int id) {
if (id == -1) // Check if this is called
return Optional.empty();
return Optional.ofNullable(TYPES.get(id));
}
@Override @Override
public int getId() { public int getId() {
return id; return id;
@ -179,16 +198,29 @@ public class EntityTypes1_10 {
public boolean isAbstractType() { public boolean isAbstractType() {
return id != -1; return id != -1;
} }
static {
for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type);
}
}
public static EntityType findById(final int id) {
if (id == -1) {
return null;
}
return TYPES.get(id);
}
} }
public enum ObjectType implements com.viaversion.viaversion.api.minecraft.entities.ObjectType { public enum ObjectType implements com.viaversion.viaversion.api.minecraft.entities.ObjectType {
BOAT(1, EntityType.BOAT), BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.DROPPED_ITEM), ITEM(2, EntityType.ITEM),
AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD), AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD),
MINECART(10, EntityType.MINECART_RIDEABLE), MINECART(10, EntityType.MINECART), // There are multiple types, but we don't need them
TNT_PRIMED(50, EntityType.PRIMED_TNT), TNT_PRIMED(50, EntityType.TNT),
ENDER_CRYSTAL(51, EntityType.ENDER_CRYSTAL), ENDER_CRYSTAL(51, EntityType.END_CRYSTAL),
TIPPED_ARROW(60, EntityType.TIPPED_ARROW), TIPPED_ARROW(60, EntityType.ARROW),
SNOWBALL(61, EntityType.SNOWBALL), SNOWBALL(61, EntityType.SNOWBALL),
EGG(62, EntityType.EGG), EGG(62, EntityType.EGG),
FIREBALL(63, EntityType.FIREBALL), FIREBALL(63, EntityType.FIREBALL),
@ -198,11 +230,11 @@ public class EntityTypes1_10 {
SHULKER_BULLET(67, EntityType.SHULKER_BULLET), SHULKER_BULLET(67, EntityType.SHULKER_BULLET),
FALLING_BLOCK(70, EntityType.FALLING_BLOCK), FALLING_BLOCK(70, EntityType.FALLING_BLOCK),
ITEM_FRAME(71, EntityType.ITEM_FRAME), ITEM_FRAME(71, EntityType.ITEM_FRAME),
ENDER_SIGNAL(72, EntityType.ENDER_SIGNAL), EYE_OF_ENDER(72, EntityType.EYE_OF_ENDER),
POTION(73, EntityType.SPLASH_POTION), POTION(73, EntityType.POTION),
THROWN_EXP_BOTTLE(75, EntityType.THROWN_EXP_BOTTLE), EXPERIENCE_BOTTLE(75, EntityType.EXPERIENCE_BOTTLE),
FIREWORK(76, EntityType.FIREWORK), FIREWORK_ROCKET(76, EntityType.FIREWORK_ROCKET),
LEASH(77, EntityType.LEASH_HITCH), LEASH(77, EntityType.LEASH_KNOT),
ARMOR_STAND(78, EntityType.ARMOR_STAND), ARMOR_STAND(78, EntityType.ARMOR_STAND),
FISHIHNG_HOOK(90, EntityType.FISHING_HOOK), FISHIHNG_HOOK(90, EntityType.FISHING_HOOK),
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW), SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
@ -234,15 +266,16 @@ public class EntityTypes1_10 {
return type; return type;
} }
public static Optional<ObjectType> findById(int id) { public static ObjectType findById(final int id) {
if (id == -1) if (id == -1) {
return Optional.empty(); return null;
return Optional.ofNullable(TYPES.get(id)); }
return TYPES.get(id);
} }
public static Optional<EntityType> getPCEntity(int id) { public static EntityType getEntityType(final int id) {
Optional<ObjectType> output = findById(id); final ObjectType objectType = findById(id);
return output.map(objectType -> objectType.type); return objectType != null ? objectType.type : null;
} }
} }
} }

Datei anzeigen

@ -25,152 +25,180 @@ package com.viaversion.viaversion.api.minecraft.entities;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
// 1.11 Entity / Object ids
public class EntityTypes1_11 { public class EntityTypes1_11 {
public static EntityType getTypeFromId(int typeID, boolean isObject) { public static EntityType getTypeFromId(final int typeId, final boolean object) {
Optional<EntityType> type; EntityType type;
if (isObject) if (object) {
type = ObjectType.getPCEntity(typeID); type = ObjectType.getEntityType(typeId);
else } else {
type = EntityType.findById(typeID); type = EntityType.findById(typeId);
}
if (type.isEmpty()) { if (type == null) {
Via.getPlatform().getLogger().severe("Could not find 1.11 type id " + typeID + " isObject=" + isObject); Via.getPlatform().getLogger().severe("Could not find 1.11 type id " + typeId + " objectType=" + object);
return EntityType.ENTITY; // Fall back to the basic ENTITY return EntityType.ENTITY; // Fall back to the basic ENTITY
} }
return type;
return type.get();
} }
public enum EntityType implements com.viaversion.viaversion.api.minecraft.entities.EntityType { public enum EntityType implements com.viaversion.viaversion.api.minecraft.entities.EntityType {
ENTITY(-1),
DROPPED_ITEM(1, ENTITY), ENTITY,
AREA_EFFECT_CLOUD(3, ENTITY),
END_CRYSTAL(200, ENTITY),
EVOKER_FANGS(33, ENTITY),
EXPERIENCE_ORB(2, ENTITY), EXPERIENCE_ORB(2, ENTITY),
LEASH_HITCH(8, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata EYE_OF_ENDER(15, ENTITY),
PAINTING(9, ENTITY), // Actually entity hanging but, it doesn't make a lot of difference for metadata
ARROW(10, ENTITY),
SNOWBALL(11, ENTITY), // Actually EntityProjectile
FIREBALL(12, ENTITY),
SMALL_FIREBALL(13, ENTITY),
ENDER_PEARL(14, ENTITY), // Actually EntityProjectile
ENDER_SIGNAL(15, ENTITY),
THROWN_EXP_BOTTLE(17, ENTITY),
ITEM_FRAME(18, ENTITY), // Actually EntityHanging
WITHER_SKULL(19, ENTITY),
PRIMED_TNT(20, ENTITY),
FALLING_BLOCK(21, ENTITY), FALLING_BLOCK(21, ENTITY),
FIREWORK(22, ENTITY), ITEM(1, ENTITY),
SPECTRAL_ARROW(24, ARROW), TNT(20, ENTITY),
LIGHTNING_BOLT(ENTITY), // Needed for entity (un)tracking
// Hanging entities
HANGING_ENTITY(ENTITY),
LEASH_KNOT(8, HANGING_ENTITY),
ITEM_FRAME(18, HANGING_ENTITY),
PAINTING(9, HANGING_ENTITY),
// Projectiles
PROJECTILE(ENTITY),
FIREWORK_ROCKET(22, ENTITY),
LLAMA_SPIT(104, ENTITY),
SHULKER_BULLET(25, ENTITY), SHULKER_BULLET(25, ENTITY),
DRAGON_FIREBALL(26, FIREBALL), SNOWBALL(11, PROJECTILE),
EVOCATION_FANGS(33, ENTITY), ENDER_PEARL(14, PROJECTILE),
EGG(7, PROJECTILE),
EXPERIENCE_BOTTLE(17, PROJECTILE),
POTION(16, PROJECTILE),
FISHING_HOOK(ENTITY),
ABSTRACT_ARROW(ENTITY),
ARROW(10, ABSTRACT_ARROW),
SPECTRAL_ARROW(24, ABSTRACT_ARROW),
ENTITY_LIVING(-1, ENTITY), HURTING_PROJECTILE(ENTITY),
ENTITY_INSENTIENT(-1, ENTITY_LIVING), DRAGON_FIREBALL(26, HURTING_PROJECTILE),
ENTITY_AGEABLE(-1, ENTITY_INSENTIENT), FIREBALL(12, HURTING_PROJECTILE),
ENTITY_TAMEABLE_ANIMAL(-1, ENTITY_AGEABLE), SMALL_FIREBALL(13, HURTING_PROJECTILE),
ENTITY_HUMAN(-1, ENTITY_LIVING), WITHER_SKULL(19, HURTING_PROJECTILE),
ARMOR_STAND(30, ENTITY_LIVING),
EVOCATION_ILLAGER(34, ENTITY_INSENTIENT),
VEX(35, ENTITY_INSENTIENT),
VINDICATION_ILLAGER(36, ENTITY_INSENTIENT),
// Vehicles // Vehicles
MINECART_ABSTRACT(-1, ENTITY),
MINECART_COMMAND(40, MINECART_ABSTRACT),
BOAT(41, ENTITY), BOAT(41, ENTITY),
MINECART_RIDEABLE(42, MINECART_ABSTRACT),
MINECART_CHEST(43, MINECART_ABSTRACT),
MINECART_FURNACE(44, MINECART_ABSTRACT),
MINECART_TNT(45, MINECART_ABSTRACT),
MINECART_HOPPER(46, MINECART_ABSTRACT),
MINECART_MOB_SPAWNER(47, MINECART_ABSTRACT),
CREEPER(50, ENTITY_INSENTIENT), ABSTRACT_MINECART(ENTITY),
MINECART(42, ABSTRACT_MINECART),
FURNACE_MINECART(44, ABSTRACT_MINECART),
COMMAND_BLOCK_MINECART(40, ABSTRACT_MINECART),
TNT_MINECART(45, ABSTRACT_MINECART),
SPAWNER_MINECART(47, ABSTRACT_MINECART),
ABSTRACT_SKELETON(-1, ENTITY_INSENTIENT), ABSTRACT_MINECART_CONTAINER(ABSTRACT_MINECART),
SKELETON(51, ABSTRACT_SKELETON), CHEST_MINECART(43, ABSTRACT_MINECART_CONTAINER),
WITHER_SKELETON(5, ABSTRACT_SKELETON), HOPPER_MINECART(46, ABSTRACT_MINECART_CONTAINER),
STRAY(6, ABSTRACT_SKELETON),
SPIDER(52, ENTITY_INSENTIENT), LIVING_ENTITY_BASE(ENTITY),
GIANT(53, ENTITY_INSENTIENT), ARMOR_STAND(30, LIVING_ENTITY_BASE),
PLAYER(LIVING_ENTITY_BASE), // Needed for entity (un)tracking
ZOMBIE(54, ENTITY_INSENTIENT), // Living entities as a larger subclass
HUSK(23, ZOMBIE), LIVING_ENTITY(LIVING_ENTITY_BASE),
ZOMBIE_VILLAGER(27, ZOMBIE), ENDER_DRAGON(63, LIVING_ENTITY),
ABSTRACT_CREATURE(LIVING_ENTITY),
SLIME(55, ENTITY_INSENTIENT), SLIME(55, LIVING_ENTITY),
GHAST(56, ENTITY_INSENTIENT),
PIG_ZOMBIE(57, ZOMBIE),
ENDERMAN(58, ENTITY_INSENTIENT),
CAVE_SPIDER(59, SPIDER),
SILVERFISH(60, ENTITY_INSENTIENT),
BLAZE(61, ENTITY_INSENTIENT),
MAGMA_CUBE(62, SLIME), MAGMA_CUBE(62, SLIME),
ENDER_DRAGON(63, ENTITY_INSENTIENT),
WITHER(64, ENTITY_INSENTIENT),
BAT(65, ENTITY_INSENTIENT),
WITCH(66, ENTITY_INSENTIENT),
ENDERMITE(67, ENTITY_INSENTIENT),
GUARDIAN(68, ENTITY_INSENTIENT), // Flying entities
ELDER_GUARDIAN(4, GUARDIAN), // Moved down to avoid illegal forward reference FLYING_MOB(LIVING_ENTITY),
GHAST(56, FLYING_MOB),
IRON_GOLEM(99, ENTITY_INSENTIENT), // moved up to avoid illegal forward references AMBIENT_CREATURE(LIVING_ENTITY),
SHULKER(69, IRON_GOLEM), BAT(65, AMBIENT_CREATURE),
PIG(90, ENTITY_AGEABLE),
SHEEP(91, ENTITY_AGEABLE),
COW(92, ENTITY_AGEABLE),
CHICKEN(93, ENTITY_AGEABLE),
SQUID(94, ENTITY_INSENTIENT),
WOLF(95, ENTITY_TAMEABLE_ANIMAL),
MUSHROOM_COW(96, COW),
SNOWMAN(97, IRON_GOLEM),
OCELOT(98, ENTITY_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(-1, ENTITY_AGEABLE), ABSTRACT_GOLEM(ABSTRACT_CREATURE),
SNOW_GOLEM(97, ABSTRACT_GOLEM),
IRON_GOLEM(99, ABSTRACT_GOLEM),
SHULKER(69, ABSTRACT_GOLEM),
WATER_ANIMAL(ABSTRACT_CREATURE),
SQUID(94, WATER_ANIMAL),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE),
VILLAGER(120, ABSTRACT_AGEABLE),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE),
CHICKEN(93, ABSTRACT_ANIMAL),
COW(92, ABSTRACT_ANIMAL),
MOOSHROOM(96, COW),
PIG(90, ABSTRACT_ANIMAL),
POLAR_BEAR(102, ABSTRACT_ANIMAL),
RABBIT(101, ABSTRACT_ANIMAL),
SHEEP(91, ABSTRACT_ANIMAL),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL),
OCELOT(98, TAMABLE_ANIMAL),
WOLF(95, TAMABLE_ANIMAL),
// Horses
ABSTRACT_HORSE(ABSTRACT_ANIMAL),
HORSE(100, ABSTRACT_HORSE), HORSE(100, ABSTRACT_HORSE),
SKELETON_HORSE(28, ABSTRACT_HORSE), SKELETON_HORSE(28, ABSTRACT_HORSE),
ZOMBIE_HORSE(29, ABSTRACT_HORSE), ZOMBIE_HORSE(29, ABSTRACT_HORSE),
CHESTED_HORSE(-1, ABSTRACT_HORSE), CHESTED_HORSE(ABSTRACT_HORSE),
DONKEY(31, CHESTED_HORSE), DONKEY(31, CHESTED_HORSE),
MULE(32, CHESTED_HORSE), MULE(32, CHESTED_HORSE),
LIAMA(103, CHESTED_HORSE), LLAMA(103, CHESTED_HORSE),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE),
BLAZE(61, ABSTRACT_MONSTER),
CREEPER(50, ABSTRACT_MONSTER),
ENDERMITE(67, ABSTRACT_MONSTER),
ENDERMAN(58, ABSTRACT_MONSTER),
GIANT(53, ABSTRACT_MONSTER),
SILVERFISH(60, ABSTRACT_MONSTER),
VEX(35, ABSTRACT_MONSTER),
WITCH(66, ABSTRACT_MONSTER),
WITHER(64, ABSTRACT_MONSTER),
RABBIT(101, ENTITY_AGEABLE), ABSTRACT_SKELETON(ABSTRACT_MONSTER),
POLAR_BEAR(102, ENTITY_AGEABLE), SKELETON(51, ABSTRACT_SKELETON),
VILLAGER(120, ENTITY_AGEABLE), STRAY(6, ABSTRACT_SKELETON),
ENDER_CRYSTAL(200, ENTITY), WITHER_SKELETON(5, ABSTRACT_SKELETON),
SPLASH_POTION(-1, ENTITY),
LINGERING_POTION(-1, SPLASH_POTION), ZOMBIE(54, ABSTRACT_MONSTER),
AREA_EFFECT_CLOUD(-1, ENTITY), HUSK(23, ZOMBIE),
EGG(-1, ENTITY), ZOMBIE_PIGMEN(57, ZOMBIE),
FISHING_HOOK(-1, ENTITY), ZOMBIE_VILLAGER(27, ZOMBIE),
LIGHTNING(-1, ENTITY),
WEATHER(-1, ENTITY), GUARDIAN(68, ABSTRACT_MONSTER),
PLAYER(-1, ENTITY_HUMAN), ELDER_GUARDIAN(4, GUARDIAN),
COMPLEX_PART(-1, ENTITY), SPIDER(52, ABSTRACT_MONSTER),
LIAMA_SPIT(-1, ENTITY); CAVE_SPIDER(59, ABSTRACT_MONSTER),
// Illagers
EVOKER(34, ABSTRACT_MONSTER),
VINDICATOR(36, ABSTRACT_MONSTER);
private static final Map<Integer, EntityType> TYPES = new HashMap<>(); private static final Map<Integer, EntityType> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType parent; private final EntityType parent;
EntityType(int id) { EntityType() {
this.id = id; this.id = -1;
this.parent = null; this.parent = null;
} }
EntityType(EntityType parent) {
this.id = -1;
this.parent = parent;
}
EntityType(int id, EntityType parent) { EntityType(int id, EntityType parent) {
this.id = id; this.id = id;
this.parent = parent; this.parent = parent;
@ -202,20 +230,21 @@ public class EntityTypes1_11 {
} }
} }
public static Optional<EntityType> findById(int id) { public static EntityType findById(final int id) {
if (id == -1) // Check if this is called if (id == -1) {
return Optional.empty(); return null;
return Optional.ofNullable(TYPES.get(id)); }
return TYPES.get(id);
} }
} }
public enum ObjectType implements com.viaversion.viaversion.api.minecraft.entities.ObjectType { public enum ObjectType implements com.viaversion.viaversion.api.minecraft.entities.ObjectType {
BOAT(1, EntityType.BOAT), BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.DROPPED_ITEM), ITEM(2, EntityType.ITEM),
AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD), AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD),
MINECART(10, EntityType.MINECART_RIDEABLE), MINECART(10, EntityType.MINECART), // There are multiple types, but we don't need them
TNT_PRIMED(50, EntityType.PRIMED_TNT), TNT_PRIMED(50, EntityType.TNT),
ENDER_CRYSTAL(51, EntityType.ENDER_CRYSTAL), ENDER_CRYSTAL(51, EntityType.END_CRYSTAL),
TIPPED_ARROW(60, EntityType.ARROW), TIPPED_ARROW(60, EntityType.ARROW),
SNOWBALL(61, EntityType.SNOWBALL), SNOWBALL(61, EntityType.SNOWBALL),
EGG(62, EntityType.EGG), EGG(62, EntityType.EGG),
@ -224,16 +253,16 @@ public class EntityTypes1_11 {
ENDER_PEARL(65, EntityType.ENDER_PEARL), ENDER_PEARL(65, EntityType.ENDER_PEARL),
WITHER_SKULL(66, EntityType.WITHER_SKULL), WITHER_SKULL(66, EntityType.WITHER_SKULL),
SHULKER_BULLET(67, EntityType.SHULKER_BULLET), SHULKER_BULLET(67, EntityType.SHULKER_BULLET),
LIAMA_SPIT(68, EntityType.LIAMA_SPIT), LLAMA_SPIT(68, EntityType.LLAMA_SPIT),
FALLING_BLOCK(70, EntityType.FALLING_BLOCK), FALLING_BLOCK(70, EntityType.FALLING_BLOCK),
ITEM_FRAME(71, EntityType.ITEM_FRAME), ITEM_FRAME(71, EntityType.ITEM_FRAME),
ENDER_SIGNAL(72, EntityType.ENDER_SIGNAL), EYE_OF_ENDER(72, EntityType.EYE_OF_ENDER),
POTION(73, EntityType.SPLASH_POTION), POTION(73, EntityType.POTION),
THROWN_EXP_BOTTLE(75, EntityType.THROWN_EXP_BOTTLE), EXPERIENCE_BOTTLE(75, EntityType.EXPERIENCE_BOTTLE),
FIREWORK(76, EntityType.FIREWORK), FIREWORK_ROCKET(76, EntityType.FIREWORK_ROCKET),
LEASH(77, EntityType.LEASH_HITCH), LEASH(77, EntityType.LEASH_KNOT),
ARMOR_STAND(78, EntityType.ARMOR_STAND), ARMOR_STAND(78, EntityType.ARMOR_STAND),
EVOCATION_FANGS(79, EntityType.EVOCATION_FANGS), EVOKER_FANGS(79, EntityType.EVOKER_FANGS),
FISHIHNG_HOOK(90, EntityType.FISHING_HOOK), FISHIHNG_HOOK(90, EntityType.FISHING_HOOK),
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW), SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL); DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
@ -264,15 +293,16 @@ public class EntityTypes1_11 {
return type; return type;
} }
public static Optional<ObjectType> findById(int id) { public static ObjectType findById(final int id) {
if (id == -1) if (id == -1) {
return Optional.empty(); return null;
return Optional.ofNullable(TYPES.get(id)); }
return TYPES.get(id);
} }
public static Optional<EntityType> getPCEntity(int id) { public static EntityType getEntityType(final int id) {
Optional<ObjectType> output = findById(id); final ObjectType objectType = findById(id);
return output.map(objectType -> objectType.type); return objectType != null ? objectType.type : null;
} }
} }
} }

Datei anzeigen

@ -20,161 +20,191 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
package com.viaversion.viaversion.api.minecraft.entities; package com.viaversion.viaversion.api.minecraft.entities;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
// 1.12 Entity / Object taken from https://github.com/Matsv/ViaBackwards/blob/master/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_12.java
public class EntityTypes1_12 { public class EntityTypes1_12 {
public static EntityType getTypeFromId(int typeID, boolean isObject) { public static EntityType getTypeFromId(final int typeId, final boolean object) {
Optional<EntityType> type; EntityType type;
if (isObject) if (object) {
type = ObjectType.getPCEntity(typeID); type = ObjectType.getEntityType(typeId);
else } else {
type = EntityType.findById(typeID); type = EntityType.findById(typeId);
}
if (type.isEmpty()) { if (type == null) {
Via.getPlatform().getLogger().severe("Could not find 1.12 type id " + typeID + " isObject=" + isObject); Via.getPlatform().getLogger().severe("Could not find 1.12 type id " + typeId + " objectType=" + object);
return EntityType.ENTITY; // Fall back to the basic ENTITY return EntityType.ENTITY; // Fall back to the basic ENTITY
} }
return type;
return type.get();
} }
public enum EntityType implements com.viaversion.viaversion.api.minecraft.entities.EntityType { public enum EntityType implements com.viaversion.viaversion.api.minecraft.entities.EntityType {
ENTITY(-1),
DROPPED_ITEM(1, ENTITY), ENTITY,
AREA_EFFECT_CLOUD(3, ENTITY),
END_CRYSTAL(200, ENTITY),
EVOKER_FANGS(33, ENTITY),
EXPERIENCE_ORB(2, ENTITY), EXPERIENCE_ORB(2, ENTITY),
LEASH_HITCH(8, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata EYE_OF_ENDER(15, ENTITY),
PAINTING(9, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata
ARROW(10, ENTITY),
SNOWBALL(11, ENTITY), // Actually EntityProjectile
FIREBALL(12, ENTITY),
SMALL_FIREBALL(13, ENTITY),
ENDER_PEARL(14, ENTITY), // Actually EntityProjectile
ENDER_SIGNAL(15, ENTITY),
THROWN_EXP_BOTTLE(17, ENTITY),
ITEM_FRAME(18, ENTITY), // Actually EntityHanging
WITHER_SKULL(19, ENTITY),
PRIMED_TNT(20, ENTITY),
FALLING_BLOCK(21, ENTITY), FALLING_BLOCK(21, ENTITY),
FIREWORK(22, ENTITY), ITEM(1, ENTITY),
SPECTRAL_ARROW(24, ARROW), TNT(20, ENTITY),
LIGHTNING_BOLT(ENTITY), // Needed for entity (un)tracking
// Hanging entities
HANGING_ENTITY(ENTITY),
LEASH_KNOT(8, HANGING_ENTITY),
ITEM_FRAME(18, HANGING_ENTITY),
PAINTING(9, HANGING_ENTITY),
// Projectiles
PROJECTILE(ENTITY),
FIREWORK_ROCKET(22, ENTITY),
LLAMA_SPIT(104, ENTITY),
SHULKER_BULLET(25, ENTITY), SHULKER_BULLET(25, ENTITY),
DRAGON_FIREBALL(26, FIREBALL), SNOWBALL(11, PROJECTILE),
EVOCATION_FANGS(33, ENTITY), ENDER_PEARL(14, PROJECTILE),
EGG(7, PROJECTILE),
EXPERIENCE_BOTTLE(17, PROJECTILE),
POTION(16, PROJECTILE),
FISHING_HOOK(ENTITY),
ABSTRACT_ARROW(ENTITY),
ARROW(10, ABSTRACT_ARROW),
SPECTRAL_ARROW(24, ABSTRACT_ARROW),
ENTITY_LIVING(-1, ENTITY), HURTING_PROJECTILE(ENTITY),
ENTITY_INSENTIENT(-1, ENTITY_LIVING), DRAGON_FIREBALL(26, HURTING_PROJECTILE),
ENTITY_AGEABLE(-1, ENTITY_INSENTIENT), FIREBALL(12, HURTING_PROJECTILE),
ENTITY_TAMEABLE_ANIMAL(-1, ENTITY_AGEABLE), SMALL_FIREBALL(13, HURTING_PROJECTILE),
ENTITY_HUMAN(-1, ENTITY_LIVING), WITHER_SKULL(19, HURTING_PROJECTILE),
ARMOR_STAND(30, ENTITY_LIVING),
ENTITY_ILLAGER_ABSTRACT(-1, ENTITY_INSENTIENT),
EVOCATION_ILLAGER(34, ENTITY_ILLAGER_ABSTRACT),
VEX(35, ENTITY_INSENTIENT),
VINDICATION_ILLAGER(36, ENTITY_ILLAGER_ABSTRACT),
ILLUSION_ILLAGER(37, EVOCATION_ILLAGER),
// Vehicles // Vehicles
MINECART_ABSTRACT(-1, ENTITY),
MINECART_COMMAND(40, MINECART_ABSTRACT),
BOAT(41, ENTITY), BOAT(41, ENTITY),
MINECART_RIDEABLE(42, MINECART_ABSTRACT),
MINECART_CHEST(43, MINECART_ABSTRACT),
MINECART_FURNACE(44, MINECART_ABSTRACT),
MINECART_TNT(45, MINECART_ABSTRACT),
MINECART_HOPPER(46, MINECART_ABSTRACT),
MINECART_MOB_SPAWNER(47, MINECART_ABSTRACT),
CREEPER(50, ENTITY_INSENTIENT), ABSTRACT_MINECART(ENTITY),
MINECART(42, ABSTRACT_MINECART),
FURNACE_MINECART(44, ABSTRACT_MINECART),
COMMAND_BLOCK_MINECART(40, ABSTRACT_MINECART),
TNT_MINECART(45, ABSTRACT_MINECART),
SPAWNER_MINECART(47, ABSTRACT_MINECART),
ABSTRACT_SKELETON(-1, ENTITY_INSENTIENT), ABSTRACT_MINECART_CONTAINER(ABSTRACT_MINECART),
SKELETON(51, ABSTRACT_SKELETON), CHEST_MINECART(43, ABSTRACT_MINECART_CONTAINER),
WITHER_SKELETON(5, ABSTRACT_SKELETON), HOPPER_MINECART(46, ABSTRACT_MINECART_CONTAINER),
STRAY(6, ABSTRACT_SKELETON),
SPIDER(52, ENTITY_INSENTIENT), LIVING_ENTITY_BASE(ENTITY),
GIANT(53, ENTITY_INSENTIENT), ARMOR_STAND(30, LIVING_ENTITY_BASE),
PLAYER(ENTITY), // Needed for entity (un)tracking
ZOMBIE(54, ENTITY_INSENTIENT), // Living entities as a larger subclass
HUSK(23, ZOMBIE), LIVING_ENTITY(LIVING_ENTITY_BASE),
ZOMBIE_VILLAGER(27, ZOMBIE), ENDER_DRAGON(63, LIVING_ENTITY),
ABSTRACT_CREATURE(LIVING_ENTITY),
SLIME(55, ENTITY_INSENTIENT), SLIME(55, LIVING_ENTITY),
GHAST(56, ENTITY_INSENTIENT),
PIG_ZOMBIE(57, ZOMBIE),
ENDERMAN(58, ENTITY_INSENTIENT),
CAVE_SPIDER(59, SPIDER),
SILVERFISH(60, ENTITY_INSENTIENT),
BLAZE(61, ENTITY_INSENTIENT),
MAGMA_CUBE(62, SLIME), MAGMA_CUBE(62, SLIME),
ENDER_DRAGON(63, ENTITY_INSENTIENT),
WITHER(64, ENTITY_INSENTIENT),
BAT(65, ENTITY_INSENTIENT),
WITCH(66, ENTITY_INSENTIENT),
ENDERMITE(67, ENTITY_INSENTIENT),
GUARDIAN(68, ENTITY_INSENTIENT), // Flying entities
ELDER_GUARDIAN(4, GUARDIAN), // Moved down to avoid illegal forward reference FLYING_MOB(LIVING_ENTITY),
GHAST(56, FLYING_MOB),
IRON_GOLEM(99, ENTITY_INSENTIENT), // moved up to avoid illegal forward references AMBIENT_CREATURE(LIVING_ENTITY),
SHULKER(69, IRON_GOLEM), BAT(65, AMBIENT_CREATURE),
PIG(90, ENTITY_AGEABLE),
SHEEP(91, ENTITY_AGEABLE),
COW(92, ENTITY_AGEABLE),
CHICKEN(93, ENTITY_AGEABLE),
SQUID(94, ENTITY_INSENTIENT),
WOLF(95, ENTITY_TAMEABLE_ANIMAL),
MUSHROOM_COW(96, COW),
SNOWMAN(97, IRON_GOLEM),
OCELOT(98, ENTITY_TAMEABLE_ANIMAL),
PARROT(105, ENTITY_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(-1, ENTITY_AGEABLE), ABSTRACT_GOLEM(ABSTRACT_CREATURE),
SNOW_GOLEM(97, ABSTRACT_GOLEM),
IRON_GOLEM(99, ABSTRACT_GOLEM),
SHULKER(69, ABSTRACT_GOLEM),
WATER_ANIMAL(ABSTRACT_CREATURE),
SQUID(94, WATER_ANIMAL),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE),
VILLAGER(120, ABSTRACT_AGEABLE),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE),
CHICKEN(93, ABSTRACT_ANIMAL),
COW(92, ABSTRACT_ANIMAL),
MOOSHROOM(96, COW),
PIG(90, ABSTRACT_ANIMAL),
POLAR_BEAR(102, ABSTRACT_ANIMAL),
RABBIT(101, ABSTRACT_ANIMAL),
SHEEP(91, ABSTRACT_ANIMAL),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL),
OCELOT(98, TAMABLE_ANIMAL),
WOLF(95, TAMABLE_ANIMAL),
ABSTRACT_SHOULDER_RIDING(TAMABLE_ANIMAL),
PARROT(105, ABSTRACT_SHOULDER_RIDING),
// Horses
ABSTRACT_HORSE(ABSTRACT_ANIMAL),
HORSE(100, ABSTRACT_HORSE), HORSE(100, ABSTRACT_HORSE),
SKELETON_HORSE(28, ABSTRACT_HORSE), SKELETON_HORSE(28, ABSTRACT_HORSE),
ZOMBIE_HORSE(29, ABSTRACT_HORSE), ZOMBIE_HORSE(29, ABSTRACT_HORSE),
CHESTED_HORSE(-1, ABSTRACT_HORSE), CHESTED_HORSE(ABSTRACT_HORSE),
DONKEY(31, CHESTED_HORSE), DONKEY(31, CHESTED_HORSE),
MULE(32, CHESTED_HORSE), MULE(32, CHESTED_HORSE),
LIAMA(103, CHESTED_HORSE), LLAMA(103, CHESTED_HORSE),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE),
BLAZE(61, ABSTRACT_MONSTER),
CREEPER(50, ABSTRACT_MONSTER),
ENDERMITE(67, ABSTRACT_MONSTER),
ENDERMAN(58, ABSTRACT_MONSTER),
GIANT(53, ABSTRACT_MONSTER),
SILVERFISH(60, ABSTRACT_MONSTER),
VEX(35, ABSTRACT_MONSTER),
WITCH(66, ABSTRACT_MONSTER),
WITHER(64, ABSTRACT_MONSTER),
RABBIT(101, ENTITY_AGEABLE), ABSTRACT_SKELETON(ABSTRACT_MONSTER),
POLAR_BEAR(102, ENTITY_AGEABLE), SKELETON(51, ABSTRACT_SKELETON),
VILLAGER(120, ENTITY_AGEABLE), STRAY(6, ABSTRACT_SKELETON),
ENDER_CRYSTAL(200, ENTITY), WITHER_SKELETON(5, ABSTRACT_SKELETON),
SPLASH_POTION(-1, ENTITY),
LINGERING_POTION(-1, SPLASH_POTION), ZOMBIE(54, ABSTRACT_MONSTER),
AREA_EFFECT_CLOUD(-1, ENTITY), HUSK(23, ZOMBIE),
EGG(-1, ENTITY), ZOMBIE_PIGMEN(57, ZOMBIE),
FISHING_HOOK(-1, ENTITY), ZOMBIE_VILLAGER(27, ZOMBIE),
LIGHTNING(-1, ENTITY),
WEATHER(-1, ENTITY), GUARDIAN(68, ABSTRACT_MONSTER),
PLAYER(-1, ENTITY_HUMAN), ELDER_GUARDIAN(4, GUARDIAN),
COMPLEX_PART(-1, ENTITY), SPIDER(52, ABSTRACT_MONSTER),
LIAMA_SPIT(-1, ENTITY); CAVE_SPIDER(59, ABSTRACT_MONSTER),
// Illagers
ABSTRACT_ILLAGER(ABSTRACT_MONSTER),
SPELLCASTER_ILLAGER(ABSTRACT_ILLAGER),
VINDICATOR(36, ABSTRACT_ILLAGER),
EVOKER(34, SPELLCASTER_ILLAGER),
ILLUSIONER(37, SPELLCASTER_ILLAGER);
private static final Map<Integer, EntityType> TYPES = new HashMap<>(); private static final Map<Integer, EntityType> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType parent; private final EntityType parent;
EntityType(int id) { EntityType() {
this.id = id; this.id = -1;
this.parent = null; this.parent = null;
} }
EntityType(EntityType parent) {
this.id = -1;
this.parent = parent;
}
EntityType(int id, EntityType parent) { EntityType(int id, EntityType parent) {
this.id = id; this.id = id;
this.parent = parent; this.parent = parent;
@ -206,20 +236,21 @@ public class EntityTypes1_12 {
} }
} }
public static Optional<EntityType> findById(int id) { public static EntityType findById(final int id) {
if (id == -1) // Check if this is called if (id == -1) {
return Optional.empty(); return null;
return Optional.ofNullable(TYPES.get(id)); }
return TYPES.get(id);
} }
} }
public enum ObjectType implements com.viaversion.viaversion.api.minecraft.entities.ObjectType { public enum ObjectType implements com.viaversion.viaversion.api.minecraft.entities.ObjectType {
BOAT(1, EntityType.BOAT), BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.DROPPED_ITEM), ITEM(2, EntityType.ITEM),
AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD), AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD),
MINECART(10, EntityType.MINECART_RIDEABLE), MINECART(10, EntityType.MINECART), // There are multiple types, but we don't need them
TNT_PRIMED(50, EntityType.PRIMED_TNT), TNT_PRIMED(50, EntityType.TNT),
ENDER_CRYSTAL(51, EntityType.ENDER_CRYSTAL), ENDER_CRYSTAL(51, EntityType.END_CRYSTAL),
TIPPED_ARROW(60, EntityType.ARROW), TIPPED_ARROW(60, EntityType.ARROW),
SNOWBALL(61, EntityType.SNOWBALL), SNOWBALL(61, EntityType.SNOWBALL),
EGG(62, EntityType.EGG), EGG(62, EntityType.EGG),
@ -228,16 +259,16 @@ public class EntityTypes1_12 {
ENDER_PEARL(65, EntityType.ENDER_PEARL), ENDER_PEARL(65, EntityType.ENDER_PEARL),
WITHER_SKULL(66, EntityType.WITHER_SKULL), WITHER_SKULL(66, EntityType.WITHER_SKULL),
SHULKER_BULLET(67, EntityType.SHULKER_BULLET), SHULKER_BULLET(67, EntityType.SHULKER_BULLET),
LIAMA_SPIT(68, EntityType.LIAMA_SPIT), LLAMA_SPIT(68, EntityType.LLAMA_SPIT),
FALLING_BLOCK(70, EntityType.FALLING_BLOCK), FALLING_BLOCK(70, EntityType.FALLING_BLOCK),
ITEM_FRAME(71, EntityType.ITEM_FRAME), ITEM_FRAME(71, EntityType.ITEM_FRAME),
ENDER_SIGNAL(72, EntityType.ENDER_SIGNAL), EYE_OF_ENDER(72, EntityType.EYE_OF_ENDER),
POTION(73, EntityType.SPLASH_POTION), POTION(73, EntityType.POTION),
THROWN_EXP_BOTTLE(75, EntityType.THROWN_EXP_BOTTLE), EXPERIENCE_BOTTLE(75, EntityType.EXPERIENCE_BOTTLE),
FIREWORK(76, EntityType.FIREWORK), FIREWORK_ROCKET(76, EntityType.FIREWORK_ROCKET),
LEASH(77, EntityType.LEASH_HITCH), LEASH(77, EntityType.LEASH_KNOT),
ARMOR_STAND(78, EntityType.ARMOR_STAND), ARMOR_STAND(78, EntityType.ARMOR_STAND),
EVOCATION_FANGS(79, EntityType.EVOCATION_FANGS), EVOKER_FANGS(79, EntityType.EVOKER_FANGS),
FISHIHNG_HOOK(90, EntityType.FISHING_HOOK), FISHIHNG_HOOK(90, EntityType.FISHING_HOOK),
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW), SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL); DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
@ -268,15 +299,16 @@ public class EntityTypes1_12 {
return type; return type;
} }
public static Optional<ObjectType> findById(int id) { public static ObjectType findById(final int id) {
if (id == -1) if (id == -1) {
return Optional.empty(); return null;
return Optional.ofNullable(TYPES.get(id)); }
return TYPES.get(id);
} }
public static Optional<EntityType> getPCEntity(int id) { public static EntityType getEntityType(final int id) {
Optional<ObjectType> output = findById(id); final ObjectType objectType = findById(id);
return output.map(objectType -> objectType.type); return objectType != null ? objectType.type : null;
} }
} }
} }

Datei anzeigen

@ -25,205 +25,197 @@ package com.viaversion.viaversion.api.minecraft.entities;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
public class EntityTypes1_13 { public class EntityTypes1_13 {
public static EntityType getTypeFromId(int typeID, boolean isObject) { public static EntityType getTypeFromId(final int typeId, final boolean object) {
Optional<EntityType> type; EntityType type;
if (isObject) if (object) {
type = ObjectType.getPCEntity(typeID); type = ObjectType.getEntityType(typeId);
else } else {
type = EntityType.findById(typeID); type = EntityType.findById(typeId);
}
if (type.isEmpty()) { if (type == null) {
Via.getPlatform().getLogger().severe("Could not find 1.13 type id " + typeID + " isObject=" + isObject); Via.getPlatform().getLogger().severe("Could not find 1.13 type id " + typeId + " objectType=" + object);
return EntityType.ENTITY; // Fall back to the basic ENTITY return EntityType.ENTITY; // Fall back to the basic ENTITY
} }
return type;
return type.get();
} }
public enum EntityType implements com.viaversion.viaversion.api.minecraft.entities.EntityType { public enum EntityType implements com.viaversion.viaversion.api.minecraft.entities.EntityType {
// Auto generated
ENTITY(-1), // abm ENTITY,
AREA_EFFECT_CLOUD(0, ENTITY), // abk AREA_EFFECT_CLOUD(0, ENTITY),
END_CRYSTAL(16, ENTITY), // aho END_CRYSTAL(16, ENTITY),
EVOKER_FANGS(20, ENTITY), // ala EVOKER_FANGS(20, ENTITY),
EXPERIENCE_ORB(22, ENTITY), // abs EXPERIENCE_ORB(22, ENTITY),
EYE_OF_ENDER(23, ENTITY), // alb EYE_OF_ENDER(23, ENTITY),
FALLING_BLOCK(24, ENTITY), // aix FALLING_BLOCK(24, ENTITY),
FIREWORK_ROCKET(25, ENTITY), // alc ITEM(32, ENTITY),
ITEM(32, ENTITY), // aiy TNT(55, ENTITY),
LLAMA_SPIT(37, ENTITY), // ale LIGHTNING_BOLT(91, ENTITY), // Weather effect entity
TNT(55, ENTITY), // aiz
SHULKER_BULLET(60, ENTITY), // alh
FISHING_BOBBER(93, ENTITY), // ais
LIVINGENTITY(-1, ENTITY), // abv // Hanging entities
ARMOR_STAND(1, LIVINGENTITY), // ail HANGING_ENTITY(ENTITY),
PLAYER(92, LIVINGENTITY), // aks LEASH_KNOT(35, HANGING_ENTITY),
ITEM_FRAME(33, HANGING_ENTITY),
ABSTRACT_INSENTIENT(-1, LIVINGENTITY), // abw PAINTING(49, HANGING_ENTITY),
ENDER_DRAGON(17, ABSTRACT_INSENTIENT), // ahp
ABSTRACT_CREATURE(-1, ABSTRACT_INSENTIENT), // acd
ABSTRACT_AGEABLE(-1, ABSTRACT_CREATURE), // abj
VILLAGER(79, ABSTRACT_AGEABLE), // akn
// Animals
ABSTRACT_ANIMAL(-1, ABSTRACT_AGEABLE), // agd
CHICKEN(7, ABSTRACT_ANIMAL), // age
COW(9, ABSTRACT_ANIMAL), // agg
MOOSHROOM(47, COW), // agi
PIG(51, ABSTRACT_ANIMAL), // agl
POLAR_BEAR(54, ABSTRACT_ANIMAL), // agm
RABBIT(56, ABSTRACT_ANIMAL), // ago
SHEEP(58, ABSTRACT_ANIMAL), // agq
TURTLE(73, ABSTRACT_ANIMAL), // agv
ABSTRACT_TAMEABLE_ANIMAL(-1, ABSTRACT_ANIMAL), // acg
OCELOT(48, ABSTRACT_TAMEABLE_ANIMAL), // agj
WOLF(86, ABSTRACT_TAMEABLE_ANIMAL), // agy
ABSTRACT_PARROT(-1, ABSTRACT_TAMEABLE_ANIMAL), // agr
PARROT(50, ABSTRACT_PARROT), // agk
// Horses
ABSTRACT_HORSE(-1, ABSTRACT_ANIMAL), // aha
CHESTED_HORSE(-1, ABSTRACT_HORSE), // agz
DONKEY(11, CHESTED_HORSE), // ahb
MULE(46, CHESTED_HORSE), // ahf
LLAMA(36, CHESTED_HORSE), // ahe
HORSE(29, ABSTRACT_HORSE), // ahc
SKELETON_HORSE(63, ABSTRACT_HORSE), // ahg
ZOMBIE_HORSE(88, ABSTRACT_HORSE), // ahi
// Golem
ABSTRACT_GOLEM(-1, ABSTRACT_CREATURE), // agc
SNOW_GOLEM(66, ABSTRACT_GOLEM), // ags
IRON_GOLEM(80, ABSTRACT_GOLEM), // agw
SHULKER(59, ABSTRACT_GOLEM), // ajx
// Fish
ABSTRACT_FISHES(-1, ABSTRACT_CREATURE), // agb
COD(8, ABSTRACT_FISHES), // agf
PUFFERFISH(52, ABSTRACT_FISHES), // agn
SALMON(57, ABSTRACT_FISHES), // agp
TROPICAL_FISH(72, ABSTRACT_FISHES), // agu
// Monsters
ABSTRACT_MONSTER(-1, ABSTRACT_CREATURE), // ajs
BLAZE(4, ABSTRACT_MONSTER), // ajd
CREEPER(10, ABSTRACT_MONSTER), // ajf
ENDERMITE(19, ABSTRACT_MONSTER), // ajj
ENDERMAN(18, ABSTRACT_MONSTER), // aji
GIANT(27, ABSTRACT_MONSTER), // ajn
SILVERFISH(61, ABSTRACT_MONSTER), // ajy
VEX(78, ABSTRACT_MONSTER), // ake
WITCH(82, ABSTRACT_MONSTER), // akg
WITHER(83, ABSTRACT_MONSTER), // aij
// Illagers
ABSTRACT_ILLAGER_BASE(-1, ABSTRACT_MONSTER), // ajb
ABSTRACT_EVO_ILLU_ILLAGER(-1, ABSTRACT_ILLAGER_BASE), // akb
EVOKER(21, ABSTRACT_EVO_ILLU_ILLAGER), // ajl
ILLUSIONER(31, ABSTRACT_EVO_ILLU_ILLAGER), // ajq
VINDICATOR(81, ABSTRACT_ILLAGER_BASE), // akf
// Skeletons
ABSTRACT_SKELETON(-1, ABSTRACT_MONSTER), // ajc
SKELETON(62, ABSTRACT_SKELETON), // ajz
STRAY(71, ABSTRACT_SKELETON), // akd
WITHER_SKELETON(84, ABSTRACT_SKELETON), // akh
// Guardians
GUARDIAN(28, ABSTRACT_MONSTER), // ajo
ELDER_GUARDIAN(15, GUARDIAN), // ajh
// Spiders
SPIDER(69, ABSTRACT_MONSTER), // akc
CAVE_SPIDER(6, SPIDER), // aje
// Zombies - META CHECKED
ZOMBIE(87, ABSTRACT_MONSTER), // aki
DROWNED(14, ZOMBIE), // ajg
HUSK(30, ZOMBIE), // ajp
ZOMBIE_PIGMAN(53, ZOMBIE), // aju
ZOMBIE_VILLAGER(89, ZOMBIE), // akj
// Flying entities
ABSTRACT_FLYING(-1, ABSTRACT_INSENTIENT), // abt
GHAST(26, ABSTRACT_FLYING), // ajm
PHANTOM(90, ABSTRACT_FLYING), // ajt
ABSTRACT_AMBIENT(-1, ABSTRACT_INSENTIENT), // afy
BAT(3, ABSTRACT_AMBIENT), // afz
ABSTRACT_WATERMOB(-1, ABSTRACT_INSENTIENT), // agx
SQUID(70, ABSTRACT_WATERMOB), // agt
DOLPHIN(12, ABSTRACT_WATERMOB),
// Slimes
SLIME(64, ABSTRACT_INSENTIENT), // aka
MAGMA_CUBE(38, SLIME), // ajr
// Hangable objects
ABSTRACT_HANGING(-1, ENTITY), // aim
LEASH_KNOT(35, ABSTRACT_HANGING), // aio
ITEM_FRAME(33, ABSTRACT_HANGING), // ain
PAINTING(49, ABSTRACT_HANGING), // aiq
ABSTRACT_LIGHTNING(-1, ENTITY), // aiu
LIGHTNING_BOLT(91, ABSTRACT_LIGHTNING), // aiv
// Arrows
ABSTRACT_ARROW(-1, ENTITY), // akw
ARROW(2, ABSTRACT_ARROW), // aky
SPECTRAL_ARROW(68, ABSTRACT_ARROW), // alk
TRIDENT(94, ABSTRACT_ARROW), // alq
// Fireballs
ABSTRACT_FIREBALL(-1, ENTITY), // akx
DRAGON_FIREBALL(13, ABSTRACT_FIREBALL), // akz
FIREBALL(34, ABSTRACT_FIREBALL), // ald
SMALL_FIREBALL(65, ABSTRACT_FIREBALL), // ali
WITHER_SKULL(85, ABSTRACT_FIREBALL), // alr
// Projectiles // Projectiles
PROJECTILE_ABSTRACT(-1, ENTITY), // all PROJECTILE(ENTITY),
SNOWBALL(67, PROJECTILE_ABSTRACT), // alj FIREWORK_ROCKET(25, ENTITY),
ENDER_PEARL(75, PROJECTILE_ABSTRACT), // aln LLAMA_SPIT(37, ENTITY),
EGG(74, PROJECTILE_ABSTRACT), // alm SHULKER_BULLET(60, ENTITY),
POTION(77, PROJECTILE_ABSTRACT), // alp SNOWBALL(67, PROJECTILE),
EXPERIENCE_BOTTLE(76, PROJECTILE_ABSTRACT), // alo ENDER_PEARL(75, PROJECTILE),
EGG(74, PROJECTILE),
EXPERIENCE_BOTTLE(76, PROJECTILE),
POTION(77, PROJECTILE),
FISHING_BOBBER(93, ENTITY),
ABSTRACT_ARROW(ENTITY),
ARROW(2, ABSTRACT_ARROW),
SPECTRAL_ARROW(68, ABSTRACT_ARROW),
TRIDENT(94, ABSTRACT_ARROW),
HURTING_PROJECTILE(ENTITY),
DRAGON_FIREBALL(13, HURTING_PROJECTILE),
FIREBALL(34, HURTING_PROJECTILE),
SMALL_FIREBALL(65, HURTING_PROJECTILE),
WITHER_SKULL(85, HURTING_PROJECTILE),
// Vehicles // Vehicles
MINECART_ABSTRACT(-1, ENTITY), // alt BOAT(5, ENTITY),
CHESTED_MINECART_ABSTRACT(-1, MINECART_ABSTRACT), // alu
CHEST_MINECART(40, CHESTED_MINECART_ABSTRACT), // alx ABSTRACT_MINECART(ENTITY),
HOPPER_MINECART(43, CHESTED_MINECART_ABSTRACT), // ama MINECART(39, ABSTRACT_MINECART),
MINECART(39, MINECART_ABSTRACT), // alw FURNACE_MINECART(42, ABSTRACT_MINECART),
FURNACE_MINECART(42, MINECART_ABSTRACT), // alz COMMAND_BLOCK_MINECART(41, ABSTRACT_MINECART),
COMMAND_BLOCK_MINECART(41, MINECART_ABSTRACT), // aly TNT_MINECART(45, ABSTRACT_MINECART),
TNT_MINECART(45, MINECART_ABSTRACT), // amc SPAWNER_MINECART(44, ABSTRACT_MINECART),
SPAWNER_MINECART(44, MINECART_ABSTRACT), // amb
BOAT(5, ENTITY); // alv ABSTRACT_MINECART_CONTAINER(ABSTRACT_MINECART),
CHEST_MINECART(40, ABSTRACT_MINECART_CONTAINER),
HOPPER_MINECART(43, ABSTRACT_MINECART_CONTAINER),
LIVING_ENTITY_BASE(ENTITY),
ARMOR_STAND(1, LIVING_ENTITY_BASE),
PLAYER(92, LIVING_ENTITY_BASE),
// Living entities as a larger subclass
LIVING_ENTITY(LIVING_ENTITY_BASE),
ENDER_DRAGON(17, LIVING_ENTITY),
ABSTRACT_CREATURE(LIVING_ENTITY),
SLIME(64, LIVING_ENTITY),
MAGMA_CUBE(38, SLIME),
// Flying entities
FLYING_MOB(ABSTRACT_CREATURE),
GHAST(26, FLYING_MOB),
PHANTOM(90, FLYING_MOB),
AMBIENT_CREATURE(-1, LIVING_ENTITY),
BAT(3, AMBIENT_CREATURE),
ABSTRACT_GOLEM(ABSTRACT_CREATURE),
SNOW_GOLEM(66, ABSTRACT_GOLEM),
IRON_GOLEM(80, ABSTRACT_GOLEM),
SHULKER(59, ABSTRACT_GOLEM),
WATER_ANIMAL(ABSTRACT_CREATURE),
SQUID(70, WATER_ANIMAL),
DOLPHIN(12, WATER_ANIMAL),
ABSTRACT_FISH(WATER_ANIMAL),
COD(8, ABSTRACT_FISH),
PUFFERFISH(52, ABSTRACT_FISH),
SALMON(57, ABSTRACT_FISH),
TROPICAL_FISH(72, ABSTRACT_FISH),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE),
VILLAGER(79, ABSTRACT_AGEABLE),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE),
CHICKEN(7, ABSTRACT_ANIMAL),
COW(9, ABSTRACT_ANIMAL),
MOOSHROOM(47, COW),
PIG(51, ABSTRACT_ANIMAL),
POLAR_BEAR(54, ABSTRACT_ANIMAL),
RABBIT(56, ABSTRACT_ANIMAL),
SHEEP(58, ABSTRACT_ANIMAL),
TURTLE(73, ABSTRACT_ANIMAL),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL),
OCELOT(48, TAMABLE_ANIMAL),
WOLF(86, TAMABLE_ANIMAL),
ABSTRACT_SHOULDER_RIDING(TAMABLE_ANIMAL),
PARROT(50, ABSTRACT_SHOULDER_RIDING),
// Horses
ABSTRACT_HORSE(ABSTRACT_ANIMAL),
HORSE(29, ABSTRACT_HORSE),
SKELETON_HORSE(63, ABSTRACT_HORSE),
ZOMBIE_HORSE(88, ABSTRACT_HORSE),
CHESTED_HORSE(ABSTRACT_HORSE),
DONKEY(11, CHESTED_HORSE),
MULE(46, CHESTED_HORSE),
LLAMA(36, CHESTED_HORSE),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE),
BLAZE(4, ABSTRACT_MONSTER),
CREEPER(10, ABSTRACT_MONSTER),
ENDERMITE(19, ABSTRACT_MONSTER),
ENDERMAN(18, ABSTRACT_MONSTER),
GIANT(27, ABSTRACT_MONSTER),
SILVERFISH(61, ABSTRACT_MONSTER),
VEX(78, ABSTRACT_MONSTER),
WITCH(82, ABSTRACT_MONSTER),
WITHER(83, ABSTRACT_MONSTER),
ABSTRACT_SKELETON(ABSTRACT_MONSTER),
SKELETON(62, ABSTRACT_SKELETON),
STRAY(71, ABSTRACT_SKELETON),
WITHER_SKELETON(84, ABSTRACT_SKELETON),
ZOMBIE(87, ABSTRACT_MONSTER),
DROWNED(14, ZOMBIE),
HUSK(30, ZOMBIE),
ZOMBIE_PIGMAN(53, ZOMBIE),
ZOMBIE_VILLAGER(89, ZOMBIE),
GUARDIAN(28, ABSTRACT_MONSTER),
ELDER_GUARDIAN(15, GUARDIAN),
SPIDER(69, ABSTRACT_MONSTER),
CAVE_SPIDER(6, SPIDER),
// Illagers
ABSTRACT_ILLAGER(ABSTRACT_MONSTER),
SPELLCASTER_ILLAGER(ABSTRACT_ILLAGER),
VINDICATOR(81, ABSTRACT_ILLAGER),
EVOKER(21, SPELLCASTER_ILLAGER),
ILLUSIONER(31, SPELLCASTER_ILLAGER);
private static final Map<Integer, EntityType> TYPES = new HashMap<>(); private static final Map<Integer, EntityType> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType parent; private final EntityType parent;
EntityType(int id) { EntityType() {
this.id = id; this.id = -1;
this.parent = null; this.parent = null;
} }
EntityType(EntityType parent) {
this.id = -1;
this.parent = parent;
}
EntityType(int id, EntityType parent) { EntityType(int id, EntityType parent) {
this.id = id; this.id = id;
this.parent = parent; this.parent = parent;
@ -255,10 +247,11 @@ public class EntityTypes1_13 {
} }
} }
public static Optional<EntityType> findById(int id) { public static EntityType findById(final int id) {
if (id == -1) // Check if this is called if (id == -1) {
return Optional.empty(); return null;
return Optional.ofNullable(TYPES.get(id)); }
return TYPES.get(id);
} }
} }
@ -266,7 +259,7 @@ public class EntityTypes1_13 {
BOAT(1, EntityType.BOAT), BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.ITEM), ITEM(2, EntityType.ITEM),
AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD), AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD),
MINECART(10, EntityType.MINECART), MINECART(10, EntityType.MINECART), // There are multiple types, but we don't need them
TNT_PRIMED(50, EntityType.TNT), TNT_PRIMED(50, EntityType.TNT),
ENDER_CRYSTAL(51, EntityType.END_CRYSTAL), ENDER_CRYSTAL(51, EntityType.END_CRYSTAL),
TIPPED_ARROW(60, EntityType.ARROW), TIPPED_ARROW(60, EntityType.ARROW),
@ -318,22 +311,16 @@ public class EntityTypes1_13 {
return type; return type;
} }
public static Optional<ObjectType> findById(int id) { public static ObjectType findById(final int id) {
if (id == -1) if (id == -1) {
return Optional.empty(); return null;
return Optional.ofNullable(TYPES.get(id)); }
return TYPES.get(id);
} }
public static Optional<EntityType> getPCEntity(int id) { public static EntityType getEntityType(final int id) {
Optional<ObjectType> output = findById(id); final ObjectType objectType = findById(id);
return output.map(objectType -> objectType.type); return objectType != null ? objectType.type : null;
}
public static Optional<ObjectType> fromEntityType(EntityType type) {
for (ObjectType ent : ObjectType.values())
if (ent.type == type)
return Optional.of(ent);
return Optional.empty();
} }
} }
} }

Datei anzeigen

@ -0,0 +1,269 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.entities;
import com.viaversion.viaversion.api.Via;
import java.util.HashMap;
import java.util.Map;
public class EntityTypes1_8 {
public static EntityType getTypeFromId(final int typeId, final boolean object) {
EntityType type;
if (object) {
type = ObjectType.getEntityType(typeId);
} else {
type = EntityType.findById(typeId);
}
if (type == null) {
Via.getPlatform().getLogger().severe("Could not find 1.8 type id " + typeId + " objectType=" + object);
return EntityType.ENTITY; // Fall back to the basic ENTITY
}
return type;
}
public enum EntityType implements com.viaversion.viaversion.api.minecraft.entities.EntityType {
ENTITY,
END_CRYSTAL(200, ENTITY),
EXPERIENCE_ORB(2, ENTITY),
EYE_OF_ENDER(15, ENTITY),
FALLING_BLOCK(21, ENTITY),
ITEM(1, ENTITY),
TNT(20, ENTITY),
LIGHTNING_BOLT(ENTITY), // Needed for entity (un)tracking
// Hanging entities
HANGING_ENTITY(ENTITY),
LEASH_KNOT(8, HANGING_ENTITY),
ITEM_FRAME(18, HANGING_ENTITY),
PAINTING(9, HANGING_ENTITY),
// Projectiles
PROJECTILE(ENTITY),
FIREWORK_ROCKET(22, ENTITY),
SNOWBALL(11, PROJECTILE),
ENDER_PEARL(14, PROJECTILE),
EGG(7, PROJECTILE),
EXPERIENCE_BOTTLE(17, PROJECTILE),
POTION(16, PROJECTILE),
FISHING_HOOK(ENTITY),
ARROW(10, ENTITY),
HURTING_PROJECTILE(ENTITY),
FIREBALL(12, HURTING_PROJECTILE),
SMALL_FIREBALL(13, HURTING_PROJECTILE),
WITHER_SKULL(19, HURTING_PROJECTILE),
// Vehicles
BOAT(41, ENTITY),
ABSTRACT_MINECART(ENTITY),
MINECART(42, ABSTRACT_MINECART),
FURNACE_MINECART(44, ABSTRACT_MINECART),
COMMAND_BLOCK_MINECART(40, ABSTRACT_MINECART),
TNT_MINECART(45, ABSTRACT_MINECART),
SPAWNER_MINECART(47, ABSTRACT_MINECART),
ABSTRACT_MINECART_CONTAINER(ABSTRACT_MINECART),
CHEST_MINECART(43, ABSTRACT_MINECART_CONTAINER),
HOPPER_MINECART(46, ABSTRACT_MINECART_CONTAINER),
LIVING_ENTITY_BASE(ENTITY),
ARMOR_STAND(30, LIVING_ENTITY_BASE),
PLAYER(LIVING_ENTITY_BASE), // Needed for entity (un)tracking and metadata indexing
// Living entities as a larger subclass
LIVING_ENTITY(48, LIVING_ENTITY_BASE),
ENDER_DRAGON(63, LIVING_ENTITY),
ABSTRACT_CREATURE(LIVING_ENTITY),
SLIME(55, LIVING_ENTITY),
MAGMA_CUBE(62, SLIME),
// Flying entities
FLYING_MOB(LIVING_ENTITY),
GHAST(56, FLYING_MOB),
AMBIENT_CREATURE(LIVING_ENTITY),
BAT(65, AMBIENT_CREATURE),
ABSTRACT_GOLEM(ABSTRACT_CREATURE),
SNOW_GOLEM(97, ABSTRACT_GOLEM),
IRON_GOLEM(99, ABSTRACT_GOLEM),
WATER_ANIMAL(LIVING_ENTITY),
SQUID(94, WATER_ANIMAL),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE),
VILLAGER(120, ABSTRACT_AGEABLE),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE),
CHICKEN(93, ABSTRACT_ANIMAL),
COW(92, ABSTRACT_ANIMAL),
MOOSHROOM(96, COW),
PIG(90, ABSTRACT_ANIMAL),
RABBIT(101, ABSTRACT_ANIMAL),
SHEEP(91, ABSTRACT_ANIMAL),
HORSE(100, ABSTRACT_ANIMAL),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL),
OCELOT(98, TAMABLE_ANIMAL),
WOLF(95, TAMABLE_ANIMAL),
// Monsters
ABSTRACT_MONSTER(49, ABSTRACT_CREATURE),
BLAZE(61, ABSTRACT_MONSTER),
CREEPER(50, ABSTRACT_MONSTER),
ENDERMITE(67, ABSTRACT_MONSTER),
ENDERMAN(58, ABSTRACT_MONSTER),
GIANT(53, ABSTRACT_MONSTER),
SILVERFISH(60, ABSTRACT_MONSTER),
WITCH(66, ABSTRACT_MONSTER),
WITHER(64, ABSTRACT_MONSTER),
SKELETON(51, ABSTRACT_MONSTER),
ZOMBIE(54, ABSTRACT_MONSTER),
ZOMBIE_PIGMEN(57, ZOMBIE),
GUARDIAN(68, ABSTRACT_MONSTER),
SPIDER(52, ABSTRACT_MONSTER),
CAVE_SPIDER(59, SPIDER);
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
private final int id;
private final EntityType parent;
EntityType() {
this.id = -1;
this.parent = null;
}
EntityType(EntityType parent) {
this.id = -1;
this.parent = parent;
}
EntityType(int id, EntityType parent) {
this.id = id;
this.parent = parent;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getParent() {
return parent;
}
@Override
public String identifier() {
throw new UnsupportedOperationException();
}
@Override
public boolean isAbstractType() {
return id != -1;
}
static {
for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type);
}
}
public static EntityType findById(final int id) {
if (id == -1) {
return null;
}
return TYPES.get(id);
}
}
public enum ObjectType implements com.viaversion.viaversion.api.minecraft.entities.ObjectType {
BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.ITEM),
MINECART(10, EntityType.MINECART), // There are multiple types, but we don't need them
TNT_PRIMED(50, EntityType.TNT),
ENDER_CRYSTAL(51, EntityType.END_CRYSTAL),
TIPPED_ARROW(60, EntityType.ARROW),
SNOWBALL(61, EntityType.SNOWBALL),
EGG(62, EntityType.EGG),
FIREBALL(63, EntityType.FIREBALL),
SMALL_FIREBALL(64, EntityType.SMALL_FIREBALL),
ENDER_PEARL(65, EntityType.ENDER_PEARL),
WITHER_SKULL(66, EntityType.WITHER_SKULL),
FALLING_BLOCK(70, EntityType.FALLING_BLOCK),
ITEM_FRAME(71, EntityType.ITEM_FRAME),
EYE_OF_ENDER(72, EntityType.EYE_OF_ENDER),
POTION(73, EntityType.POTION),
EXPERIENCE_BOTTLE(75, EntityType.EXPERIENCE_BOTTLE),
FIREWORK_ROCKET(76, EntityType.FIREWORK_ROCKET),
LEASH(77, EntityType.LEASH_KNOT),
ARMOR_STAND(78, EntityType.ARMOR_STAND),
FISHIHNG_HOOK(90, EntityType.FISHING_HOOK);
private static final Map<Integer, ObjectType> TYPES = new HashMap<>();
private final int id;
private final EntityType type;
static {
for (ObjectType type : ObjectType.values()) {
TYPES.put(type.id, type);
}
}
ObjectType(int id, EntityType type) {
this.id = id;
this.type = type;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getType() {
return type;
}
public static ObjectType findById(final int id) {
if (id == -1) {
return null;
}
return TYPES.get(id);
}
public static EntityType getEntityType(final int id) {
final ObjectType objectType = findById(id);
return objectType != null ? objectType.type : null;
}
}
}

Datei anzeigen

@ -0,0 +1,280 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.entities;
import com.viaversion.viaversion.api.Via;
import java.util.HashMap;
import java.util.Map;
public class EntityTypes1_9 {
public static EntityType getTypeFromId(final int typeId, final boolean object) {
EntityType type;
if (object) {
type = ObjectType.getEntityType(typeId);
} else {
type = EntityType.findById(typeId);
}
if (type == null) {
Via.getPlatform().getLogger().severe("Could not find 1.9 type id " + typeId + " objectType=" + object);
return EntityType.ENTITY; // Fall back to the basic ENTITY
}
return type;
}
public enum EntityType implements com.viaversion.viaversion.api.minecraft.entities.EntityType {
ENTITY,
AREA_EFFECT_CLOUD(3, ENTITY),
END_CRYSTAL(200, ENTITY),
EXPERIENCE_ORB(2, ENTITY),
EYE_OF_ENDER(15, ENTITY),
FALLING_BLOCK(21, ENTITY),
ITEM(1, ENTITY),
TNT(20, ENTITY),
LIGHTNING_BOLT(ENTITY), // Needed for entity (un)tracking
// Hanging entities
HANGING_ENTITY(ENTITY),
LEASH_KNOT(8, HANGING_ENTITY),
ITEM_FRAME(18, HANGING_ENTITY),
PAINTING(9, HANGING_ENTITY),
// Projectiles
PROJECTILE(ENTITY),
FIREWORK_ROCKET(22, ENTITY),
SHULKER_BULLET(25, ENTITY),
SNOWBALL(11, PROJECTILE),
ENDER_PEARL(14, PROJECTILE),
EGG(7, PROJECTILE),
EXPERIENCE_BOTTLE(17, PROJECTILE),
POTION(16, PROJECTILE),
FISHING_HOOK(ENTITY),
ABSTRACT_ARROW(ENTITY),
ARROW(10, ABSTRACT_ARROW),
SPECTRAL_ARROW(24, ABSTRACT_ARROW),
HURTING_PROJECTILE(ENTITY),
DRAGON_FIREBALL(26, HURTING_PROJECTILE),
FIREBALL(12, HURTING_PROJECTILE),
SMALL_FIREBALL(13, HURTING_PROJECTILE),
WITHER_SKULL(19, HURTING_PROJECTILE),
// Vehicles
BOAT(41, ENTITY),
ABSTRACT_MINECART(ENTITY),
MINECART(42, ABSTRACT_MINECART),
FURNACE_MINECART(44, ABSTRACT_MINECART),
COMMAND_BLOCK_MINECART(40, ABSTRACT_MINECART),
TNT_MINECART(45, ABSTRACT_MINECART),
SPAWNER_MINECART(47, ABSTRACT_MINECART),
ABSTRACT_MINECART_CONTAINER(ABSTRACT_MINECART),
CHEST_MINECART(43, ABSTRACT_MINECART_CONTAINER),
HOPPER_MINECART(46, ABSTRACT_MINECART_CONTAINER),
LIVING_ENTITY_BASE(ENTITY),
ARMOR_STAND(30, LIVING_ENTITY_BASE),
PLAYER(ENTITY), // Needed for entity (un)tracking
// Living entities as a larger subclass
LIVING_ENTITY(48, LIVING_ENTITY_BASE),
ENDER_DRAGON(63, LIVING_ENTITY),
ABSTRACT_CREATURE(LIVING_ENTITY),
SLIME(55, LIVING_ENTITY),
MAGMA_CUBE(62, SLIME),
// Flying entities
FLYING_MOB(LIVING_ENTITY),
GHAST(56, FLYING_MOB),
AMBIENT_CREATURE(LIVING_ENTITY),
BAT(65, AMBIENT_CREATURE),
ABSTRACT_GOLEM(ABSTRACT_CREATURE),
SNOW_GOLEM(97, ABSTRACT_GOLEM),
IRON_GOLEM(99, ABSTRACT_GOLEM),
SHULKER(69, ABSTRACT_GOLEM),
WATER_ANIMAL(LIVING_ENTITY),
SQUID(94, WATER_ANIMAL),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE),
VILLAGER(120, ABSTRACT_AGEABLE),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE),
CHICKEN(93, ABSTRACT_ANIMAL),
COW(92, ABSTRACT_ANIMAL),
MOOSHROOM(96, COW),
PIG(90, ABSTRACT_ANIMAL),
RABBIT(101, ABSTRACT_ANIMAL),
SHEEP(91, ABSTRACT_ANIMAL),
HORSE(100, ABSTRACT_ANIMAL),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL),
OCELOT(98, TAMABLE_ANIMAL),
WOLF(95, TAMABLE_ANIMAL),
// Monsters
ABSTRACT_MONSTER(49, ABSTRACT_CREATURE),
BLAZE(61, ABSTRACT_MONSTER),
CREEPER(50, ABSTRACT_MONSTER),
ENDERMITE(67, ABSTRACT_MONSTER),
ENDERMAN(58, ABSTRACT_MONSTER),
GIANT(53, ABSTRACT_MONSTER),
SILVERFISH(60, ABSTRACT_MONSTER),
WITCH(66, ABSTRACT_MONSTER),
WITHER(64, ABSTRACT_MONSTER),
SKELETON(51, ABSTRACT_MONSTER),
ZOMBIE(54, ABSTRACT_MONSTER),
ZOMBIE_PIGMEN(57, ZOMBIE),
GUARDIAN(68, ABSTRACT_MONSTER),
SPIDER(52, ABSTRACT_MONSTER),
CAVE_SPIDER(59, SPIDER);
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
private final int id;
private final EntityType parent;
EntityType() {
this.id = -1;
this.parent = null;
}
EntityType(EntityType parent) {
this.id = -1;
this.parent = parent;
}
EntityType(int id, EntityType parent) {
this.id = id;
this.parent = parent;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getParent() {
return parent;
}
@Override
public String identifier() {
throw new UnsupportedOperationException();
}
@Override
public boolean isAbstractType() {
return id != -1;
}
static {
for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type);
}
}
public static EntityType findById(final int id) {
if (id == -1) {
return null;
}
return TYPES.get(id);
}
}
public enum ObjectType implements com.viaversion.viaversion.api.minecraft.entities.ObjectType {
BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.ITEM),
AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD),
MINECART(10, EntityType.MINECART), // There are multiple types, but we don't need them
TNT_PRIMED(50, EntityType.TNT),
ENDER_CRYSTAL(51, EntityType.END_CRYSTAL),
TIPPED_ARROW(60, EntityType.ARROW),
SNOWBALL(61, EntityType.SNOWBALL),
EGG(62, EntityType.EGG),
FIREBALL(63, EntityType.FIREBALL),
SMALL_FIREBALL(64, EntityType.SMALL_FIREBALL),
ENDER_PEARL(65, EntityType.ENDER_PEARL),
WITHER_SKULL(66, EntityType.WITHER_SKULL),
SHULKER_BULLET(67, EntityType.SHULKER_BULLET),
FALLING_BLOCK(70, EntityType.FALLING_BLOCK),
ITEM_FRAME(71, EntityType.ITEM_FRAME),
EYE_OF_ENDER(72, EntityType.EYE_OF_ENDER),
POTION(73, EntityType.POTION),
EXPERIENCE_BOTTLE(75, EntityType.EXPERIENCE_BOTTLE),
FIREWORK_ROCKET(76, EntityType.FIREWORK_ROCKET),
LEASH(77, EntityType.LEASH_KNOT),
ARMOR_STAND(78, EntityType.ARMOR_STAND),
FISHIHNG_HOOK(90, EntityType.FISHING_HOOK),
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
private static final Map<Integer, ObjectType> TYPES = new HashMap<>();
private final int id;
private final EntityType type;
static {
for (ObjectType type : ObjectType.values()) {
TYPES.put(type.id, type);
}
}
ObjectType(int id, EntityType type) {
this.id = id;
this.type = type;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getType() {
return type;
}
public static ObjectType findById(final int id) {
if (id == -1) {
return null;
}
return TYPES.get(id);
}
public static EntityType getEntityType(final int id) {
final ObjectType objectType = findById(id);
return objectType != null ? objectType.type : null;
}
}
}

Datei anzeigen

@ -260,8 +260,6 @@ public class EntityPacketRewriter1_11 extends EntityRewriter<ClientboundPackets1
return null; return null;
} }
EntityType type = optType.get();
try { try {
if (type.is(EntityType.GUARDIAN)) { if (type.is(EntityType.GUARDIAN)) {
// ElderGuardian - 4 // ElderGuardian - 4

Datei anzeigen

@ -81,7 +81,7 @@ public class EntityPacketRewriter1_12 extends EntityRewriter<ClientboundPackets1
} }
}); });
filter().type(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).index(12).toIndex(13); // Aggressive filter().type(EntityTypes1_12.EntityType.ABSTRACT_ILLAGER).addIndex(12); // Aggressive
} }
@Override @Override

Datei anzeigen

@ -195,7 +195,7 @@ public class EntityPacketRewriter1_13 extends EntityRewriter<ClientboundPackets1
filter().type(EntityTypes1_13.EntityType.ZOMBIE).addIndex(15); // Shaking filter().type(EntityTypes1_13.EntityType.ZOMBIE).addIndex(15); // Shaking
filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> { filter().type(EntityTypes1_13.EntityType.ABSTRACT_MINECART).index(9).handler((event, meta) -> {
final int oldId = meta.value(); final int oldId = meta.value();
final int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15)); final int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
final int newId = WorldPacketRewriter1_13.toNewId(combined); final int newId = WorldPacketRewriter1_13.toNewId(combined);

Datei anzeigen

@ -22,7 +22,7 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.EulerAngle; import com.viaversion.viaversion.api.minecraft.EulerAngle;
import com.viaversion.viaversion.api.minecraft.Vector; import com.viaversion.viaversion.api.minecraft.Vector;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_9;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType; import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
@ -419,7 +419,7 @@ public class EntityPacketRewriter1_9 extends EntityRewriter<ClientboundPackets1_
metadata.setValue(((Integer) value).byteValue()); metadata.setValue(((Integer) value).byteValue());
} }
// After writing the last one // After writing the last one
if (metaIndex == MetaIndex1_8.ENTITY_STATUS && type == EntityTypes1_10.EntityType.PLAYER) { if (metaIndex == MetaIndex1_8.ENTITY_STATUS && type == EntityTypes1_9.EntityType.PLAYER) {
byte val = 0; byte val = 0;
if ((((Byte) value) & 0x10) == 0x10) { // Player eating/aiming/drinking if ((((Byte) value) & 0x10) == 0x10) { // Player eating/aiming/drinking
val = 1; val = 1;
@ -456,7 +456,7 @@ public class EntityPacketRewriter1_9 extends EntityRewriter<ClientboundPackets1_
metadata.setValue(value); metadata.setValue(value);
break; break;
case BOOLEAN: case BOOLEAN:
if (metaIndex == MetaIndex1_8.AGEABLE_CREATURE_AGE) if (metaIndex == MetaIndex1_8.ABSTRACT_AGEABLE_AGE)
metadata.setValue((Byte) value < 0); metadata.setValue((Byte) value < 0);
else else
metadata.setValue((Byte) value != 0); metadata.setValue((Byte) value != 0);
@ -489,11 +489,11 @@ public class EntityPacketRewriter1_9 extends EntityRewriter<ClientboundPackets1_
@Override @Override
public EntityType typeFromId(int type) { public EntityType typeFromId(int type) {
return EntityTypes1_10.getTypeFromId(type, false); return EntityTypes1_9.getTypeFromId(type, false);
} }
@Override @Override
public EntityType objectTypeFromId(int type) { public EntityType objectTypeFromId(int type) {
return EntityTypes1_10.getTypeFromId(type, true); return EntityTypes1_9.getTypeFromId(type, true);
} }
} }

Datei anzeigen

@ -25,7 +25,7 @@ import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.GameMode; import com.viaversion.viaversion.api.minecraft.GameMode;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_9;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
@ -185,7 +185,7 @@ public class PlayerPacketRewriter1_9 {
handler(wrapper -> { handler(wrapper -> {
int entityId = wrapper.get(Types.INT, 0); int entityId = wrapper.get(Types.INT, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
tracker.addEntity(entityId, EntityTypes1_10.EntityType.PLAYER); tracker.addEntity(entityId, EntityTypes1_9.EntityType.PLAYER);
tracker.setClientEntityId(entityId); tracker.setClientEntityId(entityId);
}); });
map(Types.UNSIGNED_BYTE); // 1 - Player Gamemode map(Types.UNSIGNED_BYTE); // 1 - Player Gamemode

Datei anzeigen

@ -18,7 +18,8 @@
package com.viaversion.viaversion.protocols.v1_8to1_9.rewriter; package com.viaversion.viaversion.protocols.v1_8to1_9.rewriter;
import com.viaversion.viaversion.api.data.entity.EntityTracker; import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_9;
import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
@ -62,7 +63,7 @@ public class SpawnPacketRewriter1_9 {
int entityID = wrapper.get(Types.VAR_INT, 0); int entityID = wrapper.get(Types.VAR_INT, 0);
int typeID = wrapper.get(Types.BYTE, 0); int typeID = wrapper.get(Types.BYTE, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
tracker.addEntity(entityID, EntityTypes1_10.getTypeFromId(typeID, true)); tracker.addEntity(entityID, EntityTypes1_9.getTypeFromId(typeID, true));
}); });
map(Types.INT, toNewDouble); // 3 - X - Needs to be divided by 32 map(Types.INT, toNewDouble); // 3 - X - Needs to be divided by 32
@ -98,7 +99,7 @@ public class SpawnPacketRewriter1_9 {
final int data = wrapper.get(Types.INT, 0); // Data final int data = wrapper.get(Types.INT, 0); // Data
int typeID = wrapper.get(Types.BYTE, 0); int typeID = wrapper.get(Types.BYTE, 0);
if (EntityTypes1_10.getTypeFromId(typeID, true) == EntityTypes1_10.EntityType.SPLASH_POTION) { if (EntityTypes1_8.getTypeFromId(typeID, true) == EntityTypes1_8.EntityType.POTION) {
// Convert this to meta data, woo! // Convert this to meta data, woo!
PacketWrapper metaPacket = wrapper.create(ClientboundPackets1_9.SET_ENTITY_DATA, wrapper1 -> { PacketWrapper metaPacket = wrapper.create(ClientboundPackets1_9.SET_ENTITY_DATA, wrapper1 -> {
wrapper1.write(Types.VAR_INT, entityID); wrapper1.write(Types.VAR_INT, entityID);
@ -128,7 +129,7 @@ public class SpawnPacketRewriter1_9 {
handler(wrapper -> { handler(wrapper -> {
int entityID = wrapper.get(Types.VAR_INT, 0); int entityID = wrapper.get(Types.VAR_INT, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
tracker.addEntity(entityID, EntityTypes1_10.EntityType.EXPERIENCE_ORB); tracker.addEntity(entityID, EntityTypes1_9.EntityType.EXPERIENCE_ORB);
}); });
map(Types.INT, toNewDouble); // 1 - X - Needs to be divided by 32 map(Types.INT, toNewDouble); // 1 - X - Needs to be divided by 32
@ -149,7 +150,7 @@ public class SpawnPacketRewriter1_9 {
// Currently only lightning uses this // Currently only lightning uses this
int entityID = wrapper.get(Types.VAR_INT, 0); int entityID = wrapper.get(Types.VAR_INT, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
tracker.addEntity(entityID, EntityTypes1_10.EntityType.LIGHTNING); tracker.addEntity(entityID, EntityTypes1_9.EntityType.LIGHTNING_BOLT);
}); });
map(Types.INT, toNewDouble); // 2 - X - Needs to be divided by 32 map(Types.INT, toNewDouble); // 2 - X - Needs to be divided by 32
@ -175,7 +176,7 @@ public class SpawnPacketRewriter1_9 {
int entityID = wrapper.get(Types.VAR_INT, 0); int entityID = wrapper.get(Types.VAR_INT, 0);
int typeID = wrapper.get(Types.UNSIGNED_BYTE, 0); int typeID = wrapper.get(Types.UNSIGNED_BYTE, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
tracker.addEntity(entityID, EntityTypes1_10.getTypeFromId(typeID, false)); tracker.addEntity(entityID, EntityTypes1_9.getTypeFromId(typeID, false));
}); });
map(Types.INT, toNewDouble); // 3 - X - Needs to be divided by 32 map(Types.INT, toNewDouble); // 3 - X - Needs to be divided by 32
@ -221,7 +222,7 @@ public class SpawnPacketRewriter1_9 {
handler(wrapper -> { handler(wrapper -> {
int entityID = wrapper.get(Types.VAR_INT, 0); int entityID = wrapper.get(Types.VAR_INT, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
tracker.addEntity(entityID, EntityTypes1_10.EntityType.PAINTING); tracker.addEntity(entityID, EntityTypes1_9.EntityType.PAINTING);
}); });
handler(wrapper -> { handler(wrapper -> {
int entityID = wrapper.get(Types.VAR_INT, 0); int entityID = wrapper.get(Types.VAR_INT, 0);
@ -245,7 +246,7 @@ public class SpawnPacketRewriter1_9 {
handler(wrapper -> { handler(wrapper -> {
int entityID = wrapper.get(Types.VAR_INT, 0); int entityID = wrapper.get(Types.VAR_INT, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
tracker.addEntity(entityID, EntityTypes1_10.EntityType.PLAYER); tracker.addEntity(entityID, EntityTypes1_9.EntityType.PLAYER);
}); });
map(Types.INT, toNewDouble); // 2 - X - Needs to be divided by 32 map(Types.INT, toNewDouble); // 2 - X - Needs to be divided by 32

Datei anzeigen

@ -25,7 +25,7 @@ import com.viaversion.viaversion.api.legacy.bossbar.BossColor;
import com.viaversion.viaversion.api.legacy.bossbar.BossStyle; import com.viaversion.viaversion.api.legacy.bossbar.BossStyle;
import com.viaversion.viaversion.api.minecraft.GameMode; import com.viaversion.viaversion.api.minecraft.GameMode;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_9.EntityType;
import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;