3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-19 14:30:16 +01:00

Refactor entity tracking and meta handling

This essentially merges the two approaches to the metadata handling from ViaVersion and ViaBackwards and improves on both designs.

ViaVersion did not track every single entity, but only those needed (at least in theory) and can work with untracked entities' metadata. It had a very simple method overridden by metadata rewriter implementations, directly operating on the full metadata list and manually handling meta index changes as well as item/block/particle id changes.

ViaBackwards on the other hand had to track *every single* entity and threw warnings otherwise - while less prone to errors due to giving obvious warnings in the console, it unnecessarily tracks a lot of entities, and those warnings also annoys users when encountering virtual entity plugins (operating asynchronously and sending update packets while already untracked or not yet tracked). Dedicated MetaHandlers made id changes and filtering a lot easier to read and write. However, the actual metadata list handling and its distribution to handlers was not very well implemented and required a lot of list copying and creation as well as exception throws to cancel individual metadata entries.

This version has MetaFilters built with a Builder containing multiple helper functions, and the entity tracking is properly given its own map, hashed by a Protocol's class, to be easily and generically accessible from anywhere with only a Protocol class from the UserConnection, along with more optimized metadata list iteration. The entity tracking is largely unchanged, keeping ViaVersion's approach to not having to track *all* entities (and being able to handle null types in meta handlers).

All of this is by no means absolutely perfect, but is much less prone to errors than both previous systems and takes a lot less effort to actually write. A last possible change would be to use a primitive int to object map that is built to be concurrency save for the EntityTracker, tho that would have to be chosen carefully.
Dieser Commit ist enthalten in:
KennyTV 2021-05-24 23:24:50 +02:00
Ursprung 03638028cd
Commit 3a1e364d4a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
84 geänderte Dateien mit 1924 neuen und 972 gelöschten Zeilen

Datei anzeigen

@ -23,6 +23,8 @@
package com.viaversion.viaversion.api.connection; package com.viaversion.viaversion.api.connection;
import com.viaversion.viaversion.api.configuration.ViaVersionConfig; import com.viaversion.viaversion.api.configuration.ViaVersionConfig;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.PacketTracker; import com.viaversion.viaversion.api.protocol.packet.PacketTracker;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.exception.CancelException; import com.viaversion.viaversion.exception.CancelException;
@ -32,6 +34,7 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.function.Function; import java.util.function.Function;
@ -62,6 +65,30 @@ public interface UserConnection {
*/ */
void put(StoredObject object); void put(StoredObject object);
/**
* Returns a collection of entity trackers currently registered.
*
* @return collection of entity trackers currently registered
*/
Collection<EntityTracker> getEntityTrackers();
/**
* Returns the entity tracker by the given protocol class if present.
*
* @param protocolClass protocol class
* @param <T> entity tracker type
* @return entity tracker if present
*/
@Nullable <T extends EntityTracker> T getEntityTracker(Class<? extends Protocol> protocolClass);
/**
* Adds an entity tracker to the user connection.
*
* @param protocolClass protocol class
* @param tracker entity tracker
*/
void addEntityTracker(Class<? extends Protocol> protocolClass, EntityTracker tracker);
/** /**
* Clear all the stored objects. * Clear all the stored objects.
* Used for bungee when switching servers. * Used for bungee when switching servers.

Datei anzeigen

@ -20,9 +20,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
package com.viaversion.viaversion.api.platform; package com.viaversion.viaversion.api.data.entity;
public interface ExternalJoinGameListener { public interface ClientEntityIdChangeListener {
void onExternalJoinGame(int playerEntityId); void setClientEntityId(int entityId);
} }

Datei anzeigen

@ -0,0 +1,129 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.data.entity;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface EntityTracker extends ClientEntityIdChangeListener {
/**
* User connection the tracker belongs to.
*
* @return user connection
*/
UserConnection user();
/**
* Tracks an entity.
*
* @param id entity id
* @param type entity type
*/
void addEntity(int id, EntityType type);
/**
* Returns whether the entity is currently tracked.
*
* @param id entity id
* @return whether the entity is tracked
*/
boolean hasEntity(int id);
/**
* Entity type of the entity if tracked.
* This returning null does not necessarily mean no entity by the id exists.
*
* @param id entity id
* @return entity type of the entity if tracked
*/
@Nullable EntityType entityType(int id);
/**
* Untracks an entity.
*
* @param id entity id
*/
void removeEntity(int id);
/**
* Returns the stored entity data if an entity with the id is tracked, else null.
* If no data has been initialized yet, it will be done and returned by this method.
*
* @param id entity id
* @return stored entity data if an entity with the id is tracked, else null
*/
@Nullable StoredEntityData entityData(int id);
/**
* Returns stored entity data if it has previously been initialized by {@link #entityData(int)}, else null.
*
* @param id entity id
* @return stored entity data if it has previously been initialized by {@link #entityData(int)}
*/
@Nullable StoredEntityData entityDataIfPresent(int id);
/**
* Returns the client entity id or -1 if unset.
*
* @return client entity id or -1 if unset
*/
int clientEntityId();
/**
* Sets the client entity id.
*
* @param clientEntityId client entity id
*/
void setClientEntityId(int clientEntityId);
/**
* Returns the current world section height.
* Always 16 for sub 1.17 worlds.
*
* @return current world section height
*/
int currentWorldSectionHeight();
/**
* Sets the current world section height.
*
* @param currentWorldSectionHeight world section height
*/
void setCurrentWorldSectionHeight(int currentWorldSectionHeight);
/**
* Returns the minimum y of the current player world.
*
* @return minimum y of the current world
*/
int currentMinY();
/**
* Sets the minimum y of the current player world.
*
* @param currentMinY minimum y of the current world
*/
void setCurrentMinY(int currentMinY);
}

Datei anzeigen

@ -0,0 +1,60 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.data.entity;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface StoredEntityData {
/**
* Returns the entity type of the stored entity.
*
* @return entity type
*/
EntityType type();
/**
* Checks if the storage contains an object of the given type.
*
* @param objectClass object class to check
* @return whether an object of the given type is in the storage
*/
boolean has(Class<?> objectClass);
/**
* Returns an object from the storage if present.
*
* @param objectClass class of the object to get
* @param <T> object type
* @return object if present
*/
@Nullable <T> T get(Class<T> objectClass);
/**
* Stores an object based on its class.
*
* @param object object to store
*/
void put(Object object);
}

Datei anzeigen

@ -31,12 +31,12 @@ public interface MetaType {
* *
* @return Type instance * @return Type instance
*/ */
Type getType(); Type type();
/** /**
* Get type id from the specific MetaDataType * Get type id from the specific MetaDataType
* *
* @return Type id as an integer * @return Type id as an integer
*/ */
int getTypeID(); int typeId();
} }

Datei anzeigen

@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.minecraft.metadata;
import java.util.Objects; import java.util.Objects;
public class Metadata { public final class Metadata {
private int id; private int id;
private MetaType metaType; private MetaType metaType;
private Object value; private Object value;
@ -35,7 +35,7 @@ public class Metadata {
this.value = value; this.value = value;
} }
public int getId() { public int id() {
return id; return id;
} }
@ -43,7 +43,7 @@ public class Metadata {
this.id = id; this.id = id;
} }
public MetaType getMetaType() { public MetaType metaType() {
return metaType; return metaType;
} }
@ -51,12 +51,12 @@ public class Metadata {
this.metaType = metaType; this.metaType = metaType;
} }
public Object getValue() { public <T> T value() {
return value; return (T) value;
} }
public <T> T getCastedValue() { public Object getValue() {
return (T) value; return value;
} }
public void setValue(Object value) { public void setValue(Object value) {
@ -70,7 +70,7 @@ public class Metadata {
Metadata metadata = (Metadata) o; Metadata metadata = (Metadata) o;
if (id != metadata.id) return false; if (id != metadata.id) return false;
if (!Objects.equals(metaType, metadata.metaType)) return false; if (metaType != metaType) return false;
return Objects.equals(value, metadata.value); return Objects.equals(value, metadata.value);
} }

Datei anzeigen

@ -55,12 +55,12 @@ public enum MetaType1_12 implements MetaType {
} }
@Override @Override
public int getTypeID() { public int typeId() {
return typeID; return typeID;
} }
@Override @Override
public Type getType() { public Type type() {
return type; return type;
} }
} }

Datei anzeigen

@ -58,12 +58,12 @@ public enum MetaType1_13 implements MetaType {
} }
@Override @Override
public int getTypeID() { public int typeId() {
return typeID; return typeID;
} }
@Override @Override
public Type getType() { public Type type() {
return type; return type;
} }
} }

Datei anzeigen

@ -58,12 +58,12 @@ public enum MetaType1_13_2 implements MetaType {
} }
@Override @Override
public int getTypeID() { public int typeId() {
return typeID; return typeID;
} }
@Override @Override
public Type getType() { public Type type() {
return type; return type;
} }
} }

Datei anzeigen

@ -61,12 +61,12 @@ public enum MetaType1_14 implements MetaType {
} }
@Override @Override
public int getTypeID() { public int typeId() {
return typeID; return typeID;
} }
@Override @Override
public Type getType() { public Type type() {
return type; return type;
} }
} }

Datei anzeigen

@ -61,12 +61,12 @@ public enum MetaType1_17 implements MetaType {
} }
@Override @Override
public int getTypeID() { public int typeId() {
return typeID; return typeID;
} }
@Override @Override
public Type getType() { public Type type() {
return type; return type;
} }
} }

Datei anzeigen

@ -49,12 +49,12 @@ public enum MetaType1_8 implements MetaType {
} }
@Override @Override
public int getTypeID() { public int typeId() {
return typeID; return typeID;
} }
@Override @Override
public Type getType() { public Type type() {
return type; return type;
} }
} }

Datei anzeigen

@ -54,12 +54,12 @@ public enum MetaType1_9 implements MetaType {
} }
@Override @Override
public int getTypeID() { public int typeId() {
return typeID; return typeID;
} }
@Override @Override
public Type getType() { public Type type() {
return type; return type;
} }
} }

Datei anzeigen

@ -24,6 +24,8 @@ package com.viaversion.viaversion.api.protocol;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.Direction; import com.viaversion.viaversion.api.protocol.packet.Direction;
import com.viaversion.viaversion.api.protocol.packet.PacketType; import com.viaversion.viaversion.api.protocol.packet.PacketType;
@ -144,6 +146,10 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
protected void onMappingDataLoaded() { protected void onMappingDataLoaded() {
} }
public void addEntityTracker(UserConnection connection, EntityTracker tracker) {
connection.addEntityTracker(this.getClass(), tracker);
}
@Override @Override
public void registerServerbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) { public void registerServerbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) {
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper); ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);

Datei anzeigen

@ -32,7 +32,7 @@ public abstract class ModernMetaType extends MetaTypeTemplate {
final short index = buffer.readUnsignedByte(); final short index = buffer.readUnsignedByte();
if (index == 0xff) return null; // End of metadata if (index == 0xff) return null; // End of metadata
final MetaType type = this.getType(buffer.readByte()); final MetaType type = this.getType(buffer.readByte());
return new Metadata(index, type, type.getType().read(buffer)); return new Metadata(index, type, type.type().read(buffer));
} }
protected abstract MetaType getType(final int index); protected abstract MetaType getType(final int index);
@ -42,10 +42,10 @@ public abstract class ModernMetaType extends MetaTypeTemplate {
if (object == null) { if (object == null) {
buffer.writeByte(0xff); buffer.writeByte(0xff);
} else { } else {
buffer.writeByte(object.getId()); buffer.writeByte(object.id());
final MetaType type = object.getMetaType(); final MetaType type = object.metaType();
buffer.writeByte(type.getTypeID()); buffer.writeByte(type.typeId());
type.getType().write(buffer, object.getValue()); type.type().write(buffer, object.getValue());
} }
} }
} }

Datei anzeigen

@ -37,13 +37,13 @@ public class Metadata1_8Type extends MetaTypeTemplate {
int typeID = (item & 0xE0) >> 5; int typeID = (item & 0xE0) >> 5;
MetaType1_8 type = MetaType1_8.byId(typeID); MetaType1_8 type = MetaType1_8.byId(typeID);
int id = item & 0x1F; int id = item & 0x1F;
return new Metadata(id, type, type.getType().read(buffer)); return new Metadata(id, type, type.type().read(buffer));
} }
@Override @Override
public void write(ByteBuf buffer, Metadata meta) throws Exception { public void write(ByteBuf buffer, Metadata meta) throws Exception {
byte item = (byte) (meta.getMetaType().getTypeID() << 5 | meta.getId() & 0x1F); byte item = (byte) (meta.metaType().typeId() << 5 | meta.id() & 0x1F);
buffer.writeByte(item); buffer.writeByte(item);
meta.getMetaType().getType().write(buffer, meta.getValue()); meta.metaType().type().write(buffer, meta.getValue());
} }
} }

Datei anzeigen

@ -17,15 +17,15 @@
*/ */
package com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8; package com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
public class BlockListener extends ViaBukkitListener { public class BlockListener extends ViaBukkitListener {
@ -37,9 +37,8 @@ public class BlockListener extends ViaBukkitListener {
public void placeBlock(BlockPlaceEvent e) { public void placeBlock(BlockPlaceEvent e) {
if (isOnPipe(e.getPlayer())) { if (isOnPipe(e.getPlayer())) {
Block b = e.getBlockPlaced(); Block b = e.getBlockPlaced();
getUserConnection(e.getPlayer()) EntityTracker1_9 tracker = getUserConnection(e.getPlayer()).getEntityTracker(Protocol1_9To1_8.class);
.get(EntityTracker1_9.class) tracker.addBlockInteraction(new Position(b.getX(), (short) b.getY(), b.getZ()));
.addBlockInteraction(new Position(b.getX(), (short) b.getY(), b.getZ()));
} }
} }
} }

Datei anzeigen

@ -21,10 +21,11 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.ProtocolInfo; import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.StoredObject; import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.platform.ExternalJoinGameListener; import com.viaversion.viaversion.api.data.entity.ClientEntityIdChangeListener;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry; import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
import com.viaversion.viaversion.api.protocol.ProtocolPipeline; import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
@ -125,9 +126,15 @@ public class BungeeServerHandler implements Listener {
} catch (Exception ex) { } catch (Exception ex) {
return; // Ignored return; // Ignored
} }
for (StoredObject storedObject : userConnection.getStoredObjects().values()) {
if (storedObject instanceof ExternalJoinGameListener) { for (EntityTracker tracker : userConnection.getEntityTrackers()) {
((ExternalJoinGameListener) storedObject).onExternalJoinGame(playerId); tracker.setClientEntityId(playerId);
}
// For ViaRewind
for (StoredObject object : userConnection.getStoredObjects().values()) {
if (object instanceof ClientEntityIdChangeListener) {
((ClientEntityIdChangeListener) object).setClientEntityId(playerId);
} }
} }
} }
@ -143,7 +150,7 @@ public class BungeeServerHandler implements Listener {
if (e.getServer() != null) { if (e.getServer() != null) {
if (!e.getServer().getInfo().getName().equals(storage.getCurrentServer())) { if (!e.getServer().getInfo().getName().equals(storage.getCurrentServer())) {
// Clear auto-team // Clear auto-team
EntityTracker1_9 oldEntityTracker = user.get(EntityTracker1_9.class); EntityTracker1_9 oldEntityTracker = user.getEntityTracker(Protocol1_9To1_8.class);
if (oldEntityTracker != null) { if (oldEntityTracker != null) {
if (oldEntityTracker.isAutoTeam() && oldEntityTracker.isTeamExists()) { if (oldEntityTracker.isAutoTeam() && oldEntityTracker.isTeamExists()) {
oldEntityTracker.sendTeamPacket(false, true); oldEntityTracker.sendTeamPacket(false, true);
@ -239,7 +246,7 @@ public class BungeeServerHandler implements Listener {
protocol.init(user); protocol.init(user);
} }
EntityTracker1_9 newTracker = user.get(EntityTracker1_9.class); EntityTracker1_9 newTracker = user.getEntityTracker(Protocol1_9To1_8.class);
if (newTracker != null) { if (newTracker != null) {
if (Via.getConfig().isAutoTeam()) { if (Via.getConfig().isAutoTeam()) {
String currentTeam = null; String currentTeam = null;

Datei anzeigen

@ -45,7 +45,8 @@ public class ElytraPatch implements Listener {
try { try {
if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) { if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
int entityId = user.get(EntityTracker1_9.class).getProvidedEntityId(); EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
int entityId = tracker.getProvidedEntityId();
PacketWrapper wrapper = PacketWrapper.create(0x39, null, user); PacketWrapper wrapper = PacketWrapper.create(0x39, null, user);

Datei anzeigen

@ -22,6 +22,8 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.ProtocolInfo; import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.StoredObject; import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.Direction; import com.viaversion.viaversion.api.protocol.packet.Direction;
import com.viaversion.viaversion.api.protocol.packet.PacketTracker; import com.viaversion.viaversion.api.protocol.packet.PacketTracker;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@ -35,7 +37,9 @@ import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -48,6 +52,7 @@ public class UserConnectionImpl implements UserConnection {
private static final AtomicLong IDS = new AtomicLong(); private static final AtomicLong IDS = new AtomicLong();
private final long id = IDS.incrementAndGet(); private final long id = IDS.incrementAndGet();
private final Map<Class<?>, StoredObject> storedObjects = new ConcurrentHashMap<>(); private final Map<Class<?>, StoredObject> storedObjects = new ConcurrentHashMap<>();
private final Map<Class<? extends Protocol>, EntityTracker> entityTrackers = new HashMap<>();
private final PacketTracker packetTracker = new PacketTracker(this); private final PacketTracker packetTracker = new PacketTracker(this);
private final Set<UUID> passthroughTokens = Collections.newSetFromMap(CacheBuilder.newBuilder() private final Set<UUID> passthroughTokens = Collections.newSetFromMap(CacheBuilder.newBuilder()
.expireAfterWrite(10, TimeUnit.SECONDS) .expireAfterWrite(10, TimeUnit.SECONDS)
@ -91,6 +96,21 @@ public class UserConnectionImpl implements UserConnection {
storedObjects.put(object.getClass(), object); storedObjects.put(object.getClass(), object);
} }
@Override
public Collection<EntityTracker> getEntityTrackers() {
return entityTrackers.values();
}
@Override
public @Nullable <T extends EntityTracker> T getEntityTracker(Class<? extends Protocol> protocolClass) {
return (T) entityTrackers.get(protocolClass);
}
@Override
public void addEntityTracker(Class<? extends Protocol> protocolClass, EntityTracker tracker) {
entityTrackers.put(protocolClass, tracker);
}
@Override @Override
public void clearStoredObjects() { public void clearStoredObjects() {
storedObjects.clear(); storedObjects.clear();

Datei anzeigen

@ -1,68 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.data;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.platform.ExternalJoinGameListener;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public abstract class EntityTracker extends StoredObject implements ExternalJoinGameListener {
private final Map<Integer, EntityType> clientEntityTypes = new ConcurrentHashMap<>();
private final EntityType playerType;
private int clientEntityId;
protected EntityTracker(UserConnection user, EntityType playerType) {
super(user);
this.playerType = playerType;
}
public void removeEntity(int entityId) {
clientEntityTypes.remove(entityId);
}
public void addEntity(int entityId, EntityType type) {
clientEntityTypes.put(entityId, type);
}
public boolean hasEntity(int entityId) {
return clientEntityTypes.containsKey(entityId);
}
public @Nullable EntityType getEntity(int entityId) {
return clientEntityTypes.get(entityId);
}
@Override
public void onExternalJoinGame(int playerEntityId) {
clientEntityId = playerEntityId;
clientEntityTypes.put(playerEntityId, playerType);
}
public int getClientEntityId() {
return clientEntityId;
}
public void setClientEntityId(int clientEntityId) {
this.clientEntityId = clientEntityId;
}
}

Datei anzeigen

@ -0,0 +1,133 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.data.entity;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class EntityTrackerBase implements EntityTracker {
private final Map<Integer, EntityType> entityTypes = new ConcurrentHashMap<>();
private final Map<Integer, StoredEntityData> entityData;
private final UserConnection connection;
private final EntityType playerType;
private int clientEntityId = -1;
private int currentWorldSectionHeight = 16;
private int currentMinY;
public EntityTrackerBase(UserConnection connection, @Nullable EntityType playerType) {
this(connection, playerType, false);
}
public EntityTrackerBase(UserConnection connection, @Nullable EntityType playerType, boolean storesEntityData) {
this.connection = connection;
this.playerType = playerType;
this.entityData = storesEntityData ? new ConcurrentHashMap<>() : null;
}
@Override
public UserConnection user() {
return connection;
}
@Override
public void addEntity(int id, EntityType type) {
entityTypes.put(id, type);
}
@Override
public boolean hasEntity(int id) {
return entityTypes.containsKey(id);
}
@Override
public @Nullable EntityType entityType(int id) {
return entityTypes.get(id);
}
@Override
public StoredEntityData entityData(int id) {
EntityType type = entityType(id);
return entityData.computeIfAbsent(id, s -> new StoredEntityImpl(type));
}
@Override
public @Nullable StoredEntityData entityDataIfPresent(int id) {
return entityData.get(id);
}
@Override
public void removeEntity(int id) {
entityTypes.remove(id);
if (entityData != null) {
entityData.remove(id);
}
}
@Override
public int clientEntityId() {
return clientEntityId;
}
@Override
public void setClientEntityId(int clientEntityId) {
Preconditions.checkNotNull(playerType);
entityTypes.put(clientEntityId, playerType);
if (entityData != null) {
StoredEntityData data = entityData.remove(this.clientEntityId);
if (data != null) {
entityData.put(clientEntityId, data);
}
}
this.clientEntityId = clientEntityId;
}
/**
* @return amount of chunk sections of the current world (block height / 16)
*/
@Override
public int currentWorldSectionHeight() {
return currentWorldSectionHeight;
}
@Override
public void setCurrentWorldSectionHeight(int currentWorldSectionHeight) {
this.currentWorldSectionHeight = currentWorldSectionHeight;
}
/**
* @return absolute minimum y coordinate of the current world
*/
@Override
public int currentMinY() {
return currentMinY;
}
@Override
public void setCurrentMinY(int currentMinY) {
this.currentMinY = currentMinY;
}
}

Datei anzeigen

@ -0,0 +1,54 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.data.entity;
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public final class StoredEntityImpl implements StoredEntityData {
private final Map<Class<?>, Object> storedObjects = new ConcurrentHashMap<>();
private final EntityType type;
public StoredEntityImpl(EntityType type) {
this.type = type;
}
@Override
public EntityType type() {
return type;
}
@Override
public @Nullable <T> T get(Class<T> objectClass) {
return (T) storedObjects.get(objectClass);
}
@Override
public boolean has(Class<?> objectClass) {
return storedObjects.containsKey(objectClass);
}
@Override
public void put(Object object) {
storedObjects.put(object.getClass(), object);
}
}

Datei anzeigen

@ -48,8 +48,8 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
public List<Metadata> transform(PacketWrapper wrapper, List<Metadata> inputValue) throws Exception { public List<Metadata> transform(PacketWrapper wrapper, List<Metadata> inputValue) throws Exception {
List<Metadata> metaList = new CopyOnWriteArrayList<>(inputValue); List<Metadata> metaList = new CopyOnWriteArrayList<>(inputValue);
for (Metadata m : metaList) { for (Metadata m : metaList) {
if (m.getId() >= 5) if (m.id() >= 5)
m.setId(m.getId() + 1); m.setId(m.id() + 1);
} }
return metaList; return metaList;
} }

Datei anzeigen

@ -39,7 +39,7 @@ import com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import com.viaversion.viaversion.rewriter.MetadataRewriter; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.util.Pair; import com.viaversion.viaversion.util.Pair;
@ -57,7 +57,8 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
@Override @Override
protected void registerPackets() { protected void registerPackets() {
MetadataRewriter metadataRewriter = new MetadataRewriter1_11To1_10(this); EntityRewriter metadataRewriter = new MetadataRewriter1_11To1_10(this);
metadataRewriter.register();
InventoryPackets.register(this); InventoryPackets.register(this);
@ -69,7 +70,7 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
map(Type.BYTE); // 2 - Type map(Type.BYTE); // 2 - Type
// Track Entity // Track Entity
handler(metadataRewriter.getObjectTracker()); handler(metadataRewriter.objectTrackerHandler());
} }
}); });
@ -102,7 +103,7 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
wrapper.set(Type.VAR_INT, 1, entType.getId()); wrapper.set(Type.VAR_INT, 1, entType.getId());
// Register Type ID // Register Type ID
wrapper.user().get(EntityTracker1_11.class).addEntity(entityId, entType); wrapper.user().getEntityTracker(Protocol1_11To1_10.class).addEntity(entityId, entType);
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user()); metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
} }
} }
@ -145,7 +146,7 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0); int entityID = wrapper.get(Type.VAR_INT, 0);
if (Via.getConfig().isHologramPatch()) { if (Via.getConfig().isHologramPatch()) {
EntityTracker1_11 tracker = wrapper.user().get(EntityTracker1_11.class); EntityTracker1_11 tracker = wrapper.user().getEntityTracker(Protocol1_11To1_10.class);
if (tracker.isHologram(entityID)) { if (tracker.isHologram(entityID)) {
Double newValue = wrapper.get(Type.DOUBLE, 1); Double newValue = wrapper.get(Type.DOUBLE, 1);
newValue -= (Via.getConfig().getHologramYOffset()); newValue -= (Via.getConfig().getHologramYOffset());
@ -157,7 +158,7 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
} }
}); });
metadataRewriter.registerEntityDestroy(ClientboundPackets1_9_3.DESTROY_ENTITIES); metadataRewriter.registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
registerClientbound(ClientboundPackets1_9_3.TITLE, new PacketRemapper() { registerClientbound(ClientboundPackets1_9_3.TITLE, new PacketRemapper() {
@Override @Override
@ -377,7 +378,7 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
// Entity tracker // Entity tracker
userConnection.put(new EntityTracker1_11(userConnection)); userConnection.addEntityTracker(this.getClass(), new EntityTracker1_11(userConnection));
if (!userConnection.has(ClientWorld.class)) if (!userConnection.has(ClientWorld.class))
userConnection.put(new ClientWorld(userConnection)); userConnection.put(new ClientWorld(userConnection));

Datei anzeigen

@ -29,15 +29,15 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_11to1_10.EntityIdRewriter; import com.viaversion.viaversion.protocols.protocol1_11to1_10.EntityIdRewriter;
import com.viaversion.viaversion.protocols.protocol1_11to1_10.Protocol1_11To1_10; import com.viaversion.viaversion.protocols.protocol1_11to1_10.Protocol1_11To1_10;
import com.viaversion.viaversion.protocols.protocol1_11to1_10.storage.EntityTracker1_11; import com.viaversion.viaversion.protocols.protocol1_11to1_10.storage.EntityTracker1_11;
import com.viaversion.viaversion.rewriter.MetadataRewriter; import com.viaversion.viaversion.rewriter.EntityRewriter;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
public class MetadataRewriter1_11To1_10 extends MetadataRewriter { public class MetadataRewriter1_11To1_10 extends EntityRewriter<Protocol1_11To1_10> {
public MetadataRewriter1_11To1_10(Protocol1_11To1_10 protocol) { public MetadataRewriter1_11To1_10(Protocol1_11To1_10 protocol) {
super(protocol, EntityTracker1_11.class); super(protocol);
} }
@Override @Override
@ -49,7 +49,7 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter {
if (type == null) return; if (type == null) return;
if (type.is(EntityType.ELDER_GUARDIAN) || type.is(EntityType.GUARDIAN)) { // Guardians if (type.is(EntityType.ELDER_GUARDIAN) || type.is(EntityType.GUARDIAN)) { // Guardians
int oldid = metadata.getId(); int oldid = metadata.id();
if (oldid == 12) { if (oldid == 12) {
metadata.setMetaType(MetaType1_9.Boolean); metadata.setMetaType(MetaType1_9.Boolean);
boolean val = (((byte) metadata.getValue()) & 0x02) == 0x02; boolean val = (((byte) metadata.getValue()) & 0x02) == 0x02;
@ -58,7 +58,7 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter {
} }
if (type.isOrHasParent(EntityType.ABSTRACT_SKELETON)) { // Skeletons if (type.isOrHasParent(EntityType.ABSTRACT_SKELETON)) { // Skeletons
int oldid = metadata.getId(); int oldid = metadata.id();
if (oldid == 12) { if (oldid == 12) {
metadatas.remove(metadata); metadatas.remove(metadata);
} }
@ -68,13 +68,13 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter {
} }
if (type.isOrHasParent(EntityType.ZOMBIE)) { // Zombie | Zombie Villager | Husk if (type.isOrHasParent(EntityType.ZOMBIE)) { // Zombie | Zombie Villager | Husk
if (type.is(EntityType.ZOMBIE, EntityType.HUSK) && metadata.getId() == 14) { if (type.is(EntityType.ZOMBIE, EntityType.HUSK) && metadata.id() == 14) {
metadatas.remove(metadata); metadatas.remove(metadata);
} else { } else {
if (metadata.getId() == 15) { if (metadata.id() == 15) {
metadata.setId(14); metadata.setId(14);
} else { } else {
if (metadata.getId() == 14) { if (metadata.id() == 14) {
metadata.setId(15); metadata.setId(15);
} }
} }
@ -83,7 +83,7 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter {
if (type.isOrHasParent(EntityType.ABSTRACT_HORSE)) { // Horses if (type.isOrHasParent(EntityType.ABSTRACT_HORSE)) { // Horses
// Remap metadata id // Remap metadata id
int oldid = metadata.getId(); int oldid = metadata.id();
if (oldid == 14) { // Type if (oldid == 14) { // Type
metadatas.remove(metadata); metadatas.remove(metadata);
} }
@ -99,13 +99,13 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter {
// Normal Horse // Normal Horse
} else { } else {
// Remove 15, 16 // Remove 15, 16
if (metadata.getId() == 15 || metadata.getId() == 16) { if (metadata.id() == 15 || metadata.id() == 16) {
metadatas.remove(metadata); metadatas.remove(metadata);
} }
} }
if (type.is(EntityType.DONKEY, EntityType.MULE)) { if (type.is(EntityType.DONKEY, EntityType.MULE)) {
// Chested Horse // Chested Horse
if (metadata.getId() == 13) { if (metadata.id() == 13) {
if ((((byte) metadata.getValue()) & 0x08) == 0x08) { if ((((byte) metadata.getValue()) & 0x08) == 0x08) {
metadatas.add(new Metadata(15, MetaType1_9.Boolean, true)); metadatas.add(new Metadata(15, MetaType1_9.Boolean, true));
} else { } else {
@ -116,15 +116,15 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter {
} }
if (type.is(EntityType.ARMOR_STAND) && Via.getConfig().isHologramPatch()) { if (type.is(EntityType.ARMOR_STAND) && Via.getConfig().isHologramPatch()) {
Metadata flags = getMetaByIndex(11, metadatas); Metadata flags = metaByIndex(11, metadatas);
Metadata customName = getMetaByIndex(2, metadatas); Metadata customName = metaByIndex(2, metadatas);
Metadata customNameVisible = getMetaByIndex(3, metadatas); Metadata customNameVisible = metaByIndex(3, metadatas);
if (metadata.getId() == 0 && flags != null && customName != null && customNameVisible != null) { if (metadata.id() == 0 && flags != null && customName != null && customNameVisible != null) {
byte data = (byte) metadata.getValue(); byte data = (byte) metadata.getValue();
// Check invisible | Check small | Check if custom name is empty | Check if custom name visible is true // Check invisible | Check small | Check if custom name is empty | Check if custom name visible is true
if ((data & 0x20) == 0x20 && ((byte) flags.getValue() & 0x01) == 0x01 if ((data & 0x20) == 0x20 && ((byte) flags.getValue() & 0x01) == 0x01
&& !((String) customName.getValue()).isEmpty() && (boolean) customNameVisible.getValue()) { && !((String) customName.getValue()).isEmpty() && (boolean) customNameVisible.getValue()) {
EntityTracker1_11 tracker = connection.get(EntityTracker1_11.class); EntityTracker1_11 tracker = tracker(connection);
if (!tracker.isHologram(entityId)) { if (!tracker.isHologram(entityId)) {
tracker.addHologram(entityId); tracker.addHologram(entityId);
try { try {
@ -147,12 +147,12 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter {
} }
@Override @Override
protected com.viaversion.viaversion.api.minecraft.entities.EntityType getTypeFromId(int type) { protected com.viaversion.viaversion.api.minecraft.entities.EntityType typeFromId(int type) {
return Entity1_11Types.getTypeFromId(type, false); return Entity1_11Types.getTypeFromId(type, false);
} }
@Override @Override
protected com.viaversion.viaversion.api.minecraft.entities.EntityType getObjectTypeFromId(int type) { protected com.viaversion.viaversion.api.minecraft.entities.EntityType objectTypeFromId(int type) {
return Entity1_11Types.getTypeFromId(type, true); return Entity1_11Types.getTypeFromId(type, true);
} }
@ -240,7 +240,7 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter {
public static Optional<Metadata> getById(List<Metadata> metadatas, int id) { public static Optional<Metadata> getById(List<Metadata> metadatas, int id) {
for (Metadata metadata : metadatas) { for (Metadata metadata : metadatas) {
if (metadata.getId() == id) return Optional.of(metadata); if (metadata.id() == id) return Optional.of(metadata);
} }
return Optional.empty(); return Optional.empty();
} }

Datei anzeigen

@ -20,11 +20,11 @@ package com.viaversion.viaversion.protocols.protocol1_11to1_10.storage;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types.EntityType; import com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types.EntityType;
import com.viaversion.viaversion.data.EntityTracker; import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import java.util.Set; import java.util.Set;
public class EntityTracker1_11 extends EntityTracker { public class EntityTracker1_11 extends EntityTrackerBase {
private final Set<Integer> holograms = Sets.newConcurrentHashSet(); private final Set<Integer> holograms = Sets.newConcurrentHashSet();
public EntityTracker1_11(UserConnection user) { public EntityTracker1_11(UserConnection user) {

Datei anzeigen

@ -25,6 +25,7 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_12Types;
import com.viaversion.viaversion.api.platform.providers.ViaProviders; import com.viaversion.viaversion.api.platform.providers.ViaProviders;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@ -32,16 +33,16 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_12; import com.viaversion.viaversion.api.type.types.version.Types1_12;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.metadata.MetadataRewriter1_12To1_11_1; import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.metadata.MetadataRewriter1_12To1_11_1;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider; import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.storage.EntityTracker1_12;
import com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.rewriter.MetadataRewriter; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9_3, ClientboundPackets1_12, ServerboundPackets1_9_3, ServerboundPackets1_12> { public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9_3, ClientboundPackets1_12, ServerboundPackets1_9_3, ServerboundPackets1_12> {
@ -52,7 +53,8 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9
@Override @Override
protected void registerPackets() { protected void registerPackets() {
MetadataRewriter metadataRewriter = new MetadataRewriter1_12To1_11_1(this); EntityRewriter metadataRewriter = new MetadataRewriter1_12To1_11_1(this);
metadataRewriter.register();
InventoryPackets.register(this); InventoryPackets.register(this);
@ -64,7 +66,7 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9
map(Type.BYTE); // 2 - Type map(Type.BYTE); // 2 - Type
// Track Entity // Track Entity
handler(metadataRewriter.getObjectTracker()); handler(metadataRewriter.objectTrackerHandler());
} }
}); });
@ -86,7 +88,7 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9
map(Types1_12.METADATA_LIST); // 12 - Metadata map(Types1_12.METADATA_LIST); // 12 - Metadata
// Track mob and rewrite metadata // Track mob and rewrite metadata
handler(metadataRewriter.getTrackerAndRewriter(Types1_12.METADATA_LIST)); handler(metadataRewriter.trackerAndRewriterHandler(Types1_12.METADATA_LIST));
} }
}); });
@ -153,7 +155,7 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9
} }
}); });
metadataRewriter.registerEntityDestroy(ClientboundPackets1_9_3.DESTROY_ENTITIES); metadataRewriter.registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_12.METADATA_LIST); metadataRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_12.METADATA_LIST);
registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() { registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() {
@ -255,7 +257,7 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker1_12(userConnection)); userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, Entity1_12Types.EntityType.PLAYER));
if (!userConnection.has(ClientWorld.class)) { if (!userConnection.has(ClientWorld.class)) {
userConnection.put(new ClientWorld(userConnection)); userConnection.put(new ClientWorld(userConnection));
} }

Datei anzeigen

@ -24,15 +24,14 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.BedRewriter; import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.BedRewriter;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1; import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.storage.EntityTracker1_12; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter;
import java.util.List; import java.util.List;
public class MetadataRewriter1_12To1_11_1 extends MetadataRewriter { public class MetadataRewriter1_12To1_11_1 extends EntityRewriter<Protocol1_12To1_11_1> {
public MetadataRewriter1_12To1_11_1(Protocol1_12To1_11_1 protocol) { public MetadataRewriter1_12To1_11_1(Protocol1_12To1_11_1 protocol) {
super(protocol, EntityTracker1_12.class); super(protocol);
} }
@Override @Override
@ -45,19 +44,19 @@ public class MetadataRewriter1_12To1_11_1 extends MetadataRewriter {
if (type == null) return; if (type == null) return;
// Evocation Illager aggressive property became 13 // Evocation Illager aggressive property became 13
if (type == Entity1_12Types.EntityType.EVOCATION_ILLAGER) { if (type == Entity1_12Types.EntityType.EVOCATION_ILLAGER) {
if (metadata.getId() == 12) { if (metadata.id() == 12) {
metadata.setId(13); metadata.setId(13);
} }
} }
} }
@Override @Override
protected EntityType getTypeFromId(int type) { protected EntityType typeFromId(int type) {
return Entity1_12Types.getTypeFromId(type, false); return Entity1_12Types.getTypeFromId(type, false);
} }
@Override @Override
protected EntityType getObjectTypeFromId(int type) { protected EntityType objectTypeFromId(int type) {
return Entity1_12Types.getTypeFromId(type, true); return Entity1_12Types.getTypeFromId(type, true);
} }
} }

Datei anzeigen

@ -1,29 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_12to1_11_1.storage;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_12Types.EntityType;
import com.viaversion.viaversion.data.EntityTracker;
public class EntityTracker1_12 extends EntityTracker {
public EntityTracker1_12(UserConnection user) {
super(user, EntityType.PLAYER);
}
}

Datei anzeigen

@ -20,6 +20,7 @@ package com.viaversion.viaversion.protocols.protocol1_13_1to1_13;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData; import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.data.MappingDataBase; import com.viaversion.viaversion.api.data.MappingDataBase;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@ -27,13 +28,13 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13; import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.EntityPackets; import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.EntityPackets;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.WorldPackets; import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import com.viaversion.viaversion.rewriter.RegistryType; import com.viaversion.viaversion.rewriter.RegistryType;
import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter;
@ -49,7 +50,8 @@ public class Protocol1_13_1To1_13 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
protected void registerPackets() { protected void registerPackets() {
new MetadataRewriter1_13_1To1_13(this); MetadataRewriter1_13_1To1_13 metadataRewriter = new MetadataRewriter1_13_1To1_13(this);
metadataRewriter.register();
EntityPackets.register(this); EntityPackets.register(this);
InventoryPackets.register(this); InventoryPackets.register(this);
@ -148,7 +150,7 @@ public class Protocol1_13_1To1_13 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker1_13(userConnection)); userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, Entity1_13Types.EntityType.PLAYER));
if (!userConnection.has(ClientWorld.class)) { if (!userConnection.has(ClientWorld.class)) {
userConnection.put(new ClientWorld(userConnection)); userConnection.put(new ClientWorld(userConnection));
} }

Datei anzeigen

@ -26,48 +26,47 @@ import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_13;
import com.viaversion.viaversion.api.type.types.Particle; import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13; import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter;
import java.util.List; import java.util.List;
public class MetadataRewriter1_13_1To1_13 extends MetadataRewriter { public class MetadataRewriter1_13_1To1_13 extends EntityRewriter<Protocol1_13_1To1_13> {
public MetadataRewriter1_13_1To1_13(Protocol1_13_1To1_13 protocol) { public MetadataRewriter1_13_1To1_13(Protocol1_13_1To1_13 protocol) {
super(protocol, EntityTracker1_13.class); super(protocol);
} }
@Override @Override
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) { protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
// 1.13 changed item to flat item (no data) // 1.13 changed item to flat item (no data)
if (metadata.getMetaType() == MetaType1_13.Slot) { if (metadata.metaType() == MetaType1_13.Slot) {
InventoryPackets.toClient((Item) metadata.getValue()); InventoryPackets.toClient((Item) metadata.getValue());
} else if (metadata.getMetaType() == MetaType1_13.BlockID) { } else if (metadata.metaType() == MetaType1_13.BlockID) {
// Convert to new block id // Convert to new block id
int data = (int) metadata.getValue(); int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (metadata.getMetaType() == MetaType1_13.PARTICLE) { } else if (metadata.metaType() == MetaType1_13.PARTICLE) {
rewriteParticle((Particle) metadata.getValue()); rewriteParticle((Particle) metadata.getValue());
} }
if (type == null) return; if (type == null) return;
if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) { if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.id() == 9) {
// New block format // New block format
int data = (int) metadata.getValue(); int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (type.isOrHasParent(Entity1_13Types.EntityType.ABSTRACT_ARROW) && metadata.getId() >= 7) { } else if (type.isOrHasParent(Entity1_13Types.EntityType.ABSTRACT_ARROW) && metadata.id() >= 7) {
metadata.setId(metadata.getId() + 1); // New shooter UUID metadata.setId(metadata.id() + 1); // New shooter UUID
} }
} }
@Override @Override
protected EntityType getTypeFromId(int type) { protected EntityType typeFromId(int type) {
return Entity1_13Types.getTypeFromId(type, false); return Entity1_13Types.getTypeFromId(type, false);
} }
@Override @Override
protected EntityType getObjectTypeFromId(int type) { protected EntityType objectTypeFromId(int type) {
return Entity1_13Types.getTypeFromId(type, true); return Entity1_13Types.getTypeFromId(type, true);
} }
} }

Datei anzeigen

@ -26,7 +26,6 @@ import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13; import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13; import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
public class EntityPackets { public class EntityPackets {
@ -60,7 +59,7 @@ public class EntityPackets {
wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(data)); wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} }
// Register Type ID // Register Type ID
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType); wrapper.user().getEntityTracker(Protocol1_13_1To1_13.class).addEntity(entityId, entType);
} }
} }
}); });
@ -84,7 +83,7 @@ public class EntityPackets {
map(Type.SHORT); // 11 - Velocity Z map(Type.SHORT); // 11 - Velocity Z
map(Types1_13.METADATA_LIST); // 12 - Metadata map(Types1_13.METADATA_LIST); // 12 - Metadata
handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST)); handler(metadataRewriter.trackerAndRewriterHandler(Types1_13.METADATA_LIST));
} }
}); });
@ -100,11 +99,11 @@ public class EntityPackets {
map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 6 - Pitch
map(Types1_13.METADATA_LIST); // 7 - Metadata map(Types1_13.METADATA_LIST); // 7 - Metadata
handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER)); handler(metadataRewriter.trackerAndRewriterHandler(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER));
} }
}); });
metadataRewriter.registerEntityDestroy(ClientboundPackets1_13.DESTROY_ENTITIES); metadataRewriter.registerRemoveEntities(ClientboundPackets1_13.DESTROY_ENTITIES);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13.METADATA_LIST); metadataRewriter.registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13.METADATA_LIST);
} }
} }

Datei anzeigen

@ -32,7 +32,7 @@ public class EntityPackets {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
final PacketHandler metaTypeHandler = wrapper -> { final PacketHandler metaTypeHandler = wrapper -> {
for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) {
metadata.setMetaType(MetaType1_13_2.byId(metadata.getMetaType().getTypeID())); metadata.setMetaType(MetaType1_13_2.byId(metadata.metaType().typeId()));
} }
}; };

Datei anzeigen

@ -35,6 +35,7 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.protocol.remapper.ValueCreator; import com.viaversion.viaversion.api.protocol.remapper.ValueCreator;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
@ -53,10 +54,9 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockE
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PaintingProvider; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PaintingProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockConnectionStorage; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockConnectionStorage;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.TabCompleteTracker; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.TabCompleteTracker;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import com.viaversion.viaversion.rewriter.MetadataRewriter; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.util.ChatColorUtil; import com.viaversion.viaversion.util.ChatColorUtil;
import com.viaversion.viaversion.util.GsonUtil; import com.viaversion.viaversion.util.GsonUtil;
@ -162,7 +162,8 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
protected void registerPackets() { protected void registerPackets() {
MetadataRewriter metadataRewriter = new MetadataRewriter1_13To1_12_2(this); EntityRewriter metadataRewriter = new MetadataRewriter1_13To1_12_2(this);
metadataRewriter.register();
// Register grouped packet changes // Register grouped packet changes
EntityPackets.register(this); EntityPackets.register(this);
@ -422,7 +423,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
// Store the player // Store the player
int entityId = wrapper.get(Type.INT, 0); int entityId = wrapper.get(Type.INT, 0);
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, Entity1_13Types.EntityType.PLAYER); wrapper.user().getEntityTracker(Protocol1_13To1_12_2.class).addEntity(entityId, Entity1_13Types.EntityType.PLAYER);
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1); int dimensionId = wrapper.get(Type.INT, 1);
@ -1045,7 +1046,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker1_13(userConnection)); userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, Entity1_13Types.EntityType.PLAYER));
userConnection.put(new TabCompleteTracker(userConnection)); userConnection.put(new TabCompleteTracker(userConnection));
if (!userConnection.has(ClientWorld.class)) if (!userConnection.has(ClientWorld.class))
userConnection.put(new ClientWorld(userConnection)); userConnection.put(new ClientWorld(userConnection));

Datei anzeigen

@ -30,28 +30,27 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.EntityTypeR
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.ParticleRewriter; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.WorldPackets; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter;
import java.util.List; import java.util.List;
public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter { public class MetadataRewriter1_13To1_12_2 extends EntityRewriter<Protocol1_13To1_12_2> {
public MetadataRewriter1_13To1_12_2(Protocol1_13To1_12_2 protocol) { public MetadataRewriter1_13To1_12_2(Protocol1_13To1_12_2 protocol) {
super(protocol, EntityTracker1_13.class); super(protocol);
} }
@Override @Override
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception { protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
// Handle new MetaTypes // Handle new MetaTypes
if (metadata.getMetaType().getTypeID() > 4) { if (metadata.metaType().typeId() > 4) {
metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID() + 1)); metadata.setMetaType(MetaType1_13.byId(metadata.metaType().typeId() + 1));
} else { } else {
metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID())); metadata.setMetaType(MetaType1_13.byId(metadata.metaType().typeId()));
} }
// Handle String -> Chat DisplayName // Handle String -> Chat DisplayName
if (metadata.getId() == 2) { if (metadata.id() == 2) {
metadata.setMetaType(MetaType1_13.OptChat); metadata.setMetaType(MetaType1_13.OptChat);
if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) { if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) {
metadata.setValue(ChatRewriter.legacyTextToJson((String) metadata.getValue())); metadata.setValue(ChatRewriter.legacyTextToJson((String) metadata.getValue()));
@ -61,7 +60,7 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter {
} }
// Remap held block to match new format for remapping to flat block // Remap held block to match new format for remapping to flat block
if (type == Entity1_13Types.EntityType.ENDERMAN && metadata.getId() == 12) { if (type == Entity1_13Types.EntityType.ENDERMAN && metadata.id() == 12) {
int stateId = (int) metadata.getValue(); int stateId = (int) metadata.getValue();
int id = stateId & 4095; int id = stateId & 4095;
int data = stateId >> 12 & 15; int data = stateId >> 12 & 15;
@ -69,10 +68,10 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter {
} }
// 1.13 changed item to flat item (no data) // 1.13 changed item to flat item (no data)
if (metadata.getMetaType() == MetaType1_13.Slot) { if (metadata.metaType() == MetaType1_13.Slot) {
metadata.setMetaType(MetaType1_13.Slot); metadata.setMetaType(MetaType1_13.Slot);
InventoryPackets.toClient((Item) metadata.getValue()); InventoryPackets.toClient((Item) metadata.getValue());
} else if (metadata.getMetaType() == MetaType1_13.BlockID) { } else if (metadata.metaType() == MetaType1_13.BlockID) {
// Convert to new block id // Convert to new block id
metadata.setValue(WorldPackets.toNewId((int) metadata.getValue())); metadata.setValue(WorldPackets.toNewId((int) metadata.getValue()));
} }
@ -81,18 +80,18 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter {
if (type == null) return; if (type == null) return;
// Handle new colors // Handle new colors
if (type == Entity1_13Types.EntityType.WOLF && metadata.getId() == 17) { if (type == Entity1_13Types.EntityType.WOLF && metadata.id() == 17) {
metadata.setValue(15 - (int) metadata.getValue()); metadata.setValue(15 - (int) metadata.getValue());
} }
// Handle new zombie meta (INDEX 15 - Boolean - Zombie is shaking while enabled) // Handle new zombie meta (INDEX 15 - Boolean - Zombie is shaking while enabled)
if (type.isOrHasParent(Entity1_13Types.EntityType.ZOMBIE)) { if (type.isOrHasParent(Entity1_13Types.EntityType.ZOMBIE)) {
if (metadata.getId() > 14) if (metadata.id() > 14)
metadata.setId(metadata.getId() + 1); metadata.setId(metadata.id() + 1);
} }
// Handle Minecart inner block // Handle Minecart inner block
if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) { if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.id() == 9) {
// New block format // New block format
int oldId = (int) metadata.getValue(); int oldId = (int) metadata.getValue();
int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15)); int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
@ -102,10 +101,10 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter {
// Handle other changes // Handle other changes
if (type == Entity1_13Types.EntityType.AREA_EFFECT_CLOUD) { if (type == Entity1_13Types.EntityType.AREA_EFFECT_CLOUD) {
if (metadata.getId() == 9) { if (metadata.id() == 9) {
int particleId = (int) metadata.getValue(); int particleId = (int) metadata.getValue();
Metadata parameter1Meta = getMetaByIndex(10, metadatas); Metadata parameter1Meta = metaByIndex(10, metadatas);
Metadata parameter2Meta = getMetaByIndex(11, metadatas); Metadata parameter2Meta = metaByIndex(11, metadatas);
int parameter1 = parameter1Meta != null ? (int) parameter1Meta.getValue() : 0; int parameter1 = parameter1Meta != null ? (int) parameter1Meta.getValue() : 0;
int parameter2 = parameter2Meta != null ? (int) parameter2Meta.getValue() : 0; int parameter2 = parameter2Meta != null ? (int) parameter2Meta.getValue() : 0;
@ -115,11 +114,11 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter {
} }
} }
if (metadata.getId() >= 9) if (metadata.id() >= 9)
metadatas.remove(metadata); // Remove metadatas.remove(metadata); // Remove
} }
if (metadata.getId() == 0) { if (metadata.id() == 0) {
metadata.setValue((byte) ((byte) metadata.getValue() & ~0x10)); // Previously unused, now swimming metadata.setValue((byte) ((byte) metadata.getValue() & ~0x10)); // Previously unused, now swimming
} }
@ -127,17 +126,17 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter {
} }
@Override @Override
public int getNewEntityId(final int oldId) { public int newEntityId(final int oldId) {
return EntityTypeRewriter.getNewId(oldId); return EntityTypeRewriter.getNewId(oldId);
} }
@Override @Override
protected EntityType getTypeFromId(int type) { protected EntityType typeFromId(int type) {
return Entity1_13Types.getTypeFromId(type, false); return Entity1_13Types.getTypeFromId(type, false);
} }
@Override @Override
protected EntityType getObjectTypeFromId(int type) { protected EntityType objectTypeFromId(int type) {
return Entity1_13Types.getTypeFromId(type, true); return Entity1_13Types.getTypeFromId(type, true);
} }
} }

Datei anzeigen

@ -27,7 +27,6 @@ import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
public class EntityPackets { public class EntityPackets {
@ -85,7 +84,7 @@ public class EntityPackets {
wrapper.set(Type.INT, 0, data); wrapper.set(Type.INT, 0, data);
// Register Type ID // Register Type ID
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType); wrapper.user().getEntityTracker(Protocol1_13To1_12_2.class).addEntity(entityId, entType);
} }
} }
} }
@ -110,7 +109,7 @@ public class EntityPackets {
map(Type.SHORT); // 11 - Velocity Z map(Type.SHORT); // 11 - Velocity Z
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 12 - Metadata map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 12 - Metadata
handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST)); handler(metadataRewriter.trackerAndRewriterHandler(Types1_13.METADATA_LIST));
} }
}); });
@ -126,11 +125,11 @@ public class EntityPackets {
map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 6 - Pitch
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 7 - Metadata map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 7 - Metadata
handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER)); handler(metadataRewriter.trackerAndRewriterHandler(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER));
} }
}); });
metadataRewriter.registerEntityDestroy(ClientboundPackets1_12_1.DESTROY_ENTITIES); metadataRewriter.registerRemoveEntities(ClientboundPackets1_12_1.DESTROY_ENTITIES);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_12_1.ENTITY_METADATA, Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); metadataRewriter.registerMetadataRewriter(ClientboundPackets1_12_1.ENTITY_METADATA, Types1_12.METADATA_LIST, Types1_13.METADATA_LIST);
} }
} }

Datei anzeigen

@ -1,29 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types.EntityType;
import com.viaversion.viaversion.data.EntityTracker;
public class EntityTracker1_13 extends EntityTracker {
public EntityTracker1_13(UserConnection user) {
super(user, EntityType.PLAYER);
}
}

Datei anzeigen

@ -18,13 +18,14 @@
package com.viaversion.viaversion.protocols.protocol1_14_1to1_14; package com.viaversion.viaversion.protocols.protocol1_14_1to1_14;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14; import com.viaversion.viaversion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14;
import com.viaversion.viaversion.protocols.protocol1_14_1to1_14.packets.EntityPackets; import com.viaversion.viaversion.protocols.protocol1_14_1to1_14.packets.EntityPackets;
import com.viaversion.viaversion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
import com.viaversion.viaversion.rewriter.MetadataRewriter; import com.viaversion.viaversion.rewriter.EntityRewriter;
public class Protocol1_14_1To1_14 extends AbstractProtocol<ClientboundPackets1_14, ClientboundPackets1_14, ServerboundPackets1_14, ServerboundPackets1_14> { public class Protocol1_14_1To1_14 extends AbstractProtocol<ClientboundPackets1_14, ClientboundPackets1_14, ServerboundPackets1_14, ServerboundPackets1_14> {
@ -34,13 +35,14 @@ public class Protocol1_14_1To1_14 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
protected void registerPackets() { protected void registerPackets() {
MetadataRewriter metadataRewriter = new MetadataRewriter1_14_1To1_14(this); EntityRewriter metadataRewriter = new MetadataRewriter1_14_1To1_14(this);
metadataRewriter.register();
EntityPackets.register(this); EntityPackets.register(this);
} }
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker1_14_1(userConnection)); userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, Entity1_14Types.PLAYER));
} }
} }

Datei anzeigen

@ -22,15 +22,14 @@ import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.protocols.protocol1_14_1to1_14.Protocol1_14_1To1_14; import com.viaversion.viaversion.protocols.protocol1_14_1to1_14.Protocol1_14_1To1_14;
import com.viaversion.viaversion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter;
import java.util.List; import java.util.List;
public class MetadataRewriter1_14_1To1_14 extends MetadataRewriter { public class MetadataRewriter1_14_1To1_14 extends EntityRewriter<Protocol1_14_1To1_14> {
public MetadataRewriter1_14_1To1_14(Protocol1_14_1To1_14 protocol) { public MetadataRewriter1_14_1To1_14(Protocol1_14_1To1_14 protocol) {
super(protocol, EntityTracker1_14_1.class); super(protocol);
} }
@Override @Override
@ -38,14 +37,14 @@ public class MetadataRewriter1_14_1To1_14 extends MetadataRewriter {
if (type == null) return; if (type == null) return;
if (type == Entity1_14Types.VILLAGER || type == Entity1_14Types.WANDERING_TRADER) { if (type == Entity1_14Types.VILLAGER || type == Entity1_14Types.WANDERING_TRADER) {
if (metadata.getId() >= 15) { if (metadata.id() >= 15) {
metadata.setId(metadata.getId() + 1); metadata.setId(metadata.id() + 1);
} }
} }
} }
@Override @Override
protected EntityType getTypeFromId(int type) { protected EntityType typeFromId(int type) {
return Entity1_14Types.getTypeFromId(type); return Entity1_14Types.getTypeFromId(type);
} }
} }

Datei anzeigen

@ -47,11 +47,11 @@ public class EntityPackets {
map(Type.SHORT); // 11 - Velocity Z map(Type.SHORT); // 11 - Velocity Z
map(Types1_14.METADATA_LIST); // 12 - Metadata map(Types1_14.METADATA_LIST); // 12 - Metadata
handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST)); handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST));
} }
}); });
metadataRewriter.registerEntityDestroy(ClientboundPackets1_14.DESTROY_ENTITIES); metadataRewriter.registerRemoveEntities(ClientboundPackets1_14.DESTROY_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_PLAYER, new PacketRemapper() { protocol.registerClientbound(ClientboundPackets1_14.SPAWN_PLAYER, new PacketRemapper() {
@Override @Override
@ -65,7 +65,7 @@ public class EntityPackets {
map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 6 - Pitch
map(Types1_14.METADATA_LIST); // 7 - Metadata map(Types1_14.METADATA_LIST); // 7 - Metadata
handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST, Entity1_14Types.PLAYER)); handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST, Entity1_14Types.PLAYER));
} }
}); });

Datei anzeigen

@ -36,7 +36,7 @@ import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets.WorldPac
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter;
@ -50,7 +50,8 @@ public class Protocol1_14To1_13_2 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
protected void registerPackets() { protected void registerPackets() {
MetadataRewriter metadataRewriter = new MetadataRewriter1_14To1_13_2(this); EntityRewriter metadataRewriter = new MetadataRewriter1_14To1_13_2(this);
metadataRewriter.register();
InventoryPackets.register(this); InventoryPackets.register(this);
EntityPackets.register(this); EntityPackets.register(this);
@ -58,7 +59,7 @@ public class Protocol1_14To1_13_2 extends AbstractProtocol<ClientboundPackets1_1
PlayerPackets.register(this); PlayerPackets.register(this);
new SoundRewriter(this).registerSound(ClientboundPackets1_13.SOUND); new SoundRewriter(this).registerSound(ClientboundPackets1_13.SOUND);
new StatisticsRewriter(this, metadataRewriter::getNewEntityId).register(ClientboundPackets1_13.STATISTICS); new StatisticsRewriter(this, metadataRewriter::newEntityId).register(ClientboundPackets1_13.STATISTICS);
ComponentRewriter componentRewriter = new ComponentRewriter1_14(this); ComponentRewriter componentRewriter = new ComponentRewriter1_14(this);
componentRewriter.registerChatMessage(ClientboundPackets1_13.CHAT_MESSAGE); componentRewriter.registerChatMessage(ClientboundPackets1_13.CHAT_MESSAGE);
@ -146,7 +147,7 @@ public class Protocol1_14To1_13_2 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker1_14(userConnection)); userConnection.addEntityTracker(this.getClass(), new EntityTracker1_14(userConnection));
if (!userConnection.has(ClientWorld.class)) { if (!userConnection.has(ClientWorld.class)) {
userConnection.put(new ClientWorld(userConnection)); userConnection.put(new ClientWorld(userConnection));
} }

Datei anzeigen

@ -32,41 +32,41 @@ import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
import com.viaversion.viaversion.rewriter.MetadataRewriter; import com.viaversion.viaversion.rewriter.EntityRewriter;
import java.util.List; import java.util.List;
public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter { public class MetadataRewriter1_14To1_13_2 extends EntityRewriter<Protocol1_14To1_13_2> {
public MetadataRewriter1_14To1_13_2(Protocol1_14To1_13_2 protocol) { public MetadataRewriter1_14To1_13_2(Protocol1_14To1_13_2 protocol) {
super(protocol, EntityTracker1_14.class); super(protocol);
mapTypes(Entity1_13Types.EntityType.values(), Entity1_14Types.class); mapTypes(Entity1_13Types.EntityType.values(), Entity1_14Types.class);
mapType(Entity1_13Types.EntityType.OCELOT, Entity1_14Types.CAT); //TODO remap untamed ocelots to ocelots? mapEntityType(Entity1_13Types.EntityType.OCELOT, Entity1_14Types.CAT); //TODO remap untamed ocelots to ocelots?
} }
@Override @Override
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception { protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
metadata.setMetaType(MetaType1_14.byId(metadata.getMetaType().getTypeID())); metadata.setMetaType(MetaType1_14.byId(metadata.metaType().typeId()));
EntityTracker1_14 tracker = connection.get(EntityTracker1_14.class); EntityTracker1_14 tracker = tracker(connection);
if (metadata.getMetaType() == MetaType1_14.Slot) { if (metadata.metaType() == MetaType1_14.Slot) {
InventoryPackets.toClient((Item) metadata.getValue()); InventoryPackets.toClient((Item) metadata.getValue());
} else if (metadata.getMetaType() == MetaType1_14.BlockID) { } else if (metadata.metaType() == MetaType1_14.BlockID) {
// Convert to new block id // Convert to new block id
int data = (int) metadata.getValue(); int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (metadata.getMetaType() == MetaType1_14.PARTICLE) { } else if (metadata.metaType() == MetaType1_14.PARTICLE) {
rewriteParticle((Particle) metadata.getValue()); rewriteParticle((Particle) metadata.getValue());
} }
if (type == null) return; if (type == null) return;
//Metadata 6 added to abstract_entity //Metadata 6 added to abstract_entity
if (metadata.getId() > 5) { if (metadata.id() > 5) {
metadata.setId(metadata.getId() + 1); metadata.setId(metadata.id() + 1);
} }
if (metadata.getId() == 8 && type.isOrHasParent(Entity1_14Types.LIVINGENTITY)) { if (metadata.id() == 8 && type.isOrHasParent(Entity1_14Types.LIVINGENTITY)) {
final float v = ((Number) metadata.getValue()).floatValue(); final float v = ((Number) metadata.getValue()).floatValue();
if (Float.isNaN(v) && Via.getConfig().is1_14HealthNaNFix()) { if (Float.isNaN(v) && Via.getConfig().is1_14HealthNaNFix()) {
metadata.setValue(1F); metadata.setValue(1F);
@ -74,12 +74,12 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter {
} }
//Metadata 12 added to living_entity //Metadata 12 added to living_entity
if (metadata.getId() > 11 && type.isOrHasParent(Entity1_14Types.LIVINGENTITY)) { if (metadata.id() > 11 && type.isOrHasParent(Entity1_14Types.LIVINGENTITY)) {
metadata.setId(metadata.getId() + 1); metadata.setId(metadata.id() + 1);
} }
if (type.isOrHasParent(Entity1_14Types.ABSTRACT_INSENTIENT)) { if (type.isOrHasParent(Entity1_14Types.ABSTRACT_INSENTIENT)) {
if (metadata.getId() == 13) { if (metadata.id() == 13) {
tracker.setInsentientData(entityId, (byte) ((((Number) metadata.getValue()).byteValue() & ~0x4) tracker.setInsentientData(entityId, (byte) ((((Number) metadata.getValue()).byteValue() & ~0x4)
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata | (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
metadata.setValue(tracker.getInsentientData(entityId)); metadata.setValue(tracker.getInsentientData(entityId));
@ -87,37 +87,37 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter {
} }
if (type.isOrHasParent(Entity1_14Types.PLAYER)) { if (type.isOrHasParent(Entity1_14Types.PLAYER)) {
if (entityId != tracker.getClientEntityId()) { if (entityId != tracker.clientEntityId()) {
if (metadata.getId() == 0) { if (metadata.id() == 0) {
byte flags = ((Number) metadata.getValue()).byteValue(); byte flags = ((Number) metadata.getValue()).byteValue();
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize // Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
tracker.setEntityFlags(entityId, flags); tracker.setEntityFlags(entityId, flags);
} else if (metadata.getId() == 7) { } else if (metadata.id() == 7) {
tracker.setRiptide(entityId, (((Number) metadata.getValue()).byteValue() & 0x4) != 0); tracker.setRiptide(entityId, (((Number) metadata.getValue()).byteValue() & 0x4) != 0);
} }
if (metadata.getId() == 0 || metadata.getId() == 7) { if (metadata.id() == 0 || metadata.id() == 7) {
metadatas.add(new Metadata(6, MetaType1_14.Pose, recalculatePlayerPose(entityId, tracker))); metadatas.add(new Metadata(6, MetaType1_14.Pose, recalculatePlayerPose(entityId, tracker)));
} }
} }
} else if (type.isOrHasParent(Entity1_14Types.ZOMBIE)) { } else if (type.isOrHasParent(Entity1_14Types.ZOMBIE)) {
if (metadata.getId() == 16) { if (metadata.id() == 16) {
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking | ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
metadatas.remove(metadata); // "Are hands held up" metadatas.remove(metadata); // "Are hands held up"
metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId))); metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId)));
} else if (metadata.getId() > 16) { } else if (metadata.id() > 16) {
metadata.setId(metadata.getId() - 1); metadata.setId(metadata.id() - 1);
} }
} }
if (type.isOrHasParent(Entity1_14Types.MINECART_ABSTRACT)) { if (type.isOrHasParent(Entity1_14Types.MINECART_ABSTRACT)) {
if (metadata.getId() == 10) { if (metadata.id() == 10) {
// New block format // New block format
int data = (int) metadata.getValue(); int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} }
} else if (type.is(Entity1_14Types.HORSE)) { } else if (type.is(Entity1_14Types.HORSE)) {
if (metadata.getId() == 18) { if (metadata.id() == 18) {
metadatas.remove(metadata); metadatas.remove(metadata);
int armorType = (int) metadata.getValue(); int armorType = (int) metadata.getValue();
@ -137,29 +137,29 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter {
equipmentPacket.send(Protocol1_14To1_13_2.class); equipmentPacket.send(Protocol1_14To1_13_2.class);
} }
} else if (type.is(Entity1_14Types.VILLAGER)) { } else if (type.is(Entity1_14Types.VILLAGER)) {
if (metadata.getId() == 15) { if (metadata.id() == 15) {
// plains // plains
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0)); metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
metadata.setMetaType(MetaType1_14.VillagerData); metadata.setMetaType(MetaType1_14.VillagerData);
} }
} else if (type.is(Entity1_14Types.ZOMBIE_VILLAGER)) { } else if (type.is(Entity1_14Types.ZOMBIE_VILLAGER)) {
if (metadata.getId() == 18) { if (metadata.id() == 18) {
// plains // plains
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0)); metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
metadata.setMetaType(MetaType1_14.VillagerData); metadata.setMetaType(MetaType1_14.VillagerData);
} }
} else if (type.isOrHasParent(Entity1_14Types.ABSTRACT_ARROW)) { } else if (type.isOrHasParent(Entity1_14Types.ABSTRACT_ARROW)) {
if (metadata.getId() >= 9) { // New piercing if (metadata.id() >= 9) { // New piercing
metadata.setId(metadata.getId() + 1); metadata.setId(metadata.id() + 1);
} }
} else if (type.is(Entity1_14Types.FIREWORK_ROCKET)) { } else if (type.is(Entity1_14Types.FIREWORK_ROCKET)) {
if (metadata.getId() == 8) { if (metadata.id() == 8) {
if (metadata.getValue().equals(0)) if (metadata.getValue().equals(0))
metadata.setValue(null); // https://bugs.mojang.com/browse/MC-111480 metadata.setValue(null); // https://bugs.mojang.com/browse/MC-111480
metadata.setMetaType(MetaType1_14.OptVarInt); metadata.setMetaType(MetaType1_14.OptVarInt);
} }
} else if (type.isOrHasParent(Entity1_14Types.ABSTRACT_SKELETON)) { } else if (type.isOrHasParent(Entity1_14Types.ABSTRACT_SKELETON)) {
if (metadata.getId() == 14) { if (metadata.id() == 14) {
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking | ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
metadatas.remove(metadata); // "Is swinging arms" metadatas.remove(metadata); // "Is swinging arms"
@ -168,7 +168,7 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter {
} }
if (type.isOrHasParent(Entity1_14Types.ABSTRACT_ILLAGER_BASE)) { if (type.isOrHasParent(Entity1_14Types.ABSTRACT_ILLAGER_BASE)) {
if (metadata.getId() == 14) { if (metadata.id() == 14) {
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
| (((Number) metadata.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking | (((Number) metadata.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking
metadatas.remove(metadata); // "Has target (aggressive state)" metadatas.remove(metadata); // "Has target (aggressive state)"
@ -178,14 +178,14 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter {
// TODO Are witch and ravager also abstract illagers? They all inherit the new metadata 14 added in 19w13a // TODO Are witch and ravager also abstract illagers? They all inherit the new metadata 14 added in 19w13a
if (type.is(Entity1_14Types.WITCH) || type.is(Entity1_14Types.RAVAGER) || type.isOrHasParent(Entity1_14Types.ABSTRACT_ILLAGER_BASE)) { if (type.is(Entity1_14Types.WITCH) || type.is(Entity1_14Types.RAVAGER) || type.isOrHasParent(Entity1_14Types.ABSTRACT_ILLAGER_BASE)) {
if (metadata.getId() >= 14) { // TODO 19w13 added a new boolean (raid participant - is celebrating) with id 14 if (metadata.id() >= 14) { // TODO 19w13 added a new boolean (raid participant - is celebrating) with id 14
metadata.setId(metadata.getId() + 1); metadata.setId(metadata.id() + 1);
} }
} }
} }
@Override @Override
protected EntityType getTypeFromId(int type) { protected EntityType typeFromId(int type) {
return Entity1_14Types.getTypeFromId(type); return Entity1_14Types.getTypeFromId(type);
} }

Datei anzeigen

@ -67,7 +67,7 @@ public class EntityPackets {
int typeId = wrapper.get(Type.VAR_INT, 1); int typeId = wrapper.get(Type.VAR_INT, 1);
Entity1_13Types.EntityType type1_13 = Entity1_13Types.getTypeFromId(typeId, true); Entity1_13Types.EntityType type1_13 = Entity1_13Types.getTypeFromId(typeId, true);
typeId = metadataRewriter.getNewEntityId(type1_13.getId()); typeId = metadataRewriter.newEntityId(type1_13.getId());
EntityType type1_14 = Entity1_14Types.getTypeFromId(typeId); EntityType type1_14 = Entity1_14Types.getTypeFromId(typeId);
if (type1_14 != null) { if (type1_14 != null) {
@ -111,7 +111,7 @@ public class EntityPackets {
} }
// Register Type ID // Register Type ID
wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, type1_14); wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class).addEntity(entityId, type1_14);
} }
wrapper.set(Type.VAR_INT, 1, typeId); wrapper.set(Type.VAR_INT, 1, typeId);
@ -137,7 +137,7 @@ public class EntityPackets {
map(Type.SHORT); // 11 - Velocity Z map(Type.SHORT); // 11 - Velocity Z
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 12 - Metadata map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 12 - Metadata
handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST)); handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST));
} }
}); });
@ -164,7 +164,7 @@ public class EntityPackets {
map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 6 - Pitch
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 7 - Metadata map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 7 - Metadata
handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST, Entity1_14Types.PLAYER)); handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST, Entity1_14Types.PLAYER));
} }
}); });
@ -177,14 +177,14 @@ public class EntityPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
short animation = wrapper.passthrough(Type.UNSIGNED_BYTE); short animation = wrapper.passthrough(Type.UNSIGNED_BYTE);
if (animation == 2) { //Leave bed if (animation == 2) { //Leave bed
EntityTracker1_14 tracker = wrapper.user().get(EntityTracker1_14.class); EntityTracker1_14 tracker = wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class);
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
tracker.setSleeping(entityId, false); tracker.setSleeping(entityId, false);
PacketWrapper metadataPacket = wrapper.create(0x43); PacketWrapper metadataPacket = wrapper.create(0x43);
metadataPacket.write(Type.VAR_INT, entityId); metadataPacket.write(Type.VAR_INT, entityId);
List<Metadata> metadataList = new LinkedList<>(); List<Metadata> metadataList = new LinkedList<>();
if (tracker.getClientEntityId() != entityId) { if (tracker.clientEntityId() != entityId) {
metadataList.add(new Metadata(6, MetaType1_14.Pose, MetadataRewriter1_14To1_13_2.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)); metadataList.add(new Metadata(12, MetaType1_14.OptPosition, null));
@ -203,14 +203,14 @@ public class EntityPackets {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
EntityTracker1_14 tracker = wrapper.user().get(EntityTracker1_14.class); EntityTracker1_14 tracker = wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class);
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
tracker.setSleeping(entityId, true); tracker.setSleeping(entityId, true);
Position position = wrapper.read(Type.POSITION); Position position = wrapper.read(Type.POSITION);
List<Metadata> metadataList = new LinkedList<>(); List<Metadata> metadataList = new LinkedList<>();
metadataList.add(new Metadata(12, MetaType1_14.OptPosition, position)); metadataList.add(new Metadata(12, MetaType1_14.OptPosition, position));
if (tracker.getClientEntityId() != entityId) { if (tracker.clientEntityId() != entityId) {
metadataList.add(new Metadata(6, MetaType1_14.Pose, MetadataRewriter1_14To1_13_2.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); wrapper.write(Types1_14.METADATA_LIST, metadataList);
@ -219,7 +219,7 @@ public class EntityPackets {
} }
}); });
metadataRewriter.registerEntityDestroy(ClientboundPackets1_13.DESTROY_ENTITIES); metadataRewriter.registerRemoveEntities(ClientboundPackets1_13.DESTROY_ENTITIES);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); metadataRewriter.registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST);
} }
} }

Datei anzeigen

@ -158,7 +158,8 @@ public class InventoryPackets {
wrapper.read(Type.STRING); // Remove channel wrapper.read(Type.STRING); // Remove channel
int windowId = wrapper.read(Type.INT); int windowId = wrapper.read(Type.INT);
wrapper.user().get(EntityTracker1_14.class).setLatestTradeWindowId(windowId); EntityTracker1_14 tracker = wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class);
tracker.setLatestTradeWindowId(windowId);
wrapper.write(Type.VAR_INT, windowId); wrapper.write(Type.VAR_INT, windowId);
int size = wrapper.passthrough(Type.UNSIGNED_BYTE); int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
@ -233,7 +234,8 @@ public class InventoryPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
// Selecting trade now moves the items, we need to resync the inventory // Selecting trade now moves the items, we need to resync the inventory
PacketWrapper resyncPacket = wrapper.create(0x08); PacketWrapper resyncPacket = wrapper.create(0x08);
resyncPacket.write(Type.UNSIGNED_BYTE, ((short) wrapper.user().get(EntityTracker1_14.class).getLatestTradeWindowId())); // 0 - Window ID EntityTracker1_14 tracker = wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class);
resyncPacket.write(Type.UNSIGNED_BYTE, ((short) tracker.getLatestTradeWindowId())); // 0 - Window ID
resyncPacket.write(Type.SHORT, ((short) -999)); // 1 - Slot resyncPacket.write(Type.SHORT, ((short) -999)); // 1 - Slot
resyncPacket.write(Type.BYTE, (byte) 2); // 2 - Button - End left click resyncPacket.write(Type.BYTE, (byte) 2); // 2 - Button - End left click
resyncPacket.write(Type.SHORT, ((short) ThreadLocalRandom.current().nextInt())); // 3 - Action number resyncPacket.write(Type.SHORT, ((short) ThreadLocalRandom.current().nextInt())); // 3 - Action number

Datei anzeigen

@ -240,7 +240,7 @@ public class WorldPackets {
lightPacket.write(Type.BYTE_ARRAY_PRIMITIVE, section.getLight().getBlockLight()); lightPacket.write(Type.BYTE_ARRAY_PRIMITIVE, section.getLight().getBlockLight());
} }
EntityTracker1_14 entityTracker = wrapper.user().get(EntityTracker1_14.class); EntityTracker1_14 entityTracker = wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class);
int diffX = Math.abs(entityTracker.getChunkCenterX() - chunk.getX()); int diffX = Math.abs(entityTracker.getChunkCenterX() - chunk.getX());
int diffZ = Math.abs(entityTracker.getChunkCenterZ() - chunk.getZ()); int diffZ = Math.abs(entityTracker.getChunkCenterZ() - chunk.getZ());
if (entityTracker.isForceSendCenterChunk() if (entityTracker.isForceSendCenterChunk()
@ -315,7 +315,7 @@ public class WorldPackets {
Entity1_14Types entType = Entity1_14Types.PLAYER; Entity1_14Types entType = Entity1_14Types.PLAYER;
// Register Type ID // Register Type ID
EntityTracker1_14 tracker = wrapper.user().get(EntityTracker1_14.class); EntityTracker1_14 tracker = wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class);
tracker.addEntity(entityId, entType); tracker.addEntity(entityId, entType);
tracker.setClientEntityId(entityId); tracker.setClientEntityId(entityId);
} }
@ -364,7 +364,7 @@ public class WorldPackets {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0); int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId); clientWorld.setEnvironment(dimensionId);
EntityTracker1_14 entityTracker = wrapper.user().get(EntityTracker1_14.class); EntityTracker1_14 entityTracker = wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class);
// The client may reset the center chunk if dimension is changed // The client may reset the center chunk if dimension is changed
entityTracker.setForceSendCenterChunk(true); entityTracker.setForceSendCenterChunk(true);
} }

Datei anzeigen

@ -21,14 +21,14 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types; import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.EntityTracker; import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets.WorldPackets; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets.WorldPackets;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class EntityTracker1_14 extends EntityTracker { public class EntityTracker1_14 extends EntityTrackerBase {
private final Map<Integer, Byte> insentientData = new ConcurrentHashMap<>(); private final Map<Integer, Byte> insentientData = new ConcurrentHashMap<>();
// 0x1 = sleeping, 0x2 = riptide // 0x1 = sleeping, 0x2 = riptide
private final Map<Integer, Byte> sleepingAndRiptideData = new ConcurrentHashMap<>(); private final Map<Integer, Byte> sleepingAndRiptideData = new ConcurrentHashMap<>();
@ -91,10 +91,10 @@ public class EntityTracker1_14 extends EntityTracker {
} }
@Override @Override
public void onExternalJoinGame(int playerEntityId) { public void setClientEntityId(int playerEntityId) {
super.onExternalJoinGame(playerEntityId); super.setClientEntityId(playerEntityId);
PacketWrapper setViewDistance = PacketWrapper.create(0x41, null, getUser()); PacketWrapper setViewDistance = PacketWrapper.create(0x41, null, user());
setViewDistance.write(Type.VAR_INT, WorldPackets.SERVERSIDE_VIEW_DISTANCE); setViewDistance.write(Type.VAR_INT, WorldPackets.SERVERSIDE_VIEW_DISTANCE);
try { try {
setViewDistance.send(Protocol1_14To1_13_2.class, true, true); setViewDistance.send(Protocol1_14To1_13_2.class, true, true);

Datei anzeigen

@ -18,9 +18,11 @@
package com.viaversion.viaversion.protocols.protocol1_15to1_14_4; package com.viaversion.viaversion.protocols.protocol1_15to1_14_4;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.data.MappingData; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.data.MappingData;
@ -29,8 +31,7 @@ import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.EntityPa
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.PlayerPackets; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.PlayerPackets;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.WorldPackets; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter;
import com.viaversion.viaversion.rewriter.RegistryType; import com.viaversion.viaversion.rewriter.RegistryType;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter;
@ -47,7 +48,8 @@ public class Protocol1_15To1_14_4 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
protected void registerPackets() { protected void registerPackets() {
MetadataRewriter metadataRewriter = new MetadataRewriter1_15To1_14_4(this); EntityRewriter metadataRewriter = new MetadataRewriter1_15To1_14_4(this);
metadataRewriter.register();
EntityPackets.register(this); EntityPackets.register(this);
PlayerPackets.register(this); PlayerPackets.register(this);
@ -58,7 +60,7 @@ public class Protocol1_15To1_14_4 extends AbstractProtocol<ClientboundPackets1_1
soundRewriter.registerSound(ClientboundPackets1_14.ENTITY_SOUND); // Entity Sound Effect (added somewhere in 1.14) soundRewriter.registerSound(ClientboundPackets1_14.ENTITY_SOUND); // Entity Sound Effect (added somewhere in 1.14)
soundRewriter.registerSound(ClientboundPackets1_14.SOUND); soundRewriter.registerSound(ClientboundPackets1_14.SOUND);
new StatisticsRewriter(this, metadataRewriter::getNewEntityId).register(ClientboundPackets1_14.STATISTICS); new StatisticsRewriter(this, metadataRewriter::newEntityId).register(ClientboundPackets1_14.STATISTICS);
registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() { registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {
@Override @Override
@ -82,8 +84,8 @@ public class Protocol1_15To1_14_4 extends AbstractProtocol<ClientboundPackets1_1
} }
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection connection) {
userConnection.put(new EntityTracker1_15(userConnection)); addEntityTracker(connection, new EntityTrackerBase(connection, Entity1_15Types.PLAYER));
} }
@Override @Override

Datei anzeigen

@ -28,41 +28,40 @@ import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.EntityPackets; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.EntityPackets;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter;
import java.util.List; import java.util.List;
public class MetadataRewriter1_15To1_14_4 extends MetadataRewriter { public class MetadataRewriter1_15To1_14_4 extends EntityRewriter<Protocol1_15To1_14_4> {
public MetadataRewriter1_15To1_14_4(Protocol1_15To1_14_4 protocol) { public MetadataRewriter1_15To1_14_4(Protocol1_15To1_14_4 protocol) {
super(protocol, EntityTracker1_15.class); super(protocol);
} }
@Override @Override
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception { public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
if (metadata.getMetaType() == MetaType1_14.Slot) { if (metadata.metaType() == MetaType1_14.Slot) {
InventoryPackets.toClient((Item) metadata.getValue()); InventoryPackets.toClient((Item) metadata.getValue());
} else if (metadata.getMetaType() == MetaType1_14.BlockID) { } else if (metadata.metaType() == MetaType1_14.BlockID) {
// Convert to new block id // Convert to new block id
int data = (int) metadata.getValue(); int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (metadata.getMetaType() == MetaType1_13.PARTICLE) { } else if (metadata.metaType() == MetaType1_13.PARTICLE) {
rewriteParticle((Particle) metadata.getValue()); rewriteParticle((Particle) metadata.getValue());
} }
if (type == null) return; if (type == null) return;
if (type.isOrHasParent(Entity1_15Types.MINECART_ABSTRACT) if (type.isOrHasParent(Entity1_15Types.MINECART_ABSTRACT)
&& metadata.getId() == 10) { && metadata.id() == 10) {
// Convert to new block id // Convert to new block id
int data = (int) metadata.getValue(); int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} }
// Metadata 12 added to abstract_living // Metadata 12 added to abstract_living
if (metadata.getId() > 11 && type.isOrHasParent(Entity1_15Types.LIVINGENTITY)) { if (metadata.id() > 11 && type.isOrHasParent(Entity1_15Types.LIVINGENTITY)) {
metadata.setId(metadata.getId() + 1); //TODO is it 11 or 12? what is it for? metadata.setId(metadata.id() + 1); //TODO is it 11 or 12? what is it for?
} }
//NOTES: //NOTES:
@ -70,21 +69,21 @@ public class MetadataRewriter1_15To1_14_4 extends MetadataRewriter {
//new boolean with id 17 for enderman //new boolean with id 17 for enderman
if (type.isOrHasParent(Entity1_15Types.WOLF)) { if (type.isOrHasParent(Entity1_15Types.WOLF)) {
if (metadata.getId() == 18) { if (metadata.id() == 18) {
metadatas.remove(metadata); metadatas.remove(metadata);
} else if (metadata.getId() > 18) { } else if (metadata.id() > 18) {
metadata.setId(metadata.getId() - 1); metadata.setId(metadata.id() - 1);
} }
} }
} }
@Override @Override
public int getNewEntityId(final int oldId) { public int newEntityId(final int oldId) {
return EntityPackets.getNewEntityId(oldId); return EntityPackets.getNewEntityId(oldId);
} }
@Override @Override
protected EntityType getTypeFromId(int type) { protected EntityType typeFromId(int type) {
return Entity1_15Types.getTypeFromId(type); return Entity1_15Types.getTypeFromId(type);
} }
} }

Datei anzeigen

@ -27,8 +27,7 @@ import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPacke
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter;
import java.util.List; import java.util.List;
@ -37,7 +36,7 @@ public class EntityPackets {
public static void register(Protocol1_15To1_14_4 protocol) { public static void register(Protocol1_15To1_14_4 protocol) {
MetadataRewriter1_15To1_14_4 metadataRewriter = protocol.get(MetadataRewriter1_15To1_14_4.class); MetadataRewriter1_15To1_14_4 metadataRewriter = protocol.get(MetadataRewriter1_15To1_14_4.class);
metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_14.SPAWN_ENTITY, Entity1_15Types.FALLING_BLOCK); metadataRewriter.registerTrackerWithData(ClientboundPackets1_14.SPAWN_ENTITY, Entity1_15Types.FALLING_BLOCK);
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_MOB, new PacketRemapper() { protocol.registerClientbound(ClientboundPackets1_14.SPAWN_MOB, new PacketRemapper() {
@Override @Override
@ -55,7 +54,7 @@ public class EntityPackets {
map(Type.SHORT); // 10 - Velocity Y map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z map(Type.SHORT); // 11 - Velocity Z
handler(metadataRewriter.getTracker()); handler(metadataRewriter.trackerHandler());
handler(wrapper -> sendMetadataPacket(wrapper, wrapper.get(Type.VAR_INT, 0), metadataRewriter)); handler(wrapper -> sendMetadataPacket(wrapper, wrapper.get(Type.VAR_INT, 0), metadataRewriter));
} }
}); });
@ -73,7 +72,7 @@ public class EntityPackets {
handler(wrapper -> { handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
wrapper.user().get(EntityTracker1_15.class).addEntity(entityId, Entity1_15Types.PLAYER); wrapper.user().getEntityTracker(Protocol1_15To1_14_4.class).addEntity(entityId, Entity1_15Types.PLAYER);
sendMetadataPacket(wrapper, entityId, metadataRewriter); sendMetadataPacket(wrapper, entityId, metadataRewriter);
}); });
@ -81,10 +80,10 @@ public class EntityPackets {
}); });
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST); metadataRewriter.registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST);
metadataRewriter.registerEntityDestroy(ClientboundPackets1_14.DESTROY_ENTITIES); metadataRewriter.registerRemoveEntities(ClientboundPackets1_14.DESTROY_ENTITIES);
} }
private static void sendMetadataPacket(PacketWrapper wrapper, int entityId, MetadataRewriter rewriter) throws Exception { private static void sendMetadataPacket(PacketWrapper wrapper, int entityId, EntityRewriter rewriter) throws Exception {
// Meta is no longer included in the spawn packets, but sent separately // Meta is no longer included in the spawn packets, but sent separately
List<Metadata> metadata = wrapper.read(Types1_14.METADATA_LIST); List<Metadata> metadata = wrapper.read(Types1_14.METADATA_LIST);

Datei anzeigen

@ -18,12 +18,13 @@
package com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets; package com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types; import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types;
import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
public class PlayerPackets { public class PlayerPackets {
@ -45,7 +46,7 @@ public class PlayerPackets {
handler(wrapper -> { handler(wrapper -> {
// Register Type ID // Register Type ID
EntityTracker1_15 tracker = wrapper.user().get(EntityTracker1_15.class); EntityTracker tracker = wrapper.user().getEntityTracker(Protocol1_15To1_14_4.class);
int entityId = wrapper.get(Type.INT, 0); int entityId = wrapper.get(Type.INT, 0);
tracker.addEntity(entityId, Entity1_15Types.PLAYER); tracker.addEntity(entityId, Entity1_15Types.PLAYER);
}); });

Datei anzeigen

@ -18,18 +18,19 @@
package com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1; package com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.data.MappingData; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.data.MappingData;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.metadata.MetadataRewriter1_16_2To1_16_1; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.metadata.MetadataRewriter1_16_2To1_16_1;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.EntityPackets; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.EntityPackets;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.WorldPackets; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.storage.EntityTracker1_16_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import com.viaversion.viaversion.rewriter.MetadataRewriter; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.RegistryType; import com.viaversion.viaversion.rewriter.RegistryType;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter;
@ -46,16 +47,17 @@ public class Protocol1_16_2To1_16_1 extends AbstractProtocol<ClientboundPackets1
@Override @Override
protected void registerPackets() { protected void registerPackets() {
MetadataRewriter metadataRewriter = new MetadataRewriter1_16_2To1_16_1(this); EntityRewriter metadataRewriter = new MetadataRewriter1_16_2To1_16_1(this);
metadataRewriter.register();
EntityPackets.register(this); EntityPackets.register(this);
WorldPackets.register(this); WorldPackets.register(this);
InventoryPackets.register(this); InventoryPackets.register(this);
tagRewriter = new TagRewriter(this, metadataRewriter::getNewEntityId); tagRewriter = new TagRewriter(this, metadataRewriter::newEntityId);
tagRewriter.register(ClientboundPackets1_16.TAGS, RegistryType.ENTITY); tagRewriter.register(ClientboundPackets1_16.TAGS, RegistryType.ENTITY);
new StatisticsRewriter(this, metadataRewriter::getNewEntityId).register(ClientboundPackets1_16.STATISTICS); new StatisticsRewriter(this, metadataRewriter::newEntityId).register(ClientboundPackets1_16.STATISTICS);
SoundRewriter soundRewriter = new SoundRewriter(this); SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_16.SOUND); soundRewriter.registerSound(ClientboundPackets1_16.SOUND);
@ -112,7 +114,7 @@ public class Protocol1_16_2To1_16_1 extends AbstractProtocol<ClientboundPackets1
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker1_16_2(userConnection)); userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, Entity1_16_2Types.PLAYER));
} }
@Override @Override

Datei anzeigen

@ -27,49 +27,48 @@ import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14;
import com.viaversion.viaversion.api.type.types.Particle; import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.storage.EntityTracker1_16_2; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter;
import java.util.List; import java.util.List;
public class MetadataRewriter1_16_2To1_16_1 extends MetadataRewriter { public class MetadataRewriter1_16_2To1_16_1 extends EntityRewriter<Protocol1_16_2To1_16_1> {
public MetadataRewriter1_16_2To1_16_1(Protocol1_16_2To1_16_1 protocol) { public MetadataRewriter1_16_2To1_16_1(Protocol1_16_2To1_16_1 protocol) {
super(protocol, EntityTracker1_16_2.class); super(protocol);
mapTypes(Entity1_16Types.values(), Entity1_16_2Types.class); mapTypes(Entity1_16Types.values(), Entity1_16_2Types.class);
} }
@Override @Override
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception { public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
if (metadata.getMetaType() == MetaType1_14.Slot) { if (metadata.metaType() == MetaType1_14.Slot) {
InventoryPackets.toClient((Item) metadata.getValue()); InventoryPackets.toClient((Item) metadata.getValue());
} else if (metadata.getMetaType() == MetaType1_14.BlockID) { } else if (metadata.metaType() == MetaType1_14.BlockID) {
int data = (int) metadata.getValue(); int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (metadata.getMetaType() == MetaType1_14.PARTICLE) { } else if (metadata.metaType() == MetaType1_14.PARTICLE) {
rewriteParticle((Particle) metadata.getValue()); rewriteParticle((Particle) metadata.getValue());
} }
if (type == null) return; if (type == null) return;
if (type.isOrHasParent(Entity1_16_2Types.MINECART_ABSTRACT) if (type.isOrHasParent(Entity1_16_2Types.MINECART_ABSTRACT)
&& metadata.getId() == 10) { && metadata.id() == 10) {
// Convert to new block id // Convert to new block id
int data = (int) metadata.getValue(); int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} }
if (type.isOrHasParent(Entity1_16_2Types.ABSTRACT_PIGLIN)) { if (type.isOrHasParent(Entity1_16_2Types.ABSTRACT_PIGLIN)) {
if (metadata.getId() == 15) { if (metadata.id() == 15) {
metadata.setId(16); metadata.setId(16);
} else if (metadata.getId() == 16) { } else if (metadata.id() == 16) {
metadata.setId(15); metadata.setId(15);
} }
} }
} }
@Override @Override
protected EntityType getTypeFromId(int type) { protected EntityType typeFromId(int type) {
return Entity1_16_2Types.getTypeFromId(type); return Entity1_16_2Types.getTypeFromId(type);
} }
} }

Datei anzeigen

@ -25,18 +25,17 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_14; import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.metadata.MetadataRewriter1_16_2To1_16_1; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.metadata.MetadataRewriter1_16_2To1_16_1;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.storage.EntityTracker1_16_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
public class EntityPackets { public class EntityPackets {
public static void register(Protocol1_16_2To1_16_1 protocol) { public static void register(Protocol1_16_2To1_16_1 protocol) {
MetadataRewriter1_16_2To1_16_1 metadataRewriter = protocol.get(MetadataRewriter1_16_2To1_16_1.class); MetadataRewriter1_16_2To1_16_1 metadataRewriter = protocol.get(MetadataRewriter1_16_2To1_16_1.class);
metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_16.SPAWN_ENTITY, Entity1_16_2Types.FALLING_BLOCK); metadataRewriter.registerTrackerWithData(ClientboundPackets1_16.SPAWN_ENTITY, Entity1_16_2Types.FALLING_BLOCK);
metadataRewriter.registerTracker(ClientboundPackets1_16.SPAWN_MOB); metadataRewriter.registerTracker(ClientboundPackets1_16.SPAWN_MOB);
metadataRewriter.registerTracker(ClientboundPackets1_16.SPAWN_PLAYER, Entity1_16_2Types.PLAYER); metadataRewriter.registerTracker(ClientboundPackets1_16.SPAWN_PLAYER, Entity1_16_2Types.PLAYER);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_16.ENTITY_METADATA, Types1_14.METADATA_LIST); metadataRewriter.registerMetadataRewriter(ClientboundPackets1_16.ENTITY_METADATA, Types1_14.METADATA_LIST);
metadataRewriter.registerEntityDestroy(ClientboundPackets1_16.DESTROY_ENTITIES); metadataRewriter.registerRemoveEntities(ClientboundPackets1_16.DESTROY_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_16.JOIN_GAME, new PacketRemapper() { protocol.registerClientbound(ClientboundPackets1_16.JOIN_GAME, new PacketRemapper() {
@Override @Override
@ -65,7 +64,7 @@ public class EntityPackets {
map(Type.UNSIGNED_BYTE, Type.VAR_INT); // Max players map(Type.UNSIGNED_BYTE, Type.VAR_INT); // Max players
// ... // ...
handler(wrapper -> { handler(wrapper -> {
wrapper.user().get(EntityTracker1_16_2.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16_2Types.PLAYER); wrapper.user().getEntityTracker(Protocol1_16_2To1_16_1.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16_2Types.PLAYER);
}); });
} }
}); });

Datei anzeigen

@ -1,29 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.storage;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types;
import com.viaversion.viaversion.data.EntityTracker;
public class EntityTracker1_16_2 extends EntityTracker {
public EntityTracker1_16_2(UserConnection user) {
super(user, Entity1_16_2Types.PLAYER);
}
}

Datei anzeigen

@ -23,10 +23,12 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.MappingData; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.MappingData;
@ -35,10 +37,9 @@ import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.Metadat
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.EntityPackets; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.EntityPackets;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.WorldPackets; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.EntityTracker1_16;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.RegistryType; import com.viaversion.viaversion.rewriter.RegistryType;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter;
@ -62,16 +63,17 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
protected void registerPackets() { protected void registerPackets() {
MetadataRewriter metadataRewriter = new MetadataRewriter1_16To1_15_2(this); EntityRewriter metadataRewriter = new MetadataRewriter1_16To1_15_2(this);
metadataRewriter.register();
EntityPackets.register(this); EntityPackets.register(this);
WorldPackets.register(this); WorldPackets.register(this);
InventoryPackets.register(this); InventoryPackets.register(this);
tagRewriter = new TagRewriter(this, metadataRewriter::getNewEntityId); tagRewriter = new TagRewriter(this, metadataRewriter::newEntityId);
tagRewriter.register(ClientboundPackets1_15.TAGS, RegistryType.ENTITY); tagRewriter.register(ClientboundPackets1_15.TAGS, RegistryType.ENTITY);
new StatisticsRewriter(this, metadataRewriter::getNewEntityId).register(ClientboundPackets1_15.STATISTICS); new StatisticsRewriter(this, metadataRewriter::newEntityId).register(ClientboundPackets1_15.STATISTICS);
// Login Success // Login Success
registerClientbound(State.LOGIN, 0x02, 0x02, new PacketRemapper() { registerClientbound(State.LOGIN, 0x02, 0x02, new PacketRemapper() {
@ -271,7 +273,7 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker1_16(userConnection)); userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, Entity1_16Types.PLAYER));
userConnection.put(new InventoryTracker1_16(userConnection)); userConnection.put(new InventoryTracker1_16(userConnection));
} }

Datei anzeigen

@ -27,50 +27,49 @@ import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14;
import com.viaversion.viaversion.api.type.types.Particle; import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.EntityTracker1_16; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter;
import java.util.List; import java.util.List;
public class MetadataRewriter1_16To1_15_2 extends MetadataRewriter { public class MetadataRewriter1_16To1_15_2 extends EntityRewriter<Protocol1_16To1_15_2> {
public MetadataRewriter1_16To1_15_2(Protocol1_16To1_15_2 protocol) { public MetadataRewriter1_16To1_15_2(Protocol1_16To1_15_2 protocol) {
super(protocol, EntityTracker1_16.class); super(protocol);
mapType(Entity1_15Types.ZOMBIE_PIGMAN, Entity1_16Types.ZOMBIFIED_PIGLIN); mapEntityType(Entity1_15Types.ZOMBIE_PIGMAN, Entity1_16Types.ZOMBIFIED_PIGLIN);
mapTypes(Entity1_15Types.values(), Entity1_16Types.class); mapTypes(Entity1_15Types.values(), Entity1_16Types.class);
} }
@Override @Override
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception { public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
if (metadata.getMetaType() == MetaType1_14.Slot) { if (metadata.metaType() == MetaType1_14.Slot) {
InventoryPackets.toClient((Item) metadata.getValue()); InventoryPackets.toClient((Item) metadata.getValue());
} else if (metadata.getMetaType() == MetaType1_14.BlockID) { } else if (metadata.metaType() == MetaType1_14.BlockID) {
int data = (int) metadata.getValue(); int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (metadata.getMetaType() == MetaType1_14.PARTICLE) { } else if (metadata.metaType() == MetaType1_14.PARTICLE) {
rewriteParticle((Particle) metadata.getValue()); rewriteParticle((Particle) metadata.getValue());
} }
if (type == null) return; if (type == null) return;
if (type.isOrHasParent(Entity1_16Types.MINECART_ABSTRACT) if (type.isOrHasParent(Entity1_16Types.MINECART_ABSTRACT)
&& metadata.getId() == 10) { && metadata.id() == 10) {
// Convert to new block id // Convert to new block id
int data = (int) metadata.getValue(); int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} }
if (type.isOrHasParent(Entity1_16Types.ABSTRACT_ARROW)) { if (type.isOrHasParent(Entity1_16Types.ABSTRACT_ARROW)) {
if (metadata.getId() == 8) { if (metadata.id() == 8) {
metadatas.remove(metadata); metadatas.remove(metadata);
} else if (metadata.getId() > 8) { } else if (metadata.id() > 8) {
metadata.setId(metadata.getId() - 1); metadata.setId(metadata.id() - 1);
} }
} }
} }
@Override @Override
protected EntityType getTypeFromId(int type) { protected EntityType typeFromId(int type) {
return Entity1_16Types.getTypeFromId(type); return Entity1_16Types.getTypeFromId(type);
} }
} }

Datei anzeigen

@ -35,7 +35,6 @@ import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPacke
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.EntityTracker1_16;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
import java.util.UUID; import java.util.UUID;
@ -152,7 +151,7 @@ public class EntityPackets {
public void registerMap() { public void registerMap() {
handler(wrapper -> { handler(wrapper -> {
int entityId = wrapper.passthrough(Type.VAR_INT); int entityId = wrapper.passthrough(Type.VAR_INT);
wrapper.user().get(EntityTracker1_16.class).addEntity(entityId, Entity1_16Types.LIGHTNING_BOLT); wrapper.user().getEntityTracker(Protocol1_16To1_15_2.class).addEntity(entityId, Entity1_16Types.LIGHTNING_BOLT);
wrapper.write(Type.UUID, UUID.randomUUID()); // uuid wrapper.write(Type.UUID, UUID.randomUUID()); // uuid
wrapper.write(Type.VAR_INT, Entity1_16Types.LIGHTNING_BOLT.getId()); // entity type wrapper.write(Type.VAR_INT, Entity1_16Types.LIGHTNING_BOLT.getId()); // entity type
@ -172,11 +171,11 @@ public class EntityPackets {
} }
}); });
metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_16Types.FALLING_BLOCK); metadataRewriter.registerTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_16Types.FALLING_BLOCK);
metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_MOB); metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_MOB);
metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_PLAYER, Entity1_16Types.PLAYER); metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_PLAYER, Entity1_16Types.PLAYER);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_15.ENTITY_METADATA, Types1_14.METADATA_LIST); metadataRewriter.registerMetadataRewriter(ClientboundPackets1_15.ENTITY_METADATA, Types1_14.METADATA_LIST);
metadataRewriter.registerEntityDestroy(ClientboundPackets1_15.DESTROY_ENTITIES); metadataRewriter.registerRemoveEntities(ClientboundPackets1_15.DESTROY_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_15.RESPAWN, new PacketRemapper() { protocol.registerClientbound(ClientboundPackets1_15.RESPAWN, new PacketRemapper() {
@Override @Override
@ -209,7 +208,7 @@ public class EntityPackets {
map(Type.LONG); // Seed map(Type.LONG); // Seed
map(Type.UNSIGNED_BYTE); // Max players map(Type.UNSIGNED_BYTE); // Max players
handler(wrapper -> { handler(wrapper -> {
wrapper.user().get(EntityTracker1_16.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16Types.PLAYER); wrapper.user().getEntityTracker(Protocol1_16To1_15_2.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16Types.PLAYER);
final String type = wrapper.read(Type.STRING);// level type final String type = wrapper.read(Type.STRING);// level type
wrapper.passthrough(Type.VAR_INT); // View distance wrapper.passthrough(Type.VAR_INT); // View distance

Datei anzeigen

@ -21,18 +21,19 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData; import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.data.MappingDataBase; import com.viaversion.viaversion.api.data.MappingDataBase;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.metadata.MetadataRewriter1_17To1_16_4; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.metadata.MetadataRewriter1_17To1_16_4;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.EntityPackets; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.EntityPackets;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.WorldPackets; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.EntityTracker1_17; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter;
import com.viaversion.viaversion.rewriter.RegistryType; import com.viaversion.viaversion.rewriter.RegistryType;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter;
@ -50,7 +51,8 @@ public class Protocol1_17To1_16_4 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
protected void registerPackets() { protected void registerPackets() {
MetadataRewriter metadataRewriter = new MetadataRewriter1_17To1_16_4(this); EntityRewriter metadataRewriter = new MetadataRewriter1_17To1_16_4(this);
metadataRewriter.register();
EntityPackets.register(this); EntityPackets.register(this);
InventoryPackets.register(this); InventoryPackets.register(this);
@ -87,7 +89,7 @@ public class Protocol1_17To1_16_4 extends AbstractProtocol<ClientboundPackets1_1
} }
}); });
new StatisticsRewriter(this, metadataRewriter::getNewEntityId).register(ClientboundPackets1_16_2.STATISTICS); new StatisticsRewriter(this, metadataRewriter::newEntityId).register(ClientboundPackets1_16_2.STATISTICS);
SoundRewriter soundRewriter = new SoundRewriter(this); SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_16_2.SOUND); soundRewriter.registerSound(ClientboundPackets1_16_2.SOUND);
@ -237,7 +239,7 @@ public class Protocol1_17To1_16_4 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
public void init(UserConnection user) { public void init(UserConnection user) {
user.put(new EntityTracker1_17(user)); user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_17Types.PLAYER));
} }
@Override @Override

Datei anzeigen

@ -17,73 +17,51 @@
*/ */
package com.viaversion.viaversion.protocols.protocol1_17to1_16_4.metadata; package com.viaversion.viaversion.protocols.protocol1_17to1_16_4.metadata;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types; import com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types; import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_17; import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_17;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.EntityTracker1_17; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter;
import java.util.List; public class MetadataRewriter1_17To1_16_4 extends EntityRewriter {
public class MetadataRewriter1_17To1_16_4 extends MetadataRewriter {
public MetadataRewriter1_17To1_16_4(Protocol1_17To1_16_4 protocol) { public MetadataRewriter1_17To1_16_4(Protocol1_17To1_16_4 protocol) {
super(protocol, EntityTracker1_17.class); super(protocol);
mapTypes(Entity1_16_2Types.values(), Entity1_17Types.class); mapTypes(Entity1_16_2Types.values(), Entity1_17Types.class);
} }
@Override @Override
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception { protected void registerRewrites() {
metadata.setMetaType(MetaType1_17.byId(metadata.getMetaType().getTypeID())); filter().handler((event, meta) -> {
if (metadata.getMetaType() == MetaType1_17.Slot) { meta.setMetaType(MetaType1_17.byId(meta.metaType().typeId()));
InventoryPackets.toClient((Item) metadata.getValue());
} else if (metadata.getMetaType() == MetaType1_17.BlockID) { if (meta.metaType() == MetaType1_17.Pose) {
int data = (int) metadata.getValue(); int pose = meta.value();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); if (pose > 5) {
} else if (metadata.getMetaType() == MetaType1_17.PARTICLE) { // Added LONG_JUMP at 6
rewriteParticle((Particle) metadata.getValue()); meta.setValue(pose + 1);
} else if (metadata.getMetaType() == MetaType1_17.Pose) { }
int pose = metadata.getCastedValue();
if (pose > 5) {
// Added LONG_JUMP at 6
metadata.setValue(pose + 1);
} }
} });
registerDumMetaTypeHandler(MetaType1_17.Slot, MetaType1_17.BlockID, MetaType1_17.PARTICLE, InventoryPackets::toClient);
if (type == null) return; // Ticks frozen added with id 7
filter().filterFamily(Entity1_17Types.ENTITY).addIndex(7);
if (type.isOrHasParent(Entity1_17Types.ENTITY)) { filter().filterFamily(Entity1_17Types.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
if (metadata.getId() >= 7) {
metadata.setId(metadata.getId() + 1); // Ticks frozen added with id 7
}
}
if (type.isOrHasParent(Entity1_17Types.MINECART_ABSTRACT)
&& metadata.getId() == 11) {
// Convert to new block id // Convert to new block id
int data = (int) metadata.getValue(); int data = (int) meta.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
} });
if (type == Entity1_17Types.SHULKER) { // Attachment position removed
// Attachment position removed filter().type(Entity1_17Types.SHULKER).removeIndex(16);
if (metadata.getId() == 16) {
metadatas.remove(metadata);
} else if (metadata.getId() > 16) {
metadata.setId(metadata.getId() - 1);
}
}
} }
@Override @Override
protected EntityType getTypeFromId(int type) { protected EntityType typeFromId(int type) {
return Entity1_17Types.getTypeFromId(type); return Entity1_17Types.getTypeFromId(type);
} }
} }

Datei anzeigen

@ -17,6 +17,7 @@
*/ */
package com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets; package com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types; import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@ -24,18 +25,16 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_14; import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.api.type.types.version.Types1_17; import com.viaversion.viaversion.api.type.types.version.Types1_17;
import com.viaversion.viaversion.data.EntityTracker;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.metadata.MetadataRewriter1_17To1_16_4; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.metadata.MetadataRewriter1_17To1_16_4;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.EntityTracker1_17;
public class EntityPackets { public class EntityPackets {
public static void register(Protocol1_17To1_16_4 protocol) { public static void register(Protocol1_17To1_16_4 protocol) {
MetadataRewriter1_17To1_16_4 metadataRewriter = protocol.get(MetadataRewriter1_17To1_16_4.class); MetadataRewriter1_17To1_16_4 metadataRewriter = protocol.get(MetadataRewriter1_17To1_16_4.class);
metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_16_2.SPAWN_ENTITY, Entity1_17Types.FALLING_BLOCK); metadataRewriter.registerTrackerWithData(ClientboundPackets1_16_2.SPAWN_ENTITY, Entity1_17Types.FALLING_BLOCK);
metadataRewriter.registerTracker(ClientboundPackets1_16_2.SPAWN_MOB); metadataRewriter.registerTracker(ClientboundPackets1_16_2.SPAWN_MOB);
metadataRewriter.registerTracker(ClientboundPackets1_16_2.SPAWN_PLAYER, Entity1_17Types.PLAYER); metadataRewriter.registerTracker(ClientboundPackets1_16_2.SPAWN_PLAYER, Entity1_17Types.PLAYER);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_16_2.ENTITY_METADATA, Types1_14.METADATA_LIST, Types1_17.METADATA_LIST); metadataRewriter.registerMetadataRewriter(ClientboundPackets1_16_2.ENTITY_METADATA, Types1_14.METADATA_LIST, Types1_17.METADATA_LIST);
@ -47,7 +46,7 @@ public class EntityPackets {
int[] entityIds = wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE); int[] entityIds = wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE);
wrapper.cancel(); wrapper.cancel();
EntityTracker entityTracker = wrapper.user().get(EntityTracker1_17.class); EntityTracker entityTracker = wrapper.user().getEntityTracker(Protocol1_17To1_16_4.class);
for (int entityId : entityIds) { for (int entityId : entityIds) {
entityTracker.removeEntity(entityId); entityTracker.removeEntity(entityId);

Datei anzeigen

@ -35,7 +35,6 @@ import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPac
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.EntityTracker1_17;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type;
import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.rewriter.BlockRewriter;
@ -188,7 +187,7 @@ public class WorldPackets {
addNewDimensionData(currentDimensionTag); addNewDimensionData(currentDimensionTag);
UserConnection user = wrapper.user(); UserConnection user = wrapper.user();
user.get(EntityTracker1_17.class).addEntity(wrapper.get(Type.INT, 0), Entity1_17Types.PLAYER); user.getEntityTracker(Protocol1_17To1_16_4.class).addEntity(wrapper.get(Type.INT, 0), Entity1_17Types.PLAYER);
}); });
} }
}); });

Datei anzeigen

@ -1,29 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types;
import com.viaversion.viaversion.data.EntityTracker;
public class EntityTracker1_17 extends EntityTracker {
public EntityTracker1_17(UserConnection user) {
super(user, Entity1_17Types.PLAYER);
}
}

Datei anzeigen

@ -48,7 +48,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.CommandBlock
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.InventoryTracker; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.InventoryTracker;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
import com.viaversion.viaversion.rewriter.MetadataRewriter; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.util.GsonUtil; import com.viaversion.viaversion.util.GsonUtil;
public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, ClientboundPackets1_9, ServerboundPackets1_8, ServerboundPackets1_9> { public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, ClientboundPackets1_9, ServerboundPackets1_8, ServerboundPackets1_9> {
@ -108,7 +108,8 @@ public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, Cl
@Override @Override
protected void registerPackets() { protected void registerPackets() {
MetadataRewriter metadataRewriter = new MetadataRewriter1_9To1_8(this); EntityRewriter metadataRewriter = new MetadataRewriter1_9To1_8(this);
metadataRewriter.register();
// Disconnect workaround (JSON!) // Disconnect workaround (JSON!)
registerClientbound(State.LOGIN, 0x00, 0x00, new PacketRemapper() { registerClientbound(State.LOGIN, 0x00, 0x00, new PacketRemapper() {
@ -146,7 +147,7 @@ public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, Cl
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
// Entity tracker // Entity tracker
userConnection.put(new EntityTracker1_9(userConnection)); userConnection.addEntityTracker(this.getClass(), new EntityTracker1_9(userConnection));
// Chunk tracker // Chunk tracker
userConnection.put(new ClientChunks(userConnection)); userConnection.put(new ClientChunks(userConnection));
// Movement tracker // Movement tracker

Datei anzeigen

@ -20,6 +20,7 @@ package com.viaversion.viaversion.protocols.protocol1_9to1_8.chat;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
public class ChatRewriter { public class ChatRewriter {
@ -32,7 +33,8 @@ public class ChatRewriter {
public static void toClient(JsonObject obj, UserConnection user) { public static void toClient(JsonObject obj, UserConnection user) {
//Check gamemode change //Check gamemode change
if (obj.get("translate") != null && obj.get("translate").getAsString().equals("gameMode.changed")) { if (obj.get("translate") != null && obj.get("translate").getAsString().equals("gameMode.changed")) {
String gameMode = user.get(EntityTracker1_9.class).getGameMode().getText(); EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
String gameMode = tracker.getGameMode().getText();
JsonObject gameModeObject = new JsonObject(); JsonObject gameModeObject = new JsonObject();
gameModeObject.addProperty("text", gameMode); gameModeObject.addProperty("text", gameMode);

Datei anzeigen

@ -29,21 +29,20 @@ import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9; import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter; import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.MetadataRewriter;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
public class MetadataRewriter1_9To1_8 extends MetadataRewriter { public class MetadataRewriter1_9To1_8 extends EntityRewriter<Protocol1_9To1_8> {
public MetadataRewriter1_9To1_8(Protocol1_9To1_8 protocol) { public MetadataRewriter1_9To1_8(Protocol1_9To1_8 protocol) {
super(protocol, EntityTracker1_9.class); super(protocol);
} }
@Override @Override
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception { protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
MetaIndex metaIndex = MetaIndex.searchIndex(type, metadata.getId()); MetaIndex metaIndex = MetaIndex.searchIndex(type, metadata.id());
if (metaIndex == null) { if (metaIndex == null) {
throw new Exception("Could not find valid metadata"); throw new Exception("Could not find valid metadata");
} }
@ -139,12 +138,12 @@ public class MetadataRewriter1_9To1_8 extends MetadataRewriter {
} }
@Override @Override
protected EntityType getTypeFromId(int type) { protected EntityType typeFromId(int type) {
return Entity1_10Types.getTypeFromId(type, false); return Entity1_10Types.getTypeFromId(type, false);
} }
@Override @Override
protected EntityType getObjectTypeFromId(int type) { protected EntityType objectTypeFromId(int type) {
return Entity1_10Types.getTypeFromId(type, true); return Entity1_10Types.getTypeFromId(type, true);
} }
} }

Datei anzeigen

@ -64,7 +64,7 @@ public class EntityPackets {
map(Type.BOOLEAN, new ValueTransformer<Boolean, Void>(Type.NOTHING) { map(Type.BOOLEAN, new ValueTransformer<Boolean, Void>(Type.NOTHING) {
@Override @Override
public Void transform(PacketWrapper wrapper, Boolean inputValue) throws Exception { public Void transform(PacketWrapper wrapper, Boolean inputValue) throws Exception {
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (!inputValue) { if (!inputValue) {
int passenger = wrapper.get(Type.INT, 0); int passenger = wrapper.get(Type.INT, 0);
int vehicle = wrapper.get(Type.INT, 1); int vehicle = wrapper.get(Type.INT, 1);
@ -108,7 +108,7 @@ public class EntityPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0); int entityID = wrapper.get(Type.VAR_INT, 0);
if (Via.getConfig().isHologramPatch()) { if (Via.getConfig().isHologramPatch()) {
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (tracker.getKnownHolograms().contains(entityID)) { if (tracker.getKnownHolograms().contains(entityID)) {
Double newValue = wrapper.get(Type.DOUBLE, 1); Double newValue = wrapper.get(Type.DOUBLE, 1);
newValue += (Via.getConfig().getHologramYOffset()); newValue += (Via.getConfig().getHologramYOffset());
@ -158,7 +158,7 @@ public class EntityPackets {
@Override @Override
public Integer transform(PacketWrapper wrapper, Short slot) throws Exception { public Integer transform(PacketWrapper wrapper, Short slot) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
int receiverId = wrapper.user().get(EntityTracker1_9.class).getClientEntityId(); int receiverId = wrapper.user().getEntityTracker(Protocol1_9To1_8.class).clientEntityId();
// Normally, 0 = hand and 1-4 = armor // Normally, 0 = hand and 1-4 = armor
// ... but if the sent id is equal to the receiver's id, 0-3 will instead mark the armor slots // ... but if the sent id is equal to the receiver's id, 0-3 will instead mark the armor slots
// (In 1.9+, every client treats the received the same: 0=hand, 1=offhand, 2-5=armor) // (In 1.9+, every client treats the received the same: 0=hand, 1=offhand, 2-5=armor)
@ -181,7 +181,7 @@ public class EntityPackets {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
int entityID = wrapper.get(Type.VAR_INT, 0); int entityID = wrapper.get(Type.VAR_INT, 0);
Item stack = wrapper.get(Type.ITEM, 0); Item stack = wrapper.get(Type.ITEM, 0);
@ -207,7 +207,7 @@ public class EntityPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); 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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (tracker.hasEntity(entityId)) { if (tracker.hasEntity(entityId)) {
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user()); protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user());
} else { } else {
@ -224,7 +224,7 @@ public class EntityPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); 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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.handleMetadata(entityID, metadataList); tracker.handleMetadata(entityID, metadataList);
} }
}); });
@ -288,7 +288,9 @@ public class EntityPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
if (!Via.getConfig().isMinimizeCooldown()) return; if (!Via.getConfig().isMinimizeCooldown()) return;
if (wrapper.get(Type.VAR_INT, 0) != wrapper.user().get(EntityTracker1_9.class).getProvidedEntityId()) {
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (wrapper.get(Type.VAR_INT, 0) != tracker.getProvidedEntityId()) {
return; return;
} }
int propertiesToRead = wrapper.read(Type.INT); int propertiesToRead = wrapper.read(Type.INT);

Datei anzeigen

@ -121,7 +121,7 @@ public class InventoryPackets {
// Check if it is the inventory of the player // Check if it is the inventory of the player
if (showShieldWhenSwordInHand) { if (showShieldWhenSwordInHand) {
InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class); InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
short slotID = wrapper.get(Type.SHORT, 0); short slotID = wrapper.get(Type.SHORT, 0);
short windowId = wrapper.get(Type.BYTE, 0); short windowId = wrapper.get(Type.BYTE, 0);
@ -168,7 +168,7 @@ public class InventoryPackets {
Short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0); Short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0);
InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class); InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand() boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand()
&& Via.getConfig().isShieldBlocking(); && Via.getConfig().isShieldBlocking();
@ -266,7 +266,7 @@ public class InventoryPackets {
if (showShieldWhenSwordInHand) { if (showShieldWhenSwordInHand) {
InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class); InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
short slotID = wrapper.get(Type.SHORT, 0); short slotID = wrapper.get(Type.SHORT, 0);
// Update item in slot // Update item in slot
@ -401,7 +401,7 @@ public class InventoryPackets {
boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand() boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand()
&& Via.getConfig().isShieldBlocking(); && Via.getConfig().isShieldBlocking();
EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (entityTracker.isBlocking()) { if (entityTracker.isBlocking()) {
entityTracker.setBlocking(false); entityTracker.setBlocking(false);

Datei anzeigen

@ -19,6 +19,7 @@ package com.viaversion.viaversion.protocols.protocol1_9to1_8.packets;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types; import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@ -139,7 +140,7 @@ public class PlayerPackets {
if (mode == 0 || mode == 3 || mode == 4) { if (mode == 0 || mode == 3 || mode == 4) {
String[] players = wrapper.passthrough(Type.STRING_ARRAY); // Players String[] players = wrapper.passthrough(Type.STRING_ARRAY); // Players
final EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class); final EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
String myName = wrapper.user().getProtocolInfo().getUsername(); String myName = wrapper.user().getProtocolInfo().getUsername();
String teamName = wrapper.get(Type.STRING, 0); String teamName = wrapper.get(Type.STRING, 0);
for (String player : players) { for (String player : players) {
@ -161,7 +162,7 @@ public class PlayerPackets {
} }
if (mode == 1) { // Remove team if (mode == 1) { // Remove team
final EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class); final EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
String teamName = wrapper.get(Type.STRING, 0); String teamName = wrapper.get(Type.STRING, 0);
if (entityTracker.isAutoTeam() if (entityTracker.isAutoTeam()
&& teamName.equals(entityTracker.getCurrentTeam())) { && teamName.equals(entityTracker.getCurrentTeam())) {
@ -187,7 +188,7 @@ public class PlayerPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.INT, 0); int entityId = wrapper.get(Type.INT, 0);
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.addEntity(entityId, Entity1_10Types.EntityType.PLAYER); tracker.addEntity(entityId, Entity1_10Types.EntityType.PLAYER);
tracker.setClientEntityId(entityId); tracker.setClientEntityId(entityId);
} }
@ -202,7 +203,7 @@ public class PlayerPackets {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.setGameMode(GameMode.getById(wrapper.get(Type.UNSIGNED_BYTE, 0))); //Set player gamemode tracker.setGameMode(GameMode.getById(wrapper.get(Type.UNSIGNED_BYTE, 0))); //Set player gamemode
} }
}); });
@ -221,7 +222,7 @@ public class PlayerPackets {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (Via.getConfig().isAutoTeam()) { if (Via.getConfig().isAutoTeam()) {
entityTracker.setAutoTeam(true); entityTracker.setAutoTeam(true);
// Workaround for packet order issue // Workaround for packet order issue
@ -367,7 +368,8 @@ public class PlayerPackets {
cc.getLoadedChunks().clear(); cc.getLoadedChunks().clear();
int gamemode = wrapper.get(Type.UNSIGNED_BYTE, 0); int gamemode = wrapper.get(Type.UNSIGNED_BYTE, 0);
wrapper.user().get(EntityTracker1_9.class).setGameMode(GameMode.getById(gamemode)); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.setGameMode(GameMode.getById(gamemode));
} }
}); });
@ -394,7 +396,8 @@ public class PlayerPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 3) { //Change gamemode if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 3) { //Change gamemode
int gamemode = wrapper.get(Type.FLOAT, 0).intValue(); int gamemode = wrapper.get(Type.FLOAT, 0).intValue();
wrapper.user().get(EntityTracker1_9.class).setGameMode(GameMode.getById(gamemode)); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.setGameMode(GameMode.getById(gamemode));
} }
} }
}); });
@ -496,7 +499,7 @@ public class PlayerPackets {
int action = wrapper.get(Type.VAR_INT, 0); int action = wrapper.get(Type.VAR_INT, 0);
if (action == 2) { if (action == 2) {
// cancel any blocking >.> // cancel any blocking >.>
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (tracker.isBlocking()) { if (tracker.isBlocking()) {
if (!Via.getConfig().isShowShieldWhenSwordInHand()) { if (!Via.getConfig().isShowShieldWhenSwordInHand()) {
tracker.setSecondHand(null); tracker.setSecondHand(null);

Datei anzeigen

@ -57,7 +57,7 @@ public class SpawnPackets {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void write(PacketWrapper wrapper) throws Exception {
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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID
} }
}); });
@ -69,7 +69,7 @@ public class SpawnPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0); int entityID = wrapper.get(Type.VAR_INT, 0);
int typeID = wrapper.get(Type.BYTE, 0); int typeID = wrapper.get(Type.BYTE, 0);
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.addEntity(entityID, Entity1_10Types.getTypeFromId(typeID, true)); tracker.addEntity(entityID, Entity1_10Types.getTypeFromId(typeID, true));
tracker.sendMetadataBuffer(entityID); tracker.sendMetadataBuffer(entityID);
} }
@ -143,7 +143,7 @@ public class SpawnPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.addEntity(entityID, Entity1_10Types.EntityType.EXPERIENCE_ORB); tracker.addEntity(entityID, Entity1_10Types.EntityType.EXPERIENCE_ORB);
tracker.sendMetadataBuffer(entityID); tracker.sendMetadataBuffer(entityID);
} }
@ -168,7 +168,7 @@ public class SpawnPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
// Currently only lightning uses this // Currently only lightning uses this
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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.addEntity(entityID, Entity1_10Types.EntityType.LIGHTNING); tracker.addEntity(entityID, Entity1_10Types.EntityType.LIGHTNING);
tracker.sendMetadataBuffer(entityID); tracker.sendMetadataBuffer(entityID);
} }
@ -189,7 +189,7 @@ public class SpawnPackets {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void write(PacketWrapper wrapper) throws Exception {
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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID
} }
}); });
@ -201,7 +201,7 @@ public class SpawnPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0); int entityID = wrapper.get(Type.VAR_INT, 0);
int typeID = wrapper.get(Type.UNSIGNED_BYTE, 0); int typeID = wrapper.get(Type.UNSIGNED_BYTE, 0);
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.addEntity(entityID, Entity1_10Types.getTypeFromId(typeID, false)); tracker.addEntity(entityID, Entity1_10Types.getTypeFromId(typeID, false));
tracker.sendMetadataBuffer(entityID); tracker.sendMetadataBuffer(entityID);
} }
@ -225,7 +225,7 @@ public class SpawnPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); 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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (tracker.hasEntity(entityId)) { if (tracker.hasEntity(entityId)) {
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user()); protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user());
} else { } else {
@ -240,7 +240,7 @@ public class SpawnPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); 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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.handleMetadata(entityID, metadataList); tracker.handleMetadata(entityID, metadataList);
} }
}); });
@ -257,7 +257,7 @@ public class SpawnPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.addEntity(entityID, Entity1_10Types.EntityType.PAINTING); tracker.addEntity(entityID, Entity1_10Types.EntityType.PAINTING);
tracker.sendMetadataBuffer(entityID); tracker.sendMetadataBuffer(entityID);
} }
@ -266,7 +266,7 @@ public class SpawnPackets {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void write(PacketWrapper wrapper) throws Exception {
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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID
} }
}); });
@ -288,7 +288,7 @@ public class SpawnPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.addEntity(entityID, Entity1_10Types.EntityType.PLAYER); tracker.addEntity(entityID, Entity1_10Types.EntityType.PLAYER);
tracker.sendMetadataBuffer(entityID); tracker.sendMetadataBuffer(entityID);
} }
@ -326,7 +326,7 @@ public class SpawnPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); 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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (tracker.hasEntity(entityId)) { if (tracker.hasEntity(entityId)) {
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user()); protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user());
} else { } else {
@ -342,7 +342,7 @@ public class SpawnPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); 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); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.handleMetadata(entityID, metadataList); tracker.handleMetadata(entityID, metadataList);
} }
}); });
@ -361,7 +361,7 @@ public class SpawnPackets {
int[] entities = wrapper.get(Type.VAR_INT_ARRAY_PRIMITIVE, 0); int[] entities = wrapper.get(Type.VAR_INT_ARRAY_PRIMITIVE, 0);
for (int entity : entities) { for (int entity : entities) {
// EntityTracker // EntityTracker
wrapper.user().get(EntityTracker1_9.class).removeEntity(entity); wrapper.user().getEntityTracker(Protocol1_9To1_8.class).removeEntity(entity);
} }
} }
}); });

Datei anzeigen

