Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-08 22:02:50 +02:00
abstract MetadataRewriter
Dieser Commit ist enthalten in:
Ursprung
6911d061a7
Commit
23b68a867c
@ -29,7 +29,7 @@ public class Entity1_10Types {
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum EntityType {
|
||||
public enum EntityType implements IEntityType {
|
||||
ENTITY(-1),
|
||||
DROPPED_ITEM(1, EntityType.ENTITY),
|
||||
EXPERIENCE_ORB(2, EntityType.ENTITY),
|
||||
|
@ -28,7 +28,7 @@ public class Entity1_11Types {
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum EntityType {
|
||||
public enum EntityType implements IEntityType {
|
||||
ENTITY(-1),
|
||||
DROPPED_ITEM(1, ENTITY),
|
||||
EXPERIENCE_ORB(2, ENTITY),
|
||||
|
@ -38,7 +38,7 @@ public class Entity1_12Types {
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum EntityType {
|
||||
public enum EntityType implements IEntityType {
|
||||
ENTITY(-1),
|
||||
DROPPED_ITEM(1, ENTITY),
|
||||
EXPERIENCE_ORB(2, ENTITY),
|
||||
|
@ -29,7 +29,7 @@ public class Entity1_13Types {
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum EntityType {
|
||||
public enum EntityType implements IEntityType {
|
||||
// Auto generated
|
||||
|
||||
ENTITY(-1), // abm
|
||||
|
@ -23,7 +23,7 @@ public class Entity1_14Types {
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum EntityType {
|
||||
public enum EntityType implements IEntityType {
|
||||
// Auto generated
|
||||
|
||||
ENTITY(-1),
|
||||
|
@ -0,0 +1,9 @@
|
||||
package us.myles.ViaVersion.api.entities;
|
||||
|
||||
public interface IEntityType {
|
||||
|
||||
int getId();
|
||||
|
||||
IEntityType 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.IEntityType;
|
||||
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 IEntityType> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -6,11 +6,12 @@ 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.IEntityType;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class EntityTracker<T> extends StoredObject implements ExternalJoinGameListener {
|
||||
public abstract class EntityTracker<T extends IEntityType> extends StoredObject implements ExternalJoinGameListener {
|
||||
private final Map<Integer, T> clientEntityTypes = new ConcurrentHashMap<>();
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -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.EntityTracker1_11;
|
||||
|
||||
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()) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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,6 +16,7 @@ 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.EntityTracker1_11;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||
@ -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
|
||||
@ -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(EntityTracker1_11.class).addEntity(entityId, entType);
|
||||
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
|
||||
get(MetadataRewriter1_11To1_10.class).handleMetadata(entityId, entType, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -152,7 +155,7 @@ public class Protocol1_11To1_10 extends Protocol {
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -0,0 +1,216 @@
|
||||
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> {
|
||||
|
||||
public 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();
|
||||
}
|
||||
}
|
@ -2,13 +2,13 @@ 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;
|
||||
|
||||
import static us.myles.ViaVersion.api.entities.Entity1_11Types.EntityType;
|
||||
|
||||
public class EntityTracker1_11 extends EntityTracker<EntityType> {
|
||||
public class EntityTracker1_11 extends EntityTracker<Entity1_11Types.EntityType> {
|
||||
private final Set<Integer> holograms = Sets.newConcurrentHashSet();
|
||||
|
||||
public EntityTracker1_11(UserConnection user) {
|
||||
|
@ -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,6 +19,7 @@ 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.EntityTracker1_12;
|
||||
@ -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
|
||||
@ -85,7 +88,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, false);
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_12.class).addEntity(entityId, entType);
|
||||
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
|
||||
get(MetadataRewriter1_12To1_11_1.class).handleMetadata(entityId, entType, wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -244,7 +247,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
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> {
|
||||
|
||||
public 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,11 +1,11 @@
|
||||
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;
|
||||
|
||||
import static us.myles.ViaVersion.api.entities.Entity1_12Types.EntityType;
|
||||
|
||||
public class EntityTracker1_12 extends EntityTracker<EntityType> {
|
||||
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,6 +9,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_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;
|
||||
@ -19,6 +20,8 @@ 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);
|
||||
|
@ -0,0 +1,40 @@
|
||||
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> {
|
||||
|
||||
public 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.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() {
|
||||
@ -81,7 +81,7 @@ public class EntityPackets {
|
||||
// Register Type ID
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -108,7 +108,7 @@ public class EntityPackets {
|
||||
Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -142,7 +142,7 @@ public class EntityPackets {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Optional<EntityType> type = wrapper.user().get(EntityTracker1_13.class).getEntity(entityId);
|
||||
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
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;
|
||||
@ -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);
|
||||
|
@ -0,0 +1,94 @@
|
||||
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> {
|
||||
|
||||
public 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.EntityTracker1_13;
|
||||
|
||||
public class EntityPackets {
|
||||
public static void register(Protocol protocol) {
|
||||
public static void register(final Protocol protocol) {
|
||||
// Outgoing packets
|
||||
|
||||
// Spawn Object
|
||||
@ -112,7 +112,7 @@ public class EntityPackets {
|
||||
// Register Type ID
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -139,7 +139,7 @@ public class EntityPackets {
|
||||
Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -172,7 +172,7 @@ public class EntityPackets {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Optional<Entity1_13Types.EntityType> type = wrapper.user().get(EntityTracker1_13.class).getEntity(entityId);
|
||||
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
protocol.get(MetadataRewriter1_13To1_12_2.class).handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
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;
|
||||
|
||||
import static us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
|
||||
|
||||
public class EntityTracker1_13 extends EntityTracker<EntityType> {
|
||||
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.EntityTracker1_14;
|
||||
|
||||
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()));
|
||||
|
||||
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) 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, 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;
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ 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;
|
||||
@ -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);
|
||||
|
@ -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
|
||||
public 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,7 +14,7 @@ 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.EntityTracker1_14;
|
||||
@ -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() {
|
||||
@ -139,7 +139,7 @@ public class EntityPackets {
|
||||
// Register Type ID
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -179,7 +179,7 @@ public class EntityPackets {
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -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);
|
||||
@ -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);
|
||||
}
|
||||
@ -266,7 +266,7 @@ public class EntityPackets {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker1_14.class).getEntity(entityId);
|
||||
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
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.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.EntityTracker1_14;
|
||||
@ -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);
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
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.storage.EntityTracker;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
@ -12,9 +14,7 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.WorldPackets;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static us.myles.ViaVersion.api.entities.Entity1_14Types.EntityType;
|
||||
|
||||
public class EntityTracker1_14 extends EntityTracker<EntityType> {
|
||||
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<>();
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -19,7 +19,7 @@ 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.metadata.MetadataRewriter1_9To1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
import java.util.*;
|
||||
@ -32,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() {
|
||||
|
||||
@ -184,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);
|
||||
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);
|
||||
Optional<Entity1_10Types.EntityType> type = tracker.getEntity(entityId);
|
||||
if (type.isPresent()) {
|
||||
MetadataRewriter.transform(type.get(), metadataList);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ 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.metadata.MetadataRewriter1_9To1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -32,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
|
||||
@ -213,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);
|
||||
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);
|
||||
Optional<Entity1_10Types.EntityType> type = tracker.getEntity(entityId);
|
||||
if (type.isPresent()) {
|
||||
MetadataRewriter.transform(type.get(), metadataList);
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -319,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);
|
||||
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);
|
||||
Optional<Entity1_10Types.EntityType> type = tracker.getEntity(entityId);
|
||||
if (type.isPresent()) {
|
||||
MetadataRewriter.transform(type.get(), metadataList);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import us.myles.ViaVersion.api.boss.BossColor;
|
||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||
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;
|
||||
@ -22,7 +23,7 @@ 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;
|
||||
|
||||
@ -30,10 +31,8 @@ import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static us.myles.ViaVersion.api.entities.Entity1_10Types.EntityType;
|
||||
|
||||
@Getter
|
||||
public class EntityTracker1_9 extends EntityTracker<EntityType> {
|
||||
public class EntityTracker1_9 extends EntityTracker<Entity1_10Types.EntityType> {
|
||||
private final Map<Integer, UUID> uuidMap = new ConcurrentHashMap<>();
|
||||
private final Map<Integer, List<Metadata>> metadataBuffer = new ConcurrentHashMap<>();
|
||||
private final Map<Integer, Integer> vehicleMap = new ConcurrentHashMap<>();
|
||||
@ -118,41 +117,41 @@ public class EntityTracker1_9 extends EntityTracker<EntityType> {
|
||||
}
|
||||
|
||||
public void handleMetadata(int entityId, List<Metadata> metadataList) {
|
||||
Entity1_10Types.EntityType type = getEntity(entityId).orNull();
|
||||
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();
|
||||
@ -177,7 +176,7 @@ public class EntityTracker1_9 extends EntityTracker<EntityType> {
|
||||
));
|
||||
}
|
||||
}
|
||||
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();
|
||||
@ -204,11 +203,11 @@ public class EntityTracker1_9 extends EntityTracker<EntityType> {
|
||||
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);
|
||||
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);
|
||||
@ -223,10 +222,10 @@ public class EntityTracker1_9 extends EntityTracker<EntityType> {
|
||||
} else if (metadata.getId() == 6 && !Via.getConfig().isBossbarAntiflicker()) { // If anti flicker is enabled, don't update health
|
||||
BossBar bar = bossBarMap.get(entityId);
|
||||
// Make health range between 0 and 1
|
||||
float maxHealth = type == 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);
|
||||
bar.addPlayer(uuid);
|
||||
@ -293,7 +292,8 @@ public class EntityTracker1_9 extends EntityTracker<EntityType> {
|
||||
PacketWrapper wrapper = new PacketWrapper(0x39, null, getUser());
|
||||
wrapper.write(Type.VAR_INT, entityId);
|
||||
wrapper.write(Types1_9.METADATA_LIST, metadataList);
|
||||
MetadataRewriter.transform(getEntity(entityId).orNull(), metadataList);
|
||||
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 {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren