3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-11-16 04:50:10 +01:00

Rename missing metadata references to entity data (#811)

Dieser Commit ist enthalten in:
EnZaXD 2024-07-06 21:13:55 +02:00 committet von GitHub
Ursprung 16f1bdff02
Commit 33d8485852
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
32 geänderte Dateien mit 440 neuen und 446 gelöschten Zeilen

Datei anzeigen

@ -31,7 +31,7 @@ public class EntityReplacement {
private final int replacementId; private final int replacementId;
private final String key; private final String key;
private ComponentType componentType = ComponentType.NONE; private ComponentType componentType = ComponentType.NONE;
private MetaCreator defaultMeta; private EntityDataCreator defaultData;
public EntityReplacement(BackwardsProtocol<?, ?, ?, ?> protocol, EntityType type, int replacementId) { public EntityReplacement(BackwardsProtocol<?, ?, ?, ?> protocol, EntityType type, int replacementId) {
this(protocol, type.name(), type.getId(), replacementId); this(protocol, type.name(), type.getId(), replacementId);
@ -59,13 +59,13 @@ public class EntityReplacement {
return this; return this;
} }
public EntityReplacement spawnMetadata(MetaCreator handler) { public EntityReplacement spawnEntityData(EntityDataCreator handler) {
this.defaultMeta = handler; this.defaultData = handler;
return this; return this;
} }
public boolean hasBaseMeta() { public boolean hasBaseData() {
return this.defaultMeta != null; return this.defaultData != null;
} }
public int typeId() { public int typeId() {
@ -97,8 +97,8 @@ public class EntityReplacement {
return replacementId; return replacementId;
} }
public @Nullable MetaCreator defaultMeta() { public @Nullable EntityDataCreator defaultData() {
return defaultMeta; return defaultData;
} }
public boolean isObjectType() { public boolean isObjectType() {
@ -111,18 +111,20 @@ public class EntityReplacement {
@Override @Override
public String toString() { public String toString() {
return "EntityData{" + return "EntityReplacement{" +
"id=" + id + "protocol=" + protocol +
", mobName='" + key + '\'' + ", id=" + id +
", replacementId=" + replacementId + ", replacementId=" + replacementId +
", defaultMeta=" + defaultMeta + ", key='" + key + '\'' +
", componentType=" + componentType +
", defaultData=" + defaultData +
'}'; '}';
} }
@FunctionalInterface @FunctionalInterface
public interface MetaCreator { public interface EntityDataCreator {
void createMeta(WrappedMetadata storage); void createData(WrappedEntityData storage);
} }
private enum ComponentType { private enum ComponentType {

Datei anzeigen

@ -22,28 +22,28 @@ import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public record WrappedMetadata(List<EntityData> metadataList) { public record WrappedEntityData(List<EntityData> entityDataList) {
public boolean has(EntityData data) { public boolean has(EntityData data) {
return this.metadataList.contains(data); return this.entityDataList.contains(data);
} }
public void remove(EntityData data) { public void remove(EntityData data) {
this.metadataList.remove(data); this.entityDataList.remove(data);
} }
public void remove(int index) { public void remove(int index) {
metadataList.removeIf(meta -> meta.id() == index); entityDataList.removeIf(data -> data.id() == index);
} }
public void add(EntityData data) { public void add(EntityData data) {
this.metadataList.add(data); this.entityDataList.add(data);
} }
public @Nullable EntityData get(int index) { public @Nullable EntityData get(int index) {
for (EntityData meta : this.metadataList) { for (EntityData data : this.entityDataList) {
if (index == meta.id()) { if (index == data.id()) {
return meta; return data;
} }
} }
return null; return null;

Datei anzeigen

@ -21,7 +21,7 @@ import com.google.common.base.Preconditions;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.entities.storage.EntityReplacement; import com.viaversion.viabackwards.api.entities.storage.EntityReplacement;
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata; import com.viaversion.viabackwards.api.entities.storage.WrappedEntityData;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.entity.StoredEntityData; import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.data.entity.TrackedEntity; import com.viaversion.viaversion.api.data.entity.TrackedEntity;
@ -50,24 +50,24 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*/ */
public abstract class EntityRewriterBase<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends EntityRewriter<C, T> { public abstract class EntityRewriterBase<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends EntityRewriter<C, T> {
private final Int2ObjectMap<EntityReplacement> entityDataMappings = new Int2ObjectOpenHashMap<>(); private final Int2ObjectMap<EntityReplacement> entityDataMappings = new Int2ObjectOpenHashMap<>();
private final EntityDataType displayNameMetaType; private final EntityDataType displayNameDataType;
private final EntityDataType displayVisibilityMetaType; private final EntityDataType displayVisibilityDataType;
private final int displayNameIndex; private final int displayNameIndex;
private final int displayVisibilityIndex; private final int displayVisibilityIndex;
EntityRewriterBase(T protocol, EntityDataType displayNameMetaType, int displayNameIndex, EntityRewriterBase(T protocol, EntityDataType displayNameDataType, int displayNameIndex,
EntityDataType displayVisibilityMetaType, int displayVisibilityIndex) { EntityDataType displayVisibilityDataType, int displayVisibilityIndex) {
super(protocol, false); super(protocol, false);
this.displayNameMetaType = displayNameMetaType; this.displayNameDataType = displayNameDataType;
this.displayNameIndex = displayNameIndex; this.displayNameIndex = displayNameIndex;
this.displayVisibilityMetaType = displayVisibilityMetaType; this.displayVisibilityDataType = displayVisibilityDataType;
this.displayVisibilityIndex = displayVisibilityIndex; this.displayVisibilityIndex = displayVisibilityIndex;
} }
@Override @Override
public void handleEntityData(int entityId, List<EntityData> entityDataList, UserConnection connection) { public void handleEntityData(int entityId, List<EntityData> entityDataList, UserConnection connection) {
final TrackedEntity entity = tracker(connection).entity(entityId); final TrackedEntity entity = tracker(connection).entity(entityId);
final boolean initialMetadata = !(entity != null && entity.hasSentEntityData()); final boolean initialEntityData = !(entity != null && entity.hasSentEntityData());
super.handleEntityData(entityId, entityDataList, connection); super.handleEntityData(entityId, entityDataList, connection);
@ -80,37 +80,37 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
final Object displayNameObject; final Object displayNameObject;
if (entityMapping != null && (displayNameObject = entityMapping.entityName()) != null) { if (entityMapping != null && (displayNameObject = entityMapping.entityName()) != null) {
final EntityData displayName = getData(displayNameIndex, entityDataList); final EntityData displayName = getData(displayNameIndex, entityDataList);
if (initialMetadata) { if (initialEntityData) {
if (displayName == null) { if (displayName == null) {
// Add it as new metadata // Add it as new entity data
entityDataList.add(new EntityData(displayNameIndex, displayNameMetaType, displayNameObject)); entityDataList.add(new EntityData(displayNameIndex, displayNameDataType, displayNameObject));
addDisplayVisibilityMeta(entityDataList); addDisplayVisibilityData(entityDataList);
} else if (displayName.getValue() == null || displayName.getValue().toString().isEmpty()) { } else if (displayName.getValue() == null || displayName.getValue().toString().isEmpty()) {
// Overwrite the existing null/empty display name // Overwrite the existing null/empty display name
displayName.setValue(displayNameObject); displayName.setValue(displayNameObject);
addDisplayVisibilityMeta(entityDataList); addDisplayVisibilityData(entityDataList);
} }
} else if (displayName != null && (displayName.getValue() == null || displayName.getValue().toString().isEmpty())) { } else if (displayName != null && (displayName.getValue() == null || displayName.getValue().toString().isEmpty())) {
// Overwrite null/empty display name // Overwrite null/empty display name
displayName.setValue(displayNameObject); displayName.setValue(displayNameObject);
addDisplayVisibilityMeta(entityDataList); addDisplayVisibilityData(entityDataList);
} }
} }
// Add any other extra meta for mapped entities // Add any other extra data for mapped entities
if (entityMapping != null && entityMapping.hasBaseMeta() && initialMetadata) { if (entityMapping != null && entityMapping.hasBaseData() && initialEntityData) {
entityMapping.defaultMeta().createMeta(new WrappedMetadata(entityDataList)); entityMapping.defaultData().createData(new WrappedEntityData(entityDataList));
} }
} }
private void addDisplayVisibilityMeta(List<EntityData> metadataList) { private void addDisplayVisibilityData(List<EntityData> entityDataList) {
if (alwaysShowOriginalMobName()) { if (alwaysShowOriginalMobName()) {
removeMeta(displayVisibilityIndex, metadataList); removeData(displayVisibilityIndex, entityDataList);
metadataList.add(new EntityData(displayVisibilityIndex, displayVisibilityMetaType, getDisplayVisibilityMetaValue())); entityDataList.add(new EntityData(displayVisibilityIndex, displayVisibilityDataType, getDisplayVisibilityDataValue()));
} }
} }
protected Object getDisplayVisibilityMetaValue() { protected Object getDisplayVisibilityDataValue() {
return true; return true;
} }
@ -118,17 +118,17 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
return ViaBackwards.getConfig().alwaysShowOriginalMobName(); return ViaBackwards.getConfig().alwaysShowOriginalMobName();
} }
protected @Nullable EntityData getData(int metaIndex, List<EntityData> metadataList) { protected @Nullable EntityData getData(int dataIndex, List<EntityData> entityDataList) {
for (EntityData metadata : metadataList) { for (EntityData entityData : entityDataList) {
if (metadata.id() == metaIndex) { if (entityData.id() == dataIndex) {
return metadata; return entityData;
} }
} }
return null; return null;
} }
protected void removeMeta(int metaIndex, List<EntityData> metadataList) { protected void removeData(int dataIndex, List<EntityData> entityDataList) {
metadataList.removeIf(meta -> meta.id() == metaIndex); entityDataList.removeIf(data -> data.id() == dataIndex);
} }
protected boolean hasData(EntityType type) { protected boolean hasData(EntityType type) {
@ -163,7 +163,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
return data; return data;
} }
public void registerMetaTypeHandler( public void registerEntityDataTypeHandler(
@Nullable EntityDataType itemType, @Nullable EntityDataType itemType,
@Nullable EntityDataType blockStateType, @Nullable EntityDataType blockStateType,
@Nullable EntityDataType optionalBlockStateType, @Nullable EntityDataType optionalBlockStateType,
@ -171,28 +171,28 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
@Nullable EntityDataType componentType, @Nullable EntityDataType componentType,
@Nullable EntityDataType optionalComponentType @Nullable EntityDataType optionalComponentType
) { ) {
filter().handler((event, meta) -> { filter().handler((event, data) -> {
EntityDataType type = meta.dataType(); EntityDataType type = data.dataType();
if (type == itemType) { if (type == itemType) {
protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()); protocol.getItemRewriter().handleItemToClient(event.user(), data.value());
} else if (type == blockStateType) { } else if (type == blockStateType) {
int data = meta.value(); int value = data.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); data.setValue(protocol.getMappingData().getNewBlockStateId(value));
} else if (type == optionalBlockStateType) { } else if (type == optionalBlockStateType) {
int data = meta.value(); int value = data.value();
if (data != 0) { if (value != 0) {
meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); data.setValue(protocol.getMappingData().getNewBlockStateId(value));
} }
} else if (type == particleType) { } else if (type == particleType) {
rewriteParticle(event.user(), meta.value()); rewriteParticle(event.user(), data.value());
} else if (type == optionalComponentType || type == componentType) { } else if (type == optionalComponentType || type == componentType) {
JsonElement text = meta.value(); JsonElement text = data.value();
protocol.getComponentRewriter().processText(event.user(), text); protocol.getComponentRewriter().processText(event.user(), text);
} }
}); });
} }
public void registerMetaTypeHandler1_20_3( public void registerEntityDataTypeHandler1_20_3(
@Nullable EntityDataType itemType, @Nullable EntityDataType itemType,
@Nullable EntityDataType blockStateType, @Nullable EntityDataType blockStateType,
@Nullable EntityDataType optionalBlockStateType, @Nullable EntityDataType optionalBlockStateType,
@ -201,27 +201,27 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
@Nullable EntityDataType componentType, @Nullable EntityDataType componentType,
@Nullable EntityDataType optionalComponentType @Nullable EntityDataType optionalComponentType
) { ) {
filter().handler((event, meta) -> { filter().handler((event, data) -> {
EntityDataType type = meta.dataType(); EntityDataType type = data.dataType();
if (type == itemType) { if (type == itemType) {
meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value())); data.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), data.value()));
} else if (type == blockStateType) { } else if (type == blockStateType) {
int data = meta.value(); int value = data.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); data.setValue(protocol.getMappingData().getNewBlockStateId(value));
} else if (type == optionalBlockStateType) { } else if (type == optionalBlockStateType) {
int data = meta.value(); int value = data.value();
if (data != 0) { if (value != 0) {
meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); data.setValue(protocol.getMappingData().getNewBlockStateId(value));
} }
} else if (type == particleType) { } else if (type == particleType) {
rewriteParticle(event.user(), meta.value()); rewriteParticle(event.user(), data.value());
} else if (type == particlesType) { } else if (type == particlesType) {
Particle[] particles = meta.value(); Particle[] particles = data.value();
for (final Particle particle : particles) { for (final Particle particle : particles) {
rewriteParticle(event.user(), particle); rewriteParticle(event.user(), particle);
} }
} else if (type == optionalComponentType || type == componentType) { } else if (type == optionalComponentType || type == componentType) {
protocol.getComponentRewriter().processTag(event.user(), meta.value()); protocol.getComponentRewriter().processTag(event.user(), data.value());
} }
}); });
} }

Datei anzeigen

@ -20,7 +20,7 @@ package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.entities.storage.EntityReplacement; import com.viaversion.viabackwards.api.entities.storage.EntityReplacement;
import com.viaversion.viabackwards.api.entities.storage.EntityObjectData; import com.viaversion.viabackwards.api.entities.storage.EntityObjectData;
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata; import com.viaversion.viabackwards.api.entities.storage.WrappedEntityData;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.ObjectType; import com.viaversion.viaversion.api.minecraft.entities.ObjectType;
@ -90,64 +90,64 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
} }
@Override @Override
public void registerSetEntityData(C packetType, Type<List<EntityData>> oldMetaType, Type<List<EntityData>> newMetaType) { public void registerSetEntityData(C packetType, Type<List<EntityData>> dataType, Type<List<EntityData>> mappedDataType) {
protocol.registerClientbound(packetType, new PacketHandlers() { protocol.registerClientbound(packetType, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Types.VAR_INT); // 0 - Entity ID map(Types.VAR_INT); // 0 - Entity ID
if (oldMetaType != null) { if (dataType != null) {
map(oldMetaType, newMetaType); map(dataType, mappedDataType);
} else { } else {
map(newMetaType); map(mappedDataType);
} }
handler(wrapper -> { handler(wrapper -> {
List<EntityData> metadata = wrapper.get(newMetaType, 0); List<EntityData> entityDataList = wrapper.get(mappedDataType, 0);
handleEntityData(wrapper.get(Types.VAR_INT, 0), metadata, wrapper.user()); handleEntityData(wrapper.get(Types.VAR_INT, 0), entityDataList, wrapper.user());
}); });
} }
}); });
} }
@Override @Override
public void registerSetEntityData(C packetType, Type<List<EntityData>> metaType) { public void registerSetEntityData(C packetType, Type<List<EntityData>> dataType) {
registerSetEntityData(packetType, null, metaType); registerSetEntityData(packetType, null, dataType);
} }
protected PacketHandler getMobSpawnRewriter(Type<List<EntityData>> metaType, IdSetter idSetter) { protected PacketHandler getMobSpawnRewriter(Type<List<EntityData>> dataType, IdSetter idSetter) {
return wrapper -> { return wrapper -> {
int entityId = wrapper.get(Types.VAR_INT, 0); int entityId = wrapper.get(Types.VAR_INT, 0);
EntityType type = tracker(wrapper.user()).entityType(entityId); EntityType type = tracker(wrapper.user()).entityType(entityId);
List<EntityData> metadata = wrapper.get(metaType, 0); List<EntityData> entityDataList = wrapper.get(dataType, 0);
handleEntityData(entityId, metadata, wrapper.user()); handleEntityData(entityId, entityDataList, wrapper.user());
EntityReplacement entityReplacement = entityDataForType(type); EntityReplacement entityReplacement = entityDataForType(type);
if (entityReplacement != null) { if (entityReplacement != null) {
idSetter.setId(wrapper, entityReplacement.replacementId()); idSetter.setId(wrapper, entityReplacement.replacementId());
if (entityReplacement.hasBaseMeta()) { if (entityReplacement.hasBaseData()) {
entityReplacement.defaultMeta().createMeta(new WrappedMetadata(metadata)); entityReplacement.defaultData().createData(new WrappedEntityData(entityDataList));
} }
} }
}; };
} }
public PacketHandler getMobSpawnRewriter(Type<List<EntityData>> metaType) { public PacketHandler getMobSpawnRewriter(Type<List<EntityData>> dataType) {
return getMobSpawnRewriter(metaType, (wrapper, id) -> wrapper.set(Types.UNSIGNED_BYTE, 0, (short) id)); return getMobSpawnRewriter(dataType, (wrapper, id) -> wrapper.set(Types.UNSIGNED_BYTE, 0, (short) id));
} }
public PacketHandler getMobSpawnRewriter1_11(Type<List<EntityData>> metaType) { public PacketHandler getMobSpawnRewriter1_11(Type<List<EntityData>> dataType) {
return getMobSpawnRewriter(metaType, (wrapper, id) -> wrapper.set(Types.VAR_INT, 1, id)); return getMobSpawnRewriter(dataType, (wrapper, id) -> wrapper.set(Types.VAR_INT, 1, id));
} }
protected PacketHandler getObjectTrackerHandler() { protected PacketHandler getObjectTrackerHandler() {
return wrapper -> addTrackedEntity(wrapper, wrapper.get(Types.VAR_INT, 0), objectTypeFromId(wrapper.get(Types.BYTE, 0))); return wrapper -> addTrackedEntity(wrapper, wrapper.get(Types.VAR_INT, 0), objectTypeFromId(wrapper.get(Types.BYTE, 0)));
} }
protected PacketHandler getTrackerAndMetaHandler(Type<List<EntityData>> metaType, EntityType entityType) { protected PacketHandler getTrackerAndDataHandler(Type<List<EntityData>> dataType, EntityType entityType) {
return wrapper -> { return wrapper -> {
addTrackedEntity(wrapper, wrapper.get(Types.VAR_INT, 0), entityType); addTrackedEntity(wrapper, wrapper.get(Types.VAR_INT, 0), entityType);
List<EntityData> metadata = wrapper.get(metaType, 0); List<EntityData> entityDataList = wrapper.get(dataType, 0);
handleEntityData(wrapper.get(Types.VAR_INT, 0), metadata, wrapper.user()); handleEntityData(wrapper.get(Types.VAR_INT, 0), entityDataList, wrapper.user());
}; };
} }

Datei anzeigen

@ -58,10 +58,10 @@ public class BlockItemPacketRewriter1_10 extends LegacyBlockItemRewriter<Clientb
handleChunk(chunk); handleChunk(chunk);
}); });
// Rewrite metadata items // Rewrite entity data items
protocol.getEntityRewriter().filter().handler((event, meta) -> { protocol.getEntityRewriter().filter().handler((event, data) -> {
if (meta.dataType().type().equals(Types.ITEM1_8)) // Is Item if (data.dataType().type().equals(Types.ITEM1_8)) // Is Item
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); data.setValue(handleItemToClient(event.user(), (Item) data.getValue()));
}); });
// Particle // Particle

Datei anzeigen

@ -19,7 +19,7 @@
package com.viaversion.viabackwards.protocol.v1_10to1_9_3.rewriter; package com.viaversion.viabackwards.protocol.v1_10to1_9_3.rewriter;
import com.viaversion.viabackwards.api.entities.storage.EntityReplacement; import com.viaversion.viabackwards.api.entities.storage.EntityReplacement;
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata; import com.viaversion.viabackwards.api.entities.storage.WrappedEntityData;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter; import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3; import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
@ -80,25 +80,25 @@ public class EntityPacketRewriter1_10 extends LegacyEntityRewriter<ClientboundPa
map(Types.SHORT); // 9 - Velocity X map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z map(Types.SHORT); // 11 - Velocity Z
map(Types1_9.ENTITY_DATA_LIST); // 12 - Metadata map(Types1_9.ENTITY_DATA_LIST); // 12 - Entity data
// Track entity // Track entity
handler(getTrackerHandler(Types.UNSIGNED_BYTE, 0)); handler(getTrackerHandler(Types.UNSIGNED_BYTE, 0));
// Rewrite entity type / metadata // Rewrite entity type / data
handler(wrapper -> { handler(wrapper -> {
int entityId = wrapper.get(Types.VAR_INT, 0); int entityId = wrapper.get(Types.VAR_INT, 0);
EntityType type = tracker(wrapper.user()).entityType(entityId); EntityType type = tracker(wrapper.user()).entityType(entityId);
List<EntityData> metadata = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0); List<EntityData> entityDataList = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0);
handleEntityData(wrapper.get(Types.VAR_INT, 0), metadata, wrapper.user()); handleEntityData(wrapper.get(Types.VAR_INT, 0), entityDataList, wrapper.user());
EntityReplacement entityReplacement = entityDataForType(type); EntityReplacement entityReplacement = entityDataForType(type);
if (entityReplacement != null) { if (entityReplacement != null) {
WrappedMetadata storage = new WrappedMetadata(metadata); WrappedEntityData storage = new WrappedEntityData(entityDataList);
wrapper.set(Types.UNSIGNED_BYTE, 0, (short) entityReplacement.replacementId()); wrapper.set(Types.UNSIGNED_BYTE, 0, (short) entityReplacement.replacementId());
if (entityReplacement.hasBaseMeta()) if (entityReplacement.hasBaseData())
entityReplacement.defaultMeta().createMeta(storage); entityReplacement.defaultData().createData(storage);
} }
}); });
@ -119,9 +119,9 @@ public class EntityPacketRewriter1_10 extends LegacyEntityRewriter<ClientboundPa
map(Types.DOUBLE); // 4 - Z map(Types.DOUBLE); // 4 - Z
map(Types.BYTE); // 5 - Yaw map(Types.BYTE); // 5 - Yaw
map(Types.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Types1_9.ENTITY_DATA_LIST); // 7 - Metadata list map(Types1_9.ENTITY_DATA_LIST); // 7 - Entity data list
handler(getTrackerAndMetaHandler(Types1_9.ENTITY_DATA_LIST, EntityTypes1_11.EntityType.PLAYER)); handler(getTrackerAndDataHandler(Types1_9.ENTITY_DATA_LIST, EntityTypes1_11.EntityType.PLAYER));
} }
}); });
@ -134,28 +134,28 @@ public class EntityPacketRewriter1_10 extends LegacyEntityRewriter<ClientboundPa
mapEntityTypeWithData(EntityTypes1_10.EntityType.POLAR_BEAR, EntityTypes1_10.EntityType.SHEEP).plainName(); mapEntityTypeWithData(EntityTypes1_10.EntityType.POLAR_BEAR, EntityTypes1_10.EntityType.SHEEP).plainName();
// Change the sheep color when the polar bear is standing up (index 13 -> Standing up) // Change the sheep color when the polar bear is standing up (index 13 -> Standing up)
filter().type(EntityTypes1_10.EntityType.POLAR_BEAR).index(13).handler((event, meta) -> { filter().type(EntityTypes1_10.EntityType.POLAR_BEAR).index(13).handler((event, data) -> {
boolean b = (boolean) meta.getValue(); boolean b = (boolean) data.getValue();
meta.setTypeAndValue(EntityDataTypes1_9.BYTE, b ? (byte) (14 & 0x0F) : (byte) (0)); data.setTypeAndValue(EntityDataTypes1_9.BYTE, b ? (byte) (14 & 0x0F) : (byte) (0));
}); });
// Handle husk (index 13 -> Zombie Type) // Handle husk (index 13 -> Zombie Type)
filter().type(EntityTypes1_10.EntityType.ZOMBIE).index(13).handler((event, meta) -> { filter().type(EntityTypes1_10.EntityType.ZOMBIE).index(13).handler((event, data) -> {
if ((int) meta.getValue() == 6) { // Is type Husk if ((int) data.getValue() == 6) { // Is type Husk
meta.setValue(0); data.setValue(0);
} }
}); });
// Handle Stray (index 12 -> Skeleton Type) // Handle Stray (index 12 -> Skeleton Type)
filter().type(EntityTypes1_10.EntityType.SKELETON).index(12).handler((event, meta) -> { filter().type(EntityTypes1_10.EntityType.SKELETON).index(12).handler((event, data) -> {
if ((int) meta.getValue() == 2) { if ((int) data.getValue() == 2) {
meta.setValue(0); // Change to default skeleton data.setValue(0); // Change to default skeleton
} }
}); });
// Handle the missing NoGravity tag for every metadata // Handle the missing NoGravity tag for every entity data
filter().removeIndex(5); filter().removeIndex(5);
} }

Datei anzeigen

@ -23,7 +23,6 @@ import com.viaversion.viabackwards.protocol.v1_11_1to1_11.Protocol1_11_1To1_11;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_9; import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
@ -73,12 +72,12 @@ public class EntityPacketRewriter1_11_1 extends LegacyEntityRewriter<Clientbound
map(Types.SHORT); // 9 - Velocity X map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z map(Types.SHORT); // 11 - Velocity Z
map(Types1_9.ENTITY_DATA_LIST); // 12 - Metadata map(Types1_9.ENTITY_DATA_LIST); // 12 - Entity data
// Track entity // Track entity
handler(getTrackerHandler()); handler(getTrackerHandler());
// Rewrite entity type / metadata // Rewrite entity type / data
handler(getMobSpawnRewriter1_11(Types1_9.ENTITY_DATA_LIST)); handler(getMobSpawnRewriter1_11(Types1_9.ENTITY_DATA_LIST));
} }
}); });
@ -97,9 +96,9 @@ public class EntityPacketRewriter1_11_1 extends LegacyEntityRewriter<Clientbound
map(Types.DOUBLE); // 4 - Z map(Types.DOUBLE); // 4 - Z
map(Types.BYTE); // 5 - Yaw map(Types.BYTE); // 5 - Yaw
map(Types.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Types1_9.ENTITY_DATA_LIST); // 7 - Metadata list map(Types1_9.ENTITY_DATA_LIST); // 7 - Entity data list
handler(getTrackerAndMetaHandler(Types1_9.ENTITY_DATA_LIST, EntityTypes1_11.EntityType.PLAYER)); handler(getTrackerAndDataHandler(Types1_9.ENTITY_DATA_LIST, EntityTypes1_11.EntityType.PLAYER));
} }
}); });
@ -109,10 +108,10 @@ public class EntityPacketRewriter1_11_1 extends LegacyEntityRewriter<Clientbound
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
// Handle non-existing firework metadata (index 7 entity id for boosting) // Handle non-existing firework entity data (index 7 entity id for boosting)
filter().type(EntityTypes1_11.EntityType.FIREWORK_ROCKET).cancel(7); filter().type(EntityTypes1_11.EntityType.FIREWORK_ROCKET).cancel(7);
// Handle non-existing pig metadata (index 14 - boost time) // Handle non-existing pig entity data (index 14 - boost time)
filter().type(EntityTypes1_11.EntityType.PIG).cancel(14); filter().type(EntityTypes1_11.EntityType.PIG).cancel(14);
} }

Datei anzeigen

@ -47,10 +47,10 @@ public class ItemPacketRewriter1_11_1 extends LegacyBlockItemRewriter<Clientboun
registerContainerClick(ServerboundPackets1_9_3.CONTAINER_CLICK); registerContainerClick(ServerboundPackets1_9_3.CONTAINER_CLICK);
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT); registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
// Handle item metadata // Handle item entity data
protocol.getEntityRewriter().filter().handler((event, meta) -> { protocol.getEntityRewriter().filter().handler((event, data) -> {
if (meta.dataType().type().equals(Types.ITEM1_8)) { // Is Item if (data.dataType().type().equals(Types.ITEM1_8)) { // Is Item
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); data.setValue(handleItemToClient(event.user(), (Item) data.getValue()));
} }
}); });
} }

Datei anzeigen

@ -243,9 +243,9 @@ public class BlockItemPacketRewriter1_11 extends LegacyBlockItemRewriter<Clientb
} }
}); });
protocol.getEntityRewriter().filter().handler((event, meta) -> { protocol.getEntityRewriter().filter().handler((event, data) -> {
if (meta.dataType().type().equals(Types.ITEM1_8)) // Is Item if (data.dataType().type().equals(Types.ITEM1_8)) // Is Item
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); data.setValue(handleItemToClient(event.user(), (Item) data.getValue()));
}); });
} }

Datei anzeigen

@ -18,7 +18,7 @@
package com.viaversion.viabackwards.protocol.v1_11to1_10.rewriter; package com.viaversion.viabackwards.protocol.v1_11to1_10.rewriter;
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata; import com.viaversion.viabackwards.api.entities.storage.WrappedEntityData;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter; import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.v1_11to1_10.Protocol1_11To1_10; import com.viaversion.viabackwards.protocol.v1_11to1_10.Protocol1_11To1_10;
import com.viaversion.viabackwards.protocol.v1_11to1_10.data.SplashPotionMappings1_10; import com.viaversion.viabackwards.protocol.v1_11to1_10.data.SplashPotionMappings1_10;
@ -104,19 +104,19 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
map(Types.SHORT); // 9 - Velocity X map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z map(Types.SHORT); // 11 - Velocity Z
map(Types1_9.ENTITY_DATA_LIST); // 12 - Metadata map(Types1_9.ENTITY_DATA_LIST); // 12 - Entity data
// Track entity // Track entity
handler(getTrackerHandler(Types.UNSIGNED_BYTE, 0)); handler(getTrackerHandler(Types.UNSIGNED_BYTE, 0));
// Rewrite entity type / metadata // Rewrite entity type / data
handler(getMobSpawnRewriter(Types1_9.ENTITY_DATA_LIST)); handler(getMobSpawnRewriter(Types1_9.ENTITY_DATA_LIST));
// Sub 1.11 clients will error if the list is empty // Sub 1.11 clients will error if the list is empty
handler(wrapper -> { handler(wrapper -> {
List<EntityData> metadata = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0); List<EntityData> entityDataList = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0);
if (metadata.isEmpty()) { if (entityDataList.isEmpty()) {
metadata.add(new EntityData(0, EntityDataTypes1_9.BYTE, (byte) 0)); entityDataList.add(new EntityData(0, EntityDataTypes1_9.BYTE, (byte) 0));
} }
}); });
} }
@ -136,14 +136,14 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
map(Types.DOUBLE); // 4 - Z map(Types.DOUBLE); // 4 - Z
map(Types.BYTE); // 5 - Yaw map(Types.BYTE); // 5 - Yaw
map(Types.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Types1_9.ENTITY_DATA_LIST); // 7 - Metadata list map(Types1_9.ENTITY_DATA_LIST); // 7 - Entity data list
handler(getTrackerAndMetaHandler(Types1_9.ENTITY_DATA_LIST, EntityTypes1_11.EntityType.PLAYER)); handler(getTrackerAndDataHandler(Types1_9.ENTITY_DATA_LIST, EntityTypes1_11.EntityType.PLAYER));
handler(wrapper -> { handler(wrapper -> {
// Sub 1.11 clients will cry if the list is empty // Sub 1.11 clients will cry if the list is empty
List<EntityData> metadata = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0); List<EntityData> entityDataList = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0);
if (metadata.isEmpty()) { if (entityDataList.isEmpty()) {
metadata.add(new EntityData(0, EntityDataTypes1_9.BYTE, (byte) 0)); entityDataList.add(new EntityData(0, EntityDataTypes1_9.BYTE, (byte) 0));
} }
}); });
} }
@ -177,39 +177,39 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
// Guardian // Guardian
mapEntityTypeWithData(EntityTypes1_11.EntityType.ELDER_GUARDIAN, EntityTypes1_11.EntityType.GUARDIAN); mapEntityTypeWithData(EntityTypes1_11.EntityType.ELDER_GUARDIAN, EntityTypes1_11.EntityType.GUARDIAN);
// Skeletons // Skeletons
mapEntityTypeWithData(EntityTypes1_11.EntityType.WITHER_SKELETON, EntityTypes1_11.EntityType.SKELETON).spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(1))); mapEntityTypeWithData(EntityTypes1_11.EntityType.WITHER_SKELETON, EntityTypes1_11.EntityType.SKELETON).spawnEntityData(storage -> storage.add(getSkeletonTypeData(1)));
mapEntityTypeWithData(EntityTypes1_11.EntityType.STRAY, EntityTypes1_11.EntityType.SKELETON).plainName().spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(2))); mapEntityTypeWithData(EntityTypes1_11.EntityType.STRAY, EntityTypes1_11.EntityType.SKELETON).plainName().spawnEntityData(storage -> storage.add(getSkeletonTypeData(2)));
// Zombies // Zombies
mapEntityTypeWithData(EntityTypes1_11.EntityType.HUSK, EntityTypes1_11.EntityType.ZOMBIE).plainName().spawnMetadata(storage -> handleZombieType(storage, 6)); mapEntityTypeWithData(EntityTypes1_11.EntityType.HUSK, EntityTypes1_11.EntityType.ZOMBIE).plainName().spawnEntityData(storage -> handleZombieType(storage, 6));
mapEntityTypeWithData(EntityTypes1_11.EntityType.ZOMBIE_VILLAGER, EntityTypes1_11.EntityType.ZOMBIE).spawnMetadata(storage -> handleZombieType(storage, 1)); mapEntityTypeWithData(EntityTypes1_11.EntityType.ZOMBIE_VILLAGER, EntityTypes1_11.EntityType.ZOMBIE).spawnEntityData(storage -> handleZombieType(storage, 1));
// Horses // Horses
mapEntityTypeWithData(EntityTypes1_11.EntityType.HORSE, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(0))); // Nob able to ride the horse without having the MetaType sent. mapEntityTypeWithData(EntityTypes1_11.EntityType.HORSE, EntityTypes1_11.EntityType.HORSE).spawnEntityData(storage -> storage.add(getHorseDataType(0))); // Nob able to ride the horse without having the EntityDataType sent.
mapEntityTypeWithData(EntityTypes1_11.EntityType.DONKEY, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(1))); mapEntityTypeWithData(EntityTypes1_11.EntityType.DONKEY, EntityTypes1_11.EntityType.HORSE).spawnEntityData(storage -> storage.add(getHorseDataType(1)));
mapEntityTypeWithData(EntityTypes1_11.EntityType.MULE, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(2))); mapEntityTypeWithData(EntityTypes1_11.EntityType.MULE, EntityTypes1_11.EntityType.HORSE).spawnEntityData(storage -> storage.add(getHorseDataType(2)));
mapEntityTypeWithData(EntityTypes1_11.EntityType.SKELETON_HORSE, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(4))); mapEntityTypeWithData(EntityTypes1_11.EntityType.SKELETON_HORSE, EntityTypes1_11.EntityType.HORSE).spawnEntityData(storage -> storage.add(getHorseDataType(4)));
mapEntityTypeWithData(EntityTypes1_11.EntityType.ZOMBIE_HORSE, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(3))); mapEntityTypeWithData(EntityTypes1_11.EntityType.ZOMBIE_HORSE, EntityTypes1_11.EntityType.HORSE).spawnEntityData(storage -> storage.add(getHorseDataType(3)));
// New mobs // New mobs
mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOKER_FANGS, EntityTypes1_11.EntityType.SHULKER); mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOKER_FANGS, EntityTypes1_11.EntityType.SHULKER);
mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOKER, EntityTypes1_11.EntityType.VILLAGER).plainName(); mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOKER, EntityTypes1_11.EntityType.VILLAGER).plainName();
mapEntityTypeWithData(EntityTypes1_11.EntityType.VEX, EntityTypes1_11.EntityType.BAT).plainName(); mapEntityTypeWithData(EntityTypes1_11.EntityType.VEX, EntityTypes1_11.EntityType.BAT).plainName();
mapEntityTypeWithData(EntityTypes1_11.EntityType.VINDICATOR, EntityTypes1_11.EntityType.VILLAGER).plainName().spawnMetadata(storage -> storage.add(new EntityData(13, EntityDataTypes1_9.VAR_INT, 4))); // Base Profession mapEntityTypeWithData(EntityTypes1_11.EntityType.VINDICATOR, EntityTypes1_11.EntityType.VILLAGER).plainName().spawnEntityData(storage -> storage.add(new EntityData(13, EntityDataTypes1_9.VAR_INT, 4))); // Base Profession
mapEntityTypeWithData(EntityTypes1_11.EntityType.LLAMA, EntityTypes1_11.EntityType.HORSE).plainName().spawnMetadata(storage -> storage.add(getHorseMetaType(1))); mapEntityTypeWithData(EntityTypes1_11.EntityType.LLAMA, EntityTypes1_11.EntityType.HORSE).plainName().spawnEntityData(storage -> storage.add(getHorseDataType(1)));
mapEntityTypeWithData(EntityTypes1_11.EntityType.LLAMA_SPIT, EntityTypes1_11.EntityType.SNOWBALL); mapEntityTypeWithData(EntityTypes1_11.EntityType.LLAMA_SPIT, EntityTypes1_11.EntityType.SNOWBALL);
mapObjectType(EntityTypes1_11.ObjectType.LLAMA_SPIT, EntityTypes1_11.ObjectType.SNOWBALL, -1); mapObjectType(EntityTypes1_11.ObjectType.LLAMA_SPIT, EntityTypes1_11.ObjectType.SNOWBALL, -1);
// Replace with endertorchthingies // Replace with endertorchthingies
mapObjectType(EntityTypes1_11.ObjectType.EVOKER_FANGS, EntityTypes1_11.ObjectType.FALLING_BLOCK, 198 | 1 << 12); mapObjectType(EntityTypes1_11.ObjectType.EVOKER_FANGS, EntityTypes1_11.ObjectType.FALLING_BLOCK, 198 | 1 << 12);
// Handle ElderGuardian & target metadata // Handle ElderGuardian & target entity data
filter().type(EntityTypes1_11.EntityType.GUARDIAN).index(12).handler((event, meta) -> { filter().type(EntityTypes1_11.EntityType.GUARDIAN).index(12).handler((event, data) -> {
boolean b = (boolean) meta.getValue(); boolean b = (boolean) data.getValue();
int bitmask = b ? 0x02 : 0; int bitmask = b ? 0x02 : 0;
if (event.entityType() == EntityTypes1_11.EntityType.ELDER_GUARDIAN) { if (event.entityType() == EntityTypes1_11.EntityType.ELDER_GUARDIAN) {
bitmask |= 0x04; bitmask |= 0x04;
} }
meta.setTypeAndValue(EntityDataTypes1_9.BYTE, (byte) bitmask); data.setTypeAndValue(EntityDataTypes1_9.BYTE, (byte) bitmask);
}); });
// Handle skeleton swing // Handle skeleton swing
@ -218,34 +218,34 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
/* /*
ZOMBIE CHANGES ZOMBIE CHANGES
*/ */
filter().type(EntityTypes1_11.EntityType.ZOMBIE).handler((event, meta) -> { filter().type(EntityTypes1_11.EntityType.ZOMBIE).handler((event, data) -> {
switch (meta.id()) { switch (data.id()) {
case 13 -> event.cancel(); case 13 -> event.cancel();
case 14 -> event.setIndex(15); case 14 -> event.setIndex(15);
case 15 -> event.setIndex(14); case 15 -> event.setIndex(14);
case 16 -> { case 16 -> {
// Profession // Profession
event.setIndex(13); event.setIndex(13);
meta.setValue(1 + (int) meta.getValue()); data.setValue(1 + (int) data.getValue());
} }
} }
}); });
// Handle Evocation Illager // Handle Evocation Illager
filter().type(EntityTypes1_11.EntityType.EVOKER).index(12).handler((event, meta) -> { filter().type(EntityTypes1_11.EntityType.EVOKER).index(12).handler((event, data) -> {
event.setIndex(13); event.setIndex(13);
meta.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Byte) meta.getValue()).intValue()); // Change the profession for the states data.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Byte) data.getValue()).intValue()); // Change the profession for the states
}); });
// Handle Vex (Remove this field completely since the position is not updated correctly when idling for bats. Sad ): // Handle Vex (Remove this field completely since the position is not updated correctly when idling for bats. Sad ):
filter().type(EntityTypes1_11.EntityType.VEX).index(12).handler((event, meta) -> { filter().type(EntityTypes1_11.EntityType.VEX).index(12).handler((event, data) -> {
meta.setValue((byte) 0x00); data.setValue((byte) 0x00);
}); });
// Handle VindicationIllager // Handle VindicationIllager
filter().type(EntityTypes1_11.EntityType.VINDICATOR).index(12).handler((event, meta) -> { filter().type(EntityTypes1_11.EntityType.VINDICATOR).index(12).handler((event, data) -> {
event.setIndex(13); event.setIndex(13);
meta.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Number) meta.getValue()).intValue() == 1 ? 2 : 4); data.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Number) data.getValue()).intValue() == 1 ? 2 : 4);
}); });
/* /*
@ -253,20 +253,20 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
*/ */
// Handle horse flags // Handle horse flags
filter().type(EntityTypes1_11.EntityType.ABSTRACT_HORSE).index(13).handler((event, meta) -> { filter().type(EntityTypes1_11.EntityType.ABSTRACT_HORSE).index(13).handler((event, data) -> {
StoredEntityData data = storedEntityData(event); StoredEntityData entityData = storedEntityData(event);
byte b = (byte) meta.getValue(); byte b = (byte) data.getValue();
if (data.has(ChestedHorseStorage.class) && data.get(ChestedHorseStorage.class).isChested()) { if (entityData.has(ChestedHorseStorage.class) && entityData.get(ChestedHorseStorage.class).isChested()) {
b |= 0x08; // Chested b |= 0x08; // Chested
meta.setValue(b); data.setValue(b);
} }
}); });
// Create chested horse storage // Create chested horse storage
filter().type(EntityTypes1_11.EntityType.CHESTED_HORSE).handler((event, meta) -> { filter().type(EntityTypes1_11.EntityType.CHESTED_HORSE).handler((event, data) -> {
StoredEntityData data = storedEntityData(event); StoredEntityData entityData = storedEntityData(event);
if (!data.has(ChestedHorseStorage.class)) { if (!entityData.has(ChestedHorseStorage.class)) {
data.put(new ChestedHorseStorage()); entityData.put(new ChestedHorseStorage());
} }
}); });
@ -274,32 +274,32 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
filter().type(EntityTypes1_11.EntityType.HORSE).index(16).toIndex(17); filter().type(EntityTypes1_11.EntityType.HORSE).index(16).toIndex(17);
// Handle chested horse // Handle chested horse
filter().type(EntityTypes1_11.EntityType.CHESTED_HORSE).index(15).handler((event, meta) -> { filter().type(EntityTypes1_11.EntityType.CHESTED_HORSE).index(15).handler((event, data) -> {
StoredEntityData data = storedEntityData(event); StoredEntityData entityData = storedEntityData(event);
ChestedHorseStorage storage = data.get(ChestedHorseStorage.class); ChestedHorseStorage storage = entityData.get(ChestedHorseStorage.class);
boolean b = (boolean) meta.getValue(); boolean b = (boolean) data.getValue();
storage.setChested(b); storage.setChested(b);
event.cancel(); event.cancel();
}); });
// Get rid of Liama metadata // Get rid of Liama entity data
filter().type(EntityTypes1_11.EntityType.LLAMA).handler((event, meta) -> { filter().type(EntityTypes1_11.EntityType.LLAMA).handler((event, data) -> {
StoredEntityData data = storedEntityData(event); StoredEntityData entityData = storedEntityData(event);
ChestedHorseStorage storage = data.get(ChestedHorseStorage.class); ChestedHorseStorage storage = entityData.get(ChestedHorseStorage.class);
int index = event.index(); int index = event.index();
// Store them for later (: // Store them for later (:
switch (index) { switch (index) {
case 16 -> { case 16 -> {
storage.setLiamaStrength((int) meta.getValue()); storage.setLiamaStrength((int) data.getValue());
event.cancel(); event.cancel();
} }
case 17 -> { case 17 -> {
storage.setLiamaCarpetColor((int) meta.getValue()); storage.setLiamaCarpetColor((int) data.getValue());
event.cancel(); event.cancel();
} }
case 18 -> { case 18 -> {
storage.setLiamaVariant((int) meta.getValue()); storage.setLiamaVariant((int) data.getValue());
event.cancel(); event.cancel();
} }
} }
@ -309,13 +309,13 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
filter().type(EntityTypes1_11.EntityType.ABSTRACT_HORSE).index(14).toIndex(16); filter().type(EntityTypes1_11.EntityType.ABSTRACT_HORSE).index(14).toIndex(16);
// Handle villager - Change non-existing profession // Handle villager - Change non-existing profession
filter().type(EntityTypes1_11.EntityType.VILLAGER).index(13).handler((event, meta) -> { filter().type(EntityTypes1_11.EntityType.VILLAGER).index(13).handler((event, data) -> {
if ((int) meta.getValue() == 5) { if ((int) data.getValue() == 5) {
meta.setValue(0); data.setValue(0);
} }
}); });
// handle new Shulker color meta // handle new Shulker color data
filter().type(EntityTypes1_11.EntityType.SHULKER).cancel(15); filter().type(EntityTypes1_11.EntityType.SHULKER).cancel(15);
} }
@ -325,7 +325,7 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
2 - Stray 2 - Stray
*/ */
private EntityData getSkeletonTypeMeta(int type) { private EntityData getSkeletonTypeData(int type) {
return new EntityData(12, EntityDataTypes1_9.VAR_INT, type); return new EntityData(12, EntityDataTypes1_9.VAR_INT, type);
} }
@ -334,14 +334,14 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
1-5 - Villager with profession 1-5 - Villager with profession
6 - Husk 6 - Husk
*/ */
private EntityData getZombieTypeMeta(int type) { private EntityData getZombieTypeData(int type) {
return new EntityData(13, EntityDataTypes1_9.VAR_INT, type); return new EntityData(13, EntityDataTypes1_9.VAR_INT, type);
} }
private void handleZombieType(WrappedMetadata storage, int type) { private void handleZombieType(WrappedEntityData storage, int type) {
EntityData meta = storage.get(13); EntityData meta = storage.get(13);
if (meta == null) { if (meta == null) {
storage.add(getZombieTypeMeta(type)); storage.add(getZombieTypeData(type));
} }
} }
@ -352,7 +352,7 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
Zombie horse 3 Zombie horse 3
Skeleton horse 4 Skeleton horse 4
*/ */
private EntityData getHorseMetaType(int type) { private EntityData getHorseDataType(int type) {
return new EntityData(14, EntityDataTypes1_9.VAR_INT, type); return new EntityData(14, EntityDataTypes1_9.VAR_INT, type);
} }

Datei anzeigen

@ -150,9 +150,9 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
} }
}); });
protocol.getEntityRewriter().filter().handler((event, meta) -> { protocol.getEntityRewriter().filter().handler((event, data) -> {
if (meta.dataType().type().equals(Types.ITEM1_8)) // Is Item if (data.dataType().type().equals(Types.ITEM1_8)) // Is Item
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); data.setValue(handleItemToClient(event.user(), (Item) data.getValue()));
}); });
protocol.registerServerbound(ServerboundPackets1_9_3.CLIENT_COMMAND, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_9_3.CLIENT_COMMAND, new PacketHandlers() {

Datei anzeigen

@ -83,12 +83,12 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
map(Types.SHORT); // 9 - Velocity X map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z map(Types.SHORT); // 11 - Velocity Z
map(Types1_12.ENTITY_DATA_LIST); // 12 - Metadata map(Types1_12.ENTITY_DATA_LIST); // 12 - Entity data
// Track entity // Track entity
handler(getTrackerHandler()); handler(getTrackerHandler());
// Rewrite entity type / metadata // Rewrite entity type / data
handler(getMobSpawnRewriter1_11(Types1_12.ENTITY_DATA_LIST)); handler(getMobSpawnRewriter1_11(Types1_12.ENTITY_DATA_LIST));
} }
}); });
@ -105,9 +105,9 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
map(Types.DOUBLE); // 4 - Z map(Types.DOUBLE); // 4 - Z
map(Types.BYTE); // 5 - Yaw map(Types.BYTE); // 5 - Yaw
map(Types.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Types1_12.ENTITY_DATA_LIST); // 7 - Metadata list map(Types1_12.ENTITY_DATA_LIST); // 7 - Entity data list
handler(getTrackerAndMetaHandler(Types1_12.ENTITY_DATA_LIST, EntityTypes1_12.EntityType.PLAYER)); handler(getTrackerAndDataHandler(Types1_12.ENTITY_DATA_LIST, EntityTypes1_12.EntityType.PLAYER));
} }
}); });
@ -186,42 +186,42 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
mapEntityTypeWithData(EntityTypes1_12.EntityType.PARROT, EntityTypes1_12.EntityType.BAT).plainName().spawnMetadata(storage -> storage.add(new EntityData(12, EntityDataTypes1_12.BYTE, (byte) 0x00))); mapEntityTypeWithData(EntityTypes1_12.EntityType.PARROT, EntityTypes1_12.EntityType.BAT).plainName().spawnEntityData(storage -> storage.add(new EntityData(12, EntityDataTypes1_12.BYTE, (byte) 0x00)));
mapEntityTypeWithData(EntityTypes1_12.EntityType.ILLUSIONER, EntityTypes1_12.EntityType.EVOKER).plainName(); mapEntityTypeWithData(EntityTypes1_12.EntityType.ILLUSIONER, EntityTypes1_12.EntityType.EVOKER).plainName();
filter().handler((event, meta) -> { filter().handler((event, data) -> {
if (meta.dataType() == EntityDataTypes1_12.COMPONENT) { if (data.dataType() == EntityDataTypes1_12.COMPONENT) {
protocol.getComponentRewriter().processText(event.user(), (JsonElement) meta.getValue()); protocol.getComponentRewriter().processText(event.user(), (JsonElement) data.getValue());
} }
}); });
// Handle Illager // Handle Illager
filter().type(EntityTypes1_12.EntityType.EVOKER).removeIndex(12); filter().type(EntityTypes1_12.EntityType.EVOKER).removeIndex(12);
filter().type(EntityTypes1_12.EntityType.ILLUSIONER).index(0).handler((event, meta) -> { filter().type(EntityTypes1_12.EntityType.ILLUSIONER).index(0).handler((event, data) -> {
byte mask = (byte) meta.getValue(); byte mask = (byte) data.getValue();
if ((mask & 0x20) == 0x20) { if ((mask & 0x20) == 0x20) {
mask &= ~0x20; mask &= ~0x20;
} }
meta.setValue(mask); data.setValue(mask);
}); });
// Create Parrot storage // Create Parrot storage
filter().type(EntityTypes1_12.EntityType.PARROT).handler((event, meta) -> { filter().type(EntityTypes1_12.EntityType.PARROT).handler((event, data) -> {
StoredEntityData data = storedEntityData(event); StoredEntityData entityData = storedEntityData(event);
if (!data.has(ParrotStorage.class)) { if (!entityData.has(ParrotStorage.class)) {
data.put(new ParrotStorage()); entityData.put(new ParrotStorage());
} }
}); });
// Parrot remove animal metadata // Parrot remove animal entity data
filter().type(EntityTypes1_12.EntityType.PARROT).cancel(12); // Is baby filter().type(EntityTypes1_12.EntityType.PARROT).cancel(12); // Is baby
filter().type(EntityTypes1_12.EntityType.PARROT).index(13).handler((event, meta) -> { filter().type(EntityTypes1_12.EntityType.PARROT).index(13).handler((event, data) -> {
StoredEntityData data = storedEntityData(event); StoredEntityData entityData = storedEntityData(event);
ParrotStorage storage = data.get(ParrotStorage.class); ParrotStorage storage = entityData.get(ParrotStorage.class);
boolean isSitting = (((byte) meta.getValue()) & 0x01) == 0x01; boolean isSitting = (((byte) data.getValue()) & 0x01) == 0x01;
boolean isTamed = (((byte) meta.getValue()) & 0x04) == 0x04; boolean isTamed = (((byte) data.getValue()) & 0x04) == 0x04;
if (!storage.isTamed() && isTamed) { if (!storage.isTamed() && isTamed) {
// TODO do something to let the user know it's done // TODO do something to let the user know it's done
@ -231,11 +231,11 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
if (isSitting) { if (isSitting) {
event.setIndex(12); event.setIndex(12);
meta.setValue((byte) 0x01); data.setValue((byte) 0x01);
storage.setSitting(true); storage.setSitting(true);
} else if (storage.isSitting()) { } else if (storage.isSitting()) {
event.setIndex(12); event.setIndex(12);
meta.setValue((byte) 0x00); data.setValue((byte) 0x00);
storage.setSitting(false); storage.setSitting(false);
} else { } else {
event.cancel(); event.cancel();
@ -245,8 +245,8 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
filter().type(EntityTypes1_12.EntityType.PARROT).cancel(15); // Variant filter().type(EntityTypes1_12.EntityType.PARROT).cancel(15); // Variant
// Left shoulder entity data // Left shoulder entity data
filter().type(EntityTypes1_12.EntityType.PLAYER).index(15).handler((event, meta) -> { filter().type(EntityTypes1_12.EntityType.PLAYER).index(15).handler((event, data) -> {
CompoundTag tag = (CompoundTag) meta.getValue(); CompoundTag tag = (CompoundTag) data.getValue();
ShoulderTracker tracker = event.user().get(ShoulderTracker.class); ShoulderTracker tracker = event.user().get(ShoulderTracker.class);
if (tag.isEmpty() && tracker.getLeftShoulder() != null) { if (tag.isEmpty() && tracker.getLeftShoulder() != null) {
@ -264,7 +264,7 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
}); });
// Right shoulder entity data // Right shoulder entity data
filter().type(EntityTypes1_12.EntityType.PLAYER).index(16).handler((event, meta) -> { filter().type(EntityTypes1_12.EntityType.PLAYER).index(16).handler((event, data) -> {
CompoundTag tag = (CompoundTag) event.data().getValue(); CompoundTag tag = (CompoundTag) event.data().getValue();
ShoulderTracker tracker = event.user().get(ShoulderTracker.class); ShoulderTracker tracker = event.user().get(ShoulderTracker.class);

Datei anzeigen

@ -91,15 +91,15 @@ public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter<Clientbound
map(Types.SHORT); // 9 - Velocity X map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z map(Types.SHORT); // 11 - Velocity Z
map(Types1_13.ENTITY_DATA_LIST); // 12 - Metadata map(Types1_13.ENTITY_DATA_LIST); // 12 - Entity data
// Track Entity // Track Entity
handler(getTrackerHandler()); handler(getTrackerHandler());
// Rewrite Metadata // Rewrite Entity data
handler(wrapper -> { handler(wrapper -> {
List<EntityData> metadata = wrapper.get(Types1_13.ENTITY_DATA_LIST, 0); List<EntityData> entityDataList = wrapper.get(Types1_13.ENTITY_DATA_LIST, 0);
handleEntityData(wrapper.get(Types.VAR_INT, 0), metadata, wrapper.user()); handleEntityData(wrapper.get(Types.VAR_INT, 0), entityDataList, wrapper.user());
}); });
} }
}); });
@ -114,9 +114,9 @@ public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter<Clientbound
map(Types.DOUBLE); // 4 - Z map(Types.DOUBLE); // 4 - Z
map(Types.BYTE); // 5 - Yaw map(Types.BYTE); // 5 - Yaw
map(Types.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Types1_13.ENTITY_DATA_LIST); // 7 - Metadata map(Types1_13.ENTITY_DATA_LIST); // 7 - Entity data
handler(getTrackerAndMetaHandler(Types1_13.ENTITY_DATA_LIST, EntityTypes1_13.EntityType.PLAYER)); handler(getTrackerAndDataHandler(Types1_13.ENTITY_DATA_LIST, EntityTypes1_13.EntityType.PLAYER));
} }
}); });
@ -130,17 +130,17 @@ public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter<Clientbound
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
// Rewrite items & blocks // Rewrite items & blocks
filter().handler((event, meta) -> { filter().handler((event, data) -> {
if (meta.dataType() == Types1_13.ENTITY_DATA_TYPES.itemType) { if (data.dataType() == Types1_13.ENTITY_DATA_TYPES.itemType) {
protocol.getItemRewriter().handleItemToClient(event.user(), (Item) meta.getValue()); protocol.getItemRewriter().handleItemToClient(event.user(), (Item) data.getValue());
} else if (meta.dataType() == Types1_13.ENTITY_DATA_TYPES.optionalBlockStateType) { } else if (data.dataType() == Types1_13.ENTITY_DATA_TYPES.optionalBlockStateType) {
// Convert to new block id // Convert to new block id
int data = (int) meta.getValue(); int value = (int) data.getValue();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); data.setValue(protocol.getMappingData().getNewBlockStateId(value));
} else if (meta.dataType() == Types1_13.ENTITY_DATA_TYPES.particleType) { } else if (data.dataType() == Types1_13.ENTITY_DATA_TYPES.particleType) {
rewriteParticle(event.user(), (Particle) meta.getValue()); rewriteParticle(event.user(), (Particle) data.getValue());
} else if (meta.dataType() == Types1_13.ENTITY_DATA_TYPES.optionalComponentType || meta.dataType() == Types1_13.ENTITY_DATA_TYPES.componentType) { } else if (data.dataType() == Types1_13.ENTITY_DATA_TYPES.optionalComponentType || data.dataType() == Types1_13.ENTITY_DATA_TYPES.componentType) {
JsonElement element = meta.value(); JsonElement element = data.value();
protocol.translatableRewriter().processText(event.user(), element); protocol.translatableRewriter().processText(event.user(), element);
} }
}); });

Datei anzeigen

@ -45,11 +45,11 @@ public class EntityPacketRewriter1_13_2 {
map(Types.SHORT); // 9 - Velocity X map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z map(Types.SHORT); // 11 - Velocity Z
map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 12 - Metadata map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 12 - Entity data
handler(wrapper -> { handler(wrapper -> {
for (EntityData metadata : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { for (EntityData entityData : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) {
metadata.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(metadata.dataType().typeId())); entityData.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(entityData.dataType().typeId()));
} }
}); });
} }
@ -65,11 +65,11 @@ public class EntityPacketRewriter1_13_2 {
map(Types.DOUBLE); // 4 - Z map(Types.DOUBLE); // 4 - Z
map(Types.BYTE); // 5 - Yaw map(Types.BYTE); // 5 - Yaw
map(Types.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 7 - Metadata map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 7 - Entity data
handler(wrapper -> { handler(wrapper -> {
for (EntityData metadata : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { for (EntityData entityData : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) {
metadata.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(metadata.dataType().typeId())); entityData.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(entityData.dataType().typeId()));
} }
}); });
} }
@ -79,11 +79,11 @@ public class EntityPacketRewriter1_13_2 {
@Override @Override
public void register() { public void register() {
map(Types.VAR_INT); // 0 - Entity ID map(Types.VAR_INT); // 0 - Entity ID
map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 1 - Metadata list map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 1 - Entity data list
handler(wrapper -> { handler(wrapper -> {
for (EntityData metadata : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { for (EntityData entityData : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) {
metadata.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(metadata.dataType().typeId())); entityData.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(entityData.dataType().typeId()));
} }
}); });
} }

Datei anzeigen

@ -145,7 +145,7 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
} }
}); });
// Rewrite entity type / metadata // Rewrite entity type / ddata
handler(getMobSpawnRewriter1_11(Types1_12.ENTITY_DATA_LIST)); handler(getMobSpawnRewriter1_11(Types1_12.ENTITY_DATA_LIST));
} }
}); });
@ -162,7 +162,7 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
map(Types.BYTE); map(Types.BYTE);
map(Types1_13.ENTITY_DATA_LIST, Types1_12.ENTITY_DATA_LIST); map(Types1_13.ENTITY_DATA_LIST, Types1_12.ENTITY_DATA_LIST);
handler(getTrackerAndMetaHandler(Types1_12.ENTITY_DATA_LIST, EntityTypes1_13.EntityType.PLAYER)); handler(getTrackerAndDataHandler(Types1_12.ENTITY_DATA_LIST, EntityTypes1_13.EntityType.PLAYER));
} }
}); });
@ -258,7 +258,7 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
mapEntityTypeWithData(EntityTypes1_13.EntityType.TROPICAL_FISH, EntityTypes1_13.EntityType.SQUID).plainName(); mapEntityTypeWithData(EntityTypes1_13.EntityType.TROPICAL_FISH, EntityTypes1_13.EntityType.SQUID).plainName();
// Phantom // Phantom
mapEntityTypeWithData(EntityTypes1_13.EntityType.PHANTOM, EntityTypes1_13.EntityType.PARROT).plainName().spawnMetadata(storage -> { mapEntityTypeWithData(EntityTypes1_13.EntityType.PHANTOM, EntityTypes1_13.EntityType.PARROT).plainName().spawnEntityData(storage -> {
// The phantom is grey/blue so let's do yellow/blue // The phantom is grey/blue so let's do yellow/blue
storage.add(new EntityData(15, EntityDataTypes1_12.VAR_INT, 3)); storage.add(new EntityData(15, EntityDataTypes1_12.VAR_INT, 3));
}); });
@ -269,32 +269,32 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
// Turtle // Turtle
mapEntityTypeWithData(EntityTypes1_13.EntityType.TURTLE, EntityTypes1_13.EntityType.OCELOT).plainName(); mapEntityTypeWithData(EntityTypes1_13.EntityType.TURTLE, EntityTypes1_13.EntityType.OCELOT).plainName();
// Rewrite Meta types // Rewrite Data types
filter().handler((event, meta) -> { filter().handler((event, data) -> {
int typeId = meta.dataType().typeId(); int typeId = data.dataType().typeId();
if (typeId == 4) { if (typeId == 4) {
JsonElement element = meta.value(); JsonElement element = data.value();
protocol.translatableRewriter().processText(event.user(), element); protocol.translatableRewriter().processText(event.user(), element);
meta.setDataType(EntityDataTypes1_12.COMPONENT); data.setDataType(EntityDataTypes1_12.COMPONENT);
} else if (typeId == 5) { } else if (typeId == 5) {
// Rewrite optional chat to string // Rewrite optional chat to string
JsonElement element = meta.value(); JsonElement element = data.value();
meta.setTypeAndValue(EntityDataTypes1_12.STRING, protocol.jsonToLegacy(event.user(), element)); data.setTypeAndValue(EntityDataTypes1_12.STRING, protocol.jsonToLegacy(event.user(), element));
} else if (typeId == 6) { } else if (typeId == 6) {
Item item = (Item) meta.getValue(); Item item = (Item) data.getValue();
meta.setTypeAndValue(EntityDataTypes1_12.ITEM, protocol.getItemRewriter().handleItemToClient(event.user(), item)); data.setTypeAndValue(EntityDataTypes1_12.ITEM, protocol.getItemRewriter().handleItemToClient(event.user(), item));
} else if (typeId == 15) { } else if (typeId == 15) {
// Discontinue particles // Discontinue particles
event.cancel(); event.cancel();
} else { } else {
meta.setDataType(EntityDataTypes1_12.byId(typeId > 5 ? typeId - 1 : typeId)); data.setDataType(EntityDataTypes1_12.byId(typeId > 5 ? typeId - 1 : typeId));
} }
}); });
// Handle zombie metadata // Handle zombie entity data
filter().type(EntityTypes1_13.EntityType.ZOMBIE).removeIndex(15); filter().type(EntityTypes1_13.EntityType.ZOMBIE).removeIndex(15);
// Handle turtle metadata (Remove them all for now) // Handle turtle entity data (Remove them all for now)
filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(13); // Home pos filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(13); // Home pos
filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(14); // Has egg filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(14); // Has egg
filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(15); // Laying egg filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(15); // Laying egg
@ -302,7 +302,7 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(17); // Going home filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(17); // Going home
filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(18); // Traveling filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(18); // Traveling
// Remove additional fish meta // Remove additional fish data
filter().type(EntityTypes1_13.EntityType.ABSTRACT_FISH).cancel(12); filter().type(EntityTypes1_13.EntityType.ABSTRACT_FISH).cancel(12);
filter().type(EntityTypes1_13.EntityType.ABSTRACT_FISH).cancel(13); filter().type(EntityTypes1_13.EntityType.ABSTRACT_FISH).cancel(13);
@ -316,21 +316,21 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
filter().type(EntityTypes1_13.EntityType.TRIDENT).cancel(7); filter().type(EntityTypes1_13.EntityType.TRIDENT).cancel(7);
// Handle new wolf colors // Handle new wolf colors
filter().type(EntityTypes1_13.EntityType.WOLF).index(17).handler((event, meta) -> { filter().type(EntityTypes1_13.EntityType.WOLF).index(17).handler((event, data) -> {
meta.setValue(15 - (int) meta.getValue()); data.setValue(15 - (int) data.getValue());
}); });
// Rewrite AreaEffectCloud // Rewrite AreaEffectCloud
filter().type(EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD).index(9).handler((event, meta) -> { filter().type(EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD).index(9).handler((event, data) -> {
Particle particle = (Particle) meta.getValue(); Particle particle = (Particle) data.getValue();
ParticleIdMappings1_12_2.ParticleData data = ParticleIdMappings1_12_2.getMapping(particle.id()); ParticleIdMappings1_12_2.ParticleData particleData = ParticleIdMappings1_12_2.getMapping(particle.id());
int firstArg = 0; int firstArg = 0;
int secondArg = 0; int secondArg = 0;
int[] particleArgs = data.rewriteMeta(protocol, particle.getArguments()); int[] particleArgs = particleData.rewriteMeta(protocol, particle.getArguments());
if (particleArgs != null && particleArgs.length != 0) { if (particleArgs != null && particleArgs.length != 0) {
if (data.getHandler().isBlockHandler() && particleArgs[0] == 0) { if (particleData.getHandler().isBlockHandler() && particleArgs[0] == 0) {
// Air doesn't have a break particle for sub 1.13 clients -> glass pane // Air doesn't have a break particle for sub 1.13 clients -> glass pane
particleArgs[0] = 102; particleArgs[0] = 102;
} }
@ -339,7 +339,7 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
secondArg = particleArgs.length == 2 ? particleArgs[1] : 0; secondArg = particleArgs.length == 2 ? particleArgs[1] : 0;
} }
event.createExtraData(new EntityData(9, EntityDataTypes1_12.VAR_INT, data.getHistoryId())); event.createExtraData(new EntityData(9, EntityDataTypes1_12.VAR_INT, particleData.getHistoryId()));
event.createExtraData(new EntityData(10, EntityDataTypes1_12.VAR_INT, firstArg)); event.createExtraData(new EntityData(10, EntityDataTypes1_12.VAR_INT, firstArg));
event.createExtraData(new EntityData(11, EntityDataTypes1_12.VAR_INT, secondArg)); event.createExtraData(new EntityData(11, EntityDataTypes1_12.VAR_INT, secondArg));

Datei anzeigen

@ -70,7 +70,7 @@ public class EntityPacketRewriter1_14_1 extends LegacyEntityRewriter<Clientbound
map(Types.SHORT); // 9 - Velocity X map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z map(Types.SHORT); // 11 - Velocity Z
map(Types1_14.ENTITY_DATA_LIST); // 12 - Metadata map(Types1_14.ENTITY_DATA_LIST); // 12 - Entity data
handler(wrapper -> { handler(wrapper -> {
int entityId = wrapper.get(Types.VAR_INT, 0); int entityId = wrapper.get(Types.VAR_INT, 0);
@ -79,13 +79,13 @@ public class EntityPacketRewriter1_14_1 extends LegacyEntityRewriter<Clientbound
// Register Type ID // Register Type ID
tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.getTypeFromId(type)); tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.getTypeFromId(type));
List<EntityData> metadata = wrapper.get(Types1_14.ENTITY_DATA_LIST, 0); List<EntityData> entityDataList = wrapper.get(Types1_14.ENTITY_DATA_LIST, 0);
handleEntityData(entityId, metadata, wrapper.user()); handleEntityData(entityId, entityDataList, wrapper.user());
}); });
} }
}); });
// Entity Metadata // Entity data
registerSetEntityData(ClientboundPackets1_14.SET_ENTITY_DATA, Types1_14.ENTITY_DATA_LIST); registerSetEntityData(ClientboundPackets1_14.SET_ENTITY_DATA, Types1_14.ENTITY_DATA_LIST);
} }

Datei anzeigen

@ -242,9 +242,9 @@ public class BlockItemPacketRewriter1_14 extends BackwardsItemRewriter<Clientbou
wrapper.cancel(); wrapper.cancel();
return; return;
} }
List<EntityData> metadataList = new ArrayList<>(); List<EntityData> entityDataList = new ArrayList<>();
metadataList.add(new EntityData(16, Types1_13_2.ENTITY_DATA_TYPES.varIntType, armorType)); entityDataList.add(new EntityData(16, Types1_13_2.ENTITY_DATA_TYPES.varIntType, armorType));
wrapper.write(Types1_13.ENTITY_DATA_LIST, metadataList); wrapper.write(Types1_13.ENTITY_DATA_LIST, entityDataList);
} }
}); });
} }

Datei anzeigen

@ -193,7 +193,7 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
map(Types.SHORT); // 9 - Velocity X map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z map(Types.SHORT); // 11 - Velocity Z
map(Types1_14.ENTITY_DATA_LIST, Types1_13_2.ENTITY_DATA_LIST); // 12 - Metadata map(Types1_14.ENTITY_DATA_LIST, Types1_13_2.ENTITY_DATA_LIST); // 12 - Entity data
handler(wrapper -> { handler(wrapper -> {
int type = wrapper.get(Types.VAR_INT, 1); int type = wrapper.get(Types.VAR_INT, 1);
@ -214,7 +214,7 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
} }
}); });
// Handle entity type & metadata // Handle entity type & data
handler(getMobSpawnRewriter1_11(Types1_13_2.ENTITY_DATA_LIST)); handler(getMobSpawnRewriter1_11(Types1_13_2.ENTITY_DATA_LIST));
} }
}); });
@ -266,9 +266,9 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
map(Types.DOUBLE); // 4 - Z map(Types.DOUBLE); // 4 - Z
map(Types.BYTE); // 5 - Yaw map(Types.BYTE); // 5 - Yaw
map(Types.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Types1_14.ENTITY_DATA_LIST, Types1_13_2.ENTITY_DATA_LIST); // 7 - Metadata map(Types1_14.ENTITY_DATA_LIST, Types1_13_2.ENTITY_DATA_LIST); // 7 - Entity data
handler(getTrackerAndMetaHandler(Types1_13_2.ENTITY_DATA_LIST, EntityTypes1_14.PLAYER)); handler(getTrackerAndDataHandler(Types1_13_2.ENTITY_DATA_LIST, EntityTypes1_14.PLAYER));
handler(wrapper -> positionHandler.cacheEntityPosition(wrapper, true, false)); handler(wrapper -> positionHandler.cacheEntityPosition(wrapper, true, false));
} }
}); });
@ -323,14 +323,14 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
filter().handler((event, meta) -> { filter().handler((event, data) -> {
int typeId = meta.dataType().typeId(); int typeId = data.dataType().typeId();
if (typeId <= 15) { if (typeId <= 15) {
meta.setDataType(Types1_13_2.ENTITY_DATA_TYPES.byId(typeId)); data.setDataType(Types1_13_2.ENTITY_DATA_TYPES.byId(typeId));
} }
}); });
registerMetaTypeHandler(Types1_13_2.ENTITY_DATA_TYPES.itemType, null, Types1_13_2.ENTITY_DATA_TYPES.optionalBlockStateType, null, registerEntityDataTypeHandler(Types1_13_2.ENTITY_DATA_TYPES.itemType, null, Types1_13_2.ENTITY_DATA_TYPES.optionalBlockStateType, null,
Types1_13_2.ENTITY_DATA_TYPES.componentType, Types1_13_2.ENTITY_DATA_TYPES.optionalComponentType); Types1_13_2.ENTITY_DATA_TYPES.componentType, Types1_13_2.ENTITY_DATA_TYPES.optionalComponentType);
filter().type(EntityTypes1_14.PILLAGER).cancel(15); filter().type(EntityTypes1_14.PILLAGER).cancel(15);
@ -353,15 +353,15 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
filter().type(EntityTypes1_14.ABSTRACT_RAIDER).removeIndex(14); // Celebrating filter().type(EntityTypes1_14.ABSTRACT_RAIDER).removeIndex(14); // Celebrating
filter().type(EntityTypes1_14.AREA_EFFECT_CLOUD).index(10).handler((event, meta) -> { filter().type(EntityTypes1_14.AREA_EFFECT_CLOUD).index(10).handler((event, data) -> {
rewriteParticle(event.user(), (Particle) meta.getValue()); rewriteParticle(event.user(), (Particle) data.getValue());
}); });
filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, meta) -> { filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, data) -> {
meta.setDataType(Types1_13_2.ENTITY_DATA_TYPES.varIntType); data.setDataType(Types1_13_2.ENTITY_DATA_TYPES.varIntType);
Integer value = (Integer) meta.getValue(); Integer value = (Integer) data.getValue();
if (value == null) { if (value == null) {
meta.setValue(0); data.setValue(0);
} }
}); });
@ -369,10 +369,10 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
filter().type(EntityTypes1_14.VILLAGER).cancel(15); // Head shake timer filter().type(EntityTypes1_14.VILLAGER).cancel(15); // Head shake timer
EntityDataHandler villagerDataHandler = (event, meta) -> { EntityDataHandler villagerDataHandler = (event, data) -> {
VillagerData villagerData = (VillagerData) meta.getValue(); VillagerData villagerData = (VillagerData) data.getValue();
meta.setTypeAndValue(Types1_13_2.ENTITY_DATA_TYPES.varIntType, villagerDataToProfession(villagerData)); data.setTypeAndValue(Types1_13_2.ENTITY_DATA_TYPES.varIntType, villagerDataToProfession(villagerData));
if (meta.id() == 16) { if (data.id() == 16) {
event.setIndex(15); // decreased by 2 again in one of the following handlers event.setIndex(15); // decreased by 2 again in one of the following handlers
} }
}; };
@ -381,14 +381,14 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
filter().type(EntityTypes1_14.VILLAGER).index(16).handler(villagerDataHandler); filter().type(EntityTypes1_14.VILLAGER).index(16).handler(villagerDataHandler);
// Holding arms up - from bitfield into own boolean // Holding arms up - from bitfield into own boolean
filter().type(EntityTypes1_14.ABSTRACT_SKELETON).index(13).handler((event, meta) -> { filter().type(EntityTypes1_14.ABSTRACT_SKELETON).index(13).handler((event, data) -> {
byte value = (byte) meta.getValue(); byte value = (byte) data.getValue();
if ((value & 4) != 0) { if ((value & 4) != 0) {
event.createExtraData(new EntityData(14, Types1_13_2.ENTITY_DATA_TYPES.booleanType, true)); event.createExtraData(new EntityData(14, Types1_13_2.ENTITY_DATA_TYPES.booleanType, true));
} }
}); });
filter().type(EntityTypes1_14.ZOMBIE).index(13).handler((event, meta) -> { filter().type(EntityTypes1_14.ZOMBIE).index(13).handler((event, data) -> {
byte value = (byte) meta.getValue(); byte value = (byte) data.getValue();
if ((value & 4) != 0) { if ((value & 4) != 0) {
event.createExtraData(new EntityData(16, Types1_13_2.ENTITY_DATA_TYPES.booleanType, true)); event.createExtraData(new EntityData(16, Types1_13_2.ENTITY_DATA_TYPES.booleanType, true));
} }
@ -397,10 +397,10 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
filter().type(EntityTypes1_14.ZOMBIE).addIndex(16); filter().type(EntityTypes1_14.ZOMBIE).addIndex(16);
// Remove bed location // Remove bed location
filter().type(EntityTypes1_14.LIVING_ENTITY).handler((event, meta) -> { filter().type(EntityTypes1_14.LIVING_ENTITY).handler((event, data) -> {
int index = event.index(); int index = event.index();
if (index == 12) { if (index == 12) {
BlockPosition position = (BlockPosition) meta.getValue(); BlockPosition position = (BlockPosition) data.getValue();
if (position != null) { if (position != null) {
// Use bed // Use bed
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_13.PLAYER_SLEEP, null, event.user()); PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_13.PLAYER_SLEEP, null, event.user());
@ -423,51 +423,49 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
// Pose // Pose
filter().removeIndex(6); filter().removeIndex(6);
filter().type(EntityTypes1_14.OCELOT).index(13).handler((event, meta) -> { filter().type(EntityTypes1_14.OCELOT).index(13).handler((event, data) -> {
event.setIndex(15); event.setIndex(15);
meta.setTypeAndValue(Types1_13_2.ENTITY_DATA_TYPES.varIntType, 0); data.setTypeAndValue(Types1_13_2.ENTITY_DATA_TYPES.varIntType, 0);
}); });
filter().type(EntityTypes1_14.CAT).handler((event, meta) -> { filter().type(EntityTypes1_14.CAT).handler((event, data) -> {
if (event.index() == 15) { if (event.index() == 15) {
meta.setValue(1); data.setValue(1);
} else if (event.index() == 13) { } else if (event.index() == 13) {
meta.setValue((byte) ((byte) meta.getValue() & 0x4)); data.setValue((byte) ((byte) data.getValue() & 0x4));
} }
}); });
filter().handler((event, meta) -> { filter().handler((event, data) -> {
if (meta.dataType().typeId() > 15) { if (data.dataType().typeId() > 15) {
throw new IllegalArgumentException("Unhandled metadata: " + meta); throw new IllegalArgumentException("Unhandled entity data: " + data);
} }
}); });
} }
public int villagerDataToProfession(VillagerData data) { public int villagerDataToProfession(VillagerData data) {
switch (data.profession()) { return switch (data.profession()) { // Armorer
case 1: // Armorer // Mason
case 10: // Mason // Toolsmith
case 13: // Toolsmith case 1, 10, 13, 14 -> // Weaponsmith
case 14: // Weaponsmith 3; // Blacksmith
return 3; // Blacksmith // Butcher
case 2: // Butcher case 2, 8 -> // Leatherworker
case 8: // Leatherworker 4; // Butcher
return 4; // Butcher // Cartographer
case 3: // Cartographer case 3, 9 -> // Librarian
case 9: // Librarian 1; // Librarian
return 1; // Librarian case 4 -> // Cleric
case 4: // Cleric 2; // Priest
return 2; // Priest // Farmer
case 5: // Farmer // Fisherman
case 6: // Fisherman // Fletcher
case 7: // Fletcher case 5, 6, 7, 12 -> // Shepherd
case 12: // Shepherd 0; // Farmer
return 0; // Farmer // None
case 0: // None // Nitwit
case 11: // Nitwit default -> 5; // Nitwit
default: };
return 5; // Nitwit
}
} }
@Override @Override

Datei anzeigen

@ -80,7 +80,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter<ClientboundPackets1
map(Types.SHORT); // 9 - Velocity X map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z map(Types.SHORT); // 11 - Velocity Z
handler(wrapper -> wrapper.write(Types1_14.ENTITY_DATA_LIST, new ArrayList<>())); // Metadata is no longer sent in 1.15, so we have to send an empty one handler(wrapper -> wrapper.write(Types1_14.ENTITY_DATA_LIST, new ArrayList<>())); // Entity data is no longer sent in 1.15, so we have to send an empty one
handler(wrapper -> { handler(wrapper -> {
int type = wrapper.get(Types.VAR_INT, 1); int type = wrapper.get(Types.VAR_INT, 1);
@ -136,7 +136,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter<ClientboundPackets1
map(Types.DOUBLE); // 4 - Z map(Types.DOUBLE); // 4 - Z
map(Types.BYTE); // 5 - Yaw map(Types.BYTE); // 5 - Yaw
map(Types.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
handler(wrapper -> wrapper.write(Types1_14.ENTITY_DATA_LIST, new ArrayList<>())); // Metadata is no longer sent in 1.15, so we have to send an empty one handler(wrapper -> wrapper.write(Types1_14.ENTITY_DATA_LIST, new ArrayList<>())); // Entity data is no longer sent in 1.15, so we have to send an empty one
handler(getTrackerHandler(EntityTypes1_15.PLAYER, Types.VAR_INT)); handler(getTrackerHandler(EntityTypes1_15.PLAYER, Types.VAR_INT));
} }
@ -191,7 +191,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter<ClientboundPackets1
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
registerMetaTypeHandler(Types1_14.ENTITY_DATA_TYPES.itemType, null, Types1_14.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_14.ENTITY_DATA_TYPES.particleType, registerEntityDataTypeHandler(Types1_14.ENTITY_DATA_TYPES.itemType, null, Types1_14.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_14.ENTITY_DATA_TYPES.particleType,
Types1_14.ENTITY_DATA_TYPES.componentType, Types1_14.ENTITY_DATA_TYPES.optionalComponentType); Types1_14.ENTITY_DATA_TYPES.componentType, Types1_14.ENTITY_DATA_TYPES.optionalComponentType);
filter().type(EntityTypes1_15.LIVING_ENTITY).removeIndex(12); filter().type(EntityTypes1_15.LIVING_ENTITY).removeIndex(12);
@ -204,7 +204,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter<ClientboundPackets1
// Redundant health removed in 1.15 // Redundant health removed in 1.15
filter().type(EntityTypes1_15.WOLF).addIndex(17); filter().type(EntityTypes1_15.WOLF).addIndex(17);
filter().type(EntityTypes1_15.WOLF).index(8).handler((event, meta) -> { filter().type(EntityTypes1_15.WOLF).index(8).handler((event, data) -> {
event.createExtraData(new EntityData(17/*WOLF_HEALTH*/, Types1_14.ENTITY_DATA_TYPES.floatType, event.data().value())); event.createExtraData(new EntityData(17/*WOLF_HEALTH*/, Types1_14.ENTITY_DATA_TYPES.floatType, event.data().value()));
}); });
} }
@ -213,7 +213,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter<ClientboundPackets1
public void onMappingDataLoaded() { public void onMappingDataLoaded() {
mapTypes(); mapTypes();
mapEntityTypeWithData(EntityTypes1_15.BEE, EntityTypes1_15.PUFFERFISH).jsonName().spawnMetadata(storage -> { mapEntityTypeWithData(EntityTypes1_15.BEE, EntityTypes1_15.PUFFERFISH).jsonName().spawnEntityData(storage -> {
storage.add(new EntityData(14, Types1_14.ENTITY_DATA_TYPES.booleanType, false)); storage.add(new EntityData(14, Types1_14.ENTITY_DATA_TYPES.booleanType, false));
storage.add(new EntityData(15, Types1_14.ENTITY_DATA_TYPES.varIntType, 2)); storage.add(new EntityData(15, Types1_14.ENTITY_DATA_TYPES.varIntType, 2));
}); });

Datei anzeigen

@ -120,7 +120,7 @@ public class EntityPacketRewriter1_16_2 extends EntityRewriter<ClientboundPacket
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
registerMetaTypeHandler(Types1_16.ENTITY_DATA_TYPES.itemType, null, Types1_16.ENTITY_DATA_TYPES.optionalBlockStateType, registerEntityDataTypeHandler(Types1_16.ENTITY_DATA_TYPES.itemType, null, Types1_16.ENTITY_DATA_TYPES.optionalBlockStateType,
Types1_16.ENTITY_DATA_TYPES.particleType, Types1_16.ENTITY_DATA_TYPES.componentType, Types1_16.ENTITY_DATA_TYPES.optionalComponentType); Types1_16.ENTITY_DATA_TYPES.particleType, Types1_16.ENTITY_DATA_TYPES.componentType, Types1_16.ENTITY_DATA_TYPES.optionalComponentType);
filter().type(EntityTypes1_16_2.ABSTRACT_PIGLIN).index(15).toIndex(16); filter().type(EntityTypes1_16_2.ABSTRACT_PIGLIN).index(15).toIndex(16);

Datei anzeigen

@ -230,18 +230,18 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
filter().handler((event, meta) -> { filter().handler((event, data) -> {
meta.setDataType(Types1_14.ENTITY_DATA_TYPES.byId(meta.dataType().typeId())); data.setDataType(Types1_14.ENTITY_DATA_TYPES.byId(data.dataType().typeId()));
EntityDataType type = meta.dataType(); EntityDataType type = data.dataType();
if (type == Types1_14.ENTITY_DATA_TYPES.itemType) { if (type == Types1_14.ENTITY_DATA_TYPES.itemType) {
meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), (Item) meta.getValue())); data.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), (Item) data.getValue()));
} else if (type == Types1_14.ENTITY_DATA_TYPES.optionalBlockStateType) { } else if (type == Types1_14.ENTITY_DATA_TYPES.optionalBlockStateType) {
meta.setValue(protocol.getMappingData().getNewBlockStateId((int) meta.getValue())); data.setValue(protocol.getMappingData().getNewBlockStateId((int) data.getValue()));
} else if (type == Types1_14.ENTITY_DATA_TYPES.particleType) { } else if (type == Types1_14.ENTITY_DATA_TYPES.particleType) {
rewriteParticle(event.user(), (Particle) meta.getValue()); rewriteParticle(event.user(), (Particle) data.getValue());
} else if (type == Types1_14.ENTITY_DATA_TYPES.optionalComponentType) { } else if (type == Types1_14.ENTITY_DATA_TYPES.optionalComponentType) {
JsonElement text = meta.value(); JsonElement text = data.value();
if (text != null) { if (text != null) {
protocol.getComponentRewriter().processText(event.user(), text); protocol.getComponentRewriter().processText(event.user(), text);
} }
@ -255,9 +255,9 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
filter().type(EntityTypes1_16.PIGLIN).cancel(17); filter().type(EntityTypes1_16.PIGLIN).cancel(17);
filter().type(EntityTypes1_16.PIGLIN).cancel(18); filter().type(EntityTypes1_16.PIGLIN).cancel(18);
filter().type(EntityTypes1_16.STRIDER).index(15).handler((event, meta) -> { filter().type(EntityTypes1_16.STRIDER).index(15).handler((event, data) -> {
boolean baby = meta.value(); boolean baby = data.value();
meta.setTypeAndValue(Types1_14.ENTITY_DATA_TYPES.varIntType, baby ? 1 : 3); data.setTypeAndValue(Types1_14.ENTITY_DATA_TYPES.varIntType, baby ? 1 : 3);
}); });
filter().type(EntityTypes1_16.STRIDER).cancel(16); filter().type(EntityTypes1_16.STRIDER).cancel(16);
filter().type(EntityTypes1_16.STRIDER).cancel(17); filter().type(EntityTypes1_16.STRIDER).cancel(17);
@ -266,29 +266,29 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
filter().type(EntityTypes1_16.FISHING_BOBBER).cancel(8); filter().type(EntityTypes1_16.FISHING_BOBBER).cancel(8);
filter().type(EntityTypes1_16.ABSTRACT_ARROW).cancel(8); filter().type(EntityTypes1_16.ABSTRACT_ARROW).cancel(8);
filter().type(EntityTypes1_16.ABSTRACT_ARROW).handler((event, meta) -> { filter().type(EntityTypes1_16.ABSTRACT_ARROW).handler((event, data) -> {
if (event.index() >= 8) { if (event.index() >= 8) {
event.setIndex(event.index() + 1); event.setIndex(event.index() + 1);
} }
}); });
filter().type(EntityTypes1_16.WOLF).index(16).handler((event, meta) -> { filter().type(EntityTypes1_16.WOLF).index(16).handler((event, data) -> {
byte mask = meta.value(); byte mask = data.value();
StoredEntityData data = tracker(event.user()).entityData(event.entityId()); StoredEntityData entityData = tracker(event.user()).entityData(event.entityId());
data.put(new WolfDataMaskStorage(mask)); entityData.put(new WolfDataMaskStorage(mask));
}); });
filter().type(EntityTypes1_16.WOLF).index(20).handler((event, meta) -> { filter().type(EntityTypes1_16.WOLF).index(20).handler((event, data) -> {
StoredEntityData data = tracker(event.user()).entityDataIfPresent(event.entityId()); StoredEntityData entityData = tracker(event.user()).entityDataIfPresent(event.entityId());
byte previousMask = 0; byte previousMask = 0;
if (data != null) { if (entityData != null) {
WolfDataMaskStorage wolfData = data.get(WolfDataMaskStorage.class); WolfDataMaskStorage wolfData = entityData.get(WolfDataMaskStorage.class);
if (wolfData != null) { if (wolfData != null) {
previousMask = wolfData.tameableMask(); previousMask = wolfData.tameableMask();
} }
} }
int angerTime = meta.value(); int angerTime = data.value();
byte tameableMask = (byte) (angerTime > 0 ? previousMask | 2 : previousMask & -3); byte tameableMask = (byte) (angerTime > 0 ? previousMask | 2 : previousMask & -3);
event.createExtraData(new EntityData(16, Types1_14.ENTITY_DATA_TYPES.byteType, tameableMask)); event.createExtraData(new EntityData(16, Types1_14.ENTITY_DATA_TYPES.byteType, tameableMask));
event.cancel(); event.cancel();

Datei anzeigen

@ -145,12 +145,12 @@ public final class EntityPacketRewriter1_17 extends EntityRewriter<ClientboundPa
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
filter().handler((event, meta) -> { filter().handler((event, data) -> {
meta.setDataType(Types1_16.ENTITY_DATA_TYPES.byId(meta.dataType().typeId())); data.setDataType(Types1_16.ENTITY_DATA_TYPES.byId(data.dataType().typeId()));
EntityDataType type = meta.dataType(); EntityDataType type = data.dataType();
if (type == Types1_16.ENTITY_DATA_TYPES.particleType) { if (type == Types1_16.ENTITY_DATA_TYPES.particleType) {
Particle particle = (Particle) meta.getValue(); Particle particle = (Particle) data.getValue();
if (particle.id() == 16) { // Dust / Dust Transition if (particle.id() == 16) { // Dust / Dust Transition
// Remove transition target color values 4-6 // Remove transition target color values 4-6
particle.getArguments().subList(4, 7).clear(); particle.getArguments().subList(4, 7).clear();
@ -164,17 +164,17 @@ public final class EntityPacketRewriter1_17 extends EntityRewriter<ClientboundPa
rewriteParticle(event.user(), particle); rewriteParticle(event.user(), particle);
} else if (type == Types1_16.ENTITY_DATA_TYPES.poseType) { } else if (type == Types1_16.ENTITY_DATA_TYPES.poseType) {
// Goat LONG_JUMP added at 6 // Goat LONG_JUMP added at 6
int pose = meta.value(); int pose = data.value();
if (pose == 6) { if (pose == 6) {
meta.setValue(1); // FALL_FLYING data.setValue(1); // FALL_FLYING
} else if (pose > 6) { } else if (pose > 6) {
meta.setValue(pose - 1); data.setValue(pose - 1);
} }
} }
}); });
// Particles have already been handled // Particles have already been handled
registerMetaTypeHandler(Types1_16.ENTITY_DATA_TYPES.itemType, null, Types1_16.ENTITY_DATA_TYPES.optionalBlockStateType, null, registerEntityDataTypeHandler(Types1_16.ENTITY_DATA_TYPES.itemType, null, Types1_16.ENTITY_DATA_TYPES.optionalBlockStateType, null,
Types1_16.ENTITY_DATA_TYPES.componentType, Types1_16.ENTITY_DATA_TYPES.optionalComponentType); Types1_16.ENTITY_DATA_TYPES.componentType, Types1_16.ENTITY_DATA_TYPES.optionalComponentType);
filter().type(EntityTypes1_17.AXOLOTL).cancel(17); filter().type(EntityTypes1_17.AXOLOTL).cancel(17);

Datei anzeigen

@ -24,7 +24,6 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_17; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_17;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType; import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_17; import com.viaversion.viaversion.api.type.types.version.Types1_17;
import com.viaversion.viaversion.api.type.types.version.Types1_18; import com.viaversion.viaversion.api.type.types.version.Types1_18;
@ -32,7 +31,6 @@ import com.viaversion.viaversion.protocols.v1_17_1to1_18.packet.ClientboundPacke
import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.ListTag; import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.util.TagUtil; import com.viaversion.viaversion.util.TagUtil;
public final class EntityPacketRewriter1_18 extends EntityRewriter<ClientboundPackets1_18, Protocol1_18To1_17_1> { public final class EntityPacketRewriter1_18 extends EntityRewriter<ClientboundPackets1_18, Protocol1_18To1_17_1> {
@ -94,15 +92,15 @@ public final class EntityPacketRewriter1_18 extends EntityRewriter<ClientboundPa
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
filter().handler((event, meta) -> { filter().handler((event, data) -> {
meta.setDataType(Types1_17.ENTITY_DATA_TYPES.byId(meta.dataType().typeId())); data.setDataType(Types1_17.ENTITY_DATA_TYPES.byId(data.dataType().typeId()));
EntityDataType type = meta.dataType(); EntityDataType type = data.dataType();
if (type == Types1_17.ENTITY_DATA_TYPES.particleType) { if (type == Types1_17.ENTITY_DATA_TYPES.particleType) {
Particle particle = meta.value(); Particle particle = data.value();
if (particle.id() == 3) { // Block marker if (particle.id() == 3) { // Block marker
Particle.ParticleData<?> data = particle.getArguments().remove(0); Particle.ParticleData<?> value = particle.getArguments().remove(0);
int blockState = (int) data.getValue(); int blockState = (int) value.getValue();
if (blockState == 7786) { // Light block if (blockState == 7786) { // Light block
particle.setId(3); particle.setId(3);
} else { } else {
@ -117,7 +115,7 @@ public final class EntityPacketRewriter1_18 extends EntityRewriter<ClientboundPa
}); });
// Particles have already been handled // Particles have already been handled
registerMetaTypeHandler(Types1_17.ENTITY_DATA_TYPES.itemType, null, null, null, registerEntityDataTypeHandler(Types1_17.ENTITY_DATA_TYPES.itemType, null, null, null,
Types1_17.ENTITY_DATA_TYPES.componentType, Types1_17.ENTITY_DATA_TYPES.optionalComponentType); Types1_17.ENTITY_DATA_TYPES.componentType, Types1_17.ENTITY_DATA_TYPES.optionalComponentType);
} }

Datei anzeigen

@ -27,7 +27,6 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_3;
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3; import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.BitSetType; import com.viaversion.viaversion.api.type.types.BitSetType;
import com.viaversion.viaversion.api.type.types.version.Types1_19; import com.viaversion.viaversion.api.type.types.version.Types1_19;
@ -230,25 +229,25 @@ public final class EntityPacketRewriter1_19_3 extends EntityRewriter<Clientbound
@Override @Override
public void registerRewrites() { public void registerRewrites() {
filter().handler((event, meta) -> { filter().handler((event, data) -> {
final int id = meta.dataType().typeId(); final int id = data.dataType().typeId();
if (id > 2) { if (id > 2) {
meta.setDataType(Types1_19.ENTITY_DATA_TYPES.byId(id - 1)); // long added data.setDataType(Types1_19.ENTITY_DATA_TYPES.byId(id - 1)); // long added
} else if (id != 2) { } else if (id != 2) {
meta.setDataType(Types1_19.ENTITY_DATA_TYPES.byId(id)); data.setDataType(Types1_19.ENTITY_DATA_TYPES.byId(id));
} }
}); });
registerMetaTypeHandler(Types1_19.ENTITY_DATA_TYPES.itemType, null, Types1_19.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19.ENTITY_DATA_TYPES.particleType, registerEntityDataTypeHandler(Types1_19.ENTITY_DATA_TYPES.itemType, null, Types1_19.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19.ENTITY_DATA_TYPES.particleType,
Types1_19.ENTITY_DATA_TYPES.componentType, Types1_19.ENTITY_DATA_TYPES.optionalComponentType); Types1_19.ENTITY_DATA_TYPES.componentType, Types1_19.ENTITY_DATA_TYPES.optionalComponentType);
registerBlockStateHandler(EntityTypes1_19_3.ABSTRACT_MINECART, 11); registerBlockStateHandler(EntityTypes1_19_3.ABSTRACT_MINECART, 11);
filter().dataType(Types1_19.ENTITY_DATA_TYPES.poseType).handler((event, meta) -> { filter().dataType(Types1_19.ENTITY_DATA_TYPES.poseType).handler((event, data) -> {
// Sitting pose added // Sitting pose added
final int pose = meta.value(); final int pose = data.value();
if (pose == 10) { if (pose == 10) {
meta.setValue(0); // Standing data.setValue(0); // Standing
} else if (pose > 10) { } else if (pose > 10) {
meta.setValue(pose - 1); data.setValue(pose - 1);
} }
}); });

Datei anzeigen

@ -141,39 +141,39 @@ public final class EntityPacketRewriter1_19_4 extends EntityRewriter<Clientbound
@Override @Override
public void registerRewrites() { public void registerRewrites() {
filter().handler((event, meta) -> { filter().handler((event, data) -> {
int id = meta.dataType().typeId(); int id = data.dataType().typeId();
if (id >= 25) { // Sniffer state, Vector3f, Quaternion types if (id >= 25) { // Sniffer state, Vector3f, Quaternion types
return; return;
} else if (id >= 15) { // Optional block state - just map down to block state } else if (id >= 15) { // Optional block state - just map down to block state
id--; id--;
} }
meta.setDataType(Types1_19_3.ENTITY_DATA_TYPES.byId(id)); data.setDataType(Types1_19_3.ENTITY_DATA_TYPES.byId(id));
}); });
registerMetaTypeHandler(Types1_19_3.ENTITY_DATA_TYPES.itemType, null, Types1_19_3.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19_3.ENTITY_DATA_TYPES.particleType, registerEntityDataTypeHandler(Types1_19_3.ENTITY_DATA_TYPES.itemType, null, Types1_19_3.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19_3.ENTITY_DATA_TYPES.particleType,
Types1_19_3.ENTITY_DATA_TYPES.componentType, Types1_19_3.ENTITY_DATA_TYPES.optionalComponentType); Types1_19_3.ENTITY_DATA_TYPES.componentType, Types1_19_3.ENTITY_DATA_TYPES.optionalComponentType);
registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11); registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11);
filter().type(EntityTypes1_19_4.BOAT).index(11).handler((event, meta) -> { filter().type(EntityTypes1_19_4.BOAT).index(11).handler((event, data) -> {
final int boatType = meta.value(); final int boatType = data.value();
if (boatType > 4) { // Cherry if (boatType > 4) { // Cherry
meta.setValue(boatType - 1); data.setValue(boatType - 1);
} }
}); });
filter().type(EntityTypes1_19_4.TEXT_DISPLAY).index(22).handler(((event, meta) -> { filter().type(EntityTypes1_19_4.TEXT_DISPLAY).index(22).handler(((event, data) -> {
// Send as custom display name // Send as custom display name
event.setIndex(2); event.setIndex(2);
meta.setDataType(Types1_19_3.ENTITY_DATA_TYPES.optionalComponentType); data.setDataType(Types1_19_3.ENTITY_DATA_TYPES.optionalComponentType);
event.createExtraData(new EntityData(3, Types1_19_3.ENTITY_DATA_TYPES.booleanType, true)); // Show custom name event.createExtraData(new EntityData(3, Types1_19_3.ENTITY_DATA_TYPES.booleanType, true)); // Show custom name
final JsonElement element = meta.value(); final JsonElement element = data.value();
protocol.getComponentRewriter().processText(event.user(), element); protocol.getComponentRewriter().processText(event.user(), element);
})); }));
filter().type(EntityTypes1_19_4.DISPLAY).handler((event, meta) -> { filter().type(EntityTypes1_19_4.DISPLAY).handler((event, data) -> {
// TODO Maybe spawn an extra entity to ride the armor stand for blocks and items // TODO Maybe spawn an extra entity to ride the armor stand for blocks and items
// Remove a large heap of display metadata // Remove a large heap of display entity data
if (event.index() > 7) { if (event.index() > 7) {
event.cancel(); event.cancel();
} }
@ -193,16 +193,16 @@ public final class EntityPacketRewriter1_19_4 extends EntityRewriter<Clientbound
public void onMappingDataLoaded() { public void onMappingDataLoaded() {
mapTypes(); mapTypes();
final EntityReplacement.MetaCreator displayMetaCreator = storage -> { final EntityReplacement.EntityDataCreator displayDataCreator = storage -> {
storage.add(new EntityData(0, Types1_19_3.ENTITY_DATA_TYPES.byteType, (byte) 0x20)); // Invisible storage.add(new EntityData(0, Types1_19_3.ENTITY_DATA_TYPES.byteType, (byte) 0x20)); // Invisible
storage.add(new EntityData(5, Types1_19_3.ENTITY_DATA_TYPES.booleanType, true)); // No gravity storage.add(new EntityData(5, Types1_19_3.ENTITY_DATA_TYPES.booleanType, true)); // No gravity
storage.add(new EntityData(15, Types1_19_3.ENTITY_DATA_TYPES.byteType, (byte) (0x01 | 0x10))); // Small marker storage.add(new EntityData(15, Types1_19_3.ENTITY_DATA_TYPES.byteType, (byte) (0x01 | 0x10))); // Small marker
}; };
mapEntityTypeWithData(EntityTypes1_19_4.TEXT_DISPLAY, EntityTypes1_19_4.ARMOR_STAND).spawnMetadata(displayMetaCreator); mapEntityTypeWithData(EntityTypes1_19_4.TEXT_DISPLAY, EntityTypes1_19_4.ARMOR_STAND).spawnEntityData(displayDataCreator);
mapEntityTypeWithData(EntityTypes1_19_4.ITEM_DISPLAY, EntityTypes1_19_4.ARMOR_STAND).spawnMetadata(displayMetaCreator); mapEntityTypeWithData(EntityTypes1_19_4.ITEM_DISPLAY, EntityTypes1_19_4.ARMOR_STAND).spawnEntityData(displayDataCreator);
mapEntityTypeWithData(EntityTypes1_19_4.BLOCK_DISPLAY, EntityTypes1_19_4.ARMOR_STAND).spawnMetadata(displayMetaCreator); mapEntityTypeWithData(EntityTypes1_19_4.BLOCK_DISPLAY, EntityTypes1_19_4.ARMOR_STAND).spawnEntityData(displayDataCreator);
mapEntityTypeWithData(EntityTypes1_19_4.INTERACTION, EntityTypes1_19_4.ARMOR_STAND).spawnMetadata(displayMetaCreator); // Not much we can do about this one mapEntityTypeWithData(EntityTypes1_19_4.INTERACTION, EntityTypes1_19_4.ARMOR_STAND).spawnEntityData(displayDataCreator); // Not much we can do about this one
mapEntityTypeWithData(EntityTypes1_19_4.SNIFFER, EntityTypes1_19_4.RAVAGER).jsonName(); mapEntityTypeWithData(EntityTypes1_19_4.SNIFFER, EntityTypes1_19_4.RAVAGER).jsonName();
} }

Datei anzeigen

@ -84,7 +84,7 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPa
return; return;
} else if (entityType == EntityTypes1_19.PAINTING) { } else if (entityType == EntityTypes1_19.PAINTING) {
wrapper.cancel(); wrapper.cancel();
// The entity has been tracked, now we wait for the metadata packet // The entity has been tracked, now we wait for the entity data packet
final int entityId = wrapper.get(Types.VAR_INT, 0); final int entityId = wrapper.get(Types.VAR_INT, 0);
final StoredEntityData entityData = tracker(wrapper.user()).entityData(entityId); final StoredEntityData entityData = tracker(wrapper.user()).entityData(entityId);
final BlockPosition position = new BlockPosition(wrapper.get(Types.DOUBLE, 0).intValue(), wrapper.get(Types.DOUBLE, 1).intValue(), wrapper.get(Types.DOUBLE, 2).intValue()); final BlockPosition position = new BlockPosition(wrapper.get(Types.DOUBLE, 0).intValue(), wrapper.get(Types.DOUBLE, 1).intValue(), wrapper.get(Types.DOUBLE, 2).intValue());
@ -247,14 +247,14 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPa
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
filter().handler((event, meta) -> { filter().handler((event, data) -> {
if (meta.dataType().typeId() <= Types1_18.ENTITY_DATA_TYPES.poseType.typeId()) { if (data.dataType().typeId() <= Types1_18.ENTITY_DATA_TYPES.poseType.typeId()) {
meta.setDataType(Types1_18.ENTITY_DATA_TYPES.byId(meta.dataType().typeId())); data.setDataType(Types1_18.ENTITY_DATA_TYPES.byId(data.dataType().typeId()));
} }
final EntityDataType type = meta.dataType(); final EntityDataType type = data.dataType();
if (type == Types1_18.ENTITY_DATA_TYPES.particleType) { if (type == Types1_18.ENTITY_DATA_TYPES.particleType) {
final Particle particle = (Particle) meta.getValue(); final Particle particle = (Particle) data.getValue();
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings(); final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
if (particle.id() == particleMappings.id("sculk_charge")) { if (particle.id() == particleMappings.id("sculk_charge")) {
//TODO //TODO
@ -272,19 +272,19 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPa
rewriteParticle(event.user(), particle); rewriteParticle(event.user(), particle);
} else if (type == Types1_18.ENTITY_DATA_TYPES.poseType) { } else if (type == Types1_18.ENTITY_DATA_TYPES.poseType) {
final int pose = meta.value(); final int pose = data.value();
if (pose >= 8) { if (pose >= 8) {
// Croaking, using_tongue, roaring, sniffing, emerging, digging -> standing -> standing // Croaking, using_tongue, roaring, sniffing, emerging, digging -> standing -> standing
meta.setValue(0); data.setValue(0);
} }
} }
}); });
registerMetaTypeHandler(Types1_18.ENTITY_DATA_TYPES.itemType, null, Types1_18.ENTITY_DATA_TYPES.optionalBlockStateType, null, registerEntityDataTypeHandler(Types1_18.ENTITY_DATA_TYPES.itemType, null, Types1_18.ENTITY_DATA_TYPES.optionalBlockStateType, null,
Types1_18.ENTITY_DATA_TYPES.componentType, Types1_18.ENTITY_DATA_TYPES.optionalComponentType); Types1_18.ENTITY_DATA_TYPES.componentType, Types1_18.ENTITY_DATA_TYPES.optionalComponentType);
registerBlockStateHandler(EntityTypes1_19.ABSTRACT_MINECART, 11); registerBlockStateHandler(EntityTypes1_19.ABSTRACT_MINECART, 11);
filter().type(EntityTypes1_19.PAINTING).index(8).handler((event, meta) -> { filter().type(EntityTypes1_19.PAINTING).index(8).handler((event, data) -> {
event.cancel(); event.cancel();
final StoredEntityData entityData = tracker(event.user()).entityDataIfPresent(event.entityId()); final StoredEntityData entityData = tracker(event.user()).entityDataIfPresent(event.entityId());
@ -293,7 +293,7 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPa
final PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_18.ADD_PAINTING, event.user()); final PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_18.ADD_PAINTING, event.user());
packet.write(Types.VAR_INT, storedPainting.entityId()); packet.write(Types.VAR_INT, storedPainting.entityId());
packet.write(Types.UUID, storedPainting.uuid()); packet.write(Types.UUID, storedPainting.uuid());
packet.write(Types.VAR_INT, meta.value()); packet.write(Types.VAR_INT, data.value());
packet.write(Types.BLOCK_POSITION1_14, storedPainting.position()); packet.write(Types.BLOCK_POSITION1_14, storedPainting.position());
packet.write(Types.BYTE, storedPainting.direction()); packet.write(Types.BYTE, storedPainting.direction());
try { try {
@ -305,7 +305,7 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPa
} }
}); });
filter().type(EntityTypes1_19.CAT).index(19).handler((event, meta) -> meta.setDataType(Types1_18.ENTITY_DATA_TYPES.varIntType)); filter().type(EntityTypes1_19.CAT).index(19).handler((event, data) -> data.setDataType(Types1_18.ENTITY_DATA_TYPES.varIntType));
filter().type(EntityTypes1_19.FROG).cancel(16); // Age filter().type(EntityTypes1_19.FROG).cancel(16); // Age
filter().type(EntityTypes1_19.FROG).cancel(17); // Variant filter().type(EntityTypes1_19.FROG).cancel(17); // Variant

Datei anzeigen

@ -198,8 +198,8 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
filter().handler((event, meta) -> meta.setDataType(Types1_20.ENTITY_DATA_TYPES.byId(meta.dataType().typeId()))); filter().handler((event, data) -> data.setDataType(Types1_20.ENTITY_DATA_TYPES.byId(data.dataType().typeId())));
registerMetaTypeHandler(Types1_20.ENTITY_DATA_TYPES.itemType, Types1_20.ENTITY_DATA_TYPES.blockStateType, Types1_20.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20.ENTITY_DATA_TYPES.particleType, null, null); registerEntityDataTypeHandler(Types1_20.ENTITY_DATA_TYPES.itemType, Types1_20.ENTITY_DATA_TYPES.blockStateType, Types1_20.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20.ENTITY_DATA_TYPES.particleType, null, null);
registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11); registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11);
filter().type(EntityTypes1_19_4.DISPLAY).removeIndex(10); filter().type(EntityTypes1_19_4.DISPLAY).removeIndex(10);

Datei anzeigen

@ -96,16 +96,16 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
filter().handler((event, meta) -> { filter().handler((event, data) -> {
final EntityDataType type = meta.dataType(); final EntityDataType type = data.dataType();
if (type == Types1_20_3.ENTITY_DATA_TYPES.componentType) { if (type == Types1_20_3.ENTITY_DATA_TYPES.componentType) {
meta.setTypeAndValue(Types1_20_2.ENTITY_DATA_TYPES.componentType, ComponentUtil.tagToJson(meta.value())); data.setTypeAndValue(Types1_20_2.ENTITY_DATA_TYPES.componentType, ComponentUtil.tagToJson(data.value()));
return; return;
} else if (type == Types1_20_3.ENTITY_DATA_TYPES.optionalComponentType) { } else if (type == Types1_20_3.ENTITY_DATA_TYPES.optionalComponentType) {
meta.setTypeAndValue(Types1_20_2.ENTITY_DATA_TYPES.optionalComponentType, ComponentUtil.tagToJson(meta.value())); data.setTypeAndValue(Types1_20_2.ENTITY_DATA_TYPES.optionalComponentType, ComponentUtil.tagToJson(data.value()));
return; return;
} else if (type == Types1_20_3.ENTITY_DATA_TYPES.particleType) { } else if (type == Types1_20_3.ENTITY_DATA_TYPES.particleType) {
final Particle particle = (Particle) meta.getValue(); final Particle particle = (Particle) data.getValue();
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings(); final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
if (particle.id() == particleMappings.id("vibration")) { if (particle.id() == particleMappings.id("vibration")) {
// Change the type of the position source type argument // Change the type of the position source type argument
@ -117,16 +117,16 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
} }
} }
} else if (type == Types1_20_3.ENTITY_DATA_TYPES.poseType) { } else if (type == Types1_20_3.ENTITY_DATA_TYPES.poseType) {
final int pose = meta.value(); final int pose = data.value();
if (pose >= 15) { if (pose >= 15) {
event.cancel(); event.cancel();
} }
} }
meta.setDataType(Types1_20_2.ENTITY_DATA_TYPES.byId(type.typeId())); data.setDataType(Types1_20_2.ENTITY_DATA_TYPES.byId(type.typeId()));
}); });
registerMetaTypeHandler( registerEntityDataTypeHandler(
Types1_20_2.ENTITY_DATA_TYPES.itemType, Types1_20_2.ENTITY_DATA_TYPES.itemType,
Types1_20_2.ENTITY_DATA_TYPES.blockStateType, Types1_20_2.ENTITY_DATA_TYPES.blockStateType,
Types1_20_2.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20_2.ENTITY_DATA_TYPES.optionalBlockStateType,

Datei anzeigen

@ -372,9 +372,9 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
color = item.identifier() - 445; color = item.identifier() - 445;
} }
} }
final List<EntityData> metadataList = new ArrayList<>(); final List<EntityData> entityDataList = new ArrayList<>();
metadataList.add(new EntityData(20, Types1_20_3.ENTITY_DATA_TYPES.varIntType, color)); entityDataList.add(new EntityData(20, Types1_20_3.ENTITY_DATA_TYPES.varIntType, color));
setEntityData.write(Types1_20_3.ENTITY_DATA_LIST, metadataList); setEntityData.write(Types1_20_3.ENTITY_DATA_LIST, entityDataList);
setEntityData.send(Protocol1_20_5To1_20_3.class); setEntityData.send(Protocol1_20_5To1_20_3.class);
} }
@ -408,7 +408,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
data.setDataType(Types1_20_3.ENTITY_DATA_TYPES.byId(id)); data.setDataType(Types1_20_3.ENTITY_DATA_TYPES.byId(id));
}); });
registerMetaTypeHandler1_20_3( registerEntityDataTypeHandler1_20_3(
Types1_20_3.ENTITY_DATA_TYPES.itemType, Types1_20_3.ENTITY_DATA_TYPES.itemType,
Types1_20_3.ENTITY_DATA_TYPES.blockStateType, Types1_20_3.ENTITY_DATA_TYPES.blockStateType,
Types1_20_3.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20_3.ENTITY_DATA_TYPES.optionalBlockStateType,
@ -420,10 +420,10 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11); registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11);
filter().type(EntityTypes1_20_5.AREA_EFFECT_CLOUD).addIndex(9); // Color filter().type(EntityTypes1_20_5.AREA_EFFECT_CLOUD).addIndex(9); // Color
filter().type(EntityTypes1_20_5.AREA_EFFECT_CLOUD).index(11).handler((event, meta) -> { filter().type(EntityTypes1_20_5.AREA_EFFECT_CLOUD).index(11).handler((event, data) -> {
final Particle particle = meta.value(); final Particle particle = data.value();
if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) { if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) {
// Move color to its own metadata // Move color to its own entity data
final int color = particle.<Integer>removeArgument(0).getValue(); final int color = particle.<Integer>removeArgument(0).getValue();
event.createExtraData(new EntityData(9, Types1_20_3.ENTITY_DATA_TYPES.varIntType, removeAlpha(color))); event.createExtraData(new EntityData(9, Types1_20_3.ENTITY_DATA_TYPES.varIntType, removeAlpha(color)));
} }

Datei anzeigen

@ -25,7 +25,6 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_4; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_4;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_19_4; import com.viaversion.viaversion.api.type.types.version.Types1_19_4;
import com.viaversion.viaversion.api.type.types.version.Types1_20; import com.viaversion.viaversion.api.type.types.version.Types1_20;
@ -33,7 +32,6 @@ import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPac
import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.ListTag; import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
import java.util.Set; import java.util.Set;
@ -124,13 +122,13 @@ public final class EntityPacketRewriter1_20 extends EntityRewriter<ClientboundPa
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
filter().handler((event, meta) -> meta.setDataType(Types1_19_4.ENTITY_DATA_TYPES.byId(meta.dataType().typeId()))); filter().handler((event, data) -> data.setDataType(Types1_19_4.ENTITY_DATA_TYPES.byId(data.dataType().typeId())));
registerMetaTypeHandler(Types1_19_4.ENTITY_DATA_TYPES.itemType, Types1_19_4.ENTITY_DATA_TYPES.blockStateType, Types1_19_4.ENTITY_DATA_TYPES.optionalBlockStateType, registerEntityDataTypeHandler(Types1_19_4.ENTITY_DATA_TYPES.itemType, Types1_19_4.ENTITY_DATA_TYPES.blockStateType, Types1_19_4.ENTITY_DATA_TYPES.optionalBlockStateType,
Types1_19_4.ENTITY_DATA_TYPES.particleType, Types1_19_4.ENTITY_DATA_TYPES.componentType, Types1_19_4.ENTITY_DATA_TYPES.optionalComponentType); Types1_19_4.ENTITY_DATA_TYPES.particleType, Types1_19_4.ENTITY_DATA_TYPES.componentType, Types1_19_4.ENTITY_DATA_TYPES.optionalComponentType);
registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11); registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11);
// Rotate item display by 180 degrees around the Y axis // Rotate item display by 180 degrees around the Y axis
filter().type(EntityTypes1_19_4.ITEM_DISPLAY).handler((event, meta) -> { filter().type(EntityTypes1_19_4.ITEM_DISPLAY).handler((event, data) -> {
if (event.trackedEntity().hasSentEntityData() || event.hasExtraData()) { if (event.trackedEntity().hasSentEntityData() || event.hasExtraData()) {
return; return;
} }
@ -139,9 +137,9 @@ public final class EntityPacketRewriter1_20 extends EntityRewriter<ClientboundPa
event.createExtraData(new EntityData(12, Types1_19_4.ENTITY_DATA_TYPES.quaternionType, Y_FLIPPED_ROTATION)); event.createExtraData(new EntityData(12, Types1_19_4.ENTITY_DATA_TYPES.quaternionType, Y_FLIPPED_ROTATION));
} }
}); });
filter().type(EntityTypes1_19_4.ITEM_DISPLAY).index(12).handler((event, meta) -> { filter().type(EntityTypes1_19_4.ITEM_DISPLAY).index(12).handler((event, data) -> {
final Quaternion quaternion = meta.value(); final Quaternion quaternion = data.value();
meta.setValue(rotateY180(quaternion)); data.setValue(rotateY180(quaternion));
}); });
} }

Datei anzeigen

@ -196,7 +196,7 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPa
data.setDataType(Types1_20_5.ENTITY_DATA_TYPES.byId(type.typeId())); data.setDataType(Types1_20_5.ENTITY_DATA_TYPES.byId(type.typeId()));
} }
}); });
registerMetaTypeHandler1_20_3( registerEntityDataTypeHandler1_20_3(
Types1_20_5.ENTITY_DATA_TYPES.itemType, Types1_20_5.ENTITY_DATA_TYPES.itemType,
Types1_20_5.ENTITY_DATA_TYPES.blockStateType, Types1_20_5.ENTITY_DATA_TYPES.blockStateType,
Types1_20_5.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20_5.ENTITY_DATA_TYPES.optionalBlockStateType,

Datei anzeigen

@ -42,7 +42,7 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
@Override @Override
public void registerPackets() { public void registerPackets() {
registerTrackerWithData1_19(ClientboundPackets1_20_5.ADD_ENTITY, EntityTypes1_20_5.FALLING_BLOCK); registerTrackerWithData1_19(ClientboundPackets1_20_5.ADD_ENTITY, EntityTypes1_20_5.FALLING_BLOCK);
registerSetEntityData(ClientboundPackets1_20_5.SET_ENTITY_DATA, /*Types1_OLD.METADATA_LIST, */Types1_20_5.ENTITY_DATA_LIST); // Specify old and new metadata list if changed registerSetEntityData(ClientboundPackets1_20_5.SET_ENTITY_DATA, /*Types1_OLD.ENTITY_DATA_LIST, */Types1_20_5.ENTITY_DATA_LIST); // Specify old and new entity data list if changed
registerRemoveEntities(ClientboundPackets1_20_5.REMOVE_ENTITIES); registerRemoveEntities(ClientboundPackets1_20_5.REMOVE_ENTITIES);
// TODO Item and sound id changes in registries, probably others as well // TODO Item and sound id changes in registries, probably others as well
@ -90,7 +90,7 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
data.setDataType(Types1_20_5.ENTITY_DATA_TYPES.byId(id)); data.setDataType(Types1_20_5.ENTITY_DATA_TYPES.byId(id));
});*/ });*/
registerMetaTypeHandler1_20_3( registerEntityDataTypeHandler1_20_3(
Types1_20_5.ENTITY_DATA_TYPES.itemType, Types1_20_5.ENTITY_DATA_TYPES.itemType,
Types1_20_5.ENTITY_DATA_TYPES.blockStateType, Types1_20_5.ENTITY_DATA_TYPES.blockStateType,
Types1_20_5.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20_5.ENTITY_DATA_TYPES.optionalBlockStateType,
@ -101,7 +101,7 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
); );
registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11); registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11);
// Remove metadata of new entity type // Remove entity data of new entity type
// filter().type(EntityTypes1_20_5.SNIFFER).removeIndex(newIndex); // filter().type(EntityTypes1_20_5.SNIFFER).removeIndex(newIndex);
} }