@ -113,7 +113,7 @@ public class WorldPackets {
wrapper.set(Type.STRING, 0, newname); wrapper.set(Type.STRING, 0, newname);
wrapper.write(Type.VAR_INT, catid); // Write Category ID wrapper.write(Type.VAR_INT, catid); // Write Category ID
if (effect != null && effect.isBreaksound()) { if (effect != null && effect.isBreaksound()) {
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
int x = wrapper.passthrough(Type.INT); //Position X int x = wrapper.passthrough(Type.INT); //Position X
int y = wrapper.passthrough(Type.INT); //Position Y int y = wrapper.passthrough(Type.INT); //Position Y
int z = wrapper.passthrough(Type.INT); //Position Z int z = wrapper.passthrough(Type.INT); //Position Z
@ -278,7 +278,7 @@ public class WorldPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int status = wrapper.get(Type.UNSIGNED_BYTE, 0); int status = wrapper.get(Type.UNSIGNED_BYTE, 0);
if (status == 5 || status == 4 || status == 3) { if (status == 5 || status == 4 || status == 3) {
EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (entityTracker.isBlocking()) { if (entityTracker.isBlocking()) {
entityTracker.setBlocking(false); entityTracker.setBlocking(false);
if (!Via.getConfig().isShowShieldWhenSwordInHand()) { if (!Via.getConfig().isShowShieldWhenSwordInHand()) {
@ -308,7 +308,7 @@ public class WorldPackets {
Item item = Protocol1_9To1_8.getHandItem(wrapper.user()); Item item = Protocol1_9To1_8.getHandItem(wrapper.user());
// Blocking patch // Blocking patch
if (Via.getConfig().isShieldBlocking()) { if (Via.getConfig().isShieldBlocking()) {
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
// Check if the shield is already there or if we have to give it here // Check if the shield is already there or if we have to give it here
boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand(); boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand();
@ -412,7 +412,7 @@ public class WorldPackets {
x++; x++;
break; break;
} }
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.addBlockInteraction(new Position(x, y, z)); tracker.addBlockInteraction(new Position(x, y, z));
} }
}); });

Datei anzeigen

@ -59,7 +59,8 @@ public class CommandBlockProvider implements Provider {
return; return;
PacketWrapper wrapper = PacketWrapper.create(0x1B, null, user); // Entity status PacketWrapper wrapper = PacketWrapper.create(0x1B, null, user); // Entity status
wrapper.write(Type.INT, user.get(EntityTracker1_9.class).getProvidedEntityId()); // Entity ID EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
wrapper.write(Type.INT, tracker.getProvidedEntityId()); // Entity ID
wrapper.write(Type.BYTE, (byte) 26); // Hardcoded op permission level wrapper.write(Type.BYTE, (byte) 26); // Hardcoded op permission level
wrapper.send(Protocol1_9To1_8.class); wrapper.send(Protocol1_9To1_8.class);

Datei anzeigen

@ -19,11 +19,11 @@ package com.viaversion.viaversion.protocols.protocol1_9to1_8.providers;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.platform.providers.Provider; import com.viaversion.viaversion.api.platform.providers.Provider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
public class EntityIdProvider implements Provider { public class EntityIdProvider implements Provider {
public int getEntityId(UserConnection user) throws Exception { public int getEntityId(UserConnection user) throws Exception {
return user.get(EntityTracker1_9.class).getClientEntityId(); return user.getEntityTracker(Protocol1_9To1_8.class).clientEntityId();
} }
} }

Datei anzeigen

@ -20,10 +20,10 @@ package com.viaversion.viaversion.protocols.protocol1_9to1_8.storage;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.legacy.bossbar.BossBar; import com.viaversion.viaversion.api.legacy.bossbar.BossBar;
import com.viaversion.viaversion.api.legacy.bossbar.BossColor; import com.viaversion.viaversion.api.legacy.bossbar.BossColor;
import com.viaversion.viaversion.api.legacy.bossbar.BossStyle; import com.viaversion.viaversion.api.legacy.bossbar.BossStyle;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types.EntityType; import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types.EntityType;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
@ -32,7 +32,7 @@ import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_9; import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.data.EntityTracker; import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.GameMode; import com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.GameMode;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8; import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8;
@ -48,7 +48,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class EntityTracker1_9 extends EntityTracker { public class EntityTracker1_9 extends EntityTrackerBase {
private final Map<Integer, UUID> uuidMap = new ConcurrentHashMap<>(); private final Map<Integer, UUID> uuidMap = new ConcurrentHashMap<>();
private final Map<Integer, List<Metadata>> metadataBuffer = new ConcurrentHashMap<>(); private final Map<Integer, List<Metadata>> metadataBuffer = new ConcurrentHashMap<>();
private final Map<Integer, Integer> vehicleMap = new ConcurrentHashMap<>(); private final Map<Integer, Integer> vehicleMap = new ConcurrentHashMap<>();
@ -84,11 +84,11 @@ public class EntityTracker1_9 extends EntityTracker {
} }
public void setSecondHand(Item item) { public void setSecondHand(Item item) {
setSecondHand(getClientEntityId(), item); setSecondHand(clientEntityId(), item);
} }
public void setSecondHand(int entityID, Item item) { public void setSecondHand(int entityID, Item item) {
PacketWrapper wrapper = PacketWrapper.create(0x3C, null, getUser()); PacketWrapper wrapper = PacketWrapper.create(0x3C, null, user());
wrapper.write(Type.VAR_INT, entityID); wrapper.write(Type.VAR_INT, entityID);
wrapper.write(Type.VAR_INT, 1); // slot wrapper.write(Type.VAR_INT, 1); // slot
wrapper.write(Type.ITEM, this.itemInSecondHand = item); wrapper.write(Type.ITEM, this.itemInSecondHand = item);
@ -124,7 +124,7 @@ public class EntityTracker1_9 extends EntityTracker {
* @return player has a sword in the main hand * @return player has a sword in the main hand
*/ */
public boolean hasSwordInHand() { public boolean hasSwordInHand() {
InventoryTracker inventoryTracker = getUser().get(InventoryTracker.class); InventoryTracker inventoryTracker = user().get(InventoryTracker.class);
// Get item in new selected slot // Get item in new selected slot
int inventorySlot = this.heldItemSlot + 36; // Hotbar slot index to inventory slot int inventorySlot = this.heldItemSlot + 36; // Hotbar slot index to inventory slot
@ -147,7 +147,7 @@ public class EntityTracker1_9 extends EntityTracker {
if (bar != null) { if (bar != null) {
bar.hide(); bar.hide();
// Send to provider // Send to provider
Via.getManager().getProviders().get(BossBarProvider.class).handleRemove(getUser(), bar.getId()); Via.getManager().getProviders().get(BossBarProvider.class).handleRemove(user(), bar.getId());
} }
} }
@ -160,7 +160,7 @@ public class EntityTracker1_9 extends EntityTracker {
} }
public void handleMetadata(int entityId, List<Metadata> metadataList) { public void handleMetadata(int entityId, List<Metadata> metadataList) {
com.viaversion.viaversion.api.minecraft.entities.EntityType type = getEntity(entityId); com.viaversion.viaversion.api.minecraft.entities.EntityType type = entityType(entityId);
if (type == null) { if (type == null) {
return; return;
} }
@ -168,14 +168,14 @@ public class EntityTracker1_9 extends EntityTracker {
for (Metadata metadata : new ArrayList<>(metadataList)) { for (Metadata metadata : new ArrayList<>(metadataList)) {
// Fix: wither (crash fix) // Fix: wither (crash fix)
if (type == EntityType.WITHER) { if (type == EntityType.WITHER) {
if (metadata.getId() == 10) { if (metadata.id() == 10) {
metadataList.remove(metadata); metadataList.remove(metadata);
//metadataList.add(new Metadata(10, NewType.Byte.getTypeID(), Type.BYTE, 0)); //metadataList.add(new Metadata(10, NewType.Byte.getTypeID(), Type.BYTE, 0));
} }
} }
// Fix: enderdragon (crash fix) // Fix: enderdragon (crash fix)
if (type == EntityType.ENDER_DRAGON) { if (type == EntityType.ENDER_DRAGON) {
if (metadata.getId() == 11) { if (metadata.id() == 11) {
metadataList.remove(metadata); metadataList.remove(metadata);
// metadataList.add(new Metadata(11, NewType.Byte.getTypeID(), Type.VAR_INT, 0)); // metadataList.add(new Metadata(11, NewType.Byte.getTypeID(), Type.VAR_INT, 0));
} }
@ -190,12 +190,12 @@ public class EntityTracker1_9 extends EntityTracker {
//ECHOPET Patch //ECHOPET Patch
if (type == 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) // 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) if (metadata.id() == 16 && (int) metadata.getValue() == Integer.MIN_VALUE)
metadata.setValue(0); metadata.setValue(0);
} }
if (type == EntityType.PLAYER) { if (type == EntityType.PLAYER) {
if (metadata.getId() == 0) { if (metadata.id() == 0) {
// Byte // Byte
byte data = (byte) metadata.getValue(); byte data = (byte) metadata.getValue();
if (entityId != getProvidedEntityId() && Via.getConfig().isShieldBlocking()) { if (entityId != getProvidedEntityId() && Via.getConfig().isShieldBlocking()) {
@ -211,7 +211,7 @@ public class EntityTracker1_9 extends EntityTracker {
} }
} }
} }
if (metadata.getId() == 12 && Via.getConfig().isLeftHandedHandling()) { // Player model if (metadata.id() == 12 && Via.getConfig().isLeftHandedHandling()) { // Player model
metadataList.add(new Metadata( metadataList.add(new Metadata(
13, // Main hand 13, // Main hand
MetaType1_9.Byte, MetaType1_9.Byte,
@ -220,7 +220,7 @@ public class EntityTracker1_9 extends EntityTracker {
} }
} }
if (type == EntityType.ARMOR_STAND && Via.getConfig().isHologramPatch()) { if (type == EntityType.ARMOR_STAND && Via.getConfig().isHologramPatch()) {
if (metadata.getId() == 0 && getMetaByIndex(metadataList, 10) != null) { if (metadata.id() == 0 && getMetaByIndex(metadataList, 10) != null) {
Metadata meta = getMetaByIndex(metadataList, 10); //Only happens if the armorstand is small Metadata meta = getMetaByIndex(metadataList, 10); //Only happens if the armorstand is small
byte data = (byte) metadata.getValue(); byte data = (byte) metadata.getValue();
// Check invisible | Check small | Check if custom name is empty | Check if custom name visible is true // Check invisible | Check small | Check if custom name is empty | Check if custom name visible is true
@ -233,7 +233,7 @@ public class EntityTracker1_9 extends EntityTracker {
knownHolograms.add(entityId); knownHolograms.add(entityId);
try { try {
// Send movement // Send movement
PacketWrapper wrapper = PacketWrapper.create(0x25, null, getUser()); PacketWrapper wrapper = PacketWrapper.create(0x25, null, user());
wrapper.write(Type.VAR_INT, entityId); wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Type.SHORT, (short) 0); wrapper.write(Type.SHORT, (short) 0);
wrapper.write(Type.SHORT, (short) (128D * (Via.getConfig().getHologramYOffset() * 32D))); wrapper.write(Type.SHORT, (short) (128D * (Via.getConfig().getHologramYOffset() * 32D)));
@ -249,22 +249,22 @@ public class EntityTracker1_9 extends EntityTracker {
// Boss bar // Boss bar
if (Via.getConfig().isBossbarPatch()) { if (Via.getConfig().isBossbarPatch()) {
if (type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) { if (type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) {
if (metadata.getId() == 2) { if (metadata.id() == 2) {
BossBar bar = bossBarMap.get(entityId); BossBar bar = bossBarMap.get(entityId);
String title = (String) metadata.getValue(); String title = (String) metadata.getValue();
title = title.isEmpty() ? (type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title; title = title.isEmpty() ? (type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title;
if (bar == null) { if (bar == null) {
bar = Via.getAPI().legacyAPI().createLegacyBossBar(title, BossColor.PINK, BossStyle.SOLID); bar = Via.getAPI().legacyAPI().createLegacyBossBar(title, BossColor.PINK, BossStyle.SOLID);
bossBarMap.put(entityId, bar); bossBarMap.put(entityId, bar);
bar.addConnection(getUser()); bar.addConnection(user());
bar.show(); bar.show();
// Send to provider // Send to provider
Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(getUser(), bar.getId()); Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(user(), bar.getId());
} else { } else {
bar.setTitle(title); bar.setTitle(title);
} }
} else if (metadata.getId() == 6 && !Via.getConfig().isBossbarAntiflicker()) { // If anti flicker is enabled, don't update health } else if (metadata.id() == 6 && !Via.getConfig().isBossbarAntiflicker()) { // If anti flicker is enabled, don't update health
BossBar bar = bossBarMap.get(entityId); BossBar bar = bossBarMap.get(entityId);
// Make health range between 0 and 1 // Make health range between 0 and 1
float maxHealth = type == EntityType.ENDER_DRAGON ? 200.0f : 300.0f; float maxHealth = type == EntityType.ENDER_DRAGON ? 200.0f : 300.0f;
@ -273,10 +273,10 @@ public class EntityTracker1_9 extends EntityTracker {
String title = type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither"; String title = type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither";
bar = Via.getAPI().legacyAPI().createLegacyBossBar(title, health, BossColor.PINK, BossStyle.SOLID); bar = Via.getAPI().legacyAPI().createLegacyBossBar(title, health, BossColor.PINK, BossStyle.SOLID);
bossBarMap.put(entityId, bar); bossBarMap.put(entityId, bar);
bar.addConnection(getUser()); bar.addConnection(user());
bar.show(); bar.show();
// Send to provider // Send to provider
Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(getUser(), bar.getId()); Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(user(), bar.getId());
} else { } else {
bar.setHealth(health); bar.setHealth(health);
} }
@ -288,14 +288,14 @@ public class EntityTracker1_9 extends EntityTracker {
public Metadata getMetaByIndex(List<Metadata> list, int index) { public Metadata getMetaByIndex(List<Metadata> list, int index) {
for (Metadata meta : list) for (Metadata meta : list)
if (index == meta.getId()) { if (index == meta.id()) {
return meta; return meta;
} }
return null; return null;
} }
public void sendTeamPacket(boolean add, boolean now) { public void sendTeamPacket(boolean add, boolean now) {
PacketWrapper wrapper = PacketWrapper.create(0x41, null, getUser()); PacketWrapper wrapper = PacketWrapper.create(0x41, null, user());
wrapper.write(Type.STRING, "viaversion"); // Use viaversion as name wrapper.write(Type.STRING, "viaversion"); // Use viaversion as name
if (add) { if (add) {
// add // add
@ -311,7 +311,7 @@ public class EntityTracker1_9 extends EntityTracker {
} else { } else {
wrapper.write(Type.BYTE, (byte) 3); wrapper.write(Type.BYTE, (byte) 3);
} }
wrapper.write(Type.STRING_ARRAY, new String[]{getUser().getProtocolInfo().getUsername()}); wrapper.write(Type.STRING_ARRAY, new String[]{user().getProtocolInfo().getUsername()});
} else { } else {
wrapper.write(Type.BYTE, (byte) 1); // remove team wrapper.write(Type.BYTE, (byte) 1); // remove team
} }
@ -335,11 +335,11 @@ public class EntityTracker1_9 extends EntityTracker {
public void sendMetadataBuffer(int entityId) { public void sendMetadataBuffer(int entityId) {
List<Metadata> metadataList = metadataBuffer.get(entityId); List<Metadata> metadataList = metadataBuffer.get(entityId);
if (metadataList != null) { if (metadataList != null) {
PacketWrapper wrapper = PacketWrapper.create(0x39, null, getUser()); PacketWrapper wrapper = PacketWrapper.create(0x39, null, user());
wrapper.write(Type.VAR_INT, entityId); wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Types1_9.METADATA_LIST, metadataList); wrapper.write(Types1_9.METADATA_LIST, metadataList);
Via.getManager().getProtocolManager().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class) Via.getManager().getProtocolManager().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class)
.handleMetadata(entityId, metadataList, getUser()); .handleMetadata(entityId, metadataList, user());
handleMetadata(entityId, metadataList); handleMetadata(entityId, metadataList);
if (!metadataList.isEmpty()) { if (!metadataList.isEmpty()) {
try { try {
@ -354,9 +354,9 @@ public class EntityTracker1_9 extends EntityTracker {
public int getProvidedEntityId() { public int getProvidedEntityId() {
try { try {
return Via.getManager().getProviders().get(EntityIdProvider.class).getEntityId(getUser()); return Via.getManager().getProviders().get(EntityIdProvider.class).getEntityId(user());
} catch (Exception e) { } catch (Exception e) {
return getClientEntityId(); return clientEntityId();
} }
} }

Datei anzeigen

@ -19,6 +19,7 @@ package com.viaversion.viaversion.protocols.protocol1_9to1_8.storage;
import com.viaversion.viaversion.api.connection.StoredObject; import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -83,7 +84,7 @@ public class InventoryTracker extends StoredObject {
* @param button The button to use in the click * @param button The button to use in the click
*/ */
public void handleWindowClick(short windowId, byte mode, short hoverSlot, byte button) { public void handleWindowClick(short windowId, byte mode, short hoverSlot, byte button) {
EntityTracker1_9 entityTracker = getUser().get(EntityTracker1_9.class); EntityTracker1_9 entityTracker = getUser().getEntityTracker(Protocol1_9To1_8.class);
// Skip inventory background clicks // Skip inventory background clicks
if (hoverSlot == -1) { if (hoverSlot == -1) {

Datei anzeigen

@ -0,0 +1,521 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.rewriter;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.rewriter.meta.MetaFilter;
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent;
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEventImpl;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
public abstract class EntityRewriter<T extends Protocol> extends RewriterBase<T> {
private static final Metadata[] EMPTY_ARRAY = new Metadata[0];
protected final List<MetaFilter> metadataFilters = new ArrayList<>();
protected final boolean trackMappedType;
protected Int2IntMap typeMappings;
protected EntityRewriter(T protocol) {
this(protocol, true);
}
/**
* Creates a new entity rewriter instance.
*
* @param protocol protocol
* @param trackMappedType whether the mapped or unmapped entity type should be tracked
*/
protected EntityRewriter(T protocol, boolean trackMappedType) {
super(protocol);
this.trackMappedType = trackMappedType;
protocol.put(this);
}
/**
* Returns a meta filter builder.
* <p>
* Calling {@link MetaFilter.Builder#register()} will automatically register the filter on this rewriter.
* Don't forget to call {@link MetaFilter.Builder#register()}.
*
* @return meta filter builder
*/
public MetaFilter.Builder filter() {
return new MetaFilter.Builder(this);
}
/**
* Registers a metadata filter.
* Note that {@link MetaFilter.Builder#register()} already calls this method.
*
* @param filter filter to register
* @throws IllegalArgumentException if the filter is already registered
*/
public void registerFilter(MetaFilter filter) {
Preconditions.checkArgument(!metadataFilters.contains(filter));
metadataFilters.add(filter);
}
/**
* Handles and transforms metadata of an entity.
*
* @param entityId entity id
* @param metadataList full, mutable list of metadata
* @param connection user connection
*/
public void handleMetadata(int entityId, List<Metadata> metadataList, UserConnection connection) {
EntityType type = tracker(connection).entityType(entityId);
int i = 0; // Count index for fast removal
for (Metadata metadata : metadataList.toArray(EMPTY_ARRAY)) { // Copy the list to allow mutation
// Call handlers implementing the old handleMetadata
if (!callOldMetaHandler(entityId, type, metadata, metadataList, connection)) {
metadataList.remove(i--);
continue;
}
for (MetaFilter filter : metadataFilters) {
if (filter.isFiltered(type, metadata)) {
MetaHandlerEvent event = new MetaHandlerEventImpl(connection, type, entityId, metadata.id(), metadata, metadataList);
try {
filter.handler().handle(event, metadata);
} catch (Exception e) {
logException(e, type, metadataList, metadata);
metadataList.remove(i--);
break;
}
if (event.cancelled()) {
// Remove meta, decrease list index counter, and break current filter loop
metadataList.remove(i--);
break;
}
Preconditions.checkArgument(event.index() == event.meta().id(), "Meta event id desync: Calls to meta().setId() are illegal");
if (event.extraMeta() != null) {
// Add newly created meta
metadataList.addAll(event.extraMeta());
event.clearExtraMeta();
}
}
}
i++;
}
}
@Deprecated
private boolean callOldMetaHandler(int entityId, EntityType type, Metadata metadata, List<Metadata> metadataList, UserConnection connection) {
try {
handleMetadata(entityId, type, metadata, metadataList, connection);
return true;
} catch (Exception e) {
logException(e, type, metadataList, metadata);
return false;
}
}
/**
* To be overridden to handle metadata.
*
* @param entityId entity id
* @param type entity type, or null if not tracked
* @param metadata current metadata
* @param metadatas full, mutable list of metadata
* @param connection user connection
* @deprecated use {@link #filter()}
*/
@Deprecated
protected void handleMetadata(int entityId, @Nullable EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
}
/**
* Returns the entity type from the given (mapped) type id.
*
* @param type mapped type id
* @return entity type
*/
protected abstract EntityType typeFromId(int type);
/**
* Returns the entity type from the given id.
* From 1.14 and onwards, this is the same exact value as {@link #typeFromId(int)}.
*
* @param type entity type id
* @return EntityType from id
*/
protected EntityType objectTypeFromId(int type) {
return typeFromId(type);
}
/**
* Returns the mapped entitiy (or the same if it has not changed).
*
* @param oldId old entity id
* @return mapped entity id
*/
public int newEntityId(int oldId) {
return typeMappings != null ? typeMappings.getOrDefault(oldId, oldId) : oldId;
}
/**
* Maps an entity type.
*
* @param type entity type
* @param mappedType mapped entity type
* @throws IllegalArgumentException if the types share the same implementing class
*/
public void mapEntityType(EntityType type, EntityType mappedType) {
Preconditions.checkArgument(type.getClass() != mappedType.getClass(), "EntityTypes should not be of the same class/enum");
mapEntityType(type.getId(), mappedType.getId());
}
protected void mapEntityType(int id, int mappedId) {
if (typeMappings == null) {
typeMappings = new Int2IntOpenHashMap();
typeMappings.defaultReturnValue(-1);
}
typeMappings.put(id, mappedId);
}
/**
* Maps entity ids based on the enum constant's names.
*
* @param oldTypes entity types of the higher version
* @param newTypeClass entity types enum class of the lower version
* @param <E> new enum entity type
*/
public <E extends Enum<E> & EntityType> void mapTypes(EntityType[] oldTypes, Class<E> newTypeClass) {
if (typeMappings == null) {
typeMappings = new Int2IntOpenHashMap(oldTypes.length, 1F);
typeMappings.defaultReturnValue(-1);
}
for (EntityType oldType : oldTypes) {
try {
E newType = Enum.valueOf(newTypeClass, oldType.name());
typeMappings.put(oldType.getId(), newType.getId());
} catch (IllegalArgumentException notFound) {
if (!typeMappings.containsKey(oldType.getId())) {
Via.getPlatform().getLogger().warning("Could not find new entity type for " + oldType + "! " +
"Old type: " + oldType.getClass().getEnclosingClass().getSimpleName() + ", new type: " + newTypeClass.getEnclosingClass().getSimpleName());
}
}
}
}
/**
* Registers a metadata handler to rewrite, item, block, and particle ids stored in metadata.
*
* @param itemType item meta type if needed
* @param blockType block meta type if needed
* @param particleType particle meta type if needed
* @param itemRewriter itemrewriter if needed
*/
public void registerDumMetaTypeHandler(@Nullable MetaType itemType, @Nullable MetaType blockType, @Nullable MetaType particleType, ItemRewriter.@Nullable RewriteFunction itemRewriter) {
filter().handler((event, meta) -> {
if (itemType != null && meta.metaType() == itemType) {
itemRewriter.rewrite(meta.value());
} else if (blockType != null && meta.metaType() == blockType) {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (particleType != null && meta.metaType() == particleType) {
rewriteParticle(meta.value());
}
});
}
public void registerTracker(ClientboundPacketType packetType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
handler(trackerHandler());
}
});
}
public void registerTrackerWithData(ClientboundPacketType packetType, EntityType fallingBlockType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw
map(Type.INT); // 8 - Data
handler(trackerHandler());
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType entityType = tracker(wrapper.user()).entityType(entityId);
if (entityType == fallingBlockType) {
wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(wrapper.get(Type.INT, 0)));
}
});
}
});
}
/**
* Registers an entity tracker for the extra spawn packets like player, painting, or xp orb spawns.
*
* @param packetType packet type
* @param entityType entity type
* @param intType int type of the entity id
*/
public void registerTracker(ClientboundPacketType packetType, EntityType entityType, Type<?> intType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int entityId = (int) wrapper.passthrough(intType);
tracker(wrapper.user()).addEntity(entityId, entityType);
});
}
});
}
/**
* Registers an entity tracker for the extra spawn packets.
*
* @param packetType packet type
* @param entityType entity type
*/
public void registerTracker(ClientboundPacketType packetType, EntityType entityType) {
registerTracker(packetType, entityType, Type.VAR_INT);
}
/**
* Sub 1.17 method for entity remove packets.
*
* @param packetType remove entities packet type
*/
public void registerRemoveEntities(ClientboundPacketType packetType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int[] entityIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
EntityTracker entityTracker = tracker(wrapper.user());
for (int entity : entityIds) {
entityTracker.removeEntity(entity);
}
});
}
});
}
/**
* 1.17+ method for entity remove packets.
*
* @param packetType remove entities packet type
*/
public void registerRemoveEntity(ClientboundPacketType packetType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int entityId = wrapper.passthrough(Type.VAR_INT);
tracker(wrapper.user()).removeEntity(entityId);
});
}
});
}
public void registerMetadataRewriter(ClientboundPacketType packetType, @Nullable Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
if (oldMetaType != null) {
map(oldMetaType, newMetaType);
} else {
map(newMetaType);
}
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
List<Metadata> metadata = wrapper.get(newMetaType, 0);
handleMetadata(entityId, metadata, wrapper.user());
});
}
});
}
public void registerMetadataRewriter(ClientboundPacketType packetType, Type<List<Metadata>> metaType) {
registerMetadataRewriter(packetType, null, metaType);
}
public PacketHandler trackerHandler() {
return trackerAndRewriterHandler(null);
}
protected PacketHandler worldDataTrackerHandler(int nbtIndex) {
return wrapper -> {
EntityTracker tracker = tracker(wrapper.user());
CompoundTag registryData = wrapper.get(Type.NBT, nbtIndex);
Tag height = registryData.get("height");
if (height instanceof IntTag) {
int blockHeight = ((IntTag) height).asInt();
tracker.setCurrentWorldSectionHeight(blockHeight >> 4);
} else {
Via.getPlatform().getLogger().warning("Height missing in dimension data: " + registryData);
}
Tag minY = registryData.get("min_y");
if (minY instanceof IntTag) {
tracker.setCurrentMinY(((IntTag) minY).asInt());
} else {
Via.getPlatform().getLogger().warning("Min Y missing in dimension data: " + registryData);
}
};
}
// ---------------------------------------------------------------------------
// Sub 1.14.1 methods
/**
* Returns a packethandler to track and rewrite an entity.
*
* @param metaType type of the metadata list
* @return handler for tracking and rewriting entities
*/
public PacketHandler trackerAndRewriterHandler(@Nullable Type<List<Metadata>> metaType) {
return wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
int type = wrapper.get(Type.VAR_INT, 1);
int newType = newEntityId(type);
if (newType != type) {
wrapper.set(Type.VAR_INT, 1, newType);
}
EntityType entType = typeFromId(trackMappedType ? newType : type);
// Register Type ID
tracker(wrapper.user()).addEntity(entityId, entType);
if (metaType != null) {
handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user());
}
};
}
public PacketHandler trackerAndRewriterHandler(@Nullable Type<List<Metadata>> metaType, EntityType entityType) {
return wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
// Register Type ID
tracker(wrapper.user()).addEntity(entityId, entityType);
if (metaType != null) {
handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user());
}
};
}
/**
* Returns a packethandler to track an object entity.
*
* @return handler for tracking and rewriting entities
*/
public PacketHandler objectTrackerHandler() {
return wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
byte type = wrapper.get(Type.BYTE, 0);
EntityType entType = objectTypeFromId(type);
// Register Type ID
tracker(wrapper.user()).addEntity(entityId, entType);
};
}
// ---------------------------------------------------------------------------
@Deprecated
protected @Nullable Metadata metaByIndex(int index, List<Metadata> metadataList) {
for (Metadata metadata : metadataList) {
if (metadata.id() == index) {
return metadata;
}
}
return null;
}
protected void rewriteParticle(Particle particle) {
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
int id = particle.getId();
if (id == mappings.getBlockId() || id == mappings.getFallingDustId()) {
Particle.ParticleData data = particle.getArguments().get(0);
data.setValue(protocol.getMappingData().getNewBlockStateId(data.get()));
} else if (id == mappings.getItemId()) {
Particle.ParticleData data = particle.getArguments().get(0);
data.setValue(protocol.getMappingData().getNewItemId(data.get()));
}
particle.setId(protocol.getMappingData().getNewParticleId(id));
}
/**
* Returns the entity tracker for the current protocol.
*
* @param connection user connection
* @param <T> entity tracker type
* @return entity tracker
*/
public <T extends EntityTracker> T tracker(UserConnection connection) {
return connection.getEntityTracker(protocol.getClass());
}
private void logException(Exception e, EntityType type, List<Metadata> metadataList, Metadata 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("Indexed meta: " + metadata);
logger.warning(metadataList.stream().sorted(Comparator.comparingInt(Metadata::id))
.map(Metadata::toString).collect(Collectors.joining("\n", "Metadata: ", "")));
e.printStackTrace();
}
}
}

Datei anzeigen

@ -1,330 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.rewriter;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.data.EntityTracker;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.logging.Logger;
public abstract class MetadataRewriter {
private static final Metadata[] EMPTY_ARRAY = new Metadata[0];
private final Class<? extends EntityTracker> entityTrackerClass;
protected final Protocol protocol;
private Int2IntMap typeMapping;
protected MetadataRewriter(Protocol protocol, Class<? extends EntityTracker> entityTrackerClass) {
this.protocol = protocol;
this.entityTrackerClass = entityTrackerClass;
protocol.put(this);
}
public final void handleMetadata(int entityId, List<Metadata> metadatas, UserConnection connection) {
EntityType type = connection.get(entityTrackerClass).getEntity(entityId);
for (Metadata metadata : metadatas.toArray(EMPTY_ARRAY)) {
try {
handleMetadata(entityId, type, metadata, metadatas, 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 rewriteParticle(Particle particle) {
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
int id = particle.getId();
if (id == mappings.getBlockId() || id == mappings.getFallingDustId()) {
Particle.ParticleData data = particle.getArguments().get(0);
data.setValue(protocol.getMappingData().getNewBlockStateId(data.get()));
} else if (id == mappings.getItemId()) {
Particle.ParticleData data = particle.getArguments().get(0);
data.setValue(protocol.getMappingData().getNewItemId(data.get()));
}
particle.setId(protocol.getMappingData().getNewParticleId(id));
}
//TODO add respawn/join once they stop changing too much
public void registerTracker(ClientboundPacketType packetType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
handler(getTracker());
}
});
}
public void registerSpawnTrackerWithData(ClientboundPacketType packetType, EntityType fallingBlockType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw
map(Type.INT); // 8 - Data
handler(getTracker());
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType entityType = wrapper.user().get(entityTrackerClass).getEntity(entityId);
if (entityType == fallingBlockType) {
wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(wrapper.get(Type.INT, 0)));
}
});
}
});
}
public void registerTracker(ClientboundPacketType packetType, EntityType entityType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
wrapper.user().get(entityTrackerClass).addEntity(entityId, entityType);
});
}
});
}
/**
* Sub 1.17 method for entity remove packets.
*
* @param packetType remove entities packet type
*/
public void registerEntityDestroy(ClientboundPacketType packetType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT_ARRAY_PRIMITIVE); // 0 - Entity ids
handler(wrapper -> {
EntityTracker entityTracker = wrapper.user().get(entityTrackerClass);
for (int entity : wrapper.get(Type.VAR_INT_ARRAY_PRIMITIVE, 0)) {
entityTracker.removeEntity(entity);
}
});
}
});
}
/**
* 1.17+ method for entity remove packets.
*
* @param packetType remove entities packet type
*/
public void registerRemoveEntity(ClientboundPacketType packetType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ids
handler(wrapper -> {
int entity = wrapper.get(Type.VAR_INT, 0);
wrapper.user().get(entityTrackerClass).removeEntity(entity);
});
}
});
}
public void registerMetadataRewriter(ClientboundPacketType packetType, @Nullable Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
if (oldMetaType != null) {
map(oldMetaType, newMetaType);
} else {
map(newMetaType);
}
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
List<Metadata> metadata = wrapper.get(newMetaType, 0);
handleMetadata(entityId, metadata, wrapper.user());
});
}
});
}
public void registerMetadataRewriter(ClientboundPacketType packetType, Type<List<Metadata>> metaType) {
registerMetadataRewriter(packetType, null, metaType);
}
public <T extends Enum<T> & EntityType> void mapTypes(EntityType[] oldTypes, Class<T> newTypeClass) {
if (typeMapping == null) {
typeMapping = new Int2IntOpenHashMap(oldTypes.length, 1F);
typeMapping.defaultReturnValue(-1);
}
for (EntityType oldType : oldTypes) {
try {
T newType = Enum.valueOf(newTypeClass, oldType.name());
typeMapping.put(oldType.getId(), newType.getId());
} catch (IllegalArgumentException notFound) {
if (!typeMapping.containsKey(oldType.getId())) {
Via.getPlatform().getLogger().warning("Could not find new entity type for " + oldType + "! " +
"Old type: " + oldType.getClass().getEnclosingClass().getSimpleName() + ", new type: " + newTypeClass.getEnclosingClass().getSimpleName());
}
}
}
}
public void mapType(EntityType oldType, EntityType newType) {
if (typeMapping == null) {
typeMapping = new Int2IntOpenHashMap();
typeMapping.defaultReturnValue(-1);
}
typeMapping.put(oldType.getId(), newType.getId());
}
public PacketHandler getTracker() {
return getTrackerAndRewriter(null);
}
// ---------------------------------------------------------------------------
// Sub 1.14.1 methods
/**
* Returns a packethandler to track and rewrite an entity.
*
* @param metaType type of the metadata list
* @return handler for tracking and rewriting entities
*/
public PacketHandler getTrackerAndRewriter(@Nullable Type<List<Metadata>> metaType) {
return wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
int type = wrapper.get(Type.VAR_INT, 1);
int newType = getNewEntityId(type);
if (newType != type) {
wrapper.set(Type.VAR_INT, 1, newType);
}
EntityType entType = getTypeFromId(newType);
// Register Type ID
wrapper.user().get(entityTrackerClass).addEntity(entityId, entType);
if (metaType != null) {
handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user());
}
};
}
public PacketHandler getTrackerAndRewriter(@Nullable Type<List<Metadata>> metaType, EntityType entityType) {
return wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
// Register Type ID
wrapper.user().get(entityTrackerClass).addEntity(entityId, entityType);
if (metaType != null) {
handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user());
}
};
}
/**
* Returns a packethandler to track an object entity.
*
* @return handler for tracking and rewriting entities
*/
public PacketHandler getObjectTracker() {
return wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
byte type = wrapper.get(Type.BYTE, 0);
EntityType entType = getObjectTypeFromId(type);
// Register Type ID
wrapper.user().get(entityTrackerClass).addEntity(entityId, entType);
};
}
// ---------------------------------------------------------------------------
protected abstract EntityType getTypeFromId(int type);
/**
* Returns the entity type from the given id.
* From 1.14 and onwards, this is the same exact value as {@link #getTypeFromId(int)}.
*
* @param type entity type id
* @return EntityType from id
*/
protected EntityType getObjectTypeFromId(int type) {
return getTypeFromId(type);
}
/**
* Returns the mapped entitiy (or the same if it has not changed).
*
* @param oldId old entity id
* @return mapped entity id
*/
public int getNewEntityId(int oldId) {
return typeMapping != null ? typeMapping.getOrDefault(oldId, oldId) : oldId;
}
/**
* To be overridden to handle metadata.
*
* @param entityId entity id
* @param type entity type, or null if not tracked
* @param metadata current metadata
* @param metadatas full, mutable list of metadata
* @param connection user connection
*/
protected abstract void handleMetadata(int entityId, @Nullable EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception;
protected @Nullable Metadata getMetaByIndex(int index, List<Metadata> metadataList) {
for (Metadata metadata : metadataList) {
if (metadata.getId() == index) {
return metadata;
}
}
return null;
}
}

Datei anzeigen

@ -15,15 +15,21 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viaversion.protocols.protocol1_15to1_14_4.storage; package com.viaversion.viaversion.rewriter;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types;
import com.viaversion.viaversion.data.EntityTracker;
public class EntityTracker1_15 extends EntityTracker { public interface Rewriter<T extends Protocol> {
public EntityTracker1_15(UserConnection user) { /**
super(user, Entity1_15Types.PLAYER); * Registers any packet handlers or rewrites needed.
} */
void register();
/**
* Returns the {@link Protocol} instance of this rewriter.
*
* @return protocol of the rewriter
*/
T protocol();
} }

Datei anzeigen

@ -15,15 +15,37 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viaversion.protocols.protocol1_14_1to1_14.storage; package com.viaversion.viaversion.rewriter;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types;
import com.viaversion.viaversion.data.EntityTracker;
public class EntityTracker1_14_1 extends EntityTracker { public abstract class RewriterBase<T extends Protocol> implements Rewriter<T> {
protected final T protocol;
public EntityTracker1_14_1(UserConnection user) { protected RewriterBase(T protocol) {
super(user, Entity1_14Types.PLAYER); this.protocol = protocol;
}
@Override
public void register() {
registerPackets();
registerRewrites();
}
/**
* To be overriden. Called when initializing the EntityRewriter.
*/
protected void registerPackets() {
}
/**
* To be overriden. Called when initializing the EntityRewriter.
*/
protected void registerRewrites() {
}
@Override
public T protocol() {
return protocol;
} }
} }

Datei anzeigen

@ -0,0 +1,244 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.rewriter.meta;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Objects;
public class MetaFilter {
private final MetaHandler handler;
private final EntityType type;
private final int index;
private final boolean filterFamily;
public MetaFilter(@Nullable EntityType type, boolean filterFamily, int index, MetaHandler handler) {
Preconditions.checkNotNull(handler, "MetaHandler cannot be null");
this.type = type;
this.filterFamily = filterFamily;
this.index = index;
this.handler = handler;
}
/**
* Returns the metadata index to filter, or -1.
*
* @return metadata index, or -1 if unset
*/
public int index() {
return index;
}
/**
* Returns the filtered entity type if present.
*
* @return filtered entity type if present
*/
public @Nullable EntityType type() {
return type;
}
/**
* Returns the metadata handler.
*
* @return metadata handler
*/
public MetaHandler handler() {
return handler;
}
/**
* Returns whether entity parent types should be checked against as well.
*
* @return whether entity parent types should be checked against
*/
public boolean filterFamily() {
return filterFamily;
}
/**
* Returns whether if the metadata should be handled by this filter.
*
* @param type entity type
* @param metadata metadata
* @return whether the meta should be filtered
*/
public boolean isFiltered(EntityType type, Metadata metadata) {
// First check if the filter has no type or the type is equal or part of the filtered parent types
// Applicable if no specific index is filtered or the indexes are equal
return (this.type == null || (filterFamily ? type.isOrHasParent(this.type) : this.type == type)) && (index == -1 || metadata.id() == index);
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MetaFilter that = (MetaFilter) o;
if (index != that.index) return false;
if (filterFamily != that.filterFamily) return false;
if (!handler.equals(that.handler)) return false;
return Objects.equals(type, that.type);
}
@Override
public int hashCode() {
int result = handler.hashCode();
result = 31 * result + (type != null ? type.hashCode() : 0);
result = 31 * result + index;
result = 31 * result + (filterFamily ? 1 : 0);
return result;
}
@Override
public String toString() {
return "MetaFilter{" +
"type=" + type +
", filterFamily=" + filterFamily +
", index=" + index +
", handler=" + handler +
'}';
}
public static final class Builder {
private final EntityRewriter rewriter;
private EntityType type;
private int index = -1;
private boolean filterFamily;
private MetaHandler handler;
public Builder(EntityRewriter rewriter) {
this.rewriter = rewriter;
}
public Builder type(EntityType type) {
Preconditions.checkArgument(this.type == null);
this.type = type;
return this;
}
public Builder index(int index) {
Preconditions.checkArgument(this.index == -1);
this.index = index;
return this;
}
public Builder filterFamily(EntityType type) {
Preconditions.checkArgument(this.type == null);
this.type = type;
this.filterFamily = true;
return this;
}
public Builder handlerNoRegister(MetaHandler handler) {
Preconditions.checkArgument(this.handler == null);
this.handler = handler;
return this;
}
/**
* Sets the metadata handler and registers the metadata filter.
* Should always be called last.
*
* @param handler metadata handler
*/
public void handler(MetaHandler handler) {
Preconditions.checkArgument(this.handler == null);
this.handler = handler;
register();
}
/**
* Sets a handler to remove metadata at the given index without affecting any other indexes and registers the filter.
* Should always be called last.
*
* @param index index to cancel
*/
public void cancel(int index) {
this.index = index;
handler((event, meta) -> event.cancel());
}
/**
* Sets a handler to change the index. Does not do any other transformation or shifting and registers the filter.
* Should always be called last.
*
* @param newIndex new index
* @throws IllegalArgumentException if no index has been set yet
*/
public void toIndex(int newIndex) {
Preconditions.checkArgument(this.index != -1);
handler((event, meta) -> event.setIndex(newIndex));
}
/**
* Sets a handler incrementing every index above the given one and registers the filter.
* Should always be called last.
*
* @param index index to pad
* @throws IllegalArgumentException if the index has already been set
*/
public void addIndex(int index) {
Preconditions.checkArgument(this.index == -1);
handler((event, meta) -> {
if (event.index() >= index) {
event.setIndex(event.index() + 1);
}
});
}
/**
* Sets a handler to remove metadata at the given index, decrementing every index above it and registers the filter.
* Should always be called last.
*
* @param index index to remove
* @throws IllegalArgumentException if the index has already been set
*/
public void removeIndex(int index) {
Preconditions.checkArgument(this.index == -1);
handler((event, meta) -> {
int metaIndex = event.index();
if (metaIndex == index) {
event.cancel();
} else if (metaIndex > index) {
event.setIndex(metaIndex - 1);
}
});
}
/**
* Creates and registers the created MetaFilter in the linked {@link EntityRewriter} instance.
*/
public void register() {
rewriter.registerFilter(build());
}
/**
* Returns a new metadata filter without registering it.
*
* @return created meta filter
*/
public MetaFilter build() {
return new MetaFilter(type, filterFamily, index, handler);
}
}
}

Datei anzeigen

@ -1,5 +1,5 @@
/* /*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2021 ViaVersion and contributors * Copyright (C) 2016-2021 ViaVersion and contributors
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -15,15 +15,19 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage;
import com.viaversion.viaversion.api.connection.UserConnection; package com.viaversion.viaversion.rewriter.meta;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types;
import com.viaversion.viaversion.data.EntityTracker;
public class EntityTracker1_16 extends EntityTracker { import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
public EntityTracker1_16(UserConnection user) { @FunctionalInterface
super(user, Entity1_16Types.PLAYER); public interface MetaHandler {
}
/**
* Handles a metadata entry of an entity.
*
* @param event metadata event
* @param meta metadata, convenience field for {@link MetaHandlerEvent#meta()}
*/
void handle(MetaHandlerEvent event, Metadata meta);
} }

Datei anzeigen

@ -0,0 +1,121 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.rewriter.meta;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
public interface MetaHandlerEvent {
/**
* Returns the user connection the metadata is sent to.
*
* @return user connection
*/
UserConnection user();
/**
* Returns the entity id of the entity.
*
* @return entity id
*/
int entityId();
/**
* Returns the entity type of the entity the metadata belongs to.
*
* @return entity type of the entity
*/
EntityType entityType();
/**
* Returns the metadata index.
*
* @return return meta index
*/
int index();
/**
* Sets the metadata index.
*
* @param index new metadata index
*/
void setIndex(int index);
/**
* Returns the metadata by the given index if present.
*
* @param index metadata index
* @return metadata by index if present
*/
@Nullable Metadata getMetaByIndex(int index);
/**
* Returns the metadata.
* Do NOT call {@link Metadata#setId(int)} and instead use {@link MetaHandlerEvent#setIndex(int)}.
*
* @return return metadata
*/
Metadata meta();
/**
* Prevents other handlers from being called with this metadata entry and removes it from the list.
*/
void cancel();
/**
* Returns whether this metadata entry should be removed.
*
* @return true if cancelled/removed
*/
boolean cancelled();
/**
* Returns an immutable metadata view.
*
* @return immutable metadata list
* @see #cancel()
* @see #createExtraMeta(Metadata)
*/
List<Metadata> metadataList();
/**
* Returns additionally created metadata.
* May be null; use {@link #createExtraMeta(Metadata)} for adding metadata.
*
* @return additionally created metadata if present
*/
@Nullable List<Metadata> extraMeta();
/**
* Adds the given metadata to the metadata list.
* This metadata will not be passed through handlers of the current loop.
*
* @param metadata metadata
*/
void createExtraMeta(Metadata metadata);
/**
* Clears the additional metadata.
*/
void clearExtraMeta();
}

Datei anzeigen

@ -0,0 +1,119 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.rewriter.meta;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class MetaHandlerEventImpl implements MetaHandlerEvent {
private final UserConnection connection;
private final EntityType entityType;
private final int entityId;
private final List<Metadata> metadataList;
private final Metadata meta;
private List<Metadata> extraData;
private int index;
private boolean cancel;
public MetaHandlerEventImpl(UserConnection connection, EntityType entityType, int entityId, int index, Metadata meta, List<Metadata> metadataList) {
this.connection = connection;
this.entityType = entityType;
this.entityId = entityId;
this.index = index;
this.meta = meta;
this.metadataList = metadataList;
}
@Override
public @Nullable Metadata getMetaByIndex(int index) {
for (Metadata meta : metadataList) {
if (index == meta.id()) {
return meta;
}
}
return null;
}
@Override
public UserConnection user() {
return connection;
}
@Override
public int entityId() {
return entityId;
}
@Override
public EntityType entityType() {
return entityType;
}
@Override
public int index() {
return index;
}
@Override
public void setIndex(int index) {
this.index = index;
meta.setId(index);
}
@Override
public Metadata meta() {
return meta;
}
@Override
public void cancel() {
this.cancel = true;
}
@Override
public boolean cancelled() {
return cancel;
}
@Override
public List<Metadata> metadataList() {
return Collections.unmodifiableList(metadataList);
}
@Override
public @Nullable List<Metadata> extraMeta() {
return extraData;
}
@Override
public void createExtraMeta(Metadata metadata) {
(extraData != null ? extraData : (extraData = new ArrayList<>())).add(metadata);
}
@Override
public void clearExtraMeta() {
extraData = null;
}
}

Datei anzeigen

@ -18,6 +18,7 @@
package com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8; package com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8;
import com.viaversion.viaversion.SpongePlugin; import com.viaversion.viaversion.SpongePlugin;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
@ -38,9 +39,8 @@ public class BlockListener extends ViaSpongeListener {
public void placeBlock(ChangeBlockEvent.Place e, @Root Player player) { public void placeBlock(ChangeBlockEvent.Place e, @Root Player player) {
if (isOnPipe(player.getUniqueId())) { if (isOnPipe(player.getUniqueId())) {
Location loc = e.getTransactions().get(0).getFinal().getLocation().get(); Location loc = e.getTransactions().get(0).getFinal().getLocation().get();
getUserConnection(player.getUniqueId()) EntityTracker1_9 tracker = getUserConnection(player.getUniqueId()).getEntityTracker(Protocol1_9To1_8.class);
.get(EntityTracker1_9.class) tracker.addBlockInteraction(new Position(loc.getBlockX(), (short) loc.getBlockY(), loc.getBlockZ()));
.addBlockInteraction(new Position(loc.getBlockX(), (short) loc.getBlockY(), loc.getBlockZ()));
} }
} }
} }