Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 16:12:42 +01:00
Update old metadata handlers, some cleanup
Dieser Commit ist enthalten in:
Ursprung
930454a723
Commit
5991ac5633
@ -57,8 +57,7 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
entityRewriter.register();
|
||||
itemRewriter.register();
|
||||
super.registerPackets();
|
||||
|
||||
registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketHandlers() {
|
||||
@Override
|
||||
|
@ -18,11 +18,9 @@
|
||||
package com.viaversion.viaversion.protocols.protocol1_11to1_10.metadata;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
@ -43,107 +41,95 @@ public class MetadataRewriter1_11To1_10 extends EntityRewriter<ClientboundPacket
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, com.viaversion.viaversion.api.minecraft.entities.EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
||||
if (metadata.getValue() instanceof DataItem) {
|
||||
// Apply rewrite
|
||||
EntityIdRewriter.toClientItem((Item) metadata.getValue());
|
||||
}
|
||||
protected void registerRewrites() {
|
||||
filter().handler((event, meta) -> {
|
||||
if (meta.getValue() instanceof DataItem) {
|
||||
// Apply rewrite
|
||||
EntityIdRewriter.toClientItem(meta.value());
|
||||
}
|
||||
});
|
||||
|
||||
if (type == null) return;
|
||||
if (type.is(EntityType.ELDER_GUARDIAN) || type.is(EntityType.GUARDIAN)) { // Guardians
|
||||
int oldid = metadata.id();
|
||||
if (oldid == 12) {
|
||||
boolean val = (((byte) metadata.getValue()) & 0x02) == 0x02;
|
||||
metadata.setTypeAndValue(MetaType1_9.Boolean, val);
|
||||
}
|
||||
}
|
||||
filter().type(EntityType.GUARDIAN).index(12).handler((event, meta) -> {
|
||||
boolean value = (((byte) meta.getValue()) & 0x02) == 0x02;
|
||||
meta.setTypeAndValue(MetaType1_9.Boolean, value);
|
||||
});
|
||||
|
||||
if (type.isOrHasParent(EntityType.ABSTRACT_SKELETON)) { // Skeletons
|
||||
int oldid = metadata.id();
|
||||
if (oldid == 12) {
|
||||
metadatas.remove(metadata);
|
||||
}
|
||||
if (oldid == 13) {
|
||||
metadata.setId(12);
|
||||
}
|
||||
}
|
||||
filter().type(EntityType.ABSTRACT_SKELETON).removeIndex(12);
|
||||
|
||||
if (type.isOrHasParent(EntityType.ZOMBIE)) { // Zombie | Zombie Villager | Husk
|
||||
if ((type == EntityType.ZOMBIE || type == EntityType.HUSK) && metadata.id() == 14) {
|
||||
metadatas.remove(metadata);
|
||||
} else {
|
||||
if (metadata.id() == 15) {
|
||||
metadata.setId(14);
|
||||
} else {
|
||||
if (metadata.id() == 14) {
|
||||
metadata.setId(15);
|
||||
}
|
||||
}
|
||||
filter().type(EntityType.ZOMBIE).handler((event, meta) -> {
|
||||
if ((event.entityType() == EntityType.ZOMBIE || event.entityType() == EntityType.HUSK) && meta.id() == 14) {
|
||||
event.cancel();
|
||||
} else if (meta.id() == 15) {
|
||||
meta.setId(14);
|
||||
} else if (meta.id() == 14) {
|
||||
meta.setId(15);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (type.isOrHasParent(EntityType.ABSTRACT_HORSE)) { // Horses
|
||||
// Remap metadata id
|
||||
int oldid = metadata.id();
|
||||
if (oldid == 14) { // Type
|
||||
metadatas.remove(metadata);
|
||||
filter().type(EntityType.ABSTRACT_HORSE).handler((event, metadata) -> {
|
||||
final com.viaversion.viaversion.api.minecraft.entities.EntityType type = event.entityType();
|
||||
int id = metadata.id();
|
||||
if (id == 14) { // Type
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
if (oldid == 16) { // Owner
|
||||
|
||||
if (id == 16) { // Owner
|
||||
metadata.setId(14);
|
||||
}
|
||||
if (oldid == 17) { // Armor
|
||||
} else if (id == 17) { // Armor
|
||||
metadata.setId(16);
|
||||
}
|
||||
|
||||
// Process per type
|
||||
if (type.is(EntityType.HORSE)) {
|
||||
// Normal Horse
|
||||
} else {
|
||||
// Remove 15, 16
|
||||
if (metadata.id() == 15 || metadata.id() == 16) {
|
||||
metadatas.remove(metadata);
|
||||
if (!type.is(EntityType.HORSE) && metadata.id() == 15 || metadata.id() == 16) {
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((type == EntityType.DONKEY || type == EntityType.MULE) && metadata.id() == 13) {
|
||||
if ((((byte) metadata.getValue()) & 0x08) == 0x08) {
|
||||
event.createExtraMeta(new Metadata(15, MetaType1_9.Boolean, true));
|
||||
} else {
|
||||
event.createExtraMeta(new Metadata(15, MetaType1_9.Boolean, false));
|
||||
}
|
||||
}
|
||||
if (type == EntityType.DONKEY || type == EntityType.MULE) {
|
||||
// Chested Horse
|
||||
if (metadata.id() == 13) {
|
||||
if ((((byte) metadata.getValue()) & 0x08) == 0x08) {
|
||||
metadatas.add(new Metadata(15, MetaType1_9.Boolean, true));
|
||||
} else {
|
||||
metadatas.add(new Metadata(15, MetaType1_9.Boolean, false));
|
||||
});
|
||||
|
||||
filter().type(EntityType.ARMOR_STAND).index(0).handler((event, meta) -> {
|
||||
if (!Via.getConfig().isHologramPatch()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Metadata flags = event.metaAtIndex(11);
|
||||
Metadata customName = event.metaAtIndex(2);
|
||||
Metadata customNameVisible = event.metaAtIndex(3);
|
||||
if (flags == null || customName == null || customNameVisible == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
byte data = meta.value();
|
||||
// Check invisible | Check small | Check if custom name is empty | Check if custom name visible is true
|
||||
if ((data & 0x20) == 0x20 && ((byte) flags.getValue() & 0x01) == 0x01
|
||||
&& !((String) customName.getValue()).isEmpty() && (boolean) customNameVisible.getValue()) {
|
||||
EntityTracker1_11 tracker = tracker(event.user());
|
||||
int entityId = event.entityId();
|
||||
if (tracker.addHologram(entityId)) {
|
||||
try {
|
||||
// Send movement
|
||||
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9_3.ENTITY_POSITION, null, event.user());
|
||||
wrapper.write(Type.VAR_INT, entityId);
|
||||
wrapper.write(Type.SHORT, (short) 0);
|
||||
wrapper.write(Type.SHORT, (short) (128D * (-Via.getConfig().getHologramYOffset() * 32D)));
|
||||
wrapper.write(Type.SHORT, (short) 0);
|
||||
wrapper.write(Type.BOOLEAN, true);
|
||||
|
||||
wrapper.send(Protocol1_11To1_10.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type.is(EntityType.ARMOR_STAND) && Via.getConfig().isHologramPatch()) {
|
||||
Metadata flags = metaByIndex(11, metadatas);
|
||||
Metadata customName = metaByIndex(2, metadatas);
|
||||
Metadata customNameVisible = metaByIndex(3, metadatas);
|
||||
if (metadata.id() == 0 && flags != null && customName != null && customNameVisible != null) {
|
||||
byte data = (byte) metadata.getValue();
|
||||
// Check invisible | Check small | Check if custom name is empty | Check if custom name visible is true
|
||||
if ((data & 0x20) == 0x20 && ((byte) flags.getValue() & 0x01) == 0x01
|
||||
&& !((String) customName.getValue()).isEmpty() && (boolean) customNameVisible.getValue()) {
|
||||
EntityTracker1_11 tracker = tracker(connection);
|
||||
if (tracker.addHologram(entityId)) {
|
||||
try {
|
||||
// Send movement
|
||||
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9_3.ENTITY_POSITION, null, connection);
|
||||
wrapper.write(Type.VAR_INT, entityId);
|
||||
wrapper.write(Type.SHORT, (short) 0);
|
||||
wrapper.write(Type.SHORT, (short) (128D * (-Via.getConfig().getHologramYOffset() * 32D)));
|
||||
wrapper.write(Type.SHORT, (short) 0);
|
||||
wrapper.write(Type.BOOLEAN, true);
|
||||
|
||||
wrapper.send(Protocol1_11To1_10.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,8 +58,7 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
metadataRewriter.register();
|
||||
itemRewriter.register();
|
||||
super.registerPackets();
|
||||
|
||||
registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketHandlers() {
|
||||
@Override
|
||||
|
@ -17,15 +17,12 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_12to1_11_1.metadata;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter1_12To1_11_1 extends EntityRewriter<ClientboundPackets1_9_3, Protocol1_12To1_11_1> {
|
||||
|
||||
@ -34,19 +31,14 @@ public class MetadataRewriter1_12To1_11_1 extends EntityRewriter<ClientboundPack
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
||||
if (metadata.getValue() instanceof Item) {
|
||||
// Apply rewrite
|
||||
metadata.setValue(protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue()));
|
||||
}
|
||||
|
||||
if (type == null) return;
|
||||
// Evocation Illager aggressive property became 13
|
||||
if (type == EntityTypes1_12.EntityType.EVOCATION_ILLAGER) {
|
||||
if (metadata.id() == 12) {
|
||||
metadata.setId(13);
|
||||
protected void registerRewrites() {
|
||||
filter().handler((event, meta) -> {
|
||||
if (meta.getValue() instanceof Item) {
|
||||
meta.setValue(protocol.getItemRewriter().handleItemToClient(meta.value()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
filter().type(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).index(12).toIndex(13); // Aggressive
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,8 +51,7 @@ public class Protocol1_13_1To1_13 extends AbstractProtocol<ClientboundPackets1_1
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
entityRewriter.register();
|
||||
itemRewriter.register();
|
||||
super.registerPackets();
|
||||
|
||||
EntityPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
|
@ -17,17 +17,12 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_13_1to1_13.metadata;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter1_13_1To1_13 extends EntityRewriter<ClientboundPackets1_13, Protocol1_13_1To1_13> {
|
||||
|
||||
@ -36,27 +31,13 @@ public class MetadataRewriter1_13_1To1_13 extends EntityRewriter<ClientboundPack
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
||||
// 1.13 changed item to flat item (no data)
|
||||
if (metadata.metaType() == Types1_13.META_TYPES.itemType) {
|
||||
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
|
||||
} else if (metadata.metaType() == Types1_13.META_TYPES.blockStateType) {
|
||||
// Convert to new block id
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
} else if (metadata.metaType() == Types1_13.META_TYPES.particleType) {
|
||||
rewriteParticle((Particle) metadata.getValue());
|
||||
}
|
||||
|
||||
if (type == null) return;
|
||||
|
||||
if (type.isOrHasParent(EntityTypes1_13.EntityType.MINECART_ABSTRACT) && metadata.id() == 9) {
|
||||
// New block format
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
} else if (type.isOrHasParent(EntityTypes1_13.EntityType.ABSTRACT_ARROW) && metadata.id() >= 7) {
|
||||
metadata.setId(metadata.id() + 1); // New shooter UUID
|
||||
}
|
||||
protected void registerRewrites() {
|
||||
registerMetaTypeHandler(Types1_13.META_TYPES.itemType, Types1_13.META_TYPES.blockStateType, null, Types1_13.META_TYPES.particleType);
|
||||
filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> {
|
||||
int data = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
});
|
||||
filter().type(EntityTypes1_13.EntityType.ABSTRACT_ARROW).addIndex(7); // Shooter UUID
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -162,8 +162,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
entityRewriter.register();
|
||||
itemRewriter.register();
|
||||
super.registerPackets();
|
||||
|
||||
EntityPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
|
@ -17,11 +17,9 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.metadata;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
|
||||
@ -31,7 +29,6 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.ParticleRew
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter1_13To1_12_2 extends EntityRewriter<ClientboundPackets1_12_1, Protocol1_13To1_12_2> {
|
||||
|
||||
@ -40,87 +37,61 @@ public class MetadataRewriter1_13To1_12_2 extends EntityRewriter<ClientboundPack
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
// Handle new MetaTypes
|
||||
if (metadata.metaType().typeId() > 4) {
|
||||
metadata.setMetaType(Types1_13.META_TYPES.byId(metadata.metaType().typeId() + 1));
|
||||
} else {
|
||||
metadata.setMetaType(Types1_13.META_TYPES.byId(metadata.metaType().typeId()));
|
||||
}
|
||||
protected void registerRewrites() {
|
||||
filter().mapMetaType(typeId -> Types1_13.META_TYPES.byId(typeId > 4 ? typeId + 1 : typeId));
|
||||
filter().metaType(Types1_13.META_TYPES.itemType).handler(((event, meta) -> protocol.getItemRewriter().handleItemToClient(meta.value())));
|
||||
filter().metaType(Types1_13.META_TYPES.blockStateType).handler(((event, meta) -> meta.setValue(WorldPackets.toNewId(meta.value()))));
|
||||
|
||||
// Handle String -> Chat DisplayName
|
||||
if (metadata.id() == 2) {
|
||||
if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) {
|
||||
metadata.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, ComponentUtil.legacyToJson((String) metadata.getValue()));
|
||||
// Previously unused, now swimming
|
||||
filter().index(0).handler((event, meta) -> meta.setValue((byte) ((byte) meta.getValue() & ~0x10)));
|
||||
|
||||
filter().index(2).handler(((event, meta) -> {
|
||||
if (meta.getValue() != null && !((String) meta.getValue()).isEmpty()) {
|
||||
meta.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, ComponentUtil.legacyToJson((String) meta.getValue()));
|
||||
} else {
|
||||
metadata.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, null);
|
||||
meta.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, null);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
// Remap held block to match new format for remapping to flat block
|
||||
if (type == EntityTypes1_13.EntityType.ENDERMAN && metadata.id() == 12) {
|
||||
int stateId = (int) metadata.getValue();
|
||||
filter().type(EntityTypes1_13.EntityType.ENDERMAN).index(12).handler((event, meta) -> {
|
||||
// Remap held block to match new format for remapping to flat block
|
||||
int stateId = meta.value();
|
||||
int id = stateId & 4095;
|
||||
int data = stateId >> 12 & 15;
|
||||
metadata.setValue((id << 4) | (data & 0xF));
|
||||
}
|
||||
meta.setValue((id << 4) | (data & 0xF));
|
||||
});
|
||||
|
||||
// 1.13 changed item to flat item (no data)
|
||||
if (metadata.metaType() == Types1_13.META_TYPES.itemType) {
|
||||
metadata.setMetaType(Types1_13.META_TYPES.itemType);
|
||||
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
|
||||
} else if (metadata.metaType() == Types1_13.META_TYPES.blockStateType) {
|
||||
// Convert to new block id
|
||||
metadata.setValue(WorldPackets.toNewId((int) metadata.getValue()));
|
||||
}
|
||||
filter().type(EntityTypes1_13.EntityType.WOLF).index(17).handler((event, meta) -> {
|
||||
// Handle new colors
|
||||
meta.setValue(15 - (int) meta.getValue());
|
||||
});
|
||||
|
||||
// Skip type related changes when the type is null
|
||||
if (type == null) return;
|
||||
filter().type(EntityTypes1_13.EntityType.ZOMBIE).addIndex(15); // Shaking
|
||||
|
||||
// Handle new colors
|
||||
if (type == EntityTypes1_13.EntityType.WOLF && metadata.id() == 17) {
|
||||
metadata.setValue(15 - (int) metadata.getValue());
|
||||
}
|
||||
|
||||
// Handle new zombie meta (INDEX 15 - Boolean - Zombie is shaking while enabled)
|
||||
if (type.isOrHasParent(EntityTypes1_13.EntityType.ZOMBIE)) {
|
||||
if (metadata.id() > 14)
|
||||
metadata.setId(metadata.id() + 1);
|
||||
}
|
||||
|
||||
// Handle Minecart inner block
|
||||
if (type.isOrHasParent(EntityTypes1_13.EntityType.MINECART_ABSTRACT) && metadata.id() == 9) {
|
||||
// New block format
|
||||
int oldId = (int) metadata.getValue();
|
||||
filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> {
|
||||
int oldId = meta.value();
|
||||
int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
|
||||
int newId = WorldPackets.toNewId(combined);
|
||||
metadata.setValue(newId);
|
||||
}
|
||||
meta.setValue(newId);
|
||||
});
|
||||
|
||||
// Handle other changes
|
||||
if (type == EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD) {
|
||||
if (metadata.id() == 9) {
|
||||
int particleId = (int) metadata.getValue();
|
||||
Metadata parameter1Meta = metaByIndex(10, metadatas);
|
||||
Metadata parameter2Meta = metaByIndex(11, metadatas);
|
||||
int parameter1 = parameter1Meta != null ? (int) parameter1Meta.getValue() : 0;
|
||||
int parameter2 = parameter2Meta != null ? (int) parameter2Meta.getValue() : 0;
|
||||
filter().type(EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD).handler((event, meta) -> {
|
||||
if (meta.id() == 9) {
|
||||
int particleId = meta.value();
|
||||
Metadata parameter1Meta = event.metaAtIndex(10);
|
||||
Metadata parameter2Meta = event.metaAtIndex(11);
|
||||
int parameter1 = parameter1Meta != null ? parameter1Meta.value() : 0;
|
||||
int parameter2 = parameter2Meta != null ? parameter2Meta.value() : 0;
|
||||
|
||||
Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2});
|
||||
if (particle != null && particle.getId() != -1) {
|
||||
metadatas.add(new Metadata(9, Types1_13.META_TYPES.particleType, particle));
|
||||
event.createExtraMeta(new Metadata(9, Types1_13.META_TYPES.particleType, particle));
|
||||
}
|
||||
}
|
||||
|
||||
if (metadata.id() >= 9)
|
||||
metadatas.remove(metadata); // Remove
|
||||
}
|
||||
|
||||
if (metadata.id() == 0) {
|
||||
metadata.setValue((byte) ((byte) metadata.getValue() & ~0x10)); // Previously unused, now swimming
|
||||
}
|
||||
|
||||
// TODO: Boat has changed
|
||||
if (meta.id() >= 9) {
|
||||
event.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,7 +36,7 @@ public class Protocol1_14_1To1_14 extends AbstractProtocol<ClientboundPackets1_1
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
metadataRewriter.register();
|
||||
super.registerPackets();
|
||||
|
||||
EntityPackets.register(this);
|
||||
}
|
||||
|
@ -17,14 +17,11 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_14_1to1_14.metadata;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14_1to1_14.Protocol1_14_1To1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter1_14_1To1_14 extends EntityRewriter<ClientboundPackets1_14, Protocol1_14_1To1_14> {
|
||||
|
||||
@ -33,14 +30,9 @@ public class MetadataRewriter1_14_1To1_14 extends EntityRewriter<ClientboundPack
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
||||
if (type == null) return;
|
||||
|
||||
if (type == EntityTypes1_14.VILLAGER || type == EntityTypes1_14.WANDERING_TRADER) {
|
||||
if (metadata.id() >= 15) {
|
||||
metadata.setId(metadata.id() + 1);
|
||||
}
|
||||
}
|
||||
protected void registerRewrites() {
|
||||
filter().type(EntityTypes1_14.VILLAGER).addIndex(15);
|
||||
filter().type(EntityTypes1_14.WANDERING_TRADER).addIndex(15);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,8 +52,7 @@ public class Protocol1_14To1_13_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
metadataRewriter.register();
|
||||
itemRewriter.register();
|
||||
super.registerPackets();
|
||||
|
||||
EntityPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
|
@ -18,24 +18,21 @@
|
||||
package com.viaversion.viaversion.protocols.protocol1_14to1_13_2.metadata;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.VillagerData;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter1_14To1_13_2 extends EntityRewriter<ClientboundPackets1_13, Protocol1_14To1_13_2> {
|
||||
|
||||
@ -46,141 +43,133 @@ public class MetadataRewriter1_14To1_13_2 extends EntityRewriter<ClientboundPack
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
metadata.setMetaType(Types1_14.META_TYPES.byId(metadata.metaType().typeId()));
|
||||
protected void registerRewrites() {
|
||||
filter().mapMetaType(Types1_14.META_TYPES::byId);
|
||||
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.blockStateType, null, Types1_14.META_TYPES.particleType);
|
||||
|
||||
EntityTracker1_14 tracker = tracker(connection);
|
||||
filter().type(EntityTypes1_14.ENTITY).addIndex(6);
|
||||
filter().type(EntityTypes1_14.LIVINGENTITY).addIndex(12);
|
||||
|
||||
if (metadata.metaType() == Types1_14.META_TYPES.itemType) {
|
||||
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
|
||||
} else if (metadata.metaType() == Types1_14.META_TYPES.blockStateType) {
|
||||
// Convert to new block id
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
} else if (metadata.metaType() == Types1_14.META_TYPES.particleType) {
|
||||
rewriteParticle((Particle) metadata.getValue());
|
||||
}
|
||||
|
||||
if (type == null) return;
|
||||
|
||||
//Metadata 6 added to abstract_entity
|
||||
if (metadata.id() > 5) {
|
||||
metadata.setId(metadata.id() + 1);
|
||||
}
|
||||
if (metadata.id() == 8 && type.isOrHasParent(EntityTypes1_14.LIVINGENTITY)) {
|
||||
final float v = ((Number) metadata.getValue()).floatValue();
|
||||
if (Float.isNaN(v) && Via.getConfig().is1_14HealthNaNFix()) {
|
||||
metadata.setValue(1F);
|
||||
filter().type(EntityTypes1_14.LIVINGENTITY).index(8).handler((event, meta) -> {
|
||||
float value = ((Number) meta.getValue()).floatValue();
|
||||
if (Float.isNaN(value) && Via.getConfig().is1_14HealthNaNFix()) {
|
||||
meta.setValue(1F);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//Metadata 12 added to living_entity
|
||||
if (metadata.id() > 11 && type.isOrHasParent(EntityTypes1_14.LIVINGENTITY)) {
|
||||
metadata.setId(metadata.id() + 1);
|
||||
}
|
||||
filter().type(EntityTypes1_14.ABSTRACT_INSENTIENT).index(13).handler((event, meta) -> {
|
||||
EntityTracker1_14 tracker = tracker(event.user());
|
||||
int entityId = event.entityId();
|
||||
tracker.setInsentientData(entityId, (byte) ((((Number) meta.getValue()).byteValue() & ~0x4)
|
||||
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
|
||||
meta.setValue(tracker.getInsentientData(entityId));
|
||||
});
|
||||
|
||||
if (type.isOrHasParent(EntityTypes1_14.ABSTRACT_INSENTIENT)) {
|
||||
if (metadata.id() == 13) {
|
||||
tracker.setInsentientData(entityId, (byte) ((((Number) metadata.getValue()).byteValue() & ~0x4)
|
||||
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
|
||||
metadata.setValue(tracker.getInsentientData(entityId));
|
||||
}
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(EntityTypes1_14.PLAYER)) {
|
||||
filter().type(EntityTypes1_14.PLAYER).handler((event, meta) -> {
|
||||
EntityTracker1_14 tracker = tracker(event.user());
|
||||
int entityId = event.entityId();
|
||||
if (entityId != tracker.clientEntityId()) {
|
||||
if (metadata.id() == 0) {
|
||||
byte flags = ((Number) metadata.getValue()).byteValue();
|
||||
if (meta.id() == 0) {
|
||||
byte flags = ((Number) meta.getValue()).byteValue();
|
||||
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
|
||||
tracker.setEntityFlags(entityId, flags);
|
||||
} else if (metadata.id() == 7) {
|
||||
tracker.setRiptide(entityId, (((Number) metadata.getValue()).byteValue() & 0x4) != 0);
|
||||
} else if (meta.id() == 7) {
|
||||
tracker.setRiptide(entityId, (((Number) meta.getValue()).byteValue() & 0x4) != 0);
|
||||
}
|
||||
if (metadata.id() == 0 || metadata.id() == 7) {
|
||||
metadatas.add(new Metadata(6, Types1_14.META_TYPES.poseType, recalculatePlayerPose(entityId, tracker)));
|
||||
if (meta.id() == 0 || meta.id() == 7) {
|
||||
event.createExtraMeta(new Metadata(6, Types1_14.META_TYPES.poseType, recalculatePlayerPose(entityId, tracker)));
|
||||
}
|
||||
}
|
||||
} else if (type.isOrHasParent(EntityTypes1_14.ZOMBIE)) {
|
||||
if (metadata.id() == 16) {
|
||||
});
|
||||
|
||||
filter().type(EntityTypes1_14.ZOMBIE).handler((event, meta) -> {
|
||||
if (meta.id() == 16) {
|
||||
EntityTracker1_14 tracker = tracker(event.user());
|
||||
int entityId = event.entityId();
|
||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
||||
metadatas.remove(metadata); // "Are hands held up"
|
||||
metadatas.add(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
|
||||
} else if (metadata.id() > 16) {
|
||||
metadata.setId(metadata.id() - 1);
|
||||
| ((boolean) meta.getValue() ? 0x4 : 0))); // New attacking
|
||||
event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
|
||||
event.cancel(); // "Are hands held up"
|
||||
} else if (meta.id() > 16) {
|
||||
meta.setId(meta.id() - 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (type.isOrHasParent(EntityTypes1_14.MINECART_ABSTRACT)) {
|
||||
if (metadata.id() == 10) {
|
||||
// New block format
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
filter().type(EntityTypes1_14.MINECART_ABSTRACT).index(10).handler((event, meta) -> {
|
||||
int data = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
});
|
||||
|
||||
filter().type(EntityTypes1_14.HORSE).index(18).handler((event, meta) -> {
|
||||
event.cancel();
|
||||
|
||||
int armorType = meta.value();
|
||||
Item armorItem = null;
|
||||
if (armorType == 1) { //iron armor
|
||||
armorItem = new DataItem(protocol.getMappingData().getNewItemId(727), (byte) 1, (short) 0, null);
|
||||
} else if (armorType == 2) { //gold armor
|
||||
armorItem = new DataItem(protocol.getMappingData().getNewItemId(728), (byte) 1, (short) 0, null);
|
||||
} else if (armorType == 3) { //diamond armor
|
||||
armorItem = new DataItem(protocol.getMappingData().getNewItemId(729), (byte) 1, (short) 0, null);
|
||||
}
|
||||
} else if (type.is(EntityTypes1_14.HORSE)) {
|
||||
if (metadata.id() == 18) {
|
||||
metadatas.remove(metadata);
|
||||
|
||||
int armorType = (int) metadata.getValue();
|
||||
Item armorItem = null;
|
||||
if (armorType == 1) { //iron armor
|
||||
armorItem = new DataItem(protocol.getMappingData().getNewItemId(727), (byte) 1, (short) 0, null);
|
||||
} else if (armorType == 2) { //gold armor
|
||||
armorItem = new DataItem(protocol.getMappingData().getNewItemId(728), (byte) 1, (short) 0, null);
|
||||
} else if (armorType == 3) { //diamond armor
|
||||
armorItem = new DataItem(protocol.getMappingData().getNewItemId(729), (byte) 1, (short) 0, null);
|
||||
}
|
||||
|
||||
PacketWrapper equipmentPacket = PacketWrapper.create(ClientboundPackets1_14.ENTITY_EQUIPMENT, null, connection);
|
||||
equipmentPacket.write(Type.VAR_INT, entityId);
|
||||
equipmentPacket.write(Type.VAR_INT, 4);
|
||||
equipmentPacket.write(Type.ITEM1_13_2, armorItem);
|
||||
PacketWrapper equipmentPacket = PacketWrapper.create(ClientboundPackets1_14.ENTITY_EQUIPMENT, null, event.user());
|
||||
equipmentPacket.write(Type.VAR_INT, event.entityId());
|
||||
equipmentPacket.write(Type.VAR_INT, 4);
|
||||
equipmentPacket.write(Type.ITEM1_13_2, armorItem);
|
||||
try {
|
||||
equipmentPacket.scheduleSend(Protocol1_14To1_13_2.class);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else if (type.is(EntityTypes1_14.VILLAGER)) {
|
||||
if (metadata.id() == 15) {
|
||||
// plains
|
||||
metadata.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
||||
});
|
||||
|
||||
filter().type(EntityTypes1_14.VILLAGER).index(15).handler((event, meta) -> {
|
||||
meta.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId(meta.value()), 0));
|
||||
});
|
||||
|
||||
filter().type(EntityTypes1_14.ZOMBIE_VILLAGER).index(18).handler((event, meta) -> {
|
||||
meta.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId(meta.value()), 0));
|
||||
});
|
||||
|
||||
filter().type(EntityTypes1_14.ABSTRACT_ARROW).addIndex(9); // Piercing level added
|
||||
|
||||
filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, meta) -> {
|
||||
});
|
||||
|
||||
filter().type(EntityTypes1_14.HORSE).index(18).handler((event, meta) -> {
|
||||
meta.setMetaType(Types1_14.META_TYPES.optionalVarIntType);
|
||||
if (meta.getValue().equals(0)) {
|
||||
meta.setValue(null); // https://bugs.mojang.com/browse/MC-111480
|
||||
}
|
||||
} else if (type.is(EntityTypes1_14.ZOMBIE_VILLAGER)) {
|
||||
if (metadata.id() == 18) {
|
||||
// plains
|
||||
metadata.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
||||
}
|
||||
} else if (type.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) {
|
||||
if (metadata.id() >= 9) { // New piercing
|
||||
metadata.setId(metadata.id() + 1);
|
||||
}
|
||||
} else if (type.is(EntityTypes1_14.FIREWORK_ROCKET)) {
|
||||
if (metadata.id() == 8) {
|
||||
metadata.setMetaType(Types1_14.META_TYPES.optionalVarIntType);
|
||||
if (metadata.getValue().equals(0)) {
|
||||
metadata.setValue(null); // https://bugs.mojang.com/browse/MC-111480
|
||||
});
|
||||
|
||||
filter().type(EntityTypes1_14.ABSTRACT_SKELETON).index(14).handler((event, meta) -> {
|
||||
EntityTracker1_14 tracker = tracker(event.user());
|
||||
int entityId = event.entityId();
|
||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||
| ((boolean) meta.getValue() ? 0x4 : 0))); // New attacking
|
||||
event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
|
||||
event.cancel(); // "Is swinging arms"
|
||||
});
|
||||
|
||||
filter().type(EntityTypes1_14.ABSTRACT_ILLAGER_BASE).index(14).handler((event, meta) -> {
|
||||
EntityTracker1_14 tracker = tracker(event.user());
|
||||
int entityId = event.entityId();
|
||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||
| (((Number) meta.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking
|
||||
event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
|
||||
event.cancel(); // "Has target (aggressive state)"
|
||||
});
|
||||
|
||||
filter().handler((event, meta) -> {
|
||||
EntityType type = event.entityType();
|
||||
if (type.is(EntityTypes1_14.WITCH) || type.is(EntityTypes1_14.RAVAGER) || type.isOrHasParent(EntityTypes1_14.ABSTRACT_ILLAGER_BASE)) {
|
||||
if (meta.id() >= 14) { // 19w13 added a new boolean (raid participant - is celebrating) with id 14
|
||||
meta.setId(meta.id() + 1);
|
||||
}
|
||||
}
|
||||
} else if (type.isOrHasParent(EntityTypes1_14.ABSTRACT_SKELETON)) {
|
||||
if (metadata.id() == 14) {
|
||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
||||
metadatas.remove(metadata); // "Is swinging arms"
|
||||
metadatas.add(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
|
||||
}
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(EntityTypes1_14.ABSTRACT_ILLAGER_BASE)) {
|
||||
if (metadata.id() == 14) {
|
||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||
| (((Number) metadata.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking
|
||||
metadatas.remove(metadata); // "Has target (aggressive state)"
|
||||
metadatas.add(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
|
||||
}
|
||||
}
|
||||
|
||||
if (type.is(EntityTypes1_14.WITCH) || type.is(EntityTypes1_14.RAVAGER) || type.isOrHasParent(EntityTypes1_14.ABSTRACT_ILLAGER_BASE)) {
|
||||
if (metadata.id() >= 14) { // 19w13 added a new boolean (raid participant - is celebrating) with id 14
|
||||
metadata.setId(metadata.id() + 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,10 +17,11 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
@ -32,7 +33,6 @@ import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPacke
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@ -41,6 +41,18 @@ public class EntityPackets {
|
||||
public static void register(Protocol1_14To1_13_2 protocol) {
|
||||
MetadataRewriter1_14To1_13_2 metadataRewriter = protocol.get(MetadataRewriter1_14To1_13_2.class);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_EXPERIENCE_ORB, wrapper -> {
|
||||
int entityId = wrapper.passthrough(Type.VAR_INT);
|
||||
metadataRewriter.tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.EXPERIENCE_ORB);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_GLOBAL_ENTITY, wrapper -> {
|
||||
int entityId = wrapper.passthrough(Type.VAR_INT);
|
||||
if (wrapper.passthrough(Type.BYTE) == 1) {
|
||||
metadataRewriter.tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.LIGHTNING_BOLT);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_ENTITY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
@ -144,6 +156,7 @@ public class EntityPackets {
|
||||
map(Type.VAR_INT);
|
||||
map(Type.POSITION1_8, Type.POSITION1_14);
|
||||
map(Type.BYTE);
|
||||
handler(wrapper -> metadataRewriter.tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), EntityTypes1_14.PAINTING));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -48,8 +48,7 @@ public class Protocol1_15To1_14_4 extends AbstractProtocol<ClientboundPackets1_1
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
metadataRewriter.register();
|
||||
itemRewriter.register();
|
||||
super.registerPackets();
|
||||
|
||||
EntityPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
|
@ -17,18 +17,13 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14_4to1_14_3.ClientboundPackets1_14_4;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.EntityPackets;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter1_15To1_14_4 extends EntityRewriter<ClientboundPackets1_14_4, Protocol1_15To1_14_4> {
|
||||
|
||||
@ -37,42 +32,15 @@ public class MetadataRewriter1_15To1_14_4 extends EntityRewriter<ClientboundPack
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
if (metadata.metaType() == Types1_14.META_TYPES.itemType) {
|
||||
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
|
||||
} else if (metadata.metaType() == Types1_14.META_TYPES.blockStateType) {
|
||||
// Convert to new block id
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
} else if (metadata.metaType() == Types1_14.META_TYPES.particleType) {
|
||||
rewriteParticle((Particle) metadata.getValue());
|
||||
}
|
||||
protected void registerRewrites() {
|
||||
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.blockStateType, null, Types1_14.META_TYPES.particleType);
|
||||
filter().type(EntityTypes1_15.MINECART_ABSTRACT).index(10).handler((metadatas, meta) -> {
|
||||
int data = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
});
|
||||
|
||||
if (type == null) return;
|
||||
|
||||
if (type.isOrHasParent(EntityTypes1_15.MINECART_ABSTRACT)
|
||||
&& metadata.id() == 10) {
|
||||
// Convert to new block id
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
}
|
||||
|
||||
// Metadata 12 added to abstract_living
|
||||
if (metadata.id() > 11 && type.isOrHasParent(EntityTypes1_15.LIVINGENTITY)) {
|
||||
metadata.setId(metadata.id() + 1);
|
||||
}
|
||||
|
||||
//NOTES:
|
||||
//new boolean with id 11 for trident, default = false, added in 19w45a
|
||||
//new boolean with id 17 for enderman
|
||||
|
||||
if (type.isOrHasParent(EntityTypes1_15.WOLF)) {
|
||||
if (metadata.id() == 18) {
|
||||
metadatas.remove(metadata);
|
||||
} else if (metadata.id() > 18) {
|
||||
metadata.setId(metadata.id() - 1);
|
||||
}
|
||||
}
|
||||
filter().type(EntityTypes1_15.LIVINGENTITY).addIndex(12);
|
||||
filter().type(EntityTypes1_15.WOLF).removeIndex(18);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,8 +47,7 @@ public class Protocol1_16_2To1_16_1 extends AbstractProtocol<ClientboundPackets1
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
metadataRewriter.register();
|
||||
itemRewriter.register();
|
||||
super.registerPackets();
|
||||
|
||||
EntityPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
|
@ -17,18 +17,13 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.metadata;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16_2;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_16;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter1_16_2To1_16_1 extends EntityRewriter<ClientboundPackets1_16, Protocol1_16_2To1_16_1> {
|
||||
|
||||
@ -38,32 +33,19 @@ public class MetadataRewriter1_16_2To1_16_1 extends EntityRewriter<ClientboundPa
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
if (metadata.metaType() == Types1_16.META_TYPES.itemType) {
|
||||
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
|
||||
} else if (metadata.metaType() == Types1_16.META_TYPES.blockStateType) {
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
} else if (metadata.metaType() == Types1_16.META_TYPES.particleType) {
|
||||
rewriteParticle((Particle) metadata.getValue());
|
||||
}
|
||||
|
||||
if (type == null) return;
|
||||
|
||||
if (type.isOrHasParent(EntityTypes1_16_2.MINECART_ABSTRACT)
|
||||
&& metadata.id() == 10) {
|
||||
// Convert to new block id
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(EntityTypes1_16_2.ABSTRACT_PIGLIN)) {
|
||||
if (metadata.id() == 15) {
|
||||
metadata.setId(16);
|
||||
} else if (metadata.id() == 16) {
|
||||
metadata.setId(15);
|
||||
protected void registerRewrites() {
|
||||
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.blockStateType, null, Types1_16.META_TYPES.particleType);
|
||||
filter().type(EntityTypes1_16_2.MINECART_ABSTRACT).index(10).handler((metadatas, meta) -> {
|
||||
int data = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
});
|
||||
filter().type(EntityTypes1_16_2.ABSTRACT_PIGLIN).handler((metadatas, meta) -> {
|
||||
if (meta.id() == 15) {
|
||||
meta.setId(16);
|
||||
} else if (meta.id() == 16) {
|
||||
meta.setId(15);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,8 +69,7 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
metadataRewriter.register();
|
||||
itemRewriter.register();
|
||||
super.registerPackets();
|
||||
|
||||
EntityPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
|
@ -17,18 +17,14 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_16;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter1_16To1_15_2 extends EntityRewriter<ClientboundPackets1_15, Protocol1_16To1_15_2> {
|
||||
|
||||
@ -39,41 +35,18 @@ public class MetadataRewriter1_16To1_15_2 extends EntityRewriter<ClientboundPack
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
metadata.setMetaType(Types1_16.META_TYPES.byId(metadata.metaType().typeId()));
|
||||
if (metadata.metaType() == Types1_16.META_TYPES.itemType) {
|
||||
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
|
||||
} else if (metadata.metaType() == Types1_16.META_TYPES.blockStateType) {
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
} else if (metadata.metaType() == Types1_16.META_TYPES.particleType) {
|
||||
rewriteParticle((Particle) metadata.getValue());
|
||||
}
|
||||
|
||||
if (type == null) return;
|
||||
|
||||
if (type.isOrHasParent(EntityTypes1_16.MINECART_ABSTRACT)
|
||||
&& metadata.id() == 10) {
|
||||
// Convert to new block id
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(EntityTypes1_16.ABSTRACT_ARROW)) {
|
||||
if (metadata.id() == 8) {
|
||||
metadatas.remove(metadata);
|
||||
} else if (metadata.id() > 8) {
|
||||
metadata.setId(metadata.id() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == EntityTypes1_16.WOLF) {
|
||||
if (metadata.id() == 16) {
|
||||
byte mask = metadata.value();
|
||||
int angerTime = (mask & 0x02) != 0 ? Integer.MAX_VALUE : 0;
|
||||
metadatas.add(new Metadata(20, Types1_16.META_TYPES.varIntType, angerTime));
|
||||
}
|
||||
}
|
||||
protected void registerRewrites() {
|
||||
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.blockStateType, null, Types1_16.META_TYPES.particleType);
|
||||
filter().type(EntityTypes1_16.MINECART_ABSTRACT).index(10).handler((metadatas, meta) -> {
|
||||
int data = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
});
|
||||
filter().type(EntityTypes1_16.ABSTRACT_ARROW).removeIndex(8);
|
||||
filter().type(EntityTypes1_16.WOLF).index(16).handler((event, meta) -> {
|
||||
byte mask = meta.value();
|
||||
int angerTime = (mask & 0x02) != 0 ? Integer.MAX_VALUE : 0;
|
||||
event.createExtraMeta(new Metadata(20, Types1_16.META_TYPES.varIntType, angerTime));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -151,23 +151,20 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_16_2
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
filter().handler((event, meta) -> {
|
||||
meta.setMetaType(Types1_17.META_TYPES.byId(meta.metaType().typeId()));
|
||||
|
||||
if (meta.metaType() == Types1_17.META_TYPES.poseType) {
|
||||
int pose = meta.value();
|
||||
if (pose > 5) {
|
||||
// Added LONG_JUMP at 6
|
||||
meta.setValue(pose + 1);
|
||||
}
|
||||
filter().mapMetaType(Types1_17.META_TYPES::byId);
|
||||
filter().metaType(Types1_17.META_TYPES.poseType).handler((event, meta) -> {
|
||||
int pose = meta.value();
|
||||
if (pose > 5) {
|
||||
// Added LONG_JUMP at 6
|
||||
meta.setValue(pose + 1);
|
||||
}
|
||||
});
|
||||
registerMetaTypeHandler(Types1_17.META_TYPES.itemType, Types1_17.META_TYPES.blockStateType, null, Types1_17.META_TYPES.particleType);
|
||||
|
||||
// Ticks frozen added with id 7
|
||||
filter().filterFamily(EntityTypes1_17.ENTITY).addIndex(7);
|
||||
filter().type(EntityTypes1_17.ENTITY).addIndex(7);
|
||||
|
||||
filter().filterFamily(EntityTypes1_17.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
filter().type(EntityTypes1_17.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
// Convert to new block id
|
||||
int data = (int) meta.getValue();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
|
@ -81,18 +81,16 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_17_1
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
filter().handler((event, meta) -> {
|
||||
meta.setMetaType(Types1_18.META_TYPES.byId(meta.metaType().typeId()));
|
||||
if (meta.metaType() == Types1_18.META_TYPES.particleType) {
|
||||
final Particle particle = (Particle) meta.getValue();
|
||||
if (particle.getId() == 2) { // Barrier
|
||||
particle.setId(3); // Block marker
|
||||
particle.add(Type.VAR_INT, 7754); // Barrier state
|
||||
} else if (particle.getId() == 3) { // Light block
|
||||
particle.add(Type.VAR_INT, 7786); // Light block state
|
||||
} else {
|
||||
rewriteParticle(particle);
|
||||
}
|
||||
filter().mapMetaType(Types1_18.META_TYPES::byId);
|
||||
filter().metaType(Types1_18.META_TYPES.particleType).handler((event, meta) -> {
|
||||
final Particle particle = (Particle) meta.getValue();
|
||||
if (particle.getId() == 2) { // Barrier
|
||||
particle.setId(3); // Block marker
|
||||
particle.add(Type.VAR_INT, 7754); // Barrier state
|
||||
} else if (particle.getId() == 3) { // Light block
|
||||
particle.add(Type.VAR_INT, 7786); // Light block state
|
||||
} else {
|
||||
rewriteParticle(particle);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -42,6 +42,8 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_1
|
||||
@Override
|
||||
public void registerPackets() {
|
||||
registerTrackerWithData1_19(ClientboundPackets1_19_1.SPAWN_ENTITY, EntityTypes1_19_3.FALLING_BLOCK);
|
||||
registerTracker(ClientboundPackets1_19_1.SPAWN_EXPERIENCE_ORB, EntityTypes1_19_3.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_19_1.SPAWN_PLAYER, EntityTypes1_19_3.PLAYER);
|
||||
registerMetadataRewriter(ClientboundPackets1_19_1.ENTITY_METADATA, Types1_19.METADATA_LIST, Types1_19_3.METADATA_LIST);
|
||||
registerRemoveEntities(ClientboundPackets1_19_1.REMOVE_ENTITIES);
|
||||
|
||||
@ -59,6 +61,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_1
|
||||
handler(dimensionDataHandler());
|
||||
handler(biomeSizeTracker());
|
||||
handler(worldDataTrackerHandlerByKey());
|
||||
handler(playerTrackerHandler());
|
||||
handler(wrapper -> {
|
||||
// Also enable vanilla features
|
||||
final PacketWrapper enableFeaturesPacket = wrapper.create(ClientboundPackets1_19_3.UPDATE_ENABLED_FEATURES);
|
||||
@ -149,20 +152,17 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_1
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
filter().handler((event, meta) -> {
|
||||
final int id = meta.metaType().typeId();
|
||||
meta.setMetaType(Types1_19_3.META_TYPES.byId(id >= 2 ? id + 1 : id)); // long added
|
||||
});
|
||||
filter().mapMetaType(typeId -> Types1_19_3.META_TYPES.byId(typeId >= 2 ? typeId + 1 : typeId)); // Long added
|
||||
registerMetaTypeHandler(Types1_19_3.META_TYPES.itemType, Types1_19_3.META_TYPES.blockStateType, null, Types1_19_3.META_TYPES.particleType);
|
||||
|
||||
filter().index(6).handler((event, meta) -> {
|
||||
filter().type(EntityTypes1_19_3.ENTITY).index(6).handler((event, meta) -> {
|
||||
// Sitting pose added
|
||||
final int pose = meta.value();
|
||||
if (pose >= 10) {
|
||||
meta.setValue(pose + 1);
|
||||
}
|
||||
});
|
||||
filter().filterFamily(EntityTypes1_19_3.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
filter().type(EntityTypes1_19_3.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
// Convert to new block id
|
||||
final int data = (int) meta.getValue();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
|
@ -17,7 +17,11 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.packets;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_4;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
@ -222,28 +226,22 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
filter().handler((event, meta) -> {
|
||||
int id = meta.metaType().typeId();
|
||||
if (id >= 14) { // Optional block state (and map block state=14 to optional block state)
|
||||
id++;
|
||||
}
|
||||
meta.setMetaType(Types1_19_4.META_TYPES.byId(id));
|
||||
});
|
||||
filter().mapMetaType(typeId -> Types1_19_4.META_TYPES.byId(typeId >= 14 ? typeId + 1 : typeId)); // Optional block state (and map block state=14 to optional block state)
|
||||
registerMetaTypeHandler(Types1_19_4.META_TYPES.itemType, Types1_19_4.META_TYPES.blockStateType, Types1_19_4.META_TYPES.optionalBlockStateType, Types1_19_4.META_TYPES.particleType);
|
||||
|
||||
filter().filterFamily(EntityTypes1_19_4.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
filter().type(EntityTypes1_19_4.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
final int blockState = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||
});
|
||||
|
||||
filter().filterFamily(EntityTypes1_19_4.BOAT).index(11).handler((event, meta) -> {
|
||||
filter().type(EntityTypes1_19_4.BOAT).index(11).handler((event, meta) -> {
|
||||
final int boatType = meta.value();
|
||||
if (boatType > 4) { // Cherry added
|
||||
meta.setValue(boatType + 1);
|
||||
}
|
||||
});
|
||||
|
||||
filter().filterFamily(EntityTypes1_19_4.ABSTRACT_HORSE).removeIndex(18); // Owner UUID
|
||||
filter().type(EntityTypes1_19_4.ABSTRACT_HORSE).removeIndex(18); // Owner UUID
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,8 +46,11 @@ import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.Dimensio
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18, Protocol1_19To1_18_2> {
|
||||
|
||||
@ -349,37 +352,33 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
filter().handler((event, meta) -> {
|
||||
meta.setMetaType(Types1_19.META_TYPES.byId(meta.metaType().typeId()));
|
||||
filter().mapMetaType(Types1_19.META_TYPES::byId);
|
||||
filter().metaType(Types1_19.META_TYPES.particleType).handler((event, meta) -> {
|
||||
final Particle particle = (Particle) meta.getValue();
|
||||
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
|
||||
if (particle.getId() == particleMappings.id("vibration")) {
|
||||
// Remove the position
|
||||
particle.getArguments().remove(0);
|
||||
|
||||
final MetaType type = meta.metaType();
|
||||
if (type == Types1_19.META_TYPES.particleType) {
|
||||
final Particle particle = (Particle) meta.getValue();
|
||||
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
|
||||
if (particle.getId() == particleMappings.id("vibration")) {
|
||||
// Remove the position
|
||||
particle.getArguments().remove(0);
|
||||
|
||||
final String resourceLocation = Key.stripMinecraftNamespace(particle.<String>getArgument(0).getValue());
|
||||
if (resourceLocation.equals("entity")) {
|
||||
// Add Y offset
|
||||
particle.getArguments().add(2, new Particle.ParticleData<>(Type.FLOAT, 0F));
|
||||
}
|
||||
final String resourceLocation = Key.stripMinecraftNamespace(particle.<String>getArgument(0).getValue());
|
||||
if (resourceLocation.equals("entity")) {
|
||||
// Add Y offset
|
||||
particle.getArguments().add(2, new Particle.ParticleData<>(Type.FLOAT, 0F));
|
||||
}
|
||||
|
||||
rewriteParticle(particle);
|
||||
}
|
||||
|
||||
rewriteParticle(particle);
|
||||
});
|
||||
|
||||
registerMetaTypeHandler(Types1_19.META_TYPES.itemType, Types1_19.META_TYPES.blockStateType, null, null);
|
||||
|
||||
filter().filterFamily(EntityTypes1_19.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
filter().type(EntityTypes1_19.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
// Convert to new block id
|
||||
final int data = (int) meta.getValue();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
});
|
||||
|
||||
filter().type(EntityTypes1_19.CAT).index(19).handler((event, meta) -> meta.setMetaType(Types1_19.META_TYPES.catVariantType));
|
||||
filter().type(EntityTypes1_19.CAT).index(19).mapMetaType(typeId -> Types1_19.META_TYPES.catVariantType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -174,12 +174,12 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
filter().handler((event, meta) -> meta.setMetaType(Types1_20_2.META_TYPES.byId(meta.metaType().typeId())));
|
||||
filter().mapMetaType(Types1_20_2.META_TYPES::byId);
|
||||
registerMetaTypeHandler(Types1_20_2.META_TYPES.itemType, Types1_20_2.META_TYPES.blockStateType, Types1_20_2.META_TYPES.optionalBlockStateType, Types1_20_2.META_TYPES.particleType);
|
||||
|
||||
filter().filterFamily(EntityTypes1_19_4.DISPLAY).addIndex(10);
|
||||
filter().type(EntityTypes1_19_4.DISPLAY).addIndex(10);
|
||||
|
||||
filter().filterFamily(EntityTypes1_19_4.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
filter().type(EntityTypes1_19_4.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
final int blockState = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||
});
|
||||
|
@ -106,25 +106,25 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
|
||||
meta.setTypeAndValue(Types1_20_3.META_TYPES.componentType, ComponentUtil.jsonToTag(meta.value()));
|
||||
} else if (type == Types1_20_2.META_TYPES.optionalComponentType) {
|
||||
meta.setTypeAndValue(Types1_20_3.META_TYPES.optionalComponentType, ComponentUtil.jsonToTag(meta.value()));
|
||||
} else if (type == Types1_20_2.META_TYPES.particleType) {
|
||||
final Particle particle = (Particle) meta.getValue();
|
||||
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
|
||||
if (particle.getId() == particleMappings.id("vibration")) {
|
||||
// Change the type of the resource key argument
|
||||
final String resourceLocation = particle.<String>removeArgument(0).getValue();
|
||||
if (Key.stripMinecraftNamespace(resourceLocation).equals("block")) {
|
||||
particle.add(0, Type.VAR_INT, 0);
|
||||
} else { // Entity
|
||||
particle.add(0, Type.VAR_INT, 1);
|
||||
}
|
||||
}
|
||||
|
||||
rewriteParticle(particle);
|
||||
meta.setMetaType(Types1_20_3.META_TYPES.particleType);
|
||||
} else {
|
||||
meta.setMetaType(Types1_20_3.META_TYPES.byId(type.typeId()));
|
||||
}
|
||||
});
|
||||
filter().metaType(Types1_20_3.META_TYPES.particleType).handler((event, meta) -> {
|
||||
final Particle particle = meta.value();
|
||||
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
|
||||
if (particle.getId() == particleMappings.id("vibration")) {
|
||||
// Change the type of the resource key argument
|
||||
final String resourceLocation = particle.<String>removeArgument(0).getValue();
|
||||
if (Key.stripMinecraftNamespace(resourceLocation).equals("block")) {
|
||||
particle.add(0, Type.VAR_INT, 0);
|
||||
} else { // Entity
|
||||
particle.add(0, Type.VAR_INT, 1);
|
||||
}
|
||||
}
|
||||
|
||||
rewriteParticle(particle);
|
||||
});
|
||||
|
||||
registerMetaTypeHandler(
|
||||
Types1_20_3.META_TYPES.itemType,
|
||||
@ -133,7 +133,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
|
||||
Types1_20_3.META_TYPES.particleType
|
||||
);
|
||||
|
||||
filter().filterFamily(EntityTypes1_20_3.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
filter().type(EntityTypes1_20_3.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
final int blockState = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||
});
|
||||
|
@ -17,7 +17,12 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_20to1_19_4.packets;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.api.minecraft.Quaternion;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_4;
|
||||
@ -123,11 +128,11 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_4
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
filter().handler((event, meta) -> meta.setMetaType(Types1_20.META_TYPES.byId(meta.metaType().typeId())));
|
||||
filter().mapMetaType(Types1_20.META_TYPES::byId);
|
||||
registerMetaTypeHandler(Types1_20.META_TYPES.itemType, Types1_20.META_TYPES.blockStateType, Types1_20.META_TYPES.optionalBlockStateType, Types1_20.META_TYPES.particleType);
|
||||
|
||||
// Rotate item display by 180 degrees around the Y axis
|
||||
filter().filterFamily(EntityTypes1_19_4.ITEM_DISPLAY).handler((event, meta) -> {
|
||||
filter().type(EntityTypes1_19_4.ITEM_DISPLAY).handler((event, meta) -> {
|
||||
if (event.trackedEntity().hasSentMetadata() || event.hasExtraMeta()) {
|
||||
return;
|
||||
}
|
||||
@ -136,12 +141,12 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_4
|
||||
event.createExtraMeta(new Metadata(12, Types1_20.META_TYPES.quaternionType, Y_FLIPPED_ROTATION));
|
||||
}
|
||||
});
|
||||
filter().filterFamily(EntityTypes1_19_4.ITEM_DISPLAY).index(12).handler((event, meta) -> {
|
||||
filter().type(EntityTypes1_19_4.ITEM_DISPLAY).index(12).handler((event, meta) -> {
|
||||
final Quaternion quaternion = meta.value();
|
||||
meta.setValue(rotateY180(quaternion));
|
||||
});
|
||||
|
||||
filter().filterFamily(EntityTypes1_19_4.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
filter().type(EntityTypes1_19_4.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
final int blockState = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||
});
|
||||
|
@ -95,7 +95,7 @@ public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, Cl
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
metadataRewriter.register();
|
||||
super.registerPackets();
|
||||
|
||||
// Disconnect workaround (JSON!)
|
||||
registerClientbound(State.LOGIN, 0x00, 0x00, wrapper -> {
|
||||
|
@ -17,11 +17,10 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.EulerAngle;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
@ -30,7 +29,7 @@ import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import java.util.List;
|
||||
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MetadataRewriter1_9To1_8 extends EntityRewriter<ClientboundPackets1_8, Protocol1_9To1_8> {
|
||||
@ -40,14 +39,21 @@ public class MetadataRewriter1_9To1_8 extends EntityRewriter<ClientboundPackets1
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
protected void registerRewrites() {
|
||||
filter().handler(this::handleMetadata);
|
||||
}
|
||||
|
||||
private void handleMetadata(MetaHandlerEvent event, Metadata metadata) {
|
||||
EntityType type = event.entityType();
|
||||
MetaIndex metaIndex = MetaIndex.searchIndex(type, metadata.id());
|
||||
if (metaIndex == null) {
|
||||
throw new Exception("Could not find valid metadata");
|
||||
// Almost certainly bad data, remove it
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (metaIndex.getNewType() == null) {
|
||||
metadatas.remove(metadata);
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -72,7 +78,7 @@ public class MetadataRewriter1_9To1_8 extends EntityRewriter<ClientboundPackets1
|
||||
}
|
||||
int newIndex = MetaIndex.PLAYER_HAND.getNewIndex();
|
||||
MetaType metaType = MetaIndex.PLAYER_HAND.getNewType();
|
||||
metadatas.add(new Metadata(newIndex, metaType, val));
|
||||
event.createExtraMeta(new Metadata(newIndex, metaType, val));
|
||||
}
|
||||
break;
|
||||
case OptUUID:
|
||||
@ -129,8 +135,7 @@ public class MetadataRewriter1_9To1_8 extends EntityRewriter<ClientboundPackets1
|
||||
metadata.setValue(((Number) value).intValue());
|
||||
break;
|
||||
default:
|
||||
metadatas.remove(metadata);
|
||||
throw new Exception("Unhandled MetaDataType: " + metaIndex.getNewType());
|
||||
throw new RuntimeException("Unhandled MetaDataType: " + metaIndex.getNewType());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
@ -30,6 +31,7 @@ import com.viaversion.viaversion.api.data.ParticleMappings;
|
||||
import com.viaversion.viaversion.api.data.entity.DimensionData;
|
||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.data.entity.TrackedEntity;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
@ -40,7 +42,6 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.rewriter.RewriterBase;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.data.entity.DimensionDataImpl;
|
||||
import com.viaversion.viaversion.rewriter.meta.MetaFilter;
|
||||
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent;
|
||||
@ -106,19 +107,13 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
final TrackedEntity entity = tracker(connection).entity(entityId);
|
||||
final EntityType type = entity != null ? entity.entityType() : null;
|
||||
for (final Metadata metadata : metadataList.toArray(EMPTY_ARRAY)) { // Copy the list to allow mutation
|
||||
// Call handlers implementing the old handleMetadata
|
||||
if (!callOldMetaHandler(entityId, type, metadata, metadataList, connection)) {
|
||||
metadataList.remove(metadata);
|
||||
continue;
|
||||
}
|
||||
|
||||
MetaHandlerEvent event = null;
|
||||
for (final MetaFilter filter : metadataFilters) {
|
||||
if (!filter.isFiltered(type, metadata)) {
|
||||
continue;
|
||||
}
|
||||
if (event == null) {
|
||||
// Only initialize when needed and share event instance
|
||||
// Instantiate lazily and share event instance
|
||||
event = new MetaHandlerEventImpl(connection, entity, entityId, metadata, metadataList);
|
||||
}
|
||||
|
||||
@ -137,10 +132,9 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
}
|
||||
}
|
||||
|
||||
final List<Metadata> extraMeta = event != null ? event.extraMeta() : null;
|
||||
if (extraMeta != null) {
|
||||
if (event != null && event.hasExtraMeta()) {
|
||||
// Finally, add newly created meta
|
||||
metadataList.addAll(extraMeta);
|
||||
metadataList.addAll(event.extraMeta());
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,31 +143,6 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private boolean callOldMetaHandler(int entityId, @Nullable EntityType type, Metadata metadata, List<Metadata> metadataList, UserConnection connection) {
|
||||
try {
|
||||
handleMetadata(entityId, type, metadata, metadataList, connection);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logException(e, type, metadataList, metadata);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To be overridden to handle metadata.
|
||||
*
|
||||
* @param entityId entity id
|
||||
* @param type entity type, or null if not tracked
|
||||
* @param metadata current metadata
|
||||
* @param metadatas full, mutable list of metadata
|
||||
* @param connection user connection
|
||||
* @deprecated use {@link #filter()}
|
||||
*/
|
||||
@Deprecated
|
||||
protected void handleMetadata(int entityId, @Nullable EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int newEntityId(int id) {
|
||||
return typeMappings != null ? typeMappings.getNewIdOrDefault(id, id) : id;
|
||||
@ -567,16 +536,6 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@Deprecated
|
||||
protected @Nullable Metadata metaByIndex(int index, List<Metadata> metadataList) {
|
||||
for (Metadata metadata : metadataList) {
|
||||
if (metadata.id() == index) {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void rewriteParticle(Particle particle) {
|
||||
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
|
||||
int id = particle.getId();
|
||||
|
@ -20,20 +20,24 @@ package com.viaversion.viaversion.rewriter.meta;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectFunction;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class MetaFilter {
|
||||
private final MetaHandler handler;
|
||||
private final EntityType type;
|
||||
private final MetaType metaType;
|
||||
private final int index;
|
||||
private final boolean filterFamily;
|
||||
|
||||
public MetaFilter(@Nullable EntityType type, boolean filterFamily, int index, MetaHandler handler) {
|
||||
public MetaFilter(@Nullable EntityType type, boolean filterFamily, @Nullable MetaType metaType, int index, MetaHandler handler) {
|
||||
Preconditions.checkNotNull(handler, "MetaHandler cannot be null");
|
||||
this.type = type;
|
||||
this.metaType = metaType;
|
||||
this.filterFamily = filterFamily;
|
||||
this.index = index;
|
||||
this.handler = handler;
|
||||
@ -57,6 +61,15 @@ public class MetaFilter {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the meta type to filter, or null.
|
||||
*
|
||||
* @return the meta type to filter, or null if unset
|
||||
*/
|
||||
public @Nullable MetaType metaType() {
|
||||
return metaType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the metadata handler.
|
||||
*
|
||||
@ -86,7 +99,8 @@ public class MetaFilter {
|
||||
// Check if no specific index is filtered or the indexes are equal
|
||||
// Then check if the filter has no entity type or the type is equal to or part of the filtered parent type
|
||||
return (this.index == -1 || metadata.id() == this.index)
|
||||
&& (this.type == null || matchesType(type));
|
||||
&& (this.type == null || matchesType(type))
|
||||
&& (this.metaType == null || metadata.metaType() == this.metaType);
|
||||
}
|
||||
|
||||
private boolean matchesType(@Nullable EntityType type) {
|
||||
@ -101,6 +115,7 @@ public class MetaFilter {
|
||||
if (index != that.index) return false;
|
||||
if (filterFamily != that.filterFamily) return false;
|
||||
if (!handler.equals(that.handler)) return false;
|
||||
if (!Objects.equals(metaType, that.metaType)) return false;
|
||||
return Objects.equals(type, that.type);
|
||||
}
|
||||
|
||||
@ -108,6 +123,7 @@ public class MetaFilter {
|
||||
public int hashCode() {
|
||||
int result = handler.hashCode();
|
||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||
result = 31 * result + (metaType != null ? metaType.hashCode() : 0);
|
||||
result = 31 * result + index;
|
||||
result = 31 * result + (filterFamily ? 1 : 0);
|
||||
return result;
|
||||
@ -118,6 +134,7 @@ public class MetaFilter {
|
||||
return "MetaFilter{" +
|
||||
"type=" + type +
|
||||
", filterFamily=" + filterFamily +
|
||||
", metaType=" + metaType +
|
||||
", index=" + index +
|
||||
", handler=" + handler +
|
||||
'}';
|
||||
@ -126,6 +143,7 @@ public class MetaFilter {
|
||||
public static final class Builder {
|
||||
private final EntityRewriter<?, ?> rewriter;
|
||||
private EntityType type;
|
||||
private MetaType metaType;
|
||||
private int index = -1;
|
||||
private boolean filterFamily;
|
||||
private MetaHandler handler;
|
||||
@ -134,9 +152,43 @@ public class MetaFilter {
|
||||
this.rewriter = rewriter;
|
||||
}
|
||||
|
||||
public Builder metaType(MetaType metaType) {
|
||||
Preconditions.checkArgument(this.metaType == null);
|
||||
this.metaType = metaType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type to filter, including subtypes.
|
||||
* <p>
|
||||
* You should always register a type when accessing specific indexes,
|
||||
* even if it is the base entity type, to avoid metadata from unregistered
|
||||
* entities causing issues.
|
||||
*
|
||||
* @param type entity type to filter
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder type(EntityType type) {
|
||||
Preconditions.checkArgument(this.type == null);
|
||||
this.type = type;
|
||||
this.filterFamily = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type to filter, not including subtypes.
|
||||
* <p>
|
||||
* You should always register a type when accessing specific indexes,
|
||||
* even if it is the base entity type, to avoid metadata from unregistered
|
||||
* entities causing issues.
|
||||
*
|
||||
* @param type exact entity type to filter
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder exactType(EntityType type) {
|
||||
Preconditions.checkArgument(this.type == null);
|
||||
this.type = type;
|
||||
this.filterFamily = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -146,13 +198,6 @@ public class MetaFilter {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder filterFamily(EntityType type) {
|
||||
Preconditions.checkArgument(this.type == null);
|
||||
this.type = type;
|
||||
this.filterFamily = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder handlerNoRegister(MetaHandler handler) {
|
||||
Preconditions.checkArgument(this.handler == null);
|
||||
this.handler = handler;
|
||||
@ -172,6 +217,17 @@ public class MetaFilter {
|
||||
register();
|
||||
}
|
||||
|
||||
public void mapMetaType(Int2ObjectFunction<MetaType> updateFunction) {
|
||||
handler((event, meta) -> {
|
||||
MetaType mappedType = updateFunction.apply(meta.metaType().typeId());
|
||||
if (mappedType != null) {
|
||||
meta.setMetaType(mappedType);
|
||||
} else {
|
||||
event.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a handler to remove metadata at the given index without affecting any other indexes and registers the filter.
|
||||
* Should always be called last.
|
||||
@ -243,7 +299,7 @@ public class MetaFilter {
|
||||
* @return created meta filter
|
||||
*/
|
||||
public MetaFilter build() {
|
||||
return new MetaFilter(type, filterFamily, index, handler);
|
||||
return new MetaFilter(type, filterFamily, metaType, index, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,12 +84,12 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
/* Uncomment if metatype classes changed
|
||||
filter().handler((event, meta) -> {
|
||||
int id = meta.metaType().typeId();
|
||||
filter().mapMetaType(typeId -> {
|
||||
int id = typeId;
|
||||
if (id >= SomeAddedIndex) {
|
||||
id++;
|
||||
}
|
||||
meta.setMetaType(Types1_20_3.META_TYPES.byId(id));
|
||||
return Types1_20_3.META_TYPES.byId(id);
|
||||
});*/
|
||||
|
||||
// Registers registry type id changes
|
||||
@ -101,7 +101,7 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
|
||||
);
|
||||
|
||||
// Minecarts are special
|
||||
filter().filterFamily(EntityTypes1_20_3.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
filter().type(EntityTypes1_20_3.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
final int blockState = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||
});
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren