Implement 1_11 entity / parent class structure and patch holograms the other way around! Thanks for fixing Mojang :-) #482

This commit is contained in:
Matsv 2016-09-30 20:08:39 +02:00
parent f881f3d484
commit 7031d431da
No known key found for this signature in database
GPG Key ID: 97CEC2A2EA31350F
14 changed files with 471 additions and 89 deletions

View File

@ -33,7 +33,7 @@ public class BukkitConfigAPI extends Config implements ViaVersionConfig {
@Override
public boolean isShowNewDeathMessages() {
return getBoolean("use-new-deathmessages", false);
return getBoolean("use-new-deathmessages", true);
}
@Override

View File

@ -35,7 +35,7 @@ public class BungeeConfigAPI extends Config implements ViaVersionConfig {
@Override
public boolean isShowNewDeathMessages() {
return getBoolean("use-new-deathmessages", false);
return getBoolean("use-new-deathmessages", true);
}
@Override

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.util;
package us.myles.ViaVersion.api.entities;
import com.google.common.base.Optional;
import lombok.AllArgsConstructor;
@ -6,13 +6,13 @@ import lombok.Getter;
import us.myles.ViaVersion.api.Via;
// 1.10 Entity / Object ids
public class EntityUtil {
public class Entity1_10Types {
public static EntityType getTypeFromID(int typeID, boolean isObject) {
public static EntityType getTypeFromId(int typeID, boolean isObject) {
Optional<EntityType> type;
if (isObject)
type = PCObjectTypes.getPCEntity(typeID);
type = ObjectTypes.getPCEntity(typeID);
else
type = EntityType.findById(typeID);
@ -135,7 +135,7 @@ public class EntityUtil {
@AllArgsConstructor
@Getter
public enum PCObjectTypes {
public enum ObjectTypes {
BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.DROPPED_ITEM),
AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD),
@ -165,11 +165,11 @@ public class EntityUtil {
private final int id;
private final EntityType type;
public static Optional<PCObjectTypes> findById(int id) {
public static Optional<ObjectTypes> findById(int id) {
if (id == -1)
return Optional.absent();
for (PCObjectTypes ent : PCObjectTypes.values())
for (ObjectTypes ent : ObjectTypes.values())
if (ent.getId() == id)
return Optional.of(ent);
@ -177,7 +177,7 @@ public class EntityUtil {
}
public static Optional<EntityType> getPCEntity(int id) {
Optional<PCObjectTypes> output = findById(id);
Optional<ObjectTypes> output = findById(id);
if (!output.isPresent())
return Optional.absent();

View File

@ -0,0 +1,241 @@
package us.myles.ViaVersion.api.entities;
import com.google.common.base.Optional;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.api.Via;
// 1.11 Entity / Object ids TODO maybe in the future instead of copying it, some api.
public class Entity1_11Types {
public static EntityType getTypeFromId(int typeID, boolean isObject) {
Optional<EntityType> type;
if (isObject)
type = ObjectTypes.getPCEntity(typeID);
else
type = EntityType.findById(typeID);
if (!type.isPresent()) {
Via.getPlatform().getLogger().severe("Could not find type id " + typeID + " isObject=" + isObject);
return EntityType.ENTITY; // Fall back to the basic ENTITY
}
return type.get();
}
@AllArgsConstructor
@Getter
public enum EntityType {
ENTITY(-1),
DROPPED_ITEM(1, ENTITY),
EXPERIENCE_ORB(2, ENTITY),
LEASH_HITCH(8, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata
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),
FIREWORK(22, ENTITY),
TIPPED_ARROW(23, ARROW),
SPECTRAL_ARROW(24, ARROW),
SHULKER_BULLET(25, ENTITY),
DRAGON_FIREBALL(26, FIREBALL),
EVOCATION_FANGS(33, ENTITY),
ENTITY_LIVING(-1, ENTITY),
ENTITY_INSENTIENT(-1, ENTITY_LIVING),
ENTITY_AGEABLE(-1, ENTITY_INSENTIENT),
ENTITY_TAMEABLE_ANIMAL(-1, ENTITY_AGEABLE),
ENTITY_HUMAN(-1, ENTITY_LIVING),
ARMOR_STAND(30, ENTITY_LIVING),
EVOCATION_ILLAGER(34, ENTITY_INSENTIENT),
VEX(35, ENTITY_INSENTIENT),
VINDICATION_ILLAGER(36, ENTITY_INSENTIENT),
// Vehicles
MINECART_ABSTRACT(-1, ENTITY),
MINECART_COMMAND(40, MINECART_ABSTRACT),
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_SKELETON(-1, ENTITY_INSENTIENT),
SKELETON(51, ABSTRACT_SKELETON),
WITHER_SKELETON(5, ABSTRACT_SKELETON),
STRAY(6, ABSTRACT_SKELETON),
SPIDER(52, ENTITY_INSENTIENT),
GIANT(53, ENTITY_INSENTIENT),
ZOMBIE(54, ENTITY_INSENTIENT),
HUSK(23, ZOMBIE),
ZOMBIE_VILLAGER(27, ZOMBIE),
SLIME(55, ENTITY_INSENTIENT),
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),
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),
ELDER_GUARDIAN(4, EntityType.GUARDIAN), // Moved down to avoid illegal forward reference
IRON_GOLEM(99, ENTITY_INSENTIENT), // moved up to avoid illegal forward references
SHULKER(69, EntityType.IRON_GOLEM),
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, EntityType.IRON_GOLEM),
OCELOT(98, ENTITY_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(-1, ENTITY_AGEABLE),
HORSE(100, ABSTRACT_HORSE),
SKELETON_HORSE(28, ABSTRACT_HORSE),
ZOMBIE_HORSE(29, ABSTRACT_HORSE),
CHESTED_HORSE(-1, ABSTRACT_HORSE),
DONKEY(31, CHESTED_HORSE),
MULE(32, CHESTED_HORSE),
LIAMA(103, CHESTED_HORSE),
RABBIT(101, ENTITY_AGEABLE),
POLAR_BEAR(102, ENTITY_AGEABLE),
VILLAGER(120, ENTITY_AGEABLE),
ENDER_CRYSTAL(200, ENTITY),
SPLASH_POTION(-1, ENTITY),
LINGERING_POTION(-1, SPLASH_POTION),
AREA_EFFECT_CLOUD(-1, ENTITY),
EGG(-1, ENTITY),
FISHING_HOOK(-1, ENTITY),
LIGHTNING(-1, ENTITY),
WEATHER(-1, ENTITY),
PLAYER(-1, ENTITY_HUMAN),
COMPLEX_PART(-1, ENTITY),
LIAMA_SPIT(-1, ENTITY);
private final int id;
private final EntityType parent;
EntityType(int id) {
this.id = id;
this.parent = null;
}
public static Optional<EntityType> findById(int id) {
if (id == -1) // Check if this is called
return Optional.absent();
for (EntityType ent : EntityType.values())
if (ent.getId() == id)
return Optional.of(ent);
return Optional.absent();
}
public boolean is(EntityType type) {
return this == type;
}
public boolean is(EntityType... types) {
for (EntityType type : types)
if (is(type))
return true;
return false;
}
public boolean isOrHasParent(EntityType type) {
EntityType parent = this;
do {
if (parent == type)
return true;
parent = type.getParent();
} while (parent != null);
return false;
}
}
@AllArgsConstructor
@Getter
public enum ObjectTypes {
BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.DROPPED_ITEM),
AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD),
MINECART(10, EntityType.MINECART_ABSTRACT),
TNT_PRIMED(50, EntityType.PRIMED_TNT),
ENDER_CRYSTAL(51, EntityType.ENDER_CRYSTAL),
TIPPED_ARROW(60, EntityType.TIPPED_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),
LIAMA_SPIT(68, EntityType.LIAMA_SPIT),
FALLING_BLOCK(70, EntityType.FALLING_BLOCK),
ITEM_FRAME(71, EntityType.ITEM_FRAME),
ENDER_SIGNAL(72, EntityType.ENDER_SIGNAL),
POTION(73, EntityType.SPLASH_POTION),
THROWN_EXP_BOTTLE(75, EntityType.THROWN_EXP_BOTTLE),
FIREWORK(76, EntityType.FIREWORK),
LEASH(77, EntityType.LEASH_HITCH),
ARMOR_STAND(78, EntityType.ARMOR_STAND),
EVOCATION_FANGS(39, EntityType.EVOCATION_FANGS),
FISHIHNG_HOOK(90, EntityType.FISHING_HOOK),
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
private final int id;
private final EntityType type;
public static Optional<ObjectTypes> findById(int id) {
if (id == -1)
return Optional.absent();
for (ObjectTypes ent : ObjectTypes.values())
if (ent.getId() == id)
return Optional.of(ent);
return Optional.absent();
}
public static Optional<EntityType> getPCEntity(int id) {
Optional<ObjectTypes> output = findById(id);
if (!output.isPresent())
return Optional.absent();
return Optional.of(output.get().getType());
}
}
}

View File

@ -3,13 +3,13 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
import com.google.common.base.Optional;
import lombok.Getter;
import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.entities.Entity1_10Types;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_8;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9;
import us.myles.ViaVersion.util.EntityUtil;
import java.util.HashMap;
import static us.myles.ViaVersion.util.EntityUtil.EntityType.*;
import static us.myles.ViaVersion.api.entities.Entity1_10Types.EntityType.*;
@Getter
public enum MetaIndex {
@ -142,20 +142,20 @@ public enum MetaIndex {
ENDERDRAGON_FLAG(ENDER_DRAGON, 15, MetaType1_8.Byte, MetaType1_9.Discontinued),
ENDERDRAGON_PHASE(ENDER_DRAGON, 11, MetaType1_8.Byte, MetaType1_9.VarInt);
private static final HashMap<Pair<EntityUtil.EntityType, Integer>, MetaIndex> metadataRewrites = new HashMap<>();
private static final HashMap<Pair<Entity1_10Types.EntityType, Integer>, MetaIndex> metadataRewrites = new HashMap<>();
static {
for (MetaIndex index : MetaIndex.values())
metadataRewrites.put(new Pair<>(index.getClazz(), index.getIndex()), index);
}
private EntityUtil.EntityType clazz;
private Entity1_10Types.EntityType clazz;
private int newIndex;
private MetaType1_9 newType;
private MetaType1_8 oldType;
private int index;
MetaIndex(EntityUtil.EntityType type, int index, MetaType1_8 oldType, MetaType1_9 newType) {
MetaIndex(Entity1_10Types.EntityType type, int index, MetaType1_8 oldType, MetaType1_9 newType) {
this.clazz = type;
this.index = index;
this.newIndex = index;
@ -163,7 +163,7 @@ public enum MetaIndex {
this.newType = newType;
}
MetaIndex(EntityUtil.EntityType type, int index, MetaType1_8 oldType, int newIndex, MetaType1_9 newType) {
MetaIndex(Entity1_10Types.EntityType type, int index, MetaType1_8 oldType, int newIndex, MetaType1_9 newType) {
this.clazz = type;
this.index = index;
this.oldType = oldType;
@ -171,7 +171,7 @@ public enum MetaIndex {
this.newType = newType;
}
private static Optional<MetaIndex> getIndex(EntityUtil.EntityType type, int index) {
private static Optional<MetaIndex> getIndex(Entity1_10Types.EntityType type, int index) {
Pair pair = new Pair<>(type, index);
if (metadataRewrites.containsKey(pair)) {
return Optional.of(metadataRewrites.get(pair));
@ -180,8 +180,8 @@ public enum MetaIndex {
return Optional.absent();
}
public static MetaIndex searchIndex(EntityUtil.EntityType type, int index) {
EntityUtil.EntityType currentType = type;
public static MetaIndex searchIndex(Entity1_10Types.EntityType type, int index) {
Entity1_10Types.EntityType currentType = type;
do {
Optional<MetaIndex> optMeta = getIndex(currentType, index);

View File

@ -1,6 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.entities.Entity1_10Types;
import us.myles.ViaVersion.api.minecraft.EulerAngle;
import us.myles.ViaVersion.api.minecraft.Vector;
import us.myles.ViaVersion.api.minecraft.item.Item;
@ -10,14 +11,13 @@ import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_8;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.util.EntityUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class MetadataRewriter {
public static void transform(EntityUtil.EntityType type, List<Metadata> list) {
public static void transform(Entity1_10Types.EntityType type, List<Metadata> list) {
short id = -1;
int data = -1;
for (Metadata entry : new ArrayList<>(list)) {
@ -40,7 +40,7 @@ public class MetadataRewriter {
entry.setValue(((Integer) value).byteValue());
}
// After writing the last one
if (metaIndex == MetaIndex.ENTITY_STATUS && type == EntityUtil.EntityType.PLAYER) {
if (metaIndex == MetaIndex.ENTITY_STATUS && type == Entity1_10Types.EntityType.PLAYER) {
Byte val = 0;
if ((((Byte) value) & 0x10) == 0x10) { // Player eating/aiming/drinking
val = 1;

View File

@ -4,6 +4,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.entities.Entity1_10Types;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
@ -19,7 +20,6 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.GameMode;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
import us.myles.ViaVersion.util.EntityUtil;
public class PlayerPackets {
public static void register(Protocol protocol) {
@ -165,7 +165,7 @@ public class PlayerPackets {
public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.INT, 0);
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.getClientEntityTypes().put(entityID, EntityUtil.EntityType.PLAYER);
tracker.getClientEntityTypes().put(entityID, Entity1_10Types.EntityType.PLAYER);
tracker.setEntityID(entityID);
}
});

View File

@ -1,6 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_10Types;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9;
@ -17,7 +18,6 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
import us.myles.ViaVersion.util.EntityUtil;
import java.util.ArrayList;
import java.util.List;
@ -54,7 +54,7 @@ public class SpawnPackets {
int entityID = wrapper.get(Type.VAR_INT, 0);
int typeID = wrapper.get(Type.BYTE, 0);
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.getClientEntityTypes().put(entityID, EntityUtil.getTypeFromID(typeID, true));
tracker.getClientEntityTypes().put(entityID, Entity1_10Types.getTypeFromId(typeID, true));
tracker.sendMetadataBuffer(entityID);
}
});
@ -95,7 +95,7 @@ public class SpawnPackets {
final int data = wrapper.get(Type.INT, 0); // Data
int typeID = wrapper.get(Type.BYTE, 0);
if (EntityUtil.getTypeFromID(typeID, true) == EntityUtil.EntityType.SPLASH_POTION) {
if (Entity1_10Types.getTypeFromId(typeID, true) == Entity1_10Types.EntityType.SPLASH_POTION) {
// Convert this to meta data, woo!
PacketWrapper metaPacket = wrapper.create(0x39, new ValueCreator() {
@Override
@ -129,7 +129,7 @@ public class SpawnPackets {
public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0);
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.getClientEntityTypes().put(entityID, EntityUtil.EntityType.EXPERIENCE_ORB);
tracker.getClientEntityTypes().put(entityID, Entity1_10Types.EntityType.EXPERIENCE_ORB);
tracker.sendMetadataBuffer(entityID);
}
});
@ -155,7 +155,7 @@ public class SpawnPackets {
// Currently only lightning uses this
int entityID = wrapper.get(Type.VAR_INT, 0);
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.getClientEntityTypes().put(entityID, EntityUtil.EntityType.LIGHTNING);
tracker.getClientEntityTypes().put(entityID, Entity1_10Types.EntityType.LIGHTNING);
tracker.sendMetadataBuffer(entityID);
}
});
@ -189,7 +189,7 @@ public class SpawnPackets {
int entityID = wrapper.get(Type.VAR_INT, 0);
int typeID = wrapper.get(Type.UNSIGNED_BYTE, 0);
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.getClientEntityTypes().put(entityID, EntityUtil.getTypeFromID(typeID, false));
tracker.getClientEntityTypes().put(entityID, Entity1_10Types.getTypeFromId(typeID, false));
tracker.sendMetadataBuffer(entityID);
}
});
@ -246,7 +246,7 @@ public class SpawnPackets {
public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0);
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.getClientEntityTypes().put(entityID, EntityUtil.EntityType.PAINTING);
tracker.getClientEntityTypes().put(entityID, Entity1_10Types.EntityType.PAINTING);
tracker.sendMetadataBuffer(entityID);
}
});
@ -280,7 +280,7 @@ public class SpawnPackets {
public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0);
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.getClientEntityTypes().put(entityID, EntityUtil.EntityType.PLAYER);
tracker.getClientEntityTypes().put(entityID, Entity1_10Types.EntityType.PLAYER);
tracker.sendMetadataBuffer(entityID);
}
});

View File

@ -13,6 +13,7 @@ import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossStyle;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_10Types;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
@ -23,7 +24,6 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.GameMode;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter;
import us.myles.ViaVersion.util.EntityUtil;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit;
@Getter
public class EntityTracker extends StoredObject {
private final Map<Integer, UUID> uuidMap = new ConcurrentHashMap<>();
private final Map<Integer, EntityUtil.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
private final Map<Integer, Entity1_10Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
private final Map<Integer, List<Metadata>> metadataBuffer = new ConcurrentHashMap<>();
private final Map<Integer, Integer> vehicleMap = new ConcurrentHashMap<>();
private final Map<Integer, BossBar> bossBarMap = new ConcurrentHashMap<>();
@ -116,37 +116,37 @@ public class EntityTracker extends StoredObject {
return;
}
EntityUtil.EntityType type = clientEntityTypes.get(entityID);
Entity1_10Types.EntityType type = clientEntityTypes.get(entityID);
for (Metadata metadata : new ArrayList<>(metadataList)) {
// Fix: wither (crash fix)
if (type == EntityUtil.EntityType.WITHER) {
if (type == Entity1_10Types.EntityType.WITHER) {
if (metadata.getId() == 10) {
metadataList.remove(metadata);
//metadataList.add(new Metadata(10, NewType.Byte.getTypeID(), Type.BYTE, 0));
}
}
// Fix: enderdragon (crash fix)
if (type == EntityUtil.EntityType.ENDER_DRAGON) {
if (type == Entity1_10Types.EntityType.ENDER_DRAGON) {
if (metadata.getId() == 11) {
metadataList.remove(metadata);
// metadataList.add(new Metadata(11, NewType.Byte.getTypeID(), Type.VAR_INT, 0));
}
}
if (type == EntityUtil.EntityType.SKELETON) {
if (type == Entity1_10Types.EntityType.SKELETON) {
if ((getMetaByIndex(metadataList, 12)) == null) {
metadataList.add(new Metadata(12, MetaType1_9.Boolean, true));
}
}
//ECHOPET Patch
if (type == EntityUtil.EntityType.HORSE) {
if (type == Entity1_10Types.EntityType.HORSE) {
// Wrong metadata value from EchoPet, patch since it's discontinued. (https://github.com/DSH105/EchoPet/blob/06947a8b08ce40be9a518c2982af494b3b99d140/modules/API/src/main/java/com/dsh105/echopet/compat/api/entity/HorseArmour.java#L22)
if (metadata.getId() == 16 && (int) metadata.getValue() == Integer.MIN_VALUE)
metadata.setValue(0);
}
if (type == EntityUtil.EntityType.PLAYER) {
if (type == Entity1_10Types.EntityType.PLAYER) {
if (metadata.getId() == 0) {
// Byte
byte data = (byte) metadata.getValue();
@ -162,7 +162,7 @@ public class EntityTracker extends StoredObject {
}
}
}
if (type == EntityUtil.EntityType.ARMOR_STAND && Via.getConfig().isHologramPatch()) {
if (type == Entity1_10Types.EntityType.ARMOR_STAND && Via.getConfig().isHologramPatch()) {
if (metadata.getId() == 0 && getMetaByIndex(metadataList, 10) != null) {
Metadata meta = getMetaByIndex(metadataList, 10); //Only happens if the armorstand is small
byte data = (byte) metadata.getValue();
@ -190,11 +190,11 @@ public class EntityTracker extends StoredObject {
UUID uuid = getUser().get(ProtocolInfo.class).getUuid();
// Boss bar
if (Via.getConfig().isBossbarPatch()) {
if (type == EntityUtil.EntityType.ENDER_DRAGON || type == EntityUtil.EntityType.WITHER) {
if (type == Entity1_10Types.EntityType.ENDER_DRAGON || type == Entity1_10Types.EntityType.WITHER) {
if (metadata.getId() == 2) {
BossBar bar = bossBarMap.get(entityID);
String title = (String) metadata.getValue();
title = title.isEmpty() ? (type == EntityUtil.EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title;
title = title.isEmpty() ? (type == Entity1_10Types.EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title;
if (bar == null) {
bar = Via.getAPI().createBossBar(title, BossColor.PINK, BossStyle.SOLID);
bossBarMap.put(entityID, bar);
@ -206,10 +206,10 @@ public class EntityTracker extends StoredObject {
} else if (metadata.getId() == 6 && !Via.getConfig().isBossbarAntiflicker()) { // If anti flicker is enabled, don't update health
BossBar bar = bossBarMap.get(entityID);
// Make health range between 0 and 1
float maxHealth = type == EntityUtil.EntityType.ENDER_DRAGON ? 200.0f : 300.0f;
float maxHealth = type == Entity1_10Types.EntityType.ENDER_DRAGON ? 200.0f : 300.0f;
float health = Math.max(0.0f, Math.min(((float) metadata.getValue()) / maxHealth, 1.0f));
if (bar == null) {
String title = type == EntityUtil.EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither";
String title = type == Entity1_10Types.EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither";
bar = Via.getAPI().createBossBar(title, health, BossColor.PINK, BossStyle.SOLID);
bossBarMap.put(entityID, bar);
bar.addPlayer(uuid);

View File

@ -1,39 +1,52 @@
package us.myles.ViaVersion.protocols.protocolsnapshotto1_10;
import com.google.common.base.Optional;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_11Types.EntityType;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_10.storage.EntityTracker;
import java.util.ArrayList;
import java.util.List;
public class MetadataRewriter {
public static int rewriteEntityType(int currentType, List<Metadata> metadata) {
public static EntityType rewriteEntityType(int numType, List<Metadata> metadata) {
Optional<EntityType> optType = EntityType.findById(numType);
if (!optType.isPresent()) {
Via.getManager().getPlatform().getLogger().severe("Error: could not find Entity type " + numType + " with metadata: " + metadata);
return null;
}
EntityType type = optType.get();
try {
if (currentType == 68) {
if (type.is(EntityType.GUARDIAN)) {
// ElderGuardian - 4
Optional<Metadata> options = getById(metadata, 12);
if (options.isPresent()) {
if ((((byte) options.get().getValue()) & 0x04) == 0x04) {
return 4;
return EntityType.ELDER_GUARDIAN;
}
}
}
if (currentType == 51) {
if (type.is(EntityType.SKELETON)) {
// WitherSkeleton - 5
// Stray - 6
Optional<Metadata> options = getById(metadata, 12);
if (options.isPresent()) {
if (((int) options.get().getValue()) == 1) {
return 5;
return EntityType.WITHER_SKELETON;
}
if (((int) options.get().getValue()) == 2) {
return 6;
return EntityType.STRAY;
}
}
}
if (currentType == 54) {
if (type.is(EntityType.ZOMBIE)) {
// ZombieVillager - 27
// Husk - 23
Optional<Metadata> options = getById(metadata, 13);
@ -41,14 +54,14 @@ public class MetadataRewriter {
int value = (int) options.get().getValue();
if (value > 0 && value < 6) {
metadata.add(new Metadata(16, MetaType1_9.VarInt, value - 1)); // Add profession type to new metadata
return 27;
return EntityType.ZOMBIE_VILLAGER;
}
if (value == 6) {
return 23;
return EntityType.HUSK;
}
}
}
if (currentType == 100) {
if (type.is(EntityType.HORSE)) {
// SkeletonHorse - 28
// ZombieHorse - 29
// Donkey - 31
@ -56,23 +69,22 @@ public class MetadataRewriter {
Optional<Metadata> options = getById(metadata, 14);
if (options.isPresent()) {
if (((int) options.get().getValue()) == 0) {
return currentType;
return EntityType.HORSE;
}
if (((int) options.get().getValue()) == 1) {
return 31;
return EntityType.DONKEY;
}
if (((int) options.get().getValue()) == 2) {
return 32;
return EntityType.MULE;
}
if (((int) options.get().getValue()) == 3) {
return 29;
return EntityType.ZOMBIE_HORSE;
}
if (((int) options.get().getValue()) == 4) {
return 28;
return EntityType.SKELETON_HORSE;
}
}
}
return currentType;
} catch (Exception e) {
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
System.out.println("An error occurred with entity type rewriter");
@ -80,13 +92,14 @@ public class MetadataRewriter {
e.printStackTrace();
}
}
return currentType;
return type;
}
public static void handleMetadata(int type, List<Metadata> metadatas) {
public static void handleMetadata(int entityId, EntityType type, List<Metadata> metadatas, UserConnection connection) {
for (Metadata metadata : new ArrayList<>(metadatas)) {
try {
if (type == 4 || type == 68) { // Guardians
if (type.is(EntityType.ELDER_GUARDIAN) || type.is(EntityType.GUARDIAN)) { // Guardians
int oldid = metadata.getId();
if (oldid == 12) {
metadata.setMetaType(MetaType1_9.Boolean);
@ -94,7 +107,7 @@ public class MetadataRewriter {
metadata.setValue(val);
}
}
if (type == 51 || type == 5 || type == 6) { // Skeletons
if (type.isOrHasParent(EntityType.ABSTRACT_SKELETON)) { // Skeletons
int oldid = metadata.getId();
if (oldid == 12) {
metadatas.remove(metadata);
@ -103,8 +116,8 @@ public class MetadataRewriter {
metadata.setId(12);
}
}
if (type == 54 || type == 27) { // Zombie | Zombie Villager
if (type == 54 && metadata.getId() == 14) {
if (type.isOrHasParent(EntityType.ZOMBIE)) { // Zombie | Zombie Villager | Husk
if (type.is(EntityType.ZOMBIE, EntityType.HUSK) && metadata.getId() == 14) {
metadatas.remove(metadata);
} else {
if (metadata.getId() == 15) {
@ -116,7 +129,7 @@ public class MetadataRewriter {
}
}
}
if (type == 100 || type == 31 || type == 32 || type == 29 || type == 28) { // Horses
if (type.isOrHasParent(EntityType.ABSTRACT_HORSE)) { // Horses
// Remap metadata id
int oldid = metadata.getId();
if (oldid == 14) { // Type
@ -130,7 +143,7 @@ public class MetadataRewriter {
}
// Process per type
if (type == 100) {
if (type.is(EntityType.HORSE)) {
// Normal Horse
} else {
// Remove 15, 16
@ -138,7 +151,7 @@ public class MetadataRewriter {
metadatas.remove(metadata);
}
}
if (type == 31 || type == 32) {
if (type.is(EntityType.DONKEY, EntityType.MULE)) {
// Chested Horse
if (metadata.getId() == 13) {
if ((((byte) metadata.getValue()) & 0x08) == 0x08) {
@ -148,6 +161,36 @@ public class MetadataRewriter {
}
}
}
if (type.is(EntityType.ARMOR_STAND) && Via.getConfig().isHologramPatch()) {
Optional<Metadata> flags = getById(metadatas, 11);
Optional<Metadata> customName = getById(metadatas, 2);
Optional<Metadata> customNameVisible = getById(metadatas, 3);
if (metadata.getId() == 0 && flags.isPresent() && customName.isPresent() && customNameVisible.isPresent()) {
Metadata meta = flags.get();
byte data = (byte) metadata.getValue();
// Check invisible | Check small | Check if custom name is empty | Check if custom name visible is true
if ((data & 0x20) == 0x20 && ((byte) meta.getValue() & 0x01) == 0x01
&& ((String) customName.get().getValue()).length() != 0 && (boolean) customNameVisible.get().getValue()) {
EntityTracker tracker = connection.get(EntityTracker.class);
if (!tracker.isHologram(entityId)) {
tracker.addHologram(entityId);
try {
// Send movement
PacketWrapper wrapper = new PacketWrapper(0x25, null, connection);
wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Type.SHORT, (short) 0);
wrapper.write(Type.SHORT, (short) (128D * (-Via.getConfig().getHologramYOffset() * 32D)));
wrapper.write(Type.SHORT, (short) 0);
wrapper.write(Type.BOOLEAN, true);
wrapper.send(ProtocolSnapshotTo1_10.class);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}
} catch (Exception e) {
metadatas.remove(metadata);

View File

@ -1,7 +1,10 @@
package us.myles.ViaVersion.protocols.protocolsnapshotto1_10;
import com.google.common.base.Optional;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_11Types;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
@ -25,6 +28,31 @@ public class ProtocolSnapshotTo1_10 extends Protocol {
protected void registerPackets() {
InventoryPackets.register(this);
// Spawn Object
registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID
map(Type.BYTE); // 2 - Type
// Track Entity
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
byte type = wrapper.get(Type.BYTE, 0);
Entity1_11Types.EntityType entType = Entity1_11Types.getTypeFromId(type, true);
// Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
}
});
}
});
// Spawn mob packet
registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() {
@Override
@ -46,13 +74,17 @@ public class ProtocolSnapshotTo1_10 extends Protocol {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
// Change Type :)
int type = wrapper.get(Type.VAR_INT, 1);
type = MetadataRewriter.rewriteEntityType(type, wrapper.get(Types1_9.METADATA_LIST, 0));
wrapper.set(Type.VAR_INT, 1, type);
Entity1_11Types.EntityType entType = MetadataRewriter.rewriteEntityType(type, wrapper.get(Types1_9.METADATA_LIST, 0));
if (entType != null)
wrapper.set(Type.VAR_INT, 1, entType.getId());
// Register Type ID
wrapper.user().get(EntityTracker.class).getClientEntityTypes().put(wrapper.get(Type.VAR_INT, 0), type);
MetadataRewriter.handleMetadata(type, wrapper.get(Types1_9.METADATA_LIST, 0));
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
}
});
}
@ -84,11 +116,41 @@ public class ProtocolSnapshotTo1_10 extends Protocol {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
if (!wrapper.user().get(EntityTracker.class).getClientEntityTypes().containsKey(entityId)) {
Optional<Entity1_11Types.EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
if (!type.isPresent())
return;
MetadataRewriter.handleMetadata(entityId, type.get(), wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
}
});
}
});
// Entity teleport
registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.DOUBLE); // 1 - x
map(Type.DOUBLE); // 2 - y
map(Type.DOUBLE); // 3 - z
map(Type.BYTE); // 4 - yaw
map(Type.BYTE); // 5 - pitch
map(Type.BOOLEAN); // 6 - onGround
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0);
if (Via.getConfig().isHologramPatch()) {
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
if (tracker.isHologram(entityID)) {
Double newValue = wrapper.get(Type.DOUBLE, 1);
newValue -= (Via.getConfig().getHologramYOffset());
wrapper.set(Type.DOUBLE, 1, newValue);
}
}
int type = wrapper.user().get(EntityTracker.class).getClientEntityTypes().get(entityId);
MetadataRewriter.handleMetadata(type, wrapper.get(Types1_9.METADATA_LIST, 0));
}
});
}

View File

@ -1,21 +1,52 @@
package us.myles.ViaVersion.protocols.protocolsnapshotto1_10.storage;
import lombok.Getter;
import com.google.common.base.Optional;
import com.google.common.collect.Sets;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_11Types;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@Getter
public class EntityTracker extends StoredObject {
private final Map<Integer, Integer> clientEntityTypes = new ConcurrentHashMap<>();
private final Map<Integer, Entity1_11Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
private final Set<Integer> holograms = Sets.newConcurrentHashSet();
public EntityTracker(UserConnection user) {
super(user);
}
public void removeEntity(Integer entityID) {
clientEntityTypes.remove(entityID);
public void removeEntity(int entityId) {
removeEntity(entityId);
if (isHologram(entityId))
removeHologram(entityId);
}
public void addEntity(int entityId, Entity1_11Types.EntityType type) {
clientEntityTypes.put(entityId, type);
}
public boolean has(int entityId) {
return clientEntityTypes.containsKey(entityId);
}
public Optional<Entity1_11Types.EntityType> get(int id) {
if (!has(id))
return Optional.absent();
return Optional.of(clientEntityTypes.get(id));
}
public void addHologram(int entId) {
holograms.add(entId);
}
public boolean isHologram(int entId) {
return holograms.contains(entId);
}
public void removeHologram(int entId) {
holograms.remove(entId);
}
}

View File

@ -48,6 +48,16 @@ tracking-max-warnings: 4
tracking-max-kick-msg: "You are sending too many packets, :("
#
#----------------------------------------------------------#
# MULTIPLE VERSIONS OPTIONS #
#----------------------------------------------------------#
#
# Should we enable our hologram patch?
# If they're in the wrong place enable this
hologram-patch: false
# This is the offset, should work as default when enabled.
hologram-y: -0.96
#
#----------------------------------------------------------#
# 1.9 & 1.10 CLIENTS ON 1.8 SERVERS OPTIONS #
#----------------------------------------------------------#
#
@ -60,11 +70,6 @@ auto-team: true
suppress-metadata-errors: false
# When enabled 1.9 & 1.10 will be able to block by using shields
shield-blocking: true
# Should we enable our hologram patch?
# If they're in the wrong place enable this
hologram-patch: false
# This is the offset, should work as default when enabled.
hologram-y: -0.96
# Enable player tick simulation, this fixes eating, drinking, nether portals.
simulate-pt: true
# Should we use nms player to simulate packets, (may fix anti-cheat issues)
@ -76,7 +81,7 @@ bossbar-anti-flicker: false
# This will show the new effect indicator in the top-right corner for 1.9 & 1.10 players.
use-new-effect-indicator: true
# Show the new death messages for 1.9 & 1.10 on the death screen
use-new-deathmessages: false
use-new-deathmessages: true
# Should we cache our items, this will prevent server from being lagged out, however the cost is a constant task caching items
item-cache: true
# Patch the Anti xray to work on 1.9 & 1.10 (If your server is 1.8) This can cost more performance, so disable it if you don't use it.

View File

@ -35,7 +35,7 @@ public class SpongeConfigAPI extends Config implements ViaVersionConfig {
@Override
public boolean isShowNewDeathMessages() {
return getBoolean("use-new-deathmessages", false);
return getBoolean("use-new-deathmessages", true);
}
@Override