Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Merge pull request #1323 from Gerrygames/abstraction
Abstract EntityTracker and MetadataRewriter
Dieser Commit ist enthalten in:
Commit
e71b08de3f
@ -8,7 +8,7 @@ import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
import us.myles.ViaVersion.api.minecraft.Position;
|
||||
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
public class BlockListener extends ViaBukkitListener {
|
||||
|
||||
@ -21,7 +21,7 @@ public class BlockListener extends ViaBukkitListener {
|
||||
if (isOnPipe(e.getPlayer())) {
|
||||
Block b = e.getBlockPlaced();
|
||||
getUserConnection(e.getPlayer())
|
||||
.get(EntityTracker.class)
|
||||
.get(EntityTracker1_9.class)
|
||||
.addBlockInteraction(new Position((long) b.getX(), (long) b.getY(), (long) b.getZ()));
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -124,7 +124,7 @@ public class BungeeServerHandler implements Listener {
|
||||
if (e.getServer() != null) {
|
||||
if (!e.getServer().getInfo().getName().equals(storage.getCurrentServer())) {
|
||||
// Clear auto-team
|
||||
EntityTracker oldEntityTracker = user.get(EntityTracker.class);
|
||||
EntityTracker1_9 oldEntityTracker = user.get(EntityTracker1_9.class);
|
||||
if (oldEntityTracker != null) {
|
||||
if (oldEntityTracker.isAutoTeam() && oldEntityTracker.isTeamExists()) {
|
||||
oldEntityTracker.sendTeamPacket(false, true);
|
||||
@ -215,7 +215,7 @@ public class BungeeServerHandler implements Listener {
|
||||
protocol.init(user);
|
||||
}
|
||||
|
||||
EntityTracker newTracker = user.get(EntityTracker.class);
|
||||
EntityTracker1_9 newTracker = user.get(EntityTracker1_9.class);
|
||||
if (newTracker != null) {
|
||||
if (Via.getConfig().isAutoTeam()) {
|
||||
String currentTeam = null;
|
||||
|
@ -13,7 +13,7 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
||||
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.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@ -29,7 +29,7 @@ public class ElytraPatch implements Listener {
|
||||
|
||||
try {
|
||||
if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9To1_8.class)) {
|
||||
int entityId = user.get(EntityTracker.class).getProvidedEntityId();
|
||||
int entityId = user.get(EntityTracker1_9.class).getProvidedEntityId();
|
||||
|
||||
PacketWrapper wrapper = new PacketWrapper(0x39, null, user);
|
||||
|
||||
|
@ -29,28 +29,28 @@ public class Entity1_10Types {
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum EntityType {
|
||||
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
|
||||
ENTITY(-1),
|
||||
DROPPED_ITEM(1, EntityType.ENTITY),
|
||||
EXPERIENCE_ORB(2, EntityType.ENTITY),
|
||||
LEASH_HITCH(8, EntityType.ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata
|
||||
PAINTING(9, EntityType.ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata
|
||||
ARROW(10, EntityType.ENTITY),
|
||||
SNOWBALL(11, EntityType.ENTITY), // Actually EntityProjectile
|
||||
FIREBALL(12, EntityType.ENTITY),
|
||||
SMALL_FIREBALL(13, EntityType.ENTITY),
|
||||
ENDER_PEARL(14, EntityType.ENTITY), // Actually EntityProjectile
|
||||
ENDER_SIGNAL(15, EntityType.ENTITY),
|
||||
THROWN_EXP_BOTTLE(17, EntityType.ENTITY),
|
||||
ITEM_FRAME(18, EntityType.ENTITY), // Actually EntityHanging
|
||||
WITHER_SKULL(19, EntityType.ENTITY),
|
||||
PRIMED_TNT(20, EntityType.ENTITY),
|
||||
FALLING_BLOCK(21, EntityType.ENTITY),
|
||||
FIREWORK(22, EntityType.ENTITY),
|
||||
TIPPED_ARROW(23, EntityType.ARROW),
|
||||
SPECTRAL_ARROW(24, EntityType.ARROW),
|
||||
SHULKER_BULLET(25, EntityType.ENTITY),
|
||||
DRAGON_FIREBALL(26, EntityType.FIREBALL),
|
||||
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),
|
||||
|
||||
ENTITY_LIVING(-1, ENTITY),
|
||||
ENTITY_INSENTIENT(-1, ENTITY_LIVING),
|
||||
@ -58,7 +58,7 @@ public class Entity1_10Types {
|
||||
ENTITY_TAMEABLE_ANIMAL(-1, ENTITY_AGEABLE),
|
||||
ENTITY_HUMAN(-1, ENTITY_LIVING),
|
||||
|
||||
ARMOR_STAND(30, EntityType.ENTITY_LIVING),
|
||||
ARMOR_STAND(30, ENTITY_LIVING),
|
||||
|
||||
// Vehicles
|
||||
MINECART_ABSTRACT(-1, ENTITY),
|
||||
@ -91,7 +91,7 @@ public class Entity1_10Types {
|
||||
ENDERMITE(67, ENTITY_INSENTIENT),
|
||||
GUARDIAN(68, ENTITY_INSENTIENT),
|
||||
IRON_GOLEM(99, ENTITY_INSENTIENT), // moved up to avoid illegal forward references
|
||||
SHULKER(69, EntityType.IRON_GOLEM),
|
||||
SHULKER(69, IRON_GOLEM),
|
||||
PIG(90, ENTITY_AGEABLE),
|
||||
SHEEP(91, ENTITY_AGEABLE),
|
||||
COW(92, ENTITY_AGEABLE),
|
||||
@ -99,7 +99,7 @@ public class Entity1_10Types {
|
||||
SQUID(94, ENTITY_INSENTIENT),
|
||||
WOLF(95, ENTITY_TAMEABLE_ANIMAL),
|
||||
MUSHROOM_COW(96, COW),
|
||||
SNOWMAN(97, EntityType.IRON_GOLEM),
|
||||
SNOWMAN(97, IRON_GOLEM),
|
||||
OCELOT(98, ENTITY_TAMEABLE_ANIMAL),
|
||||
HORSE(100, ENTITY_AGEABLE),
|
||||
RABBIT(101, ENTITY_AGEABLE),
|
||||
|
@ -28,7 +28,7 @@ public class Entity1_11Types {
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum EntityType {
|
||||
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
|
||||
ENTITY(-1),
|
||||
DROPPED_ITEM(1, ENTITY),
|
||||
EXPERIENCE_ORB(2, ENTITY),
|
||||
@ -103,10 +103,10 @@ public class Entity1_11Types {
|
||||
ENDERMITE(67, ENTITY_INSENTIENT),
|
||||
|
||||
GUARDIAN(68, ENTITY_INSENTIENT),
|
||||
ELDER_GUARDIAN(4, EntityType.GUARDIAN), // Moved down to avoid illegal forward reference
|
||||
ELDER_GUARDIAN(4, 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),
|
||||
SHULKER(69, IRON_GOLEM),
|
||||
PIG(90, ENTITY_AGEABLE),
|
||||
SHEEP(91, ENTITY_AGEABLE),
|
||||
COW(92, ENTITY_AGEABLE),
|
||||
@ -114,7 +114,7 @@ public class Entity1_11Types {
|
||||
SQUID(94, ENTITY_INSENTIENT),
|
||||
WOLF(95, ENTITY_TAMEABLE_ANIMAL),
|
||||
MUSHROOM_COW(96, COW),
|
||||
SNOWMAN(97, EntityType.IRON_GOLEM),
|
||||
SNOWMAN(97, IRON_GOLEM),
|
||||
OCELOT(98, ENTITY_TAMEABLE_ANIMAL),
|
||||
|
||||
ABSTRACT_HORSE(-1, ENTITY_AGEABLE),
|
||||
|
@ -38,7 +38,7 @@ public class Entity1_12Types {
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum EntityType {
|
||||
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
|
||||
ENTITY(-1),
|
||||
DROPPED_ITEM(1, ENTITY),
|
||||
EXPERIENCE_ORB(2, ENTITY),
|
||||
@ -115,10 +115,10 @@ public class Entity1_12Types {
|
||||
ENDERMITE(67, ENTITY_INSENTIENT),
|
||||
|
||||
GUARDIAN(68, ENTITY_INSENTIENT),
|
||||
ELDER_GUARDIAN(4, EntityType.GUARDIAN), // Moved down to avoid illegal forward reference
|
||||
ELDER_GUARDIAN(4, 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),
|
||||
SHULKER(69, IRON_GOLEM),
|
||||
PIG(90, ENTITY_AGEABLE),
|
||||
SHEEP(91, ENTITY_AGEABLE),
|
||||
COW(92, ENTITY_AGEABLE),
|
||||
@ -126,7 +126,7 @@ public class Entity1_12Types {
|
||||
SQUID(94, ENTITY_INSENTIENT),
|
||||
WOLF(95, ENTITY_TAMEABLE_ANIMAL),
|
||||
MUSHROOM_COW(96, COW),
|
||||
SNOWMAN(97, EntityType.IRON_GOLEM),
|
||||
SNOWMAN(97, IRON_GOLEM),
|
||||
OCELOT(98, ENTITY_TAMEABLE_ANIMAL),
|
||||
PARROT(105, ENTITY_TAMEABLE_ANIMAL),
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class Entity1_13Types {
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum EntityType {
|
||||
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
|
||||
// Auto generated
|
||||
|
||||
ENTITY(-1), // abm
|
||||
|
@ -11,11 +11,11 @@ import java.util.Map;
|
||||
|
||||
public class Entity1_14Types {
|
||||
public static EntityType getTypeFromId(int typeID) {
|
||||
Optional<EntityType> type = EntityType.findById(typeID);
|
||||
Optional<EntityType> type = Entity1_14Types.EntityType.findById(typeID);
|
||||
|
||||
if (!type.isPresent()) {
|
||||
Via.getPlatform().getLogger().severe("Could not find type id " + typeID);
|
||||
return EntityType.ENTITY; // Fall back to the basic ENTITY
|
||||
return Entity1_14Types.EntityType.ENTITY; // Fall back to the basic ENTITY
|
||||
}
|
||||
|
||||
return type.get();
|
||||
@ -23,7 +23,7 @@ public class Entity1_14Types {
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum EntityType {
|
||||
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
|
||||
// Auto generated
|
||||
|
||||
ENTITY(-1),
|
||||
@ -210,7 +210,7 @@ public class Entity1_14Types {
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
for (EntityType type : Entity1_14Types.EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package us.myles.ViaVersion.api.entities;
|
||||
|
||||
public interface EntityType {
|
||||
|
||||
int getId();
|
||||
|
||||
EntityType getParent();
|
||||
|
||||
}
|
@ -15,12 +15,15 @@ import us.myles.ViaVersion.packets.State;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public abstract class Protocol {
|
||||
private final Map<Pair<State, Integer>, ProtocolPacket> incoming = new HashMap<>();
|
||||
private final Map<Pair<State, Integer>, ProtocolPacket> outgoing = new HashMap<>();
|
||||
|
||||
private final Map<Class, Object> storedObjects = new ConcurrentHashMap<>();
|
||||
|
||||
public Protocol() {
|
||||
registerPackets();
|
||||
}
|
||||
@ -173,6 +176,14 @@ public abstract class Protocol {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T get(Class<T> objectClass) {
|
||||
return (T) storedObjects.get(objectClass);
|
||||
}
|
||||
|
||||
public void put(Object object) {
|
||||
storedObjects.put(object.getClass(), object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Protocol:" + getClass().getSimpleName();
|
||||
|
@ -151,6 +151,13 @@ public class ProtocolPipeline extends Protocol {
|
||||
return false;
|
||||
}
|
||||
|
||||
public <P extends Protocol> P getProtocol(Class<P> pipeClass) {
|
||||
for (Protocol protocol : protocolList) {
|
||||
if (protocol.getClass() == pipeClass) return (P) protocol;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the pipeline to filter a NMS packet
|
||||
*
|
||||
|
@ -0,0 +1,50 @@
|
||||
package us.myles.ViaVersion.api.rewriters;
|
||||
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.EntityType;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class MetadataRewriter<T extends EntityType> {
|
||||
|
||||
public final void handleMetadata(int entityId, T type, List<Metadata> metadatas, UserConnection connection) {
|
||||
Map<Integer, Metadata> metadataMap = new HashMap<>(metadatas.size());
|
||||
for (Metadata metadata : metadatas) {
|
||||
metadataMap.put(metadata.getId(), metadata);
|
||||
}
|
||||
|
||||
metadataMap = Collections.unmodifiableMap(metadataMap);
|
||||
|
||||
for (Metadata metadata : new ArrayList<>(metadatas)) {
|
||||
int oldId = metadata.getId();
|
||||
try {
|
||||
handleMetadata(entityId, type, metadata, metadatas, metadataMap, connection);
|
||||
} catch (Exception e) {
|
||||
metadatas.remove(metadata);
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
Logger logger = Via.getPlatform().getLogger();
|
||||
|
||||
logger.warning("An error occurred with entity metadata handler");
|
||||
logger.warning("This is most likely down to one of your plugins sending bad datawatchers. Please test if this occurs without any plugins except ViaVersion before reporting it on GitHub");
|
||||
logger.warning("Also make sure that all your plugins are compatible with your server version.");
|
||||
logger.warning("Entity type: " + type);
|
||||
logger.warning("Metadata: " + metadata);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleMetadata(int entityId, T type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {}
|
||||
|
||||
protected void handleMetadata(int entityId, T type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
|
||||
handleMetadata(entityId, type, metadata, metadatas, connection);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package us.myles.ViaVersion.api.storage;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import us.myles.ViaVersion.api.data.ExternalJoinGameListener;
|
||||
import us.myles.ViaVersion.api.data.StoredObject;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.EntityType;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class EntityTracker<T extends EntityType> extends StoredObject implements ExternalJoinGameListener {
|
||||
private final Map<Integer, T> clientEntityTypes = new ConcurrentHashMap<>();
|
||||
@Getter
|
||||
@Setter
|
||||
private int clientEntityId;
|
||||
private final T playerType;
|
||||
|
||||
protected EntityTracker(UserConnection user, T playerType) {
|
||||
super(user);
|
||||
this.playerType = playerType;
|
||||
}
|
||||
|
||||
public void removeEntity(int entityId) {
|
||||
clientEntityTypes.remove(entityId);
|
||||
}
|
||||
|
||||
public void addEntity(int entityId, T type) {
|
||||
clientEntityTypes.put(entityId, type);
|
||||
}
|
||||
|
||||
public boolean hasEntity(int entityId) {
|
||||
return clientEntityTypes.containsKey(entityId);
|
||||
}
|
||||
|
||||
public Optional<T> getEntity(int entityId) {
|
||||
return Optional.fromNullable(clientEntityTypes.get(entityId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExternalJoinGame(int playerEntityId) {
|
||||
clientEntityId = playerEntityId;
|
||||
clientEntityTypes.put(playerEntityId, playerType);
|
||||
}
|
||||
}
|
@ -1,218 +0,0 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_11to1_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.item.Item;
|
||||
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.protocol1_11to1_10.storage.EntityTracker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter {
|
||||
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 (type.is(EntityType.GUARDIAN)) {
|
||||
// ElderGuardian - 4
|
||||
Optional<Metadata> options = getById(metadata, 12);
|
||||
if (options.isPresent()) {
|
||||
if ((((byte) options.get().getValue()) & 0x04) == 0x04) {
|
||||
return EntityType.ELDER_GUARDIAN;
|
||||
}
|
||||
}
|
||||
}
|
||||
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 EntityType.WITHER_SKELETON;
|
||||
}
|
||||
if (((int) options.get().getValue()) == 2) {
|
||||
return EntityType.STRAY;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type.is(EntityType.ZOMBIE)) {
|
||||
// ZombieVillager - 27
|
||||
// Husk - 23
|
||||
Optional<Metadata> options = getById(metadata, 13);
|
||||
if (options.isPresent()) {
|
||||
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 EntityType.ZOMBIE_VILLAGER;
|
||||
}
|
||||
if (value == 6) {
|
||||
return EntityType.HUSK;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type.is(EntityType.HORSE)) {
|
||||
// SkeletonHorse - 28
|
||||
// ZombieHorse - 29
|
||||
// Donkey - 31
|
||||
// Mule - 32
|
||||
Optional<Metadata> options = getById(metadata, 14);
|
||||
if (options.isPresent()) {
|
||||
if (((int) options.get().getValue()) == 0) {
|
||||
return EntityType.HORSE;
|
||||
}
|
||||
if (((int) options.get().getValue()) == 1) {
|
||||
return EntityType.DONKEY;
|
||||
}
|
||||
if (((int) options.get().getValue()) == 2) {
|
||||
return EntityType.MULE;
|
||||
}
|
||||
if (((int) options.get().getValue()) == 3) {
|
||||
return EntityType.ZOMBIE_HORSE;
|
||||
}
|
||||
if (((int) options.get().getValue()) == 4) {
|
||||
return EntityType.SKELETON_HORSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().warning("An error occurred with entity type rewriter");
|
||||
Via.getPlatform().getLogger().warning("Metadata: " + metadata);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public static void handleMetadata(int entityId, EntityType type, List<Metadata> metadatas, UserConnection connection) {
|
||||
for (Metadata metadata : new ArrayList<>(metadatas)) {
|
||||
try {
|
||||
if (metadata.getValue() instanceof Item) {
|
||||
// Apply rewrite
|
||||
EntityIdRewriter.toClientItem((Item) metadata.getValue());
|
||||
}
|
||||
if (type.is(EntityType.ELDER_GUARDIAN) || type.is(EntityType.GUARDIAN)) { // Guardians
|
||||
int oldid = metadata.getId();
|
||||
if (oldid == 12) {
|
||||
metadata.setMetaType(MetaType1_9.Boolean);
|
||||
boolean val = (((byte) metadata.getValue()) & 0x02) == 0x02;
|
||||
metadata.setValue(val);
|
||||
}
|
||||
}
|
||||
if (type.isOrHasParent(EntityType.ABSTRACT_SKELETON)) { // Skeletons
|
||||
int oldid = metadata.getId();
|
||||
if (oldid == 12) {
|
||||
metadatas.remove(metadata);
|
||||
}
|
||||
if (oldid == 13) {
|
||||
metadata.setId(12);
|
||||
}
|
||||
}
|
||||
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) {
|
||||
metadata.setId(14);
|
||||
} else {
|
||||
if (metadata.getId() == 14) {
|
||||
metadata.setId(15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type.isOrHasParent(EntityType.ABSTRACT_HORSE)) { // Horses
|
||||
// Remap metadata id
|
||||
int oldid = metadata.getId();
|
||||
if (oldid == 14) { // Type
|
||||
metadatas.remove(metadata);
|
||||
}
|
||||
if (oldid == 16) { // Owner
|
||||
metadata.setId(14);
|
||||
}
|
||||
if (oldid == 17) { // Armor
|
||||
metadata.setId(16);
|
||||
}
|
||||
|
||||
// Process per type
|
||||
if (type.is(EntityType.HORSE)) {
|
||||
// Normal Horse
|
||||
} else {
|
||||
// Remove 15, 16
|
||||
if (metadata.getId() == 15 || metadata.getId() == 16) {
|
||||
metadatas.remove(metadata);
|
||||
}
|
||||
}
|
||||
if (type.is(EntityType.DONKEY, EntityType.MULE)) {
|
||||
// Chested Horse
|
||||
if (metadata.getId() == 13) {
|
||||
if ((((byte) metadata.getValue()) & 0x08) == 0x08) {
|
||||
metadatas.add(new Metadata(15, MetaType1_9.Boolean, true));
|
||||
} else {
|
||||
metadatas.add(new Metadata(15, MetaType1_9.Boolean, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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(Protocol1_11To1_10.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
metadatas.remove(metadata);
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler");
|
||||
Via.getPlatform().getLogger().warning("Metadata: " + metadata);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Optional<Metadata> getById(List<Metadata> metadatas, int id) {
|
||||
for (Metadata metadata : metadatas) {
|
||||
if (metadata.getId() == id) return Optional.of(metadata);
|
||||
}
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
@ -16,8 +16,9 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_11to1_10.metadata.MetadataRewriter1_11To1_10;
|
||||
import us.myles.ViaVersion.protocols.protocol1_11to1_10.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_11to1_10.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_11to1_10.storage.EntityTracker1_11;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
@ -31,6 +32,8 @@ public class Protocol1_11To1_10 extends Protocol {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
put(new MetadataRewriter1_11To1_10());
|
||||
|
||||
InventoryPackets.register(this);
|
||||
|
||||
// Spawn Object
|
||||
@ -52,7 +55,7 @@ public class Protocol1_11To1_10 extends Protocol {
|
||||
Entity1_11Types.EntityType entType = Entity1_11Types.getTypeFromId(type, true);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
wrapper.user().get(EntityTracker1_11.class).addEntity(entityId, entType);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -83,13 +86,13 @@ public class Protocol1_11To1_10 extends Protocol {
|
||||
// Change Type :)
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
Entity1_11Types.EntityType entType = MetadataRewriter.rewriteEntityType(type, wrapper.get(Types1_9.METADATA_LIST, 0));
|
||||
Entity1_11Types.EntityType entType = MetadataRewriter1_11To1_10.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).addEntity(entityId, entType);
|
||||
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
|
||||
wrapper.user().get(EntityTracker1_11.class).addEntity(entityId, entType);
|
||||
get(MetadataRewriter1_11To1_10.class).handleMetadata(entityId, entType, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -148,11 +151,11 @@ public class Protocol1_11To1_10 extends Protocol {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Optional<Entity1_11Types.EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
|
||||
Optional<Entity1_11Types.EntityType> type = wrapper.user().get(EntityTracker1_11.class).getEntity(entityId);
|
||||
if (!type.isPresent())
|
||||
return;
|
||||
|
||||
MetadataRewriter.handleMetadata(entityId, type.get(), wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
|
||||
get(MetadataRewriter1_11To1_10.class).handleMetadata(entityId, type.get(), wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -175,7 +178,7 @@ public class Protocol1_11To1_10 extends Protocol {
|
||||
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);
|
||||
EntityTracker1_11 tracker = wrapper.user().get(EntityTracker1_11.class);
|
||||
if (tracker.isHologram(entityID)) {
|
||||
Double newValue = wrapper.get(Type.DOUBLE, 1);
|
||||
newValue -= (Via.getConfig().getHologramYOffset());
|
||||
@ -197,7 +200,7 @@ public class Protocol1_11To1_10 extends Protocol {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
|
||||
wrapper.user().get(EntityTracker.class).removeEntity(entity);
|
||||
wrapper.user().get(EntityTracker1_11.class).removeEntity(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -411,7 +414,7 @@ public class Protocol1_11To1_10 extends Protocol {
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
userConnection.put(new EntityTracker(userConnection));
|
||||
userConnection.put(new EntityTracker1_11(userConnection));
|
||||
if (!userConnection.has(ClientWorld.class))
|
||||
userConnection.put(new ClientWorld(userConnection));
|
||||
}
|
||||
|
@ -0,0 +1,217 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_11to1_10.metadata;
|
||||
|
||||
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.entities.Entity1_11Types.EntityType;
|
||||
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;
|
||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_11to1_10.EntityIdRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_11to1_10.Protocol1_11To1_10;
|
||||
import us.myles.ViaVersion.protocols.protocol1_11to1_10.storage.EntityTracker1_11;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MetadataRewriter1_11To1_10 extends MetadataRewriter<Entity1_11Types.EntityType> {
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) {
|
||||
if (metadata.getValue() instanceof Item) {
|
||||
// Apply rewrite
|
||||
EntityIdRewriter.toClientItem((Item) metadata.getValue());
|
||||
}
|
||||
|
||||
if (type.is(EntityType.ELDER_GUARDIAN) || type.is(EntityType.GUARDIAN)) { // Guardians
|
||||
int oldid = metadata.getId();
|
||||
if (oldid == 12) {
|
||||
metadata.setMetaType(MetaType1_9.Boolean);
|
||||
boolean val = (((byte) metadata.getValue()) & 0x02) == 0x02;
|
||||
metadata.setValue(val);
|
||||
}
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(EntityType.ABSTRACT_SKELETON)) { // Skeletons
|
||||
int oldid = metadata.getId();
|
||||
if (oldid == 12) {
|
||||
metadatas.remove(metadata);
|
||||
}
|
||||
if (oldid == 13) {
|
||||
metadata.setId(12);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
metadata.setId(14);
|
||||
} else {
|
||||
if (metadata.getId() == 14) {
|
||||
metadata.setId(15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(EntityType.ABSTRACT_HORSE)) { // Horses
|
||||
// Remap metadata id
|
||||
int oldid = metadata.getId();
|
||||
if (oldid == 14) { // Type
|
||||
metadatas.remove(metadata);
|
||||
}
|
||||
if (oldid == 16) { // Owner
|
||||
metadata.setId(14);
|
||||
}
|
||||
if (oldid == 17) { // Armor
|
||||
metadata.setId(16);
|
||||
}
|
||||
|
||||
// Process per type
|
||||
if (type.is(EntityType.HORSE)) {
|
||||
// Normal Horse
|
||||
} else {
|
||||
// Remove 15, 16
|
||||
if (metadata.getId() == 15 || metadata.getId() == 16) {
|
||||
metadatas.remove(metadata);
|
||||
}
|
||||
}
|
||||
if (type.is(EntityType.DONKEY, EntityType.MULE)) {
|
||||
// Chested Horse
|
||||
if (metadata.getId() == 13) {
|
||||
if ((((byte) metadata.getValue()) & 0x08) == 0x08) {
|
||||
metadatas.add(new Metadata(15, MetaType1_9.Boolean, true));
|
||||
} else {
|
||||
metadatas.add(new Metadata(15, MetaType1_9.Boolean, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type.is(EntityType.ARMOR_STAND) && Via.getConfig().isHologramPatch()) {
|
||||
Optional<Metadata> flags = Optional.fromNullable(metadataMap.get(11));
|
||||
Optional<Metadata> customName = Optional.fromNullable(metadataMap.get(2));
|
||||
Optional<Metadata> customNameVisible = Optional.fromNullable(metadataMap.get(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()).isEmpty() && (boolean) customNameVisible.get().getValue()) {
|
||||
EntityTracker1_11 tracker = connection.get(EntityTracker1_11.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(Protocol1_11To1_10.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 (type.is(EntityType.GUARDIAN)) {
|
||||
// ElderGuardian - 4
|
||||
Optional<Metadata> options = getById(metadata, 12);
|
||||
if (options.isPresent()) {
|
||||
if ((((byte) options.get().getValue()) & 0x04) == 0x04) {
|
||||
return EntityType.ELDER_GUARDIAN;
|
||||
}
|
||||
}
|
||||
}
|
||||
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 EntityType.WITHER_SKELETON;
|
||||
}
|
||||
if (((int) options.get().getValue()) == 2) {
|
||||
return EntityType.STRAY;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type.is(EntityType.ZOMBIE)) {
|
||||
// ZombieVillager - 27
|
||||
// Husk - 23
|
||||
Optional<Metadata> options = getById(metadata, 13);
|
||||
if (options.isPresent()) {
|
||||
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 EntityType.ZOMBIE_VILLAGER;
|
||||
}
|
||||
if (value == 6) {
|
||||
return EntityType.HUSK;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type.is(EntityType.HORSE)) {
|
||||
// SkeletonHorse - 28
|
||||
// ZombieHorse - 29
|
||||
// Donkey - 31
|
||||
// Mule - 32
|
||||
Optional<Metadata> options = getById(metadata, 14);
|
||||
if (options.isPresent()) {
|
||||
if (((int) options.get().getValue()) == 0) {
|
||||
return EntityType.HORSE;
|
||||
}
|
||||
if (((int) options.get().getValue()) == 1) {
|
||||
return EntityType.DONKEY;
|
||||
}
|
||||
if (((int) options.get().getValue()) == 2) {
|
||||
return EntityType.MULE;
|
||||
}
|
||||
if (((int) options.get().getValue()) == 3) {
|
||||
return EntityType.ZOMBIE_HORSE;
|
||||
}
|
||||
if (((int) options.get().getValue()) == 4) {
|
||||
return EntityType.SKELETON_HORSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().warning("An error occurred with entity type rewriter");
|
||||
Via.getPlatform().getLogger().warning("Metadata: " + metadata);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public static Optional<Metadata> getById(List<Metadata> metadatas, int id) {
|
||||
for (Metadata metadata : metadatas) {
|
||||
if (metadata.getId() == id) return Optional.of(metadata);
|
||||
}
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_11to1_10.storage;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Sets;
|
||||
import us.myles.ViaVersion.api.data.ExternalJoinGameListener;
|
||||
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;
|
||||
|
||||
public class EntityTracker extends StoredObject implements ExternalJoinGameListener {
|
||||
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(int entityId) {
|
||||
clientEntityTypes.remove(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) {
|
||||
return Optional.fromNullable(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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExternalJoinGame(int playerEntityId) {
|
||||
clientEntityTypes.put(playerEntityId, Entity1_11Types.EntityType.PLAYER);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_11to1_10.storage;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_11Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_11Types.EntityType;
|
||||
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class EntityTracker1_11 extends EntityTracker<Entity1_11Types.EntityType> {
|
||||
private final Set<Integer> holograms = Sets.newConcurrentHashSet();
|
||||
|
||||
public EntityTracker1_11(UserConnection user) {
|
||||
super(user, EntityType.PLAYER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(int entityId) {
|
||||
super.removeEntity(entityId);
|
||||
|
||||
if (isHologram(entityId))
|
||||
removeHologram(entityId);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_12to1_11_1;
|
||||
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter {
|
||||
public static void handleMetadata(int entityId, Entity1_12Types.EntityType type, List<Metadata> metadatas, UserConnection connection) {
|
||||
for (Metadata metadata : new ArrayList<>(metadatas)) {
|
||||
try {
|
||||
if (metadata.getValue() instanceof Item) {
|
||||
// Apply rewrite
|
||||
BedRewriter.toClientItem((Item) metadata.getValue());
|
||||
}
|
||||
// Evocation Illager aggressive property became 13
|
||||
if (type.is(Entity1_12Types.EntityType.EVOCATION_ILLAGER)) {
|
||||
if (metadata.getId() == 12) {
|
||||
metadata.setId(13);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
metadatas.remove(metadata);
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler");
|
||||
Via.getPlatform().getLogger().warning("Metadata: " + metadata);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -19,9 +19,10 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_12;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.metadata.MetadataRewriter1_12To1_11_1;
|
||||
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.EntityTracker1_12;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
@ -30,6 +31,8 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
put(new MetadataRewriter1_12To1_11_1());
|
||||
|
||||
InventoryPackets.register(this);
|
||||
// Outgoing
|
||||
// Spawn Object
|
||||
@ -51,7 +54,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, true);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
wrapper.user().get(EntityTracker1_12.class).addEntity(entityId, entType);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -84,8 +87,8 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
|
||||
Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, false);
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
|
||||
wrapper.user().get(EntityTracker1_12.class).addEntity(entityId, entType);
|
||||
get(MetadataRewriter1_12To1_11_1.class).handleMetadata(entityId, entType, wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -198,7 +201,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
|
||||
wrapper.user().get(EntityTracker.class).removeEntity(entity);
|
||||
wrapper.user().get(EntityTracker1_12.class).removeEntity(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -240,11 +243,11 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Optional<Entity1_12Types.EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
|
||||
Optional<Entity1_12Types.EntityType> type = wrapper.user().get(EntityTracker1_12.class).getEntity(entityId);
|
||||
if (!type.isPresent())
|
||||
return;
|
||||
|
||||
MetadataRewriter.handleMetadata(entityId, type.get(), wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
|
||||
get(MetadataRewriter1_12To1_11_1.class).handleMetadata(entityId, type.get(), wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -427,7 +430,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
userConnection.put(new EntityTracker(userConnection));
|
||||
userConnection.put(new EntityTracker1_12(userConnection));
|
||||
if (!userConnection.has(ClientWorld.class))
|
||||
userConnection.put(new ClientWorld(userConnection));
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.metadata;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types.EntityType;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.BedRewriter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter1_12To1_11_1 extends MetadataRewriter<Entity1_12Types.EntityType> {
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
||||
if (metadata.getValue() instanceof Item) {
|
||||
// Apply rewrite
|
||||
BedRewriter.toClientItem((Item) metadata.getValue());
|
||||
}
|
||||
// Evocation Illager aggressive property became 13
|
||||
if (type.is(EntityType.EVOCATION_ILLAGER)) {
|
||||
if (metadata.getId() == 12) {
|
||||
metadata.setId(13);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import us.myles.ViaVersion.api.data.ExternalJoinGameListener;
|
||||
import us.myles.ViaVersion.api.data.StoredObject;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class EntityTracker extends StoredObject implements ExternalJoinGameListener {
|
||||
private final Map<Integer, Entity1_12Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
|
||||
|
||||
public EntityTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void removeEntity(int entityId) {
|
||||
clientEntityTypes.remove(entityId);
|
||||
}
|
||||
|
||||
public void addEntity(int entityId, Entity1_12Types.EntityType type) {
|
||||
clientEntityTypes.put(entityId, type);
|
||||
}
|
||||
|
||||
public boolean has(int entityId) {
|
||||
return clientEntityTypes.containsKey(entityId);
|
||||
}
|
||||
|
||||
public Optional<Entity1_12Types.EntityType> get(int id) {
|
||||
return Optional.fromNullable(clientEntityTypes.get(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExternalJoinGame(int playerEntityId) {
|
||||
clientEntityTypes.put(playerEntityId, Entity1_12Types.EntityType.PLAYER);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types.EntityType;
|
||||
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||
|
||||
public class EntityTracker1_12 extends EntityTracker<Entity1_12Types.EntityType> {
|
||||
|
||||
public EntityTracker1_12(UserConnection user) {
|
||||
super(user, EntityType.PLAYER);
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_13_1to1_13;
|
||||
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
|
||||
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_13;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets.InventoryPackets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter {
|
||||
|
||||
public static void handleMetadata(int entityId, Entity1_13Types.EntityType type, List<Metadata> metadatas, UserConnection connection) {
|
||||
for (Metadata metadata : new ArrayList<>(metadatas)) {
|
||||
try {
|
||||
// 1.13 changed item to flat item (no data)
|
||||
if (metadata.getMetaType() == MetaType1_13.Slot) {
|
||||
InventoryPackets.toClient((Item) metadata.getValue());
|
||||
} else if (metadata.getMetaType() == MetaType1_13.BlockID) {
|
||||
// Convert to new block id
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(Protocol1_13_1To1_13.getNewBlockStateId(data));
|
||||
}
|
||||
if (type == null) continue;
|
||||
if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
|
||||
// New block format
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(Protocol1_13_1To1_13.getNewBlockStateId(data));
|
||||
}
|
||||
if (type.isOrHasParent(EntityType.ABSTRACT_ARROW) && metadata.getId() >= 7) {
|
||||
metadata.setId(metadata.getId() + 1); // New shooter UUID
|
||||
}
|
||||
} catch (Exception e) {
|
||||
metadatas.remove(metadata);
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler");
|
||||
Via.getPlatform().getLogger().warning("Metadata: " + metadata);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -9,16 +9,19 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets.EntityPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets.WorldPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
public class Protocol1_13_1To1_13 extends Protocol {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
put(new MetadataRewriter1_13_1To1_13());
|
||||
|
||||
EntityPackets.register(this);
|
||||
InventoryPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
@ -205,7 +208,7 @@ public class Protocol1_13_1To1_13 extends Protocol {
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
userConnection.put(new EntityTracker(userConnection));
|
||||
userConnection.put(new EntityTracker1_13(userConnection));
|
||||
if (!userConnection.has(ClientWorld.class))
|
||||
userConnection.put(new ClientWorld(userConnection));
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_13_1to1_13.metadata;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
|
||||
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_13;
|
||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets.InventoryPackets;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter1_13_1To1_13 extends MetadataRewriter<Entity1_13Types.EntityType> {
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
||||
// 1.13 changed item to flat item (no data)
|
||||
if (metadata.getMetaType() == MetaType1_13.Slot) {
|
||||
InventoryPackets.toClient((Item) metadata.getValue());
|
||||
} else if (metadata.getMetaType() == MetaType1_13.BlockID) {
|
||||
// Convert to new block id
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(Protocol1_13_1To1_13.getNewBlockStateId(data));
|
||||
}
|
||||
|
||||
if (type == null) return;
|
||||
|
||||
if (type.isOrHasParent(EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
|
||||
// New block format
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(Protocol1_13_1To1_13.getNewBlockStateId(data));
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(EntityType.ABSTRACT_ARROW) && metadata.getId() >= 7) {
|
||||
metadata.setId(metadata.getId() + 1); // New shooter UUID
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -10,13 +10,13 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_13;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.MetadataRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
|
||||
|
||||
public class EntityPackets {
|
||||
|
||||
public static void register(Protocol protocol) {
|
||||
public static void register(final Protocol protocol) {
|
||||
|
||||
//spawn entity
|
||||
protocol.registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() {
|
||||
@ -47,7 +47,7 @@ public class EntityPackets {
|
||||
}
|
||||
}
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -79,9 +79,9 @@ public class EntityPackets {
|
||||
Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
|
||||
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
protocol.get(MetadataRewriter1_13_1To1_13.class).handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -107,8 +107,8 @@ public class EntityPackets {
|
||||
|
||||
Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
protocol.get(MetadataRewriter1_13_1To1_13.class).handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -123,7 +123,7 @@ public class EntityPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
|
||||
wrapper.user().get(EntityTracker.class).removeEntity(entity);
|
||||
wrapper.user().get(EntityTracker1_13.class).removeEntity(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -141,8 +141,8 @@ public class EntityPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Optional<EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
|
||||
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
Optional<EntityType> type = wrapper.user().get(EntityTracker1_13.class).getEntity(entityId);
|
||||
protocol.get(MetadataRewriter1_13_1To1_13.class).handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,109 +0,0 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2;
|
||||
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||
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_13;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter {
|
||||
public static void handleMetadata(int entityId, Entity1_13Types.EntityType type, List<Metadata> metadatas, UserConnection connection) {
|
||||
int particleId = -1, parameter1 = 0, parameter2 = 0;
|
||||
for (Metadata metadata : new ArrayList<>(metadatas)) {
|
||||
try {
|
||||
// Handle new MetaTypes
|
||||
if (metadata.getMetaType().getTypeID() > 4) {
|
||||
metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID() + 1));
|
||||
} else {
|
||||
metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID()));
|
||||
}
|
||||
|
||||
// Handle String -> Chat DisplayName
|
||||
if (metadata.getId() == 2) {
|
||||
metadata.setMetaType(MetaType1_13.OptChat);
|
||||
if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) {
|
||||
metadata.setValue(ChatRewriter.legacyTextToJson((String) metadata.getValue()));
|
||||
} else {
|
||||
metadata.setValue(null);
|
||||
}
|
||||
}
|
||||
|
||||
// 1.13 changed item to flat item (no data)
|
||||
if (metadata.getMetaType() == MetaType1_13.Slot) {
|
||||
metadata.setMetaType(MetaType1_13.Slot);
|
||||
InventoryPackets.toClient((Item) metadata.getValue());
|
||||
} else if (metadata.getMetaType() == MetaType1_13.BlockID) {
|
||||
// Convert to new block id
|
||||
metadata.setValue(WorldPackets.toNewId((int) metadata.getValue()));
|
||||
}
|
||||
|
||||
// Skip type related changes when the type is null
|
||||
if (type == null)
|
||||
continue;
|
||||
|
||||
// Handle new colors
|
||||
if (type.is(Entity1_13Types.EntityType.WOLF) && metadata.getId() == 17) {
|
||||
metadata.setValue(15 - (int) metadata.getValue());
|
||||
}
|
||||
|
||||
// Handle new zombie meta (INDEX 15 - Boolean - Zombie is shaking while enabled)
|
||||
if (type.isOrHasParent(Entity1_13Types.EntityType.ZOMBIE)) {
|
||||
if (metadata.getId() > 14)
|
||||
metadata.setId(metadata.getId() + 1);
|
||||
}
|
||||
|
||||
// Handle Minecart inner block
|
||||
if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
|
||||
// New block format
|
||||
int oldId = (int) metadata.getValue();
|
||||
int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
|
||||
int newId = WorldPackets.toNewId(combined);
|
||||
metadata.setValue(newId);
|
||||
}
|
||||
|
||||
// Handle other changes
|
||||
if (type.is(Entity1_13Types.EntityType.AREA_EFFECT_CLOUD)) {
|
||||
if (metadata.getId() == 9) {
|
||||
particleId = (int) metadata.getValue();
|
||||
} else if (metadata.getId() == 10) {
|
||||
parameter1 = (int) metadata.getValue();
|
||||
} else if (metadata.getId() == 11) {
|
||||
parameter2 = (int) metadata.getValue();
|
||||
}
|
||||
|
||||
if (metadata.getId() >= 9)
|
||||
metadatas.remove(metadata); // Remove
|
||||
}
|
||||
|
||||
if (metadata.getId() == 0) {
|
||||
metadata.setValue((byte) ((byte) metadata.getValue() & ~0x10)); // Previously unused, now swimming
|
||||
}
|
||||
|
||||
// TODO: Boat has changed
|
||||
} catch (Exception e) {
|
||||
metadatas.remove(metadata);
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler");
|
||||
Via.getPlatform().getLogger().warning("Metadata: " + metadata);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle AreaEffectCloud outside the loop
|
||||
if (type != null && type.is(Entity1_13Types.EntityType.AREA_EFFECT_CLOUD) && particleId != -1) {
|
||||
Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2});
|
||||
if (particle != null && particle.getId() != -1) {
|
||||
metadatas.add(new Metadata(9, MetaType1_13.PARTICLE, particle));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.provi
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.BlockIdData;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.RecipeData;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.EntityPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
||||
@ -30,7 +31,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityP
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.PaintingProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockConnectionStorage;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockStorage;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.TabCompleteTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Particle1_13Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
@ -133,6 +134,8 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
put(new MetadataRewriter1_13To1_12_2());
|
||||
|
||||
// Register grouped packet changes
|
||||
EntityPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
@ -385,7 +388,7 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
// Store the player
|
||||
int entityId = wrapper.get(Type.INT, 0);
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, Entity1_13Types.EntityType.PLAYER);
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, Entity1_13Types.EntityType.PLAYER);
|
||||
|
||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 1);
|
||||
@ -1134,7 +1137,7 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
userConnection.put(new EntityTracker(userConnection));
|
||||
userConnection.put(new EntityTracker1_13(userConnection));
|
||||
userConnection.put(new TabCompleteTracker(userConnection));
|
||||
if (!userConnection.has(ClientWorld.class))
|
||||
userConnection.put(new ClientWorld(userConnection));
|
||||
|
@ -0,0 +1,95 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
|
||||
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_13;
|
||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter<Entity1_13Types.EntityType> {
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
|
||||
// Handle new MetaTypes
|
||||
if (metadata.getMetaType().getTypeID() > 4) {
|
||||
metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID() + 1));
|
||||
} else {
|
||||
metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID()));
|
||||
}
|
||||
|
||||
// Handle String -> Chat DisplayName
|
||||
if (metadata.getId() == 2) {
|
||||
metadata.setMetaType(MetaType1_13.OptChat);
|
||||
if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) {
|
||||
metadata.setValue(ChatRewriter.legacyTextToJson((String) metadata.getValue()));
|
||||
} else {
|
||||
metadata.setValue(null);
|
||||
}
|
||||
}
|
||||
|
||||
// 1.13 changed item to flat item (no data)
|
||||
if (metadata.getMetaType() == MetaType1_13.Slot) {
|
||||
metadata.setMetaType(MetaType1_13.Slot);
|
||||
InventoryPackets.toClient((Item) metadata.getValue());
|
||||
} else if (metadata.getMetaType() == MetaType1_13.BlockID) {
|
||||
// Convert to new block id
|
||||
metadata.setValue(WorldPackets.toNewId((int) metadata.getValue()));
|
||||
}
|
||||
|
||||
// Skip type related changes when the type is null
|
||||
if (type == null) return;
|
||||
|
||||
// Handle new colors
|
||||
if (type.is(EntityType.WOLF) && metadata.getId() == 17) {
|
||||
metadata.setValue(15 - (int) metadata.getValue());
|
||||
}
|
||||
|
||||
// Handle new zombie meta (INDEX 15 - Boolean - Zombie is shaking while enabled)
|
||||
if (type.isOrHasParent(EntityType.ZOMBIE)) {
|
||||
if (metadata.getId() > 14)
|
||||
metadata.setId(metadata.getId() + 1);
|
||||
}
|
||||
|
||||
// Handle Minecart inner block
|
||||
if (type.isOrHasParent(EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
|
||||
// New block format
|
||||
int oldId = (int) metadata.getValue();
|
||||
int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
|
||||
int newId = WorldPackets.toNewId(combined);
|
||||
metadata.setValue(newId);
|
||||
}
|
||||
|
||||
// Handle other changes
|
||||
if (type.is(EntityType.AREA_EFFECT_CLOUD)) {
|
||||
if (metadata.getId() == 9) {
|
||||
int particleId = (int) metadata.getValue();
|
||||
int parameter1 = metadataMap.containsKey(10) ? (int) metadataMap.get(10).getValue() : 0;
|
||||
int parameter2 = metadataMap.containsKey(11) ? (int) metadataMap.get(11).getValue() : 0;
|
||||
|
||||
Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2});
|
||||
if (particle != null && particle.getId() != -1) {
|
||||
metadatas.add(new Metadata(9, MetaType1_13.PARTICLE, particle));
|
||||
}
|
||||
}
|
||||
|
||||
if (metadata.getId() >= 9)
|
||||
metadatas.remove(metadata); // Remove
|
||||
}
|
||||
|
||||
if (metadata.getId() == 0) {
|
||||
metadata.setValue((byte) ((byte) metadata.getValue() & ~0x10)); // Previously unused, now swimming
|
||||
}
|
||||
|
||||
// TODO: Boat has changed
|
||||
}
|
||||
}
|
@ -10,12 +10,12 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_12;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_13;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.MetadataRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
|
||||
|
||||
public class EntityPackets {
|
||||
public static void register(Protocol protocol) {
|
||||
public static void register(final Protocol protocol) {
|
||||
// Outgoing packets
|
||||
|
||||
// Spawn Object
|
||||
@ -72,7 +72,7 @@ public class EntityPackets {
|
||||
|
||||
}
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -110,9 +110,9 @@ public class EntityPackets {
|
||||
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
|
||||
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
protocol.get(MetadataRewriter1_13To1_12_2.class).handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -138,8 +138,8 @@ public class EntityPackets {
|
||||
|
||||
Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
protocol.get(MetadataRewriter1_13To1_12_2.class).handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -154,7 +154,7 @@ public class EntityPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
|
||||
wrapper.user().get(EntityTracker.class).removeEntity(entity);
|
||||
wrapper.user().get(EntityTracker1_13.class).removeEntity(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -171,8 +171,8 @@ public class EntityPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Optional<Entity1_13Types.EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
|
||||
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
Optional<Entity1_13Types.EntityType> type = wrapper.user().get(EntityTracker1_13.class).getEntity(entityId);
|
||||
protocol.get(MetadataRewriter1_13To1_12_2.class).handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import us.myles.ViaVersion.api.data.ExternalJoinGameListener;
|
||||
import us.myles.ViaVersion.api.data.StoredObject;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class EntityTracker extends StoredObject implements ExternalJoinGameListener {
|
||||
private final Map<Integer, Entity1_13Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
|
||||
|
||||
public EntityTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void removeEntity(int entityId) {
|
||||
clientEntityTypes.remove(entityId);
|
||||
}
|
||||
|
||||
public void addEntity(int entityId, Entity1_13Types.EntityType type) {
|
||||
clientEntityTypes.put(entityId, type);
|
||||
}
|
||||
|
||||
public boolean has(int entityId) {
|
||||
return clientEntityTypes.containsKey(entityId);
|
||||
}
|
||||
|
||||
public Optional<Entity1_13Types.EntityType> get(int id) {
|
||||
return Optional.fromNullable(clientEntityTypes.get(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExternalJoinGame(int playerEntityId) {
|
||||
clientEntityTypes.put(playerEntityId, Entity1_13Types.EntityType.PLAYER);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
|
||||
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||
|
||||
public class EntityTracker1_13 extends EntityTracker<Entity1_13Types.EntityType> {
|
||||
|
||||
public EntityTracker1_13(UserConnection user) {
|
||||
super(user, EntityType.PLAYER);
|
||||
}
|
||||
}
|
@ -1,235 +0,0 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2;
|
||||
|
||||
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_14Types;
|
||||
import us.myles.ViaVersion.api.minecraft.VillagerData;
|
||||
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_14;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter {
|
||||
|
||||
public static void handleMetadata(int entityId, Entity1_14Types.EntityType type, List<Metadata> metadatas, UserConnection connection) {
|
||||
for (Metadata metadata : new ArrayList<>(metadatas)) {
|
||||
try {
|
||||
metadata.setMetaType(MetaType1_14.byId(metadata.getMetaType().getTypeID()));
|
||||
|
||||
EntityTracker tracker = connection.get(EntityTracker.class);
|
||||
|
||||
if (metadata.getMetaType() == MetaType1_14.Slot) {
|
||||
InventoryPackets.toClient((Item) metadata.getValue());
|
||||
} else if (metadata.getMetaType() == MetaType1_14.BlockID) {
|
||||
// Convert to new block id
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
|
||||
}
|
||||
|
||||
if (type == null) continue;
|
||||
|
||||
//Metadata 6 added to abstract_entity
|
||||
if (metadata.getId() > 5) {
|
||||
metadata.setId(metadata.getId() + 1);
|
||||
}
|
||||
|
||||
//Metadata 12 added to living_entity
|
||||
if (metadata.getId() > 11 && type.isOrHasParent(Entity1_14Types.EntityType.LIVINGENTITY)) {
|
||||
metadata.setId(metadata.getId() + 1);
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_INSENTIENT)) {
|
||||
if (metadata.getId() == 13) {
|
||||
tracker.setInsentientData(entityId, (byte) ((((Number) metadata.getValue()).byteValue() & ~0x4)
|
||||
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
|
||||
metadata.setValue(tracker.getInsentientData(entityId));
|
||||
}
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(Entity1_14Types.EntityType.PLAYER)) {
|
||||
if (entityId != tracker.getClientEntityId()) {
|
||||
if (metadata.getId() == 0) {
|
||||
byte flags = ((Number) metadata.getValue()).byteValue();
|
||||
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
|
||||
tracker.setEntityFlags(entityId, flags);
|
||||
} else if (metadata.getId() == 7) {
|
||||
tracker.setRiptide(entityId, (((Number) metadata.getValue()).byteValue() & 0x4) != 0);
|
||||
}
|
||||
if (metadata.getId() == 0 || metadata.getId() == 7) {
|
||||
metadatas.add(new Metadata(6, MetaType1_14.Pose, recalculatePlayerPose(entityId, tracker)));
|
||||
}
|
||||
}
|
||||
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ZOMBIE)) {
|
||||
if (metadata.getId() == 16) {
|
||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
||||
metadatas.remove(metadata); // "Are hands held up"
|
||||
metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId)));
|
||||
} else if (metadata.getId() > 16) {
|
||||
metadata.setId(metadata.getId() - 1);
|
||||
}
|
||||
}
|
||||
if (type.isOrHasParent(Entity1_14Types.EntityType.MINECART_ABSTRACT)) {
|
||||
if (metadata.getId() == 10) {
|
||||
// New block format
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
|
||||
}
|
||||
} else if (type.is(Entity1_14Types.EntityType.HORSE)) {
|
||||
if (metadata.getId() == 18) {
|
||||
metadatas.remove(metadata);
|
||||
|
||||
int armorType = (int) metadata.getValue();
|
||||
Item armorItem = null;
|
||||
if (armorType == 1) { //iron armor
|
||||
armorItem = new Item(InventoryPackets.getNewItemId(727), (byte) 1, (short) 0, null);
|
||||
} else if (armorType == 2) { //gold armor
|
||||
armorItem = new Item(InventoryPackets.getNewItemId(728), (byte) 1, (short) 0, null);
|
||||
} else if (armorType == 3) { //diamond armor
|
||||
armorItem = new Item(InventoryPackets.getNewItemId(729), (byte) 1, (short) 0, null);
|
||||
}
|
||||
|
||||
PacketWrapper equipmentPacket = new PacketWrapper(0x46, null, connection);
|
||||
equipmentPacket.write(Type.VAR_INT, entityId);
|
||||
equipmentPacket.write(Type.VAR_INT, 4);
|
||||
equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, armorItem);
|
||||
equipmentPacket.send(Protocol1_14To1_13_2.class);
|
||||
}
|
||||
} else if (type.is(Entity1_14Types.EntityType.VILLAGER)) {
|
||||
if (metadata.getId() == 15) {
|
||||
// plains
|
||||
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
||||
metadata.setMetaType(MetaType1_14.VillagerData);
|
||||
}
|
||||
} else if (type.is(Entity1_14Types.EntityType.ZOMBIE_VILLAGER)) {
|
||||
if (metadata.getId() == 18) {
|
||||
// plains
|
||||
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
||||
metadata.setMetaType(MetaType1_14.VillagerData);
|
||||
}
|
||||
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ARROW)) {
|
||||
if (metadata.getId() >= 9) { // New piercing
|
||||
metadata.setId(metadata.getId() + 1);
|
||||
}
|
||||
} else if (type.is(Entity1_14Types.EntityType.FIREWORKS_ROCKET)) {
|
||||
if (metadata.getId() == 8) {
|
||||
if (metadata.getValue().equals(0))
|
||||
metadata.setValue(null); // https://bugs.mojang.com/browse/MC-111480
|
||||
metadata.setMetaType(MetaType1_14.OptVarInt);
|
||||
}
|
||||
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_SKELETON)) {
|
||||
if (metadata.getId() == 14) {
|
||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
||||
metadatas.remove(metadata); // "Is swinging arms"
|
||||
metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId)));
|
||||
}
|
||||
} else if (type.is(Entity1_14Types.EntityType.AREA_EFFECT_CLOUD)) {
|
||||
if (metadata.getId() == 10) {
|
||||
Particle particle = (Particle) metadata.getValue();
|
||||
particle.setId(getNewParticleId(particle.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ILLAGER_BASE)) {
|
||||
if (metadata.getId() == 14) {
|
||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||
| (((Number) metadata.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking
|
||||
metadatas.remove(metadata); // "Has target (aggressive state)"
|
||||
metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId)));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Are witch and ravager also abstract illagers? They all inherit the new metadata 14 added in 19w13a
|
||||
if (type.is(Entity1_14Types.EntityType.WITCH) || type.is(Entity1_14Types.EntityType.RAVAGER) || type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ILLAGER_BASE)) {
|
||||
if (metadata.getId() >= 14) { // TODO 19w13 added a new boolean (raid participant - is celebrating) with id 14
|
||||
metadata.setId(metadata.getId() + 1);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
metadatas.remove(metadata);
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler");
|
||||
Via.getPlatform().getLogger().warning("Metadata: " + metadata);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSneaking(byte flags) {
|
||||
return (flags & 0x2) != 0;
|
||||
}
|
||||
|
||||
private static boolean isSwimming(byte flags) {
|
||||
return (flags & 0x10) != 0;
|
||||
}
|
||||
|
||||
private static int getNewProfessionId(int old) {
|
||||
// profession -> career
|
||||
switch (old) {
|
||||
case 0: // farmer
|
||||
return 5;
|
||||
case 1: // librarian
|
||||
return 9;
|
||||
case 2: // priest
|
||||
return 4; // cleric
|
||||
case 3: // blacksmith
|
||||
return 1; // armorer
|
||||
case 4: // butcher
|
||||
return 2;
|
||||
case 5: // nitwit
|
||||
return 11;
|
||||
default:
|
||||
return 0; // none
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isFallFlying(int entityFlags) {
|
||||
return (entityFlags & 0x80) != 0;
|
||||
}
|
||||
|
||||
public static int recalculatePlayerPose(int entityId, EntityTracker tracker) {
|
||||
byte flags = tracker.getEntityFlags(entityId);
|
||||
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
|
||||
int pose = 0; // standing
|
||||
if (isFallFlying(flags)) {
|
||||
pose = 1;
|
||||
} else if (tracker.isSleeping(entityId)) {
|
||||
pose = 2;
|
||||
} else if (isSwimming(flags)) {
|
||||
pose = 3;
|
||||
} else if (tracker.isRiptide(entityId)) {
|
||||
pose = 4;
|
||||
} else if (isSneaking(flags)) {
|
||||
pose = 5;
|
||||
}
|
||||
return pose;
|
||||
}
|
||||
|
||||
public static int getNewParticleId(int id) {
|
||||
if (id >= 10) {
|
||||
id += 2; // new lava drips 10, 11
|
||||
}
|
||||
if (id >= 13) {
|
||||
id += 1; // new water drip 11 -> 13
|
||||
}
|
||||
if (id >= 27) {
|
||||
id += 1; // new 24 -> 27
|
||||
}
|
||||
if (id >= 29) {
|
||||
id += 1; // skip new short happy villager
|
||||
}
|
||||
if (id >= 44) {
|
||||
id += 1; // new 39 -> 44
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
@ -9,11 +9,12 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.EntityPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.PlayerPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.WorldPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
public class Protocol1_14To1_13_2 extends Protocol {
|
||||
@ -24,6 +25,8 @@ public class Protocol1_14To1_13_2 extends Protocol {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
put(new MetadataRewriter1_14To1_13_2());
|
||||
|
||||
InventoryPackets.register(this);
|
||||
EntityPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
@ -321,7 +324,7 @@ public class Protocol1_14To1_13_2 extends Protocol {
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
userConnection.put(new EntityTracker(userConnection));
|
||||
userConnection.put(new EntityTracker1_14(userConnection));
|
||||
if (!userConnection.has(ClientWorld.class))
|
||||
userConnection.put(new ClientWorld(userConnection));
|
||||
|
||||
|
@ -0,0 +1,227 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types.EntityType;
|
||||
import us.myles.ViaVersion.api.minecraft.VillagerData;
|
||||
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_14;
|
||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter<Entity1_14Types.EntityType> {
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
metadata.setMetaType(MetaType1_14.byId(metadata.getMetaType().getTypeID()));
|
||||
|
||||
EntityTracker1_14 tracker = connection.get(EntityTracker1_14.class);
|
||||
|
||||
if (metadata.getMetaType() == MetaType1_14.Slot) {
|
||||
InventoryPackets.toClient((Item) metadata.getValue());
|
||||
} else if (metadata.getMetaType() == MetaType1_14.BlockID) {
|
||||
// Convert to new block id
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
|
||||
}
|
||||
|
||||
if (type == null) return;
|
||||
|
||||
//Metadata 6 added to abstract_entity
|
||||
if (metadata.getId() > 5) {
|
||||
metadata.setId(metadata.getId() + 1);
|
||||
}
|
||||
|
||||
//Metadata 12 added to living_entity
|
||||
if (metadata.getId() > 11 && type.isOrHasParent(EntityType.LIVINGENTITY)) {
|
||||
metadata.setId(metadata.getId() + 1);
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(EntityType.ABSTRACT_INSENTIENT)) {
|
||||
if (metadata.getId() == 13) {
|
||||
tracker.setInsentientData(entityId, (byte) ((((Number) metadata.getValue()).byteValue() & ~0x4)
|
||||
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
|
||||
metadata.setValue(tracker.getInsentientData(entityId));
|
||||
}
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(EntityType.PLAYER)) {
|
||||
if (entityId != tracker.getClientEntityId()) {
|
||||
if (metadata.getId() == 0) {
|
||||
byte flags = ((Number) metadata.getValue()).byteValue();
|
||||
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
|
||||
tracker.setEntityFlags(entityId, flags);
|
||||
} else if (metadata.getId() == 7) {
|
||||
tracker.setRiptide(entityId, (((Number) metadata.getValue()).byteValue() & 0x4) != 0);
|
||||
}
|
||||
if (metadata.getId() == 0 || metadata.getId() == 7) {
|
||||
metadatas.add(new Metadata(6, MetaType1_14.Pose, recalculatePlayerPose(entityId, tracker)));
|
||||
}
|
||||
}
|
||||
} else if (type.isOrHasParent(EntityType.ZOMBIE)) {
|
||||
if (metadata.getId() == 16) {
|
||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
||||
metadatas.remove(metadata); // "Are hands held up"
|
||||
metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId)));
|
||||
} else if (metadata.getId() > 16) {
|
||||
metadata.setId(metadata.getId() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(EntityType.MINECART_ABSTRACT)) {
|
||||
if (metadata.getId() == 10) {
|
||||
// New block format
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
|
||||
}
|
||||
} else if (type.is(EntityType.HORSE)) {
|
||||
if (metadata.getId() == 18) {
|
||||
metadatas.remove(metadata);
|
||||
|
||||
int armorType = (int) metadata.getValue();
|
||||
Item armorItem = null;
|
||||
if (armorType == 1) { //iron armor
|
||||
armorItem = new Item(InventoryPackets.getNewItemId(727), (byte) 1, (short) 0, null);
|
||||
} else if (armorType == 2) { //gold armor
|
||||
armorItem = new Item(InventoryPackets.getNewItemId(728), (byte) 1, (short) 0, null);
|
||||
} else if (armorType == 3) { //diamond armor
|
||||
armorItem = new Item(InventoryPackets.getNewItemId(729), (byte) 1, (short) 0, null);
|
||||
}
|
||||
|
||||
PacketWrapper equipmentPacket = new PacketWrapper(0x46, null, connection);
|
||||
equipmentPacket.write(Type.VAR_INT, entityId);
|
||||
equipmentPacket.write(Type.VAR_INT, 4);
|
||||
equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, armorItem);
|
||||
equipmentPacket.send(Protocol1_14To1_13_2.class);
|
||||
}
|
||||
} else if (type.is(EntityType.VILLAGER)) {
|
||||
if (metadata.getId() == 15) {
|
||||
// plains
|
||||
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
||||
metadata.setMetaType(MetaType1_14.VillagerData);
|
||||
}
|
||||
} else if (type.is(EntityType.ZOMBIE_VILLAGER)) {
|
||||
if (metadata.getId() == 18) {
|
||||
// plains
|
||||
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
||||
metadata.setMetaType(MetaType1_14.VillagerData);
|
||||
}
|
||||
} else if (type.isOrHasParent(EntityType.ABSTRACT_ARROW)) {
|
||||
if (metadata.getId() >= 9) { // New piercing
|
||||
metadata.setId(metadata.getId() + 1);
|
||||
}
|
||||
} else if (type.is(EntityType.FIREWORKS_ROCKET)) {
|
||||
if (metadata.getId() == 8) {
|
||||
if (metadata.getValue().equals(0))
|
||||
metadata.setValue(null); // https://bugs.mojang.com/browse/MC-111480
|
||||
metadata.setMetaType(MetaType1_14.OptVarInt);
|
||||
}
|
||||
} else if (type.isOrHasParent(EntityType.ABSTRACT_SKELETON)) {
|
||||
if (metadata.getId() == 14) {
|
||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
||||
metadatas.remove(metadata); // "Is swinging arms"
|
||||
metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId)));
|
||||
}
|
||||
} else if (type.is(EntityType.AREA_EFFECT_CLOUD)) {
|
||||
if (metadata.getId() == 10) {
|
||||
Particle particle = (Particle) metadata.getValue();
|
||||
particle.setId(getNewParticleId(particle.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(EntityType.ABSTRACT_ILLAGER_BASE)) {
|
||||
if (metadata.getId() == 14) {
|
||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||
| (((Number) metadata.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking
|
||||
metadatas.remove(metadata); // "Has target (aggressive state)"
|
||||
metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId)));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Are witch and ravager also abstract illagers? They all inherit the new metadata 14 added in 19w13a
|
||||
if (type.is(EntityType.WITCH) || type.is(EntityType.RAVAGER) || type.isOrHasParent(EntityType.ABSTRACT_ILLAGER_BASE)) {
|
||||
if (metadata.getId() >= 14) { // TODO 19w13 added a new boolean (raid participant - is celebrating) with id 14
|
||||
metadata.setId(metadata.getId() + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSneaking(byte flags) {
|
||||
return (flags & 0x2) != 0;
|
||||
}
|
||||
|
||||
private static boolean isSwimming(byte flags) {
|
||||
return (flags & 0x10) != 0;
|
||||
}
|
||||
|
||||
private static int getNewProfessionId(int old) {
|
||||
// profession -> career
|
||||
switch (old) {
|
||||
case 0: // farmer
|
||||
return 5;
|
||||
case 1: // librarian
|
||||
return 9;
|
||||
case 2: // priest
|
||||
return 4; // cleric
|
||||
case 3: // blacksmith
|
||||
return 1; // armorer
|
||||
case 4: // butcher
|
||||
return 2;
|
||||
case 5: // nitwit
|
||||
return 11;
|
||||
default:
|
||||
return 0; // none
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isFallFlying(int entityFlags) {
|
||||
return (entityFlags & 0x80) != 0;
|
||||
}
|
||||
|
||||
public static int recalculatePlayerPose(int entityId, EntityTracker1_14 tracker) {
|
||||
byte flags = tracker.getEntityFlags(entityId);
|
||||
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
|
||||
int pose = 0; // standing
|
||||
if (isFallFlying(flags)) {
|
||||
pose = 1;
|
||||
} else if (tracker.isSleeping(entityId)) {
|
||||
pose = 2;
|
||||
} else if (isSwimming(flags)) {
|
||||
pose = 3;
|
||||
} else if (tracker.isRiptide(entityId)) {
|
||||
pose = 4;
|
||||
} else if (isSneaking(flags)) {
|
||||
pose = 5;
|
||||
}
|
||||
return pose;
|
||||
}
|
||||
|
||||
public static int getNewParticleId(int id) {
|
||||
if (id >= 10) {
|
||||
id += 2; // new lava drips 10, 11
|
||||
}
|
||||
if (id >= 13) {
|
||||
id += 1; // new water drip 11 -> 13
|
||||
}
|
||||
if (id >= 27) {
|
||||
id += 1; // new 24 -> 27
|
||||
}
|
||||
if (id >= 29) {
|
||||
id += 1; // skip new short happy villager
|
||||
}
|
||||
if (id >= 44) {
|
||||
id += 1; // new 39 -> 44
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
@ -14,10 +14,10 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_13_2;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_14;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.MetadataRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.EntityTypeRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -25,7 +25,7 @@ import java.util.UUID;
|
||||
|
||||
public class EntityPackets {
|
||||
|
||||
public static void register(Protocol protocol) {
|
||||
public static void register(final Protocol protocol) {
|
||||
|
||||
// Spawn entity
|
||||
protocol.registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() {
|
||||
@ -99,7 +99,7 @@ public class EntityPackets {
|
||||
|
||||
wrapper.set(Type.VAR_INT, 1, typeId);
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, type1_14);
|
||||
wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, type1_14);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -137,9 +137,9 @@ public class EntityPackets {
|
||||
wrapper.set(Type.VAR_INT, 1, type);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, entType);
|
||||
|
||||
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
protocol.get(MetadataRewriter1_14To1_13_2.class).handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -178,8 +178,8 @@ public class EntityPackets {
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, entType);
|
||||
protocol.get(MetadataRewriter1_14To1_13_2.class).handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -195,7 +195,7 @@ public class EntityPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
short animation = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
if (animation == 2) { //Leave bed
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_14 tracker = wrapper.user().get(EntityTracker1_14.class);
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
tracker.setSleeping(entityId, false);
|
||||
|
||||
@ -203,7 +203,7 @@ public class EntityPackets {
|
||||
metadataPacket.write(Type.VAR_INT, entityId);
|
||||
List<Metadata> metadataList = new LinkedList<>();
|
||||
if (tracker.getClientEntityId() != entityId) {
|
||||
metadataList.add(new Metadata(6, MetaType1_14.Pose, MetadataRewriter.recalculatePlayerPose(entityId, tracker)));
|
||||
metadataList.add(new Metadata(6, MetaType1_14.Pose, MetadataRewriter1_14To1_13_2.recalculatePlayerPose(entityId, tracker)));
|
||||
}
|
||||
metadataList.add(new Metadata(12, MetaType1_14.OptPosition, null));
|
||||
metadataPacket.write(Types1_14.METADATA_LIST, metadataList);
|
||||
@ -222,7 +222,7 @@ public class EntityPackets {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_14 tracker = wrapper.user().get(EntityTracker1_14.class);
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
tracker.setSleeping(entityId, true);
|
||||
|
||||
@ -230,7 +230,7 @@ public class EntityPackets {
|
||||
List<Metadata> metadataList = new LinkedList<>();
|
||||
metadataList.add(new Metadata(12, MetaType1_14.OptPosition, position));
|
||||
if (tracker.getClientEntityId() != entityId) {
|
||||
metadataList.add(new Metadata(6, MetaType1_14.Pose, MetadataRewriter.recalculatePlayerPose(entityId, tracker)));
|
||||
metadataList.add(new Metadata(6, MetaType1_14.Pose, MetadataRewriter1_14To1_13_2.recalculatePlayerPose(entityId, tracker)));
|
||||
}
|
||||
wrapper.write(Types1_14.METADATA_LIST, metadataList);
|
||||
}
|
||||
@ -248,7 +248,7 @@ public class EntityPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
|
||||
wrapper.user().get(EntityTracker.class).removeEntity(entity);
|
||||
wrapper.user().get(EntityTracker1_14.class).removeEntity(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -265,8 +265,8 @@ public class EntityPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
|
||||
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker1_14.class).getEntity(entityId);
|
||||
protocol.get(MetadataRewriter1_14To1_13_2.class).handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.InventoryNameRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
@ -153,7 +153,7 @@ public class InventoryPackets {
|
||||
wrapper.read(Type.STRING); // Remove channel
|
||||
|
||||
int windowId = wrapper.read(Type.INT);
|
||||
wrapper.user().get(EntityTracker.class).setLatestTradeWindowId(windowId);
|
||||
wrapper.user().get(EntityTracker1_14.class).setLatestTradeWindowId(windowId);
|
||||
wrapper.write(Type.VAR_INT, windowId);
|
||||
|
||||
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
@ -292,7 +292,7 @@ public class InventoryPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
// Selecting trade now moves the items, we need to resync the inventory
|
||||
PacketWrapper resyncPacket = wrapper.create(0x08);
|
||||
resyncPacket.write(Type.UNSIGNED_BYTE, ((short) wrapper.user().get(EntityTracker.class).getLatestTradeWindowId())); // 0 - Window ID
|
||||
resyncPacket.write(Type.UNSIGNED_BYTE, ((short) wrapper.user().get(EntityTracker1_14.class).getLatestTradeWindowId())); // 0 - Window ID
|
||||
resyncPacket.write(Type.SHORT, ((short) -999)); // 1 - Slot
|
||||
resyncPacket.write(Type.BYTE, (byte) 2); // 2 - Button - End left click
|
||||
resyncPacket.write(Type.SHORT, ((short) ThreadLocalRandom.current().nextInt())); // 3 - Action number
|
||||
|
@ -15,10 +15,10 @@ import us.myles.ViaVersion.api.remapper.ValueCreator;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.MetadataRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
@ -195,7 +195,7 @@ public class WorldPackets {
|
||||
lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(section.getBlockLight()).toArray(new Byte[0]));
|
||||
}
|
||||
|
||||
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_14 entityTracker = wrapper.user().get(EntityTracker1_14.class);
|
||||
int diffX = Math.abs(entityTracker.getChunkCenterX() - chunk.getX());
|
||||
int diffZ = Math.abs(entityTracker.getChunkCenterZ() - chunk.getZ());
|
||||
if (entityTracker.isForceSendCenterChunk()
|
||||
@ -262,7 +262,7 @@ public class WorldPackets {
|
||||
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
|
||||
}
|
||||
|
||||
int newId = MetadataRewriter.getNewParticleId(id);
|
||||
int newId = MetadataRewriter1_14To1_13_2.getNewParticleId(id);
|
||||
if (newId != id) {
|
||||
wrapper.set(Type.INT, 0, newId);
|
||||
}
|
||||
@ -291,7 +291,7 @@ public class WorldPackets {
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_14 tracker = wrapper.user().get(EntityTracker1_14.class);
|
||||
tracker.addEntity(entityId, entType);
|
||||
tracker.setClientEntityId(entityId);
|
||||
}
|
||||
@ -342,7 +342,7 @@ public class WorldPackets {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 0);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_14 entityTracker = wrapper.user().get(EntityTracker1_14.class);
|
||||
// The client may reset the center chunk if dimension is changed
|
||||
entityTracker.setForceSendCenterChunk(true);
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.data.ExternalJoinGameListener;
|
||||
import us.myles.ViaVersion.api.data.StoredObject;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types.EntityType;
|
||||
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.WorldPackets;
|
||||
@ -15,8 +14,7 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.WorldPackets;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class EntityTracker extends StoredObject implements ExternalJoinGameListener {
|
||||
private final Map<Integer, Entity1_14Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
|
||||
public class EntityTracker1_14 extends EntityTracker<Entity1_14Types.EntityType> {
|
||||
private final Map<Integer, Byte> insentientData = new ConcurrentHashMap<>();
|
||||
// 0x1 = sleeping, 0x2 = riptide
|
||||
private final Map<Integer, Byte> sleepingAndRiptideData = new ConcurrentHashMap<>();
|
||||
@ -26,29 +24,24 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
private int latestTradeWindowId;
|
||||
@Getter
|
||||
@Setter
|
||||
private int clientEntityId;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean forceSendCenterChunk = true;
|
||||
@Getter
|
||||
@Setter
|
||||
private int chunkCenterX, chunkCenterZ;
|
||||
|
||||
public EntityTracker(UserConnection user) {
|
||||
super(user);
|
||||
public EntityTracker1_14(UserConnection user) {
|
||||
super(user, EntityType.PLAYER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(int entityId) {
|
||||
clientEntityTypes.remove(entityId);
|
||||
super.removeEntity(entityId);
|
||||
|
||||
insentientData.remove(entityId);
|
||||
sleepingAndRiptideData.remove(entityId);
|
||||
playerEntityFlags.remove(entityId);
|
||||
}
|
||||
|
||||
public void addEntity(int entityId, Entity1_14Types.EntityType type) {
|
||||
clientEntityTypes.put(entityId, type);
|
||||
}
|
||||
|
||||
public byte getInsentientData(int entity) {
|
||||
Byte val = insentientData.get(entity);
|
||||
return val == null ? 0 : val;
|
||||
@ -89,18 +82,10 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
}
|
||||
}
|
||||
|
||||
public boolean has(int entityId) {
|
||||
return clientEntityTypes.containsKey(entityId);
|
||||
}
|
||||
|
||||
public Optional<Entity1_14Types.EntityType> get(int id) {
|
||||
return Optional.fromNullable(clientEntityTypes.get(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExternalJoinGame(int playerEntityId) {
|
||||
clientEntityId = playerEntityId;
|
||||
clientEntityTypes.put(playerEntityId, Entity1_14Types.EntityType.PLAYER);
|
||||
super.onExternalJoinGame(playerEntityId);
|
||||
|
||||
PacketWrapper setViewDistance = new PacketWrapper(0x41, null, getUser());
|
||||
setViewDistance.write(Type.VAR_INT, WorldPackets.SERVERSIDE_VIEW_DISTANCE);
|
||||
try {
|
@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.*;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.*;
|
||||
@ -72,6 +73,8 @@ public class Protocol1_9To1_8 extends Protocol {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
put(new MetadataRewriter1_9To1_8());
|
||||
|
||||
// Disconnect workaround (JSON!)
|
||||
registerOutgoing(State.LOGIN, 0x00, 0x00, new PacketRemapper() {
|
||||
@Override
|
||||
@ -116,7 +119,7 @@ public class Protocol1_9To1_8 extends Protocol {
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
// Entity tracker
|
||||
userConnection.put(new EntityTracker(userConnection));
|
||||
userConnection.put(new EntityTracker1_9(userConnection));
|
||||
// Chunk tracker
|
||||
userConnection.put(new ClientChunks(userConnection));
|
||||
// Movement tracker
|
||||
|
@ -3,7 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.chat;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
public class ChatRewriter {
|
||||
/**
|
||||
@ -15,7 +15,7 @@ public class ChatRewriter {
|
||||
public static void toClient(JsonObject obj, UserConnection user) {
|
||||
//Check gamemode change
|
||||
if (obj.get("translate") != null && obj.get("translate").getAsString().equals("gameMode.changed")) {
|
||||
String gameMode = user.get(EntityTracker.class).getGameMode().getText();
|
||||
String gameMode = user.get(EntityTracker1_9.class).getGameMode().getText();
|
||||
|
||||
JsonObject gameModeObject = new JsonObject();
|
||||
gameModeObject.addProperty("text", gameMode);
|
||||
|
@ -1,156 +0,0 @@
|
||||
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;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class MetadataRewriter {
|
||||
public static void transform(Entity1_10Types.EntityType type, List<Metadata> list) {
|
||||
short id = -1;
|
||||
int data = -1;
|
||||
for (Metadata entry : new ArrayList<>(list)) {
|
||||
MetaIndex metaIndex = MetaIndex.searchIndex(type, entry.getId());
|
||||
try {
|
||||
if (metaIndex != null) {
|
||||
if (metaIndex.getNewType() != MetaType1_9.Discontinued) {
|
||||
if (metaIndex.getNewType() != MetaType1_9.BlockID || id != -1 && data == -1 || id == -1 && data != -1) { // block ID is only written if we have both parts
|
||||
entry.setId(metaIndex.getNewIndex());
|
||||
entry.setMetaType(metaIndex.getNewType());
|
||||
}
|
||||
Object value = entry.getValue();
|
||||
switch (metaIndex.getNewType()) {
|
||||
case Byte:
|
||||
// convert from int, byte
|
||||
if (metaIndex.getOldType() == MetaType1_8.Byte) {
|
||||
entry.setValue(value);
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_8.Int) {
|
||||
entry.setValue(((Integer) value).byteValue());
|
||||
}
|
||||
// After writing the last one
|
||||
if (metaIndex == MetaIndex.ENTITY_STATUS && type == Entity1_10Types.EntityType.PLAYER) {
|
||||
Byte val = 0;
|
||||
if ((((Byte) value) & 0x10) == 0x10) { // Player eating/aiming/drinking
|
||||
val = 1;
|
||||
}
|
||||
int newIndex = MetaIndex.PLAYER_HAND.getNewIndex();
|
||||
MetaType metaType = MetaIndex.PLAYER_HAND.getNewType();
|
||||
Metadata metadata = new Metadata(newIndex, metaType, val);
|
||||
list.add(metadata);
|
||||
}
|
||||
break;
|
||||
case OptUUID:
|
||||
String owner = (String) value;
|
||||
UUID toWrite = null;
|
||||
if (owner.length() != 0) {
|
||||
try {
|
||||
toWrite = UUID.fromString(owner);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
entry.setValue(toWrite);
|
||||
break;
|
||||
case BlockID:
|
||||
// if we have both sources :))
|
||||
if (metaIndex.getOldType() == MetaType1_8.Byte) {
|
||||
data = (Byte) value;
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_8.Short) {
|
||||
id = (Short) value;
|
||||
}
|
||||
if (id != -1 && data != -1) {
|
||||
int combined = id | (data & 0xF);
|
||||
data = -1;
|
||||
id = -1;
|
||||
entry.setValue(combined);
|
||||
} else {
|
||||
list.remove(entry);
|
||||
}
|
||||
break;
|
||||
case VarInt:
|
||||
// convert from int, short, byte
|
||||
if (metaIndex.getOldType() == MetaType1_8.Byte) {
|
||||
entry.setValue(((Byte) value).intValue());
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_8.Short) {
|
||||
entry.setValue(((Short) value).intValue());
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_8.Int) {
|
||||
entry.setValue(value);
|
||||
}
|
||||
break;
|
||||
case Float:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
case String:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
case Boolean:
|
||||
if (metaIndex == MetaIndex.AGEABLE_AGE)
|
||||
entry.setValue((Byte) value < 0);
|
||||
else
|
||||
entry.setValue((Byte) value != 0);
|
||||
break;
|
||||
case Slot:
|
||||
entry.setValue(value);
|
||||
ItemRewriter.toClient((Item) entry.getValue());
|
||||
break;
|
||||
case Position:
|
||||
Vector vector = (Vector) value;
|
||||
entry.setValue(vector);
|
||||
break;
|
||||
case Vector3F:
|
||||
EulerAngle angle = (EulerAngle) value;
|
||||
entry.setValue(angle);
|
||||
break;
|
||||
case Chat:
|
||||
value = Protocol1_9To1_8.fixJson((String) value);
|
||||
entry.setValue(value);
|
||||
break;
|
||||
default:
|
||||
Via.getPlatform().getLogger().warning("[Out] Unhandled MetaDataType: " + metaIndex.getNewType());
|
||||
list.remove(entry);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
list.remove(entry);
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Could not find valid metadata");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
list.remove(entry);
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
Logger log = Via.getPlatform().getLogger();
|
||||
|
||||
log.warning("This is most likely down to one of your plugins sending bad datawatchers. Please test if this occurs without any plugins except ViaVersion before reporting it on GitHub");
|
||||
log.warning("Also make sure that all your plugins are compatible with your server version.");
|
||||
if (type != null)
|
||||
log.severe("An error occurred with entity meta data for " + type + " OldID: " + entry.getId());
|
||||
else
|
||||
log.severe("An error occurred with entity meta data for UNKNOWN_ENTITY OldID: " + entry.getId());
|
||||
if (metaIndex != null) {
|
||||
log.severe("Value: " + entry.getValue());
|
||||
log.severe("Old ID: " + metaIndex.getIndex() + " New ID: " + metaIndex.getNewIndex());
|
||||
log.severe("Old Type: " + metaIndex.getOldType() + " New Type: " + metaIndex.getNewType());
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_10Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_10Types.EntityType;
|
||||
import us.myles.ViaVersion.api.minecraft.EulerAngle;
|
||||
import us.myles.ViaVersion.api.minecraft.Vector;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_8;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9;
|
||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MetadataRewriter1_9To1_8 extends MetadataRewriter<Entity1_10Types.EntityType> {
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
|
||||
MetaIndex metaIndex = MetaIndex.searchIndex(type, metadata.getId());
|
||||
if (metaIndex == null) {
|
||||
throw new Exception("Could not find valid metadata");
|
||||
}
|
||||
|
||||
if (metaIndex.getNewType() == MetaType1_9.Discontinued) {
|
||||
metadatas.remove(metadata);
|
||||
return;
|
||||
}
|
||||
|
||||
metadata.setId(metaIndex.getNewIndex());
|
||||
metadata.setMetaType(metaIndex.getNewType());
|
||||
|
||||
if (type == EntityType.ENDERMAN && metaIndex.getNewType() == MetaType1_9.BlockID) {
|
||||
if (metaIndex.getOldType() == MetaType1_8.Short) {
|
||||
int id = (Short) metadata.getValue();
|
||||
int data = metadataMap.containsKey(17) ? (Byte) metadataMap.get(17).getValue() : 0;
|
||||
int combined = (id << 4) | (data & 0xF);
|
||||
metadata.setValue(combined);
|
||||
} else {
|
||||
metadatas.remove(metadata);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Object value = metadata.getValue();
|
||||
switch (metaIndex.getNewType()) {
|
||||
case Byte:
|
||||
// convert from int, byte
|
||||
if (metaIndex.getOldType() == MetaType1_8.Byte) {
|
||||
metadata.setValue(value);
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_8.Int) {
|
||||
metadata.setValue(((Integer) value).byteValue());
|
||||
}
|
||||
// After writing the last one
|
||||
if (metaIndex == MetaIndex.ENTITY_STATUS && type == EntityType.PLAYER) {
|
||||
Byte val = 0;
|
||||
if ((((Byte) value) & 0x10) == 0x10) { // Player eating/aiming/drinking
|
||||
val = 1;
|
||||
}
|
||||
int newIndex = MetaIndex.PLAYER_HAND.getNewIndex();
|
||||
MetaType metaType = MetaIndex.PLAYER_HAND.getNewType();
|
||||
metadatas.add(new Metadata(newIndex, metaType, val));
|
||||
}
|
||||
break;
|
||||
case OptUUID:
|
||||
String owner = (String) value;
|
||||
UUID toWrite = null;
|
||||
if (!owner.isEmpty()) {
|
||||
try {
|
||||
toWrite = UUID.fromString(owner);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
metadata.setValue(toWrite);
|
||||
break;
|
||||
case VarInt:
|
||||
// convert from int, short, byte
|
||||
if (metaIndex.getOldType() == MetaType1_8.Byte) {
|
||||
metadata.setValue(((Byte) value).intValue());
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_8.Short) {
|
||||
metadata.setValue(((Short) value).intValue());
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_8.Int) {
|
||||
metadata.setValue(value);
|
||||
}
|
||||
break;
|
||||
case Float:
|
||||
metadata.setValue(value);
|
||||
break;
|
||||
case String:
|
||||
metadata.setValue(value);
|
||||
break;
|
||||
case Boolean:
|
||||
if (metaIndex == MetaIndex.AGEABLE_AGE)
|
||||
metadata.setValue((Byte) value < 0);
|
||||
else
|
||||
metadata.setValue((Byte) value != 0);
|
||||
break;
|
||||
case Slot:
|
||||
metadata.setValue(value);
|
||||
ItemRewriter.toClient((Item) metadata.getValue());
|
||||
break;
|
||||
case Position:
|
||||
Vector vector = (Vector) value;
|
||||
metadata.setValue(vector);
|
||||
break;
|
||||
case Vector3F:
|
||||
EulerAngle angle = (EulerAngle) value;
|
||||
metadata.setValue(angle);
|
||||
break;
|
||||
case Chat:
|
||||
value = Protocol1_9To1_8.fixJson((String) value);
|
||||
metadata.setValue(value);
|
||||
break;
|
||||
default:
|
||||
metadatas.remove(metadata);
|
||||
throw new Exception("Unhandled MetaDataType: " + metaIndex.getNewType());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Pair;
|
||||
@ -18,8 +19,8 @@ import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
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.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -31,7 +32,7 @@ public class EntityPackets {
|
||||
}
|
||||
};
|
||||
|
||||
public static void register(Protocol protocol) {
|
||||
public static void register(final Protocol protocol) {
|
||||
// Attach Entity Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x1B, 0x3A, new PacketRemapper() {
|
||||
|
||||
@ -44,7 +45,7 @@ public class EntityPackets {
|
||||
map(Type.BOOLEAN, new ValueTransformer<Boolean, Void>(Type.NOTHING) {
|
||||
@Override
|
||||
public Void transform(PacketWrapper wrapper, Boolean inputValue) throws Exception {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
if (!inputValue) {
|
||||
int passenger = wrapper.get(Type.INT, 0);
|
||||
int vehicle = wrapper.get(Type.INT, 1);
|
||||
@ -89,7 +90,7 @@ public class EntityPackets {
|
||||
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);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
if (tracker.getKnownHolograms().contains(entityID)) {
|
||||
Double newValue = wrapper.get(Type.DOUBLE, 1);
|
||||
newValue += (Via.getConfig().getHologramYOffset());
|
||||
@ -157,7 +158,7 @@ public class EntityPackets {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
Item stack = wrapper.get(Type.ITEM, 0);
|
||||
|
||||
@ -183,14 +184,14 @@ public class EntityPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
Entity1_10Types.EntityType type = tracker.getClientEntityTypes().get(entityID);
|
||||
if (type != null) {
|
||||
MetadataRewriter.transform(type, metadataList);
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
Optional<Entity1_10Types.EntityType> type = tracker.getEntity(entityId);
|
||||
if (type.isPresent()) {
|
||||
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, type.get(), metadataList, wrapper.user());
|
||||
} else {
|
||||
// Buffer
|
||||
tracker.addMetadataToBuffer(entityID, metadataList);
|
||||
tracker.addMetadataToBuffer(entityId, metadataList);
|
||||
wrapper.cancel();
|
||||
}
|
||||
}
|
||||
@ -202,7 +203,7 @@ public class EntityPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
tracker.handleMetadata(entityID, metadataList);
|
||||
}
|
||||
});
|
||||
@ -283,7 +284,7 @@ public class EntityPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
if (!Via.getConfig().isMinimizeCooldown()) return;
|
||||
if (wrapper.get(Type.VAR_INT, 0) != wrapper.user().get(EntityTracker.class).getProvidedEntityId()) {
|
||||
if (wrapper.get(Type.VAR_INT, 0) != wrapper.user().get(EntityTracker1_9.class).getProvidedEntityId()) {
|
||||
return;
|
||||
}
|
||||
int propertiesToRead = wrapper.read(Type.INT);
|
||||
|
@ -10,7 +10,7 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
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.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.InventoryTracker;
|
||||
|
||||
public class InventoryPackets {
|
||||
@ -320,7 +320,7 @@ public class InventoryPackets {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
if (entityTracker.isBlocking()) {
|
||||
entityTracker.setBlocking(false);
|
||||
entityTracker.setSecondHand(null);
|
||||
|
@ -21,7 +21,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.GameMode;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MainHandProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
public class PlayerPackets {
|
||||
public static void register(Protocol protocol) {
|
||||
@ -131,7 +131,7 @@ public class PlayerPackets {
|
||||
|
||||
if (mode == 0 || mode == 3 || mode == 4) {
|
||||
String[] players = wrapper.passthrough(Type.STRING_ARRAY); // Players
|
||||
final EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
|
||||
final EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
String myName = wrapper.user().get(ProtocolInfo.class).getUsername();
|
||||
String teamName = wrapper.get(Type.STRING, 0);
|
||||
for (String player : players) {
|
||||
@ -153,7 +153,7 @@ public class PlayerPackets {
|
||||
}
|
||||
|
||||
if (mode == 1) { // Remove team
|
||||
final EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
|
||||
final EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
String teamName = wrapper.get(Type.STRING, 0);
|
||||
if (entityTracker.isAutoTeam()
|
||||
&& teamName.equals(entityTracker.getCurrentTeam())) {
|
||||
@ -179,10 +179,10 @@ public class PlayerPackets {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
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, Entity1_10Types.EntityType.PLAYER);
|
||||
tracker.setEntityID(entityID);
|
||||
int entityId = wrapper.get(Type.INT, 0);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
tracker.addEntity(entityId, Entity1_10Types.EntityType.PLAYER);
|
||||
tracker.setClientEntityId(entityId);
|
||||
}
|
||||
});
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Player Gamemode
|
||||
@ -195,7 +195,7 @@ public class PlayerPackets {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
tracker.setGameMode(GameMode.getById(wrapper.get(Type.UNSIGNED_BYTE, 0))); //Set player gamemode
|
||||
}
|
||||
});
|
||||
@ -214,7 +214,7 @@ public class PlayerPackets {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
if (Via.getConfig().isAutoTeam()) {
|
||||
entityTracker.setAutoTeam(true);
|
||||
// Workaround for packet order issue
|
||||
@ -364,7 +364,7 @@ public class PlayerPackets {
|
||||
cc.getLoadedChunks().clear();
|
||||
|
||||
int gamemode = wrapper.get(Type.UNSIGNED_BYTE, 0);
|
||||
wrapper.user().get(EntityTracker.class).setGameMode(GameMode.getById(gamemode));
|
||||
wrapper.user().get(EntityTracker1_9.class).setGameMode(GameMode.getById(gamemode));
|
||||
}
|
||||
});
|
||||
|
||||
@ -392,7 +392,7 @@ public class PlayerPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 3) { //Change gamemode
|
||||
int gamemode = wrapper.get(Type.FLOAT, 0).intValue();
|
||||
wrapper.user().get(EntityTracker.class).setGameMode(GameMode.getById(gamemode));
|
||||
wrapper.user().get(EntityTracker1_9.class).setGameMode(GameMode.getById(gamemode));
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -565,7 +565,7 @@ public class PlayerPackets {
|
||||
int action = wrapper.get(Type.VAR_INT, 0);
|
||||
if (action == 2) {
|
||||
// cancel any blocking >.>
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
if (tracker.isBlocking()) {
|
||||
tracker.setSecondHand(null);
|
||||
tracker.setBlocking(false);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_10Types;
|
||||
@ -17,8 +18,8 @@ import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
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.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -31,7 +32,7 @@ public class SpawnPackets {
|
||||
}
|
||||
};
|
||||
|
||||
public static void register(Protocol protocol) {
|
||||
public static void register(final Protocol protocol) {
|
||||
// Spawn Object Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x0E, 0x00, new PacketRemapper() {
|
||||
@Override
|
||||
@ -42,7 +43,7 @@ public class SpawnPackets {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID
|
||||
}
|
||||
});
|
||||
@ -54,8 +55,8 @@ public class SpawnPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
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, Entity1_10Types.getTypeFromId(typeID, true));
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
tracker.addEntity(entityID, Entity1_10Types.getTypeFromId(typeID, true));
|
||||
tracker.sendMetadataBuffer(entityID);
|
||||
}
|
||||
});
|
||||
@ -129,8 +130,8 @@ public class SpawnPackets {
|
||||
@Override
|
||||
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, Entity1_10Types.EntityType.EXPERIENCE_ORB);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
tracker.addEntity(entityID, Entity1_10Types.EntityType.EXPERIENCE_ORB);
|
||||
tracker.sendMetadataBuffer(entityID);
|
||||
}
|
||||
});
|
||||
@ -155,8 +156,8 @@ public class SpawnPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
// Currently only lightning uses this
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
tracker.getClientEntityTypes().put(entityID, Entity1_10Types.EntityType.LIGHTNING);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
tracker.addEntity(entityID, Entity1_10Types.EntityType.LIGHTNING);
|
||||
tracker.sendMetadataBuffer(entityID);
|
||||
}
|
||||
});
|
||||
@ -177,7 +178,7 @@ public class SpawnPackets {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID
|
||||
}
|
||||
});
|
||||
@ -189,8 +190,8 @@ public class SpawnPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
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, Entity1_10Types.getTypeFromId(typeID, false));
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
tracker.addEntity(entityID, Entity1_10Types.getTypeFromId(typeID, false));
|
||||
tracker.sendMetadataBuffer(entityID);
|
||||
}
|
||||
});
|
||||
@ -212,13 +213,13 @@ public class SpawnPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
Entity1_10Types.EntityType type = tracker.getClientEntityTypes().get(entityID);
|
||||
if (type != null) {
|
||||
MetadataRewriter.transform(type, metadataList);
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
Optional<Entity1_10Types.EntityType> type = tracker.getEntity(entityId);
|
||||
if (type.isPresent()) {
|
||||
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, type.get(), metadataList, wrapper.user());
|
||||
} else {
|
||||
Via.getPlatform().getLogger().warning("Unable to find entity for metadata, entity ID: " + entityID);
|
||||
Via.getPlatform().getLogger().warning("Unable to find entity for metadata, entity ID: " + entityId);
|
||||
metadataList.clear();
|
||||
}
|
||||
}
|
||||
@ -229,7 +230,7 @@ public class SpawnPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
tracker.handleMetadata(entityID, metadataList);
|
||||
}
|
||||
});
|
||||
@ -247,8 +248,8 @@ public class SpawnPackets {
|
||||
@Override
|
||||
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, Entity1_10Types.EntityType.PAINTING);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
tracker.addEntity(entityID, Entity1_10Types.EntityType.PAINTING);
|
||||
tracker.sendMetadataBuffer(entityID);
|
||||
}
|
||||
});
|
||||
@ -258,7 +259,7 @@ public class SpawnPackets {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID
|
||||
}
|
||||
});
|
||||
@ -281,8 +282,8 @@ public class SpawnPackets {
|
||||
@Override
|
||||
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, Entity1_10Types.EntityType.PLAYER);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
tracker.addEntity(entityID, Entity1_10Types.EntityType.PLAYER);
|
||||
tracker.sendMetadataBuffer(entityID);
|
||||
}
|
||||
});
|
||||
@ -318,13 +319,13 @@ public class SpawnPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
Entity1_10Types.EntityType type = tracker.getClientEntityTypes().get(entityID);
|
||||
if (type != null) {
|
||||
MetadataRewriter.transform(type, metadataList);
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
Optional<Entity1_10Types.EntityType> type = tracker.getEntity(entityId);
|
||||
if (type.isPresent()) {
|
||||
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, type.get(), metadataList, wrapper.user());
|
||||
} else {
|
||||
Via.getPlatform().getLogger().warning("Unable to find entity for metadata, entity ID: " + entityID);
|
||||
Via.getPlatform().getLogger().warning("Unable to find entity for metadata, entity ID: " + entityId);
|
||||
metadataList.clear();
|
||||
}
|
||||
}
|
||||
@ -336,7 +337,7 @@ public class SpawnPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
tracker.handleMetadata(entityID, metadataList);
|
||||
}
|
||||
});
|
||||
@ -356,7 +357,7 @@ public class SpawnPackets {
|
||||
Integer[] entities = wrapper.get(Type.VAR_INT_ARRAY, 0);
|
||||
for (Integer entity : entities) {
|
||||
// EntityTracker
|
||||
wrapper.user().get(EntityTracker.class).removeEntity(entity);
|
||||
wrapper.user().get(EntityTracker1_9.class).removeEntity(entity);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -22,7 +22,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProv
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.Effect;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.SoundEffect;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.PlaceBlockTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.Chunk1_9to1_8Type;
|
||||
|
||||
@ -99,7 +99,7 @@ public class WorldPackets {
|
||||
wrapper.set(Type.STRING, 0, newname);
|
||||
wrapper.write(Type.VAR_INT, catid); // Write Category ID
|
||||
if (effect != null && effect.isBreaksound()) {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
int x = wrapper.passthrough(Type.INT); //Position X
|
||||
int y = wrapper.passthrough(Type.INT); //Position Y
|
||||
int z = wrapper.passthrough(Type.INT); //Position Z
|
||||
@ -268,7 +268,7 @@ public class WorldPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int status = wrapper.get(Type.UNSIGNED_BYTE, 0);
|
||||
if (status == 5 || status == 4 || status == 3) {
|
||||
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
if (entityTracker.isBlocking()) {
|
||||
entityTracker.setBlocking(false);
|
||||
entityTracker.setSecondHand(null);
|
||||
@ -297,7 +297,7 @@ public class WorldPackets {
|
||||
Item item = Protocol1_9To1_8.getHandItem(wrapper.user());
|
||||
// Blocking patch
|
||||
if (Via.getConfig().isShieldBlocking()) {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
|
||||
if (item != null && Protocol1_9To1_8.isSword(item.getId())) {
|
||||
if (hand == 0) {
|
||||
@ -386,7 +386,7 @@ public class WorldPackets {
|
||||
x++;
|
||||
break;
|
||||
}
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||
tracker.addBlockInteraction(new Position(x, y, z));
|
||||
}
|
||||
});
|
||||
|
@ -9,7 +9,7 @@ import us.myles.ViaVersion.api.platform.providers.Provider;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.CommandBlockStorage;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
public class CommandBlockProvider implements Provider {
|
||||
|
||||
@ -41,7 +41,7 @@ public class CommandBlockProvider implements Provider {
|
||||
return;
|
||||
PacketWrapper wrapper = new PacketWrapper(0x1B, null, user); // Entity status
|
||||
|
||||
wrapper.write(Type.INT, user.get(EntityTracker.class).getProvidedEntityId()); // Entity ID
|
||||
wrapper.write(Type.INT, user.get(EntityTracker1_9.class).getProvidedEntityId()); // Entity ID
|
||||
wrapper.write(Type.BYTE, (byte) 26); // Hardcoded op permission level
|
||||
|
||||
wrapper.send(Protocol1_9To1_8.class);
|
||||
|
@ -2,11 +2,11 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.providers;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.platform.providers.Provider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
public class EntityIdProvider implements Provider {
|
||||
|
||||
public int getEntityId(UserConnection user) throws Exception {
|
||||
return user.get(EntityTracker.class).getEntityID();
|
||||
return user.get(EntityTracker1_9.class).getClientEntityId();
|
||||
}
|
||||
}
|
||||
|
@ -10,20 +10,20 @@ import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.boss.BossBar;
|
||||
import us.myles.ViaVersion.api.boss.BossColor;
|
||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||
import us.myles.ViaVersion.api.data.ExternalJoinGameListener;
|
||||
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.entities.Entity1_10Types.EntityType;
|
||||
import us.myles.ViaVersion.api.minecraft.Position;
|
||||
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;
|
||||
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
||||
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.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider;
|
||||
|
||||
@ -32,9 +32,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Getter
|
||||
public class EntityTracker extends StoredObject implements ExternalJoinGameListener {
|
||||
public class EntityTracker1_9 extends EntityTracker<Entity1_10Types.EntityType> {
|
||||
private final Map<Integer, UUID> uuidMap = 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<>();
|
||||
@ -46,8 +45,6 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
@Setter
|
||||
private boolean autoTeam = false;
|
||||
@Setter
|
||||
private int entityID = -1;
|
||||
@Setter
|
||||
private Position currentlyDigging = null;
|
||||
private boolean teamExists = false;
|
||||
@Setter
|
||||
@ -55,8 +52,8 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
@Setter
|
||||
private String currentTeam;
|
||||
|
||||
public EntityTracker(UserConnection user) {
|
||||
super(user);
|
||||
public EntityTracker1_9(UserConnection user) {
|
||||
super(user, EntityType.PLAYER);
|
||||
}
|
||||
|
||||
public UUID getEntityUUID(int id) {
|
||||
@ -70,7 +67,7 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
}
|
||||
|
||||
public void setSecondHand(Item item) {
|
||||
setSecondHand(entityID, item);
|
||||
setSecondHand(getClientEntityId(), item);
|
||||
}
|
||||
|
||||
public void setSecondHand(int entityID, Item item) {
|
||||
@ -85,15 +82,17 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
}
|
||||
}
|
||||
|
||||
public void removeEntity(Integer entityID) {
|
||||
clientEntityTypes.remove(entityID);
|
||||
vehicleMap.remove(entityID);
|
||||
uuidMap.remove(entityID);
|
||||
validBlocking.remove(entityID);
|
||||
knownHolograms.remove(entityID);
|
||||
metadataBuffer.remove(entityID);
|
||||
@Override
|
||||
public void removeEntity(int entityId) {
|
||||
super.removeEntity(entityId);
|
||||
|
||||
BossBar bar = bossBarMap.remove(entityID);
|
||||
vehicleMap.remove(entityId);
|
||||
uuidMap.remove(entityId);
|
||||
validBlocking.remove(entityId);
|
||||
knownHolograms.remove(entityId);
|
||||
metadataBuffer.remove(entityId);
|
||||
|
||||
BossBar bar = bossBarMap.remove(entityId);
|
||||
if (bar != null) {
|
||||
bar.hide();
|
||||
// Send to provider
|
||||
@ -117,55 +116,55 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
blockInteractions.put(p, 0);
|
||||
}
|
||||
|
||||
public void handleMetadata(int entityID, List<Metadata> metadataList) {
|
||||
Entity1_10Types.EntityType type = clientEntityTypes.get(entityID);
|
||||
public void handleMetadata(int entityId, List<Metadata> metadataList) {
|
||||
EntityType type = getEntity(entityId).orNull();
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Metadata metadata : new ArrayList<>(metadataList)) {
|
||||
// Fix: wither (crash fix)
|
||||
if (type == Entity1_10Types.EntityType.WITHER) {
|
||||
if (type == 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 == Entity1_10Types.EntityType.ENDER_DRAGON) {
|
||||
if (type == EntityType.ENDER_DRAGON) {
|
||||
if (metadata.getId() == 11) {
|
||||
metadataList.remove(metadata);
|
||||
// metadataList.add(new Metadata(11, NewType.Byte.getTypeID(), Type.VAR_INT, 0));
|
||||
}
|
||||
}
|
||||
|
||||
if (type == Entity1_10Types.EntityType.SKELETON) {
|
||||
if (type == EntityType.SKELETON) {
|
||||
if ((getMetaByIndex(metadataList, 12)) == null) {
|
||||
metadataList.add(new Metadata(12, MetaType1_9.Boolean, true));
|
||||
}
|
||||
}
|
||||
|
||||
//ECHOPET Patch
|
||||
if (type == Entity1_10Types.EntityType.HORSE) {
|
||||
if (type == 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 == Entity1_10Types.EntityType.PLAYER) {
|
||||
if (type == EntityType.PLAYER) {
|
||||
if (metadata.getId() == 0) {
|
||||
// Byte
|
||||
byte data = (byte) metadata.getValue();
|
||||
if (entityID != getProvidedEntityId() && Via.getConfig().isShieldBlocking()) {
|
||||
if (entityId != getProvidedEntityId() && Via.getConfig().isShieldBlocking()) {
|
||||
if ((data & 0x10) == 0x10) {
|
||||
if (validBlocking.contains(entityID)) {
|
||||
if (validBlocking.contains(entityId)) {
|
||||
Item shield = new Item((short) 442, (byte) 1, (short) 0, null);
|
||||
setSecondHand(entityID, shield);
|
||||
setSecondHand(entityId, shield);
|
||||
} else {
|
||||
setSecondHand(entityID, null);
|
||||
setSecondHand(entityId, null);
|
||||
}
|
||||
} else {
|
||||
setSecondHand(entityID, null);
|
||||
setSecondHand(entityId, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -177,19 +176,19 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
));
|
||||
}
|
||||
}
|
||||
if (type == Entity1_10Types.EntityType.ARMOR_STAND && Via.getConfig().isHologramPatch()) {
|
||||
if (type == 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();
|
||||
// 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) getMetaByIndex(metadataList, 2).getValue()).length() != 0 && (boolean) getMetaByIndex(metadataList, 3).getValue()) {
|
||||
if (!knownHolograms.contains(entityID)) {
|
||||
knownHolograms.add(entityID);
|
||||
&& !((String) getMetaByIndex(metadataList, 2).getValue()).isEmpty() && (boolean) getMetaByIndex(metadataList, 3).getValue()) {
|
||||
if (!knownHolograms.contains(entityId)) {
|
||||
knownHolograms.add(entityId);
|
||||
try {
|
||||
// Send movement
|
||||
PacketWrapper wrapper = new PacketWrapper(0x25, null, getUser());
|
||||
wrapper.write(Type.VAR_INT, entityID);
|
||||
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);
|
||||
@ -204,14 +203,14 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
UUID uuid = getUser().get(ProtocolInfo.class).getUuid();
|
||||
// Boss bar
|
||||
if (Via.getConfig().isBossbarPatch()) {
|
||||
if (type == Entity1_10Types.EntityType.ENDER_DRAGON || type == Entity1_10Types.EntityType.WITHER) {
|
||||
if (type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) {
|
||||
if (metadata.getId() == 2) {
|
||||
BossBar bar = bossBarMap.get(entityID);
|
||||
BossBar bar = bossBarMap.get(entityId);
|
||||
String title = (String) metadata.getValue();
|
||||
title = title.isEmpty() ? (type == Entity1_10Types.EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title;
|
||||
title = title.isEmpty() ? (type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title;
|
||||
if (bar == null) {
|
||||
bar = Via.getAPI().createBossBar(title, BossColor.PINK, BossStyle.SOLID);
|
||||
bossBarMap.put(entityID, bar);
|
||||
bossBarMap.put(entityId, bar);
|
||||
bar.addPlayer(uuid);
|
||||
bar.show();
|
||||
|
||||
@ -221,14 +220,14 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
bar.setTitle(title);
|
||||
}
|
||||
} else if (metadata.getId() == 6 && !Via.getConfig().isBossbarAntiflicker()) { // If anti flicker is enabled, don't update health
|
||||
BossBar bar = bossBarMap.get(entityID);
|
||||
BossBar bar = bossBarMap.get(entityId);
|
||||
// Make health range between 0 and 1
|
||||
float maxHealth = type == Entity1_10Types.EntityType.ENDER_DRAGON ? 200.0f : 300.0f;
|
||||
float maxHealth = type == 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 == Entity1_10Types.EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither";
|
||||
String title = type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither";
|
||||
bar = Via.getAPI().createBossBar(title, health, BossColor.PINK, BossStyle.SOLID);
|
||||
bossBarMap.put(entityID, bar);
|
||||
bossBarMap.put(entityId, bar);
|
||||
bar.addPlayer(uuid);
|
||||
bar.show();
|
||||
// Send to provider
|
||||
@ -287,22 +286,23 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMetadataBuffer(int entityID) {
|
||||
List<Metadata> metadataList = metadataBuffer.get(entityID);
|
||||
public void sendMetadataBuffer(int entityId) {
|
||||
List<Metadata> metadataList = metadataBuffer.get(entityId);
|
||||
if (metadataList != null) {
|
||||
PacketWrapper wrapper = new PacketWrapper(0x39, null, getUser());
|
||||
wrapper.write(Type.VAR_INT, entityID);
|
||||
wrapper.write(Type.VAR_INT, entityId);
|
||||
wrapper.write(Types1_9.METADATA_LIST, metadataList);
|
||||
MetadataRewriter.transform(getClientEntityTypes().get(entityID), metadataList);
|
||||
handleMetadata(entityID, metadataList);
|
||||
if (metadataList.size() > 0) {
|
||||
getUser().get(ProtocolInfo.class).getPipeline().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class)
|
||||
.handleMetadata(entityId, getEntity(entityId).orNull(), metadataList, getUser());
|
||||
handleMetadata(entityId, metadataList);
|
||||
if (!metadataList.isEmpty()) {
|
||||
try {
|
||||
wrapper.send(Protocol1_9To1_8.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
metadataBuffer.remove(entityID);
|
||||
metadataBuffer.remove(entityId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -310,12 +310,7 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
try {
|
||||
return Via.getManager().getProviders().get(EntityIdProvider.class).getEntityId(getUser());
|
||||
} catch (Exception e) {
|
||||
return entityID;
|
||||
return getClientEntityId();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExternalJoinGame(int playerEntityId) {
|
||||
clientEntityTypes.put(playerEntityId, Entity1_10Types.EntityType.PLAYER);
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ import org.spongepowered.api.world.Location;
|
||||
import us.myles.ViaVersion.SpongePlugin;
|
||||
import us.myles.ViaVersion.api.minecraft.Position;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
import us.myles.ViaVersion.sponge.listeners.ViaSpongeListener;
|
||||
|
||||
public class BlockListener extends ViaSpongeListener {
|
||||
@ -22,7 +22,7 @@ public class BlockListener extends ViaSpongeListener {
|
||||
if (isOnPipe(player.getUniqueId())) {
|
||||
Location loc = e.getTransactions().get(0).getFinal().getLocation().get();
|
||||
getUserConnection(player.getUniqueId())
|
||||
.get(EntityTracker.class)
|
||||
.get(EntityTracker1_9.class)
|
||||
.addBlockInteraction(new Position((long) loc.getX(), (long) loc.getY(), (long) loc.getZ()));
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
||||
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.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@ -28,7 +28,7 @@ public class ElytraPatch {
|
||||
|
||||
try {
|
||||
if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9To1_8.class)) {
|
||||
int entityId = user.get(EntityTracker.class).getProvidedEntityId();
|
||||
int entityId = user.get(EntityTracker1_9.class).getProvidedEntityId();
|
||||
|
||||
PacketWrapper wrapper = new PacketWrapper(0x39, null, user);
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren