Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 16:40:10 +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
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
entityRewriter.register();
|
super.registerPackets();
|
||||||
itemRewriter.register();
|
|
||||||
|
|
||||||
registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketHandlers() {
|
registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketHandlers() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,11 +18,9 @@
|
|||||||
package com.viaversion.viaversion.protocols.protocol1_11to1_10.metadata;
|
package com.viaversion.viaversion.protocols.protocol1_11to1_10.metadata;
|
||||||
|
|
||||||
import com.viaversion.viaversion.api.Via;
|
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;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11.EntityType;
|
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.DataItem;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
|
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
@ -43,93 +41,82 @@ public class MetadataRewriter1_11To1_10 extends EntityRewriter<ClientboundPacket
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleMetadata(int entityId, com.viaversion.viaversion.api.minecraft.entities.EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
protected void registerRewrites() {
|
||||||
if (metadata.getValue() instanceof DataItem) {
|
filter().handler((event, meta) -> {
|
||||||
|
if (meta.getValue() instanceof DataItem) {
|
||||||
// Apply rewrite
|
// Apply rewrite
|
||||||
EntityIdRewriter.toClientItem((Item) metadata.getValue());
|
EntityIdRewriter.toClientItem(meta.value());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
filter().type(EntityType.GUARDIAN).index(12).handler((event, meta) -> {
|
||||||
|
boolean value = (((byte) meta.getValue()) & 0x02) == 0x02;
|
||||||
|
meta.setTypeAndValue(MetaType1_9.Boolean, value);
|
||||||
|
});
|
||||||
|
|
||||||
|
filter().type(EntityType.ABSTRACT_SKELETON).removeIndex(12);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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 (type == null) return;
|
if (id == 16) { // Owner
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.isOrHasParent(EntityType.ABSTRACT_SKELETON)) { // Skeletons
|
|
||||||
int oldid = metadata.id();
|
|
||||||
if (oldid == 12) {
|
|
||||||
metadatas.remove(metadata);
|
|
||||||
}
|
|
||||||
if (oldid == 13) {
|
|
||||||
metadata.setId(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);
|
metadata.setId(14);
|
||||||
} else {
|
} else if (id == 17) { // Armor
|
||||||
if (metadata.id() == 14) {
|
|
||||||
metadata.setId(15);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.isOrHasParent(EntityType.ABSTRACT_HORSE)) { // Horses
|
|
||||||
// Remap metadata id
|
|
||||||
int oldid = metadata.id();
|
|
||||||
if (oldid == 14) { // Type
|
|
||||||
metadatas.remove(metadata);
|
|
||||||
}
|
|
||||||
if (oldid == 16) { // Owner
|
|
||||||
metadata.setId(14);
|
|
||||||
}
|
|
||||||
if (oldid == 17) { // Armor
|
|
||||||
metadata.setId(16);
|
metadata.setId(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process per type
|
// Process per type
|
||||||
if (type.is(EntityType.HORSE)) {
|
if (!type.is(EntityType.HORSE) && metadata.id() == 15 || metadata.id() == 16) {
|
||||||
// Normal Horse
|
event.cancel();
|
||||||
} else {
|
return;
|
||||||
// Remove 15, 16
|
|
||||||
if (metadata.id() == 15 || metadata.id() == 16) {
|
|
||||||
metadatas.remove(metadata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.is(EntityType.ARMOR_STAND) && Via.getConfig().isHologramPatch()) {
|
if ((type == EntityType.DONKEY || type == EntityType.MULE) && metadata.id() == 13) {
|
||||||
Metadata flags = metaByIndex(11, metadatas);
|
if ((((byte) metadata.getValue()) & 0x08) == 0x08) {
|
||||||
Metadata customName = metaByIndex(2, metadatas);
|
event.createExtraMeta(new Metadata(15, MetaType1_9.Boolean, true));
|
||||||
Metadata customNameVisible = metaByIndex(3, metadatas);
|
} else {
|
||||||
if (metadata.id() == 0 && flags != null && customName != null && customNameVisible != null) {
|
event.createExtraMeta(new Metadata(15, MetaType1_9.Boolean, false));
|
||||||
byte data = (byte) metadata.getValue();
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
// Check invisible | Check small | Check if custom name is empty | Check if custom name visible is true
|
||||||
if ((data & 0x20) == 0x20 && ((byte) flags.getValue() & 0x01) == 0x01
|
if ((data & 0x20) == 0x20 && ((byte) flags.getValue() & 0x01) == 0x01
|
||||||
&& !((String) customName.getValue()).isEmpty() && (boolean) customNameVisible.getValue()) {
|
&& !((String) customName.getValue()).isEmpty() && (boolean) customNameVisible.getValue()) {
|
||||||
EntityTracker1_11 tracker = tracker(connection);
|
EntityTracker1_11 tracker = tracker(event.user());
|
||||||
|
int entityId = event.entityId();
|
||||||
if (tracker.addHologram(entityId)) {
|
if (tracker.addHologram(entityId)) {
|
||||||
try {
|
try {
|
||||||
// Send movement
|
// Send movement
|
||||||
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9_3.ENTITY_POSITION, null, connection);
|
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9_3.ENTITY_POSITION, null, event.user());
|
||||||
wrapper.write(Type.VAR_INT, entityId);
|
wrapper.write(Type.VAR_INT, entityId);
|
||||||
wrapper.write(Type.SHORT, (short) 0);
|
wrapper.write(Type.SHORT, (short) 0);
|
||||||
wrapper.write(Type.SHORT, (short) (128D * (-Via.getConfig().getHologramYOffset() * 32D)));
|
wrapper.write(Type.SHORT, (short) (128D * (-Via.getConfig().getHologramYOffset() * 32D)));
|
||||||
@ -142,8 +129,7 @@ public class MetadataRewriter1_11To1_10 extends EntityRewriter<ClientboundPacket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,8 +58,7 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
metadataRewriter.register();
|
super.registerPackets();
|
||||||
itemRewriter.register();
|
|
||||||
|
|
||||||
registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketHandlers() {
|
registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketHandlers() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,15 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_12to1_11_1.metadata;
|
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.EntityType;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
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_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.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
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> {
|
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
|
@Override
|
||||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
protected void registerRewrites() {
|
||||||
if (metadata.getValue() instanceof Item) {
|
filter().handler((event, meta) -> {
|
||||||
// Apply rewrite
|
if (meta.getValue() instanceof Item) {
|
||||||
metadata.setValue(protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue()));
|
meta.setValue(protocol.getItemRewriter().handleItemToClient(meta.value()));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (type == null) return;
|
filter().type(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).index(12).toIndex(13); // Aggressive
|
||||||
// Evocation Illager aggressive property became 13
|
|
||||||
if (type == EntityTypes1_12.EntityType.EVOCATION_ILLAGER) {
|
|
||||||
if (metadata.id() == 12) {
|
|
||||||
metadata.setId(13);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,8 +51,7 @@ public class Protocol1_13_1To1_13 extends AbstractProtocol<ClientboundPackets1_1
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
entityRewriter.register();
|
super.registerPackets();
|
||||||
itemRewriter.register();
|
|
||||||
|
|
||||||
EntityPackets.register(this);
|
EntityPackets.register(this);
|
||||||
WorldPackets.register(this);
|
WorldPackets.register(this);
|
||||||
|
@ -17,17 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_13_1to1_13.metadata;
|
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.entities.EntityType;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
|
||||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_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_13_1to1_13.Protocol1_13_1To1_13;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MetadataRewriter1_13_1To1_13 extends EntityRewriter<ClientboundPackets1_13, Protocol1_13_1To1_13> {
|
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
|
@Override
|
||||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
protected void registerRewrites() {
|
||||||
// 1.13 changed item to flat item (no data)
|
registerMetaTypeHandler(Types1_13.META_TYPES.itemType, Types1_13.META_TYPES.blockStateType, null, Types1_13.META_TYPES.particleType);
|
||||||
if (metadata.metaType() == Types1_13.META_TYPES.itemType) {
|
filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> {
|
||||||
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
|
int data = meta.value();
|
||||||
} else if (metadata.metaType() == Types1_13.META_TYPES.blockStateType) {
|
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||||
// Convert to new block id
|
});
|
||||||
int data = (int) metadata.getValue();
|
filter().type(EntityTypes1_13.EntityType.ABSTRACT_ARROW).addIndex(7); // Shooter UUID
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -162,8 +162,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
entityRewriter.register();
|
super.registerPackets();
|
||||||
itemRewriter.register();
|
|
||||||
|
|
||||||
EntityPackets.register(this);
|
EntityPackets.register(this);
|
||||||
WorldPackets.register(this);
|
WorldPackets.register(this);
|
||||||
|
@ -17,11 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.metadata;
|
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.Particle;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
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_13;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_13;
|
import com.viaversion.viaversion.api.type.types.version.Types1_13;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
|
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
|
||||||
@ -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.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
import com.viaversion.viaversion.util.ComponentUtil;
|
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> {
|
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
|
@Override
|
||||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
protected void registerRewrites() {
|
||||||
// Handle new MetaTypes
|
filter().mapMetaType(typeId -> Types1_13.META_TYPES.byId(typeId > 4 ? typeId + 1 : typeId));
|
||||||
if (metadata.metaType().typeId() > 4) {
|
filter().metaType(Types1_13.META_TYPES.itemType).handler(((event, meta) -> protocol.getItemRewriter().handleItemToClient(meta.value())));
|
||||||
metadata.setMetaType(Types1_13.META_TYPES.byId(metadata.metaType().typeId() + 1));
|
filter().metaType(Types1_13.META_TYPES.blockStateType).handler(((event, meta) -> meta.setValue(WorldPackets.toNewId(meta.value()))));
|
||||||
} else {
|
|
||||||
metadata.setMetaType(Types1_13.META_TYPES.byId(metadata.metaType().typeId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle String -> Chat DisplayName
|
// Previously unused, now swimming
|
||||||
if (metadata.id() == 2) {
|
filter().index(0).handler((event, meta) -> meta.setValue((byte) ((byte) meta.getValue() & ~0x10)));
|
||||||
if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) {
|
|
||||||
metadata.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, ComponentUtil.legacyToJson((String) metadata.getValue()));
|
|
||||||
} else {
|
|
||||||
metadata.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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 {
|
||||||
|
meta.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, null);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
filter().type(EntityTypes1_13.EntityType.ENDERMAN).index(12).handler((event, meta) -> {
|
||||||
// Remap held block to match new format for remapping to flat block
|
// Remap held block to match new format for remapping to flat block
|
||||||
if (type == EntityTypes1_13.EntityType.ENDERMAN && metadata.id() == 12) {
|
int stateId = meta.value();
|
||||||
int stateId = (int) metadata.getValue();
|
|
||||||
int id = stateId & 4095;
|
int id = stateId & 4095;
|
||||||
int data = stateId >> 12 & 15;
|
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()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip type related changes when the type is null
|
|
||||||
if (type == null) return;
|
|
||||||
|
|
||||||
|
filter().type(EntityTypes1_13.EntityType.WOLF).index(17).handler((event, meta) -> {
|
||||||
// Handle new colors
|
// Handle new colors
|
||||||
if (type == EntityTypes1_13.EntityType.WOLF && metadata.id() == 17) {
|
meta.setValue(15 - (int) meta.getValue());
|
||||||
metadata.setValue(15 - (int) metadata.getValue());
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// Handle new zombie meta (INDEX 15 - Boolean - Zombie is shaking while enabled)
|
filter().type(EntityTypes1_13.EntityType.ZOMBIE).addIndex(15); // Shaking
|
||||||
if (type.isOrHasParent(EntityTypes1_13.EntityType.ZOMBIE)) {
|
|
||||||
if (metadata.id() > 14)
|
|
||||||
metadata.setId(metadata.id() + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle Minecart inner block
|
filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> {
|
||||||
if (type.isOrHasParent(EntityTypes1_13.EntityType.MINECART_ABSTRACT) && metadata.id() == 9) {
|
int oldId = meta.value();
|
||||||
// New block format
|
|
||||||
int oldId = (int) metadata.getValue();
|
|
||||||
int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
|
int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
|
||||||
int newId = WorldPackets.toNewId(combined);
|
int newId = WorldPackets.toNewId(combined);
|
||||||
metadata.setValue(newId);
|
meta.setValue(newId);
|
||||||
}
|
});
|
||||||
|
|
||||||
// Handle other changes
|
filter().type(EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD).handler((event, meta) -> {
|
||||||
if (type == EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD) {
|
if (meta.id() == 9) {
|
||||||
if (metadata.id() == 9) {
|
int particleId = meta.value();
|
||||||
int particleId = (int) metadata.getValue();
|
Metadata parameter1Meta = event.metaAtIndex(10);
|
||||||
Metadata parameter1Meta = metaByIndex(10, metadatas);
|
Metadata parameter2Meta = event.metaAtIndex(11);
|
||||||
Metadata parameter2Meta = metaByIndex(11, metadatas);
|
int parameter1 = parameter1Meta != null ? parameter1Meta.value() : 0;
|
||||||
int parameter1 = parameter1Meta != null ? (int) parameter1Meta.getValue() : 0;
|
int parameter2 = parameter2Meta != null ? parameter2Meta.value() : 0;
|
||||||
int parameter2 = parameter2Meta != null ? (int) parameter2Meta.getValue() : 0;
|
|
||||||
|
|
||||||
Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2});
|
Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2});
|
||||||
if (particle != null && particle.getId() != -1) {
|
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 (meta.id() >= 9) {
|
||||||
if (metadata.id() >= 9)
|
event.cancel();
|
||||||
metadatas.remove(metadata); // Remove
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
if (metadata.id() == 0) {
|
|
||||||
metadata.setValue((byte) ((byte) metadata.getValue() & ~0x10)); // Previously unused, now swimming
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Boat has changed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -36,7 +36,7 @@ public class Protocol1_14_1To1_14 extends AbstractProtocol<ClientboundPackets1_1
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
metadataRewriter.register();
|
super.registerPackets();
|
||||||
|
|
||||||
EntityPackets.register(this);
|
EntityPackets.register(this);
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_14_1to1_14.metadata;
|
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.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_14_1to1_14.Protocol1_14_1To1_14;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MetadataRewriter1_14_1To1_14 extends EntityRewriter<ClientboundPackets1_14, Protocol1_14_1To1_14> {
|
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
|
@Override
|
||||||
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
protected void registerRewrites() {
|
||||||
if (type == null) return;
|
filter().type(EntityTypes1_14.VILLAGER).addIndex(15);
|
||||||
|
filter().type(EntityTypes1_14.WANDERING_TRADER).addIndex(15);
|
||||||
if (type == EntityTypes1_14.VILLAGER || type == EntityTypes1_14.WANDERING_TRADER) {
|
|
||||||
if (metadata.id() >= 15) {
|
|
||||||
metadata.setId(metadata.id() + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,8 +52,7 @@ public class Protocol1_14To1_13_2 extends AbstractProtocol<ClientboundPackets1_1
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
metadataRewriter.register();
|
super.registerPackets();
|
||||||
itemRewriter.register();
|
|
||||||
|
|
||||||
EntityPackets.register(this);
|
EntityPackets.register(this);
|
||||||
WorldPackets.register(this);
|
WorldPackets.register(this);
|
||||||
|
@ -18,24 +18,21 @@
|
|||||||
package com.viaversion.viaversion.protocols.protocol1_14to1_13_2.metadata;
|
package com.viaversion.viaversion.protocols.protocol1_14to1_13_2.metadata;
|
||||||
|
|
||||||
import com.viaversion.viaversion.api.Via;
|
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.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_13;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
|
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.DataItem;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
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.ClientboundPackets1_14;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MetadataRewriter1_14To1_13_2 extends EntityRewriter<ClientboundPackets1_13, Protocol1_14To1_13_2> {
|
public class MetadataRewriter1_14To1_13_2 extends EntityRewriter<ClientboundPackets1_13, Protocol1_14To1_13_2> {
|
||||||
|
|
||||||
@ -46,82 +43,67 @@ public class MetadataRewriter1_14To1_13_2 extends EntityRewriter<ClientboundPack
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
protected void registerRewrites() {
|
||||||
metadata.setMetaType(Types1_14.META_TYPES.byId(metadata.metaType().typeId()));
|
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) {
|
filter().type(EntityTypes1_14.LIVINGENTITY).index(8).handler((event, meta) -> {
|
||||||
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
|
float value = ((Number) meta.getValue()).floatValue();
|
||||||
} else if (metadata.metaType() == Types1_14.META_TYPES.blockStateType) {
|
if (Float.isNaN(value) && Via.getConfig().is1_14HealthNaNFix()) {
|
||||||
// Convert to new block id
|
meta.setValue(1F);
|
||||||
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;
|
filter().type(EntityTypes1_14.ABSTRACT_INSENTIENT).index(13).handler((event, meta) -> {
|
||||||
|
EntityTracker1_14 tracker = tracker(event.user());
|
||||||
//Metadata 6 added to abstract_entity
|
int entityId = event.entityId();
|
||||||
if (metadata.id() > 5) {
|
tracker.setInsentientData(entityId, (byte) ((((Number) meta.getValue()).byteValue() & ~0x4)
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Metadata 12 added to living_entity
|
|
||||||
if (metadata.id() > 11 && type.isOrHasParent(EntityTypes1_14.LIVINGENTITY)) {
|
|
||||||
metadata.setId(metadata.id() + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
|
||||||
metadata.setValue(tracker.getInsentientData(entityId));
|
meta.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 (entityId != tracker.clientEntityId()) {
|
||||||
if (metadata.id() == 0) {
|
if (meta.id() == 0) {
|
||||||
byte flags = ((Number) metadata.getValue()).byteValue();
|
byte flags = ((Number) meta.getValue()).byteValue();
|
||||||
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
|
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
|
||||||
tracker.setEntityFlags(entityId, flags);
|
tracker.setEntityFlags(entityId, flags);
|
||||||
} else if (metadata.id() == 7) {
|
} else if (meta.id() == 7) {
|
||||||
tracker.setRiptide(entityId, (((Number) metadata.getValue()).byteValue() & 0x4) != 0);
|
tracker.setRiptide(entityId, (((Number) meta.getValue()).byteValue() & 0x4) != 0);
|
||||||
}
|
}
|
||||||
if (metadata.id() == 0 || metadata.id() == 7) {
|
if (meta.id() == 0 || meta.id() == 7) {
|
||||||
metadatas.add(new Metadata(6, Types1_14.META_TYPES.poseType, recalculatePlayerPose(entityId, tracker)));
|
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)
|
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||||
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
| ((boolean) meta.getValue() ? 0x4 : 0))); // New attacking
|
||||||
metadatas.remove(metadata); // "Are hands held up"
|
event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
|
||||||
metadatas.add(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
|
event.cancel(); // "Are hands held up"
|
||||||
} else if (metadata.id() > 16) {
|
} else if (meta.id() > 16) {
|
||||||
metadata.setId(metadata.id() - 1);
|
meta.setId(meta.id() - 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (type.isOrHasParent(EntityTypes1_14.MINECART_ABSTRACT)) {
|
filter().type(EntityTypes1_14.MINECART_ABSTRACT).index(10).handler((event, meta) -> {
|
||||||
if (metadata.id() == 10) {
|
int data = meta.value();
|
||||||
// New block format
|
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||||
int data = (int) metadata.getValue();
|
});
|
||||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
|
||||||
}
|
|
||||||
} else if (type.is(EntityTypes1_14.HORSE)) {
|
|
||||||
if (metadata.id() == 18) {
|
|
||||||
metadatas.remove(metadata);
|
|
||||||
|
|
||||||
int armorType = (int) metadata.getValue();
|
filter().type(EntityTypes1_14.HORSE).index(18).handler((event, meta) -> {
|
||||||
|
event.cancel();
|
||||||
|
|
||||||
|
int armorType = meta.value();
|
||||||
Item armorItem = null;
|
Item armorItem = null;
|
||||||
if (armorType == 1) { //iron armor
|
if (armorType == 1) { //iron armor
|
||||||
armorItem = new DataItem(protocol.getMappingData().getNewItemId(727), (byte) 1, (short) 0, null);
|
armorItem = new DataItem(protocol.getMappingData().getNewItemId(727), (byte) 1, (short) 0, null);
|
||||||
@ -131,56 +113,63 @@ public class MetadataRewriter1_14To1_13_2 extends EntityRewriter<ClientboundPack
|
|||||||
armorItem = new DataItem(protocol.getMappingData().getNewItemId(729), (byte) 1, (short) 0, null);
|
armorItem = new DataItem(protocol.getMappingData().getNewItemId(729), (byte) 1, (short) 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketWrapper equipmentPacket = PacketWrapper.create(ClientboundPackets1_14.ENTITY_EQUIPMENT, null, connection);
|
PacketWrapper equipmentPacket = PacketWrapper.create(ClientboundPackets1_14.ENTITY_EQUIPMENT, null, event.user());
|
||||||
equipmentPacket.write(Type.VAR_INT, entityId);
|
equipmentPacket.write(Type.VAR_INT, event.entityId());
|
||||||
equipmentPacket.write(Type.VAR_INT, 4);
|
equipmentPacket.write(Type.VAR_INT, 4);
|
||||||
equipmentPacket.write(Type.ITEM1_13_2, armorItem);
|
equipmentPacket.write(Type.ITEM1_13_2, armorItem);
|
||||||
|
try {
|
||||||
equipmentPacket.scheduleSend(Protocol1_14To1_13_2.class);
|
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));
|
|
||||||
}
|
|
||||||
} 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} 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)) {
|
filter().type(EntityTypes1_14.VILLAGER).index(15).handler((event, meta) -> {
|
||||||
if (metadata.id() == 14) {
|
meta.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId(meta.value()), 0));
|
||||||
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)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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 (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
|
if (meta.id() >= 14) { // 19w13 added a new boolean (raid participant - is celebrating) with id 14
|
||||||
metadata.setId(metadata.id() + 1);
|
meta.setId(meta.id() + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,10 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets;
|
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.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_13;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
|
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.metadata.Metadata;
|
||||||
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;
|
||||||
@ -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.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.metadata.MetadataRewriter1_14To1_13_2;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -41,6 +41,18 @@ public class EntityPackets {
|
|||||||
public static void register(Protocol1_14To1_13_2 protocol) {
|
public static void register(Protocol1_14To1_13_2 protocol) {
|
||||||
MetadataRewriter1_14To1_13_2 metadataRewriter = protocol.get(MetadataRewriter1_14To1_13_2.class);
|
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() {
|
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_ENTITY, new PacketHandlers() {
|
||||||
@Override
|
@Override
|
||||||
public void register() {
|
public void register() {
|
||||||
@ -144,6 +156,7 @@ public class EntityPackets {
|
|||||||
map(Type.VAR_INT);
|
map(Type.VAR_INT);
|
||||||
map(Type.POSITION1_8, Type.POSITION1_14);
|
map(Type.POSITION1_8, Type.POSITION1_14);
|
||||||
map(Type.BYTE);
|
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
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
metadataRewriter.register();
|
super.registerPackets();
|
||||||
itemRewriter.register();
|
|
||||||
|
|
||||||
EntityPackets.register(this);
|
EntityPackets.register(this);
|
||||||
WorldPackets.register(this);
|
WorldPackets.register(this);
|
||||||
|
@ -17,18 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata;
|
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.entities.EntityType;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
|
||||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_14_4to1_14_3.ClientboundPackets1_14_4;
|
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.Protocol1_15To1_14_4;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.EntityPackets;
|
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.EntityPackets;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
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> {
|
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
|
@Override
|
||||||
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
protected void registerRewrites() {
|
||||||
if (metadata.metaType() == Types1_14.META_TYPES.itemType) {
|
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.blockStateType, null, Types1_14.META_TYPES.particleType);
|
||||||
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
|
filter().type(EntityTypes1_15.MINECART_ABSTRACT).index(10).handler((metadatas, meta) -> {
|
||||||
} else if (metadata.metaType() == Types1_14.META_TYPES.blockStateType) {
|
int data = meta.value();
|
||||||
// Convert to new block id
|
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||||
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;
|
filter().type(EntityTypes1_15.LIVINGENTITY).addIndex(12);
|
||||||
|
filter().type(EntityTypes1_15.WOLF).removeIndex(18);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -47,8 +47,7 @@ public class Protocol1_16_2To1_16_1 extends AbstractProtocol<ClientboundPackets1
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
metadataRewriter.register();
|
super.registerPackets();
|
||||||
itemRewriter.register();
|
|
||||||
|
|
||||||
EntityPackets.register(this);
|
EntityPackets.register(this);
|
||||||
WorldPackets.register(this);
|
WorldPackets.register(this);
|
||||||
|
@ -17,18 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.metadata;
|
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;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16_2;
|
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.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_16_2to1_16_1.Protocol1_16_2To1_16_1;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
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> {
|
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
|
@Override
|
||||||
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
protected void registerRewrites() {
|
||||||
if (metadata.metaType() == Types1_16.META_TYPES.itemType) {
|
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.blockStateType, null, Types1_16.META_TYPES.particleType);
|
||||||
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
|
filter().type(EntityTypes1_16_2.MINECART_ABSTRACT).index(10).handler((metadatas, meta) -> {
|
||||||
} else if (metadata.metaType() == Types1_16.META_TYPES.blockStateType) {
|
int data = meta.value();
|
||||||
int data = (int) metadata.getValue();
|
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
});
|
||||||
} else if (metadata.metaType() == Types1_16.META_TYPES.particleType) {
|
filter().type(EntityTypes1_16_2.ABSTRACT_PIGLIN).handler((metadatas, meta) -> {
|
||||||
rewriteParticle((Particle) metadata.getValue());
|
if (meta.id() == 15) {
|
||||||
}
|
meta.setId(16);
|
||||||
|
} else if (meta.id() == 16) {
|
||||||
if (type == null) return;
|
meta.setId(15);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,8 +69,7 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
metadataRewriter.register();
|
super.registerPackets();
|
||||||
itemRewriter.register();
|
|
||||||
|
|
||||||
EntityPackets.register(this);
|
EntityPackets.register(this);
|
||||||
WorldPackets.register(this);
|
WorldPackets.register(this);
|
||||||
|
@ -17,18 +17,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata;
|
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_15;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
|
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.metadata.Metadata;
|
||||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_16;
|
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_15to1_14_4.ClientboundPackets1_15;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
|
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MetadataRewriter1_16To1_15_2 extends EntityRewriter<ClientboundPackets1_15, Protocol1_16To1_15_2> {
|
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
|
@Override
|
||||||
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
protected void registerRewrites() {
|
||||||
metadata.setMetaType(Types1_16.META_TYPES.byId(metadata.metaType().typeId()));
|
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.blockStateType, null, Types1_16.META_TYPES.particleType);
|
||||||
if (metadata.metaType() == Types1_16.META_TYPES.itemType) {
|
filter().type(EntityTypes1_16.MINECART_ABSTRACT).index(10).handler((metadatas, meta) -> {
|
||||||
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
|
int data = meta.value();
|
||||||
} else if (metadata.metaType() == Types1_16.META_TYPES.blockStateType) {
|
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||||
int data = (int) metadata.getValue();
|
});
|
||||||
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
filter().type(EntityTypes1_16.ABSTRACT_ARROW).removeIndex(8);
|
||||||
} else if (metadata.metaType() == Types1_16.META_TYPES.particleType) {
|
filter().type(EntityTypes1_16.WOLF).index(16).handler((event, meta) -> {
|
||||||
rewriteParticle((Particle) metadata.getValue());
|
byte mask = meta.value();
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
int angerTime = (mask & 0x02) != 0 ? Integer.MAX_VALUE : 0;
|
||||||
metadatas.add(new Metadata(20, Types1_16.META_TYPES.varIntType, angerTime));
|
event.createExtraMeta(new Metadata(20, Types1_16.META_TYPES.varIntType, angerTime));
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -151,23 +151,20 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_16_2
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
filter().handler((event, meta) -> {
|
filter().mapMetaType(Types1_17.META_TYPES::byId);
|
||||||
meta.setMetaType(Types1_17.META_TYPES.byId(meta.metaType().typeId()));
|
filter().metaType(Types1_17.META_TYPES.poseType).handler((event, meta) -> {
|
||||||
|
|
||||||
if (meta.metaType() == Types1_17.META_TYPES.poseType) {
|
|
||||||
int pose = meta.value();
|
int pose = meta.value();
|
||||||
if (pose > 5) {
|
if (pose > 5) {
|
||||||
// Added LONG_JUMP at 6
|
// Added LONG_JUMP at 6
|
||||||
meta.setValue(pose + 1);
|
meta.setValue(pose + 1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
registerMetaTypeHandler(Types1_17.META_TYPES.itemType, Types1_17.META_TYPES.blockStateType, null, Types1_17.META_TYPES.particleType);
|
registerMetaTypeHandler(Types1_17.META_TYPES.itemType, Types1_17.META_TYPES.blockStateType, null, Types1_17.META_TYPES.particleType);
|
||||||
|
|
||||||
// Ticks frozen added with id 7
|
// 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
|
// Convert to new block id
|
||||||
int data = (int) meta.getValue();
|
int data = (int) meta.getValue();
|
||||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||||
|
@ -81,9 +81,8 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_17_1
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
filter().handler((event, meta) -> {
|
filter().mapMetaType(Types1_18.META_TYPES::byId);
|
||||||
meta.setMetaType(Types1_18.META_TYPES.byId(meta.metaType().typeId()));
|
filter().metaType(Types1_18.META_TYPES.particleType).handler((event, meta) -> {
|
||||||
if (meta.metaType() == Types1_18.META_TYPES.particleType) {
|
|
||||||
final Particle particle = (Particle) meta.getValue();
|
final Particle particle = (Particle) meta.getValue();
|
||||||
if (particle.getId() == 2) { // Barrier
|
if (particle.getId() == 2) { // Barrier
|
||||||
particle.setId(3); // Block marker
|
particle.setId(3); // Block marker
|
||||||
@ -93,7 +92,6 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_17_1
|
|||||||
} else {
|
} else {
|
||||||
rewriteParticle(particle);
|
rewriteParticle(particle);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
registerMetaTypeHandler(Types1_18.META_TYPES.itemType, null, null, null);
|
registerMetaTypeHandler(Types1_18.META_TYPES.itemType, null, null, null);
|
||||||
|
@ -42,6 +42,8 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_1
|
|||||||
@Override
|
@Override
|
||||||
public void registerPackets() {
|
public void registerPackets() {
|
||||||
registerTrackerWithData1_19(ClientboundPackets1_19_1.SPAWN_ENTITY, EntityTypes1_19_3.FALLING_BLOCK);
|
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);
|
registerMetadataRewriter(ClientboundPackets1_19_1.ENTITY_METADATA, Types1_19.METADATA_LIST, Types1_19_3.METADATA_LIST);
|
||||||
registerRemoveEntities(ClientboundPackets1_19_1.REMOVE_ENTITIES);
|
registerRemoveEntities(ClientboundPackets1_19_1.REMOVE_ENTITIES);
|
||||||
|
|
||||||
@ -59,6 +61,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_1
|
|||||||
handler(dimensionDataHandler());
|
handler(dimensionDataHandler());
|
||||||
handler(biomeSizeTracker());
|
handler(biomeSizeTracker());
|
||||||
handler(worldDataTrackerHandlerByKey());
|
handler(worldDataTrackerHandlerByKey());
|
||||||
|
handler(playerTrackerHandler());
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
// Also enable vanilla features
|
// Also enable vanilla features
|
||||||
final PacketWrapper enableFeaturesPacket = wrapper.create(ClientboundPackets1_19_3.UPDATE_ENABLED_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
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
filter().handler((event, meta) -> {
|
filter().mapMetaType(typeId -> Types1_19_3.META_TYPES.byId(typeId >= 2 ? typeId + 1 : typeId)); // Long added
|
||||||
final int id = meta.metaType().typeId();
|
|
||||||
meta.setMetaType(Types1_19_3.META_TYPES.byId(id >= 2 ? id + 1 : id)); // long added
|
|
||||||
});
|
|
||||||
registerMetaTypeHandler(Types1_19_3.META_TYPES.itemType, Types1_19_3.META_TYPES.blockStateType, null, Types1_19_3.META_TYPES.particleType);
|
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
|
// Sitting pose added
|
||||||
final int pose = meta.value();
|
final int pose = meta.value();
|
||||||
if (pose >= 10) {
|
if (pose >= 10) {
|
||||||
meta.setValue(pose + 1);
|
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
|
// Convert to new block id
|
||||||
final int data = (int) meta.getValue();
|
final int data = (int) meta.getValue();
|
||||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||||
|
@ -17,7 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.packets;
|
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.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.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
@ -222,28 +226,22 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
filter().handler((event, meta) -> {
|
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)
|
||||||
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));
|
|
||||||
});
|
|
||||||
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);
|
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();
|
final int blockState = meta.value();
|
||||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
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();
|
final int boatType = meta.value();
|
||||||
if (boatType > 4) { // Cherry added
|
if (boatType > 4) { // Cherry added
|
||||||
meta.setValue(boatType + 1);
|
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
|
@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.rewriter.EntityRewriter;
|
||||||
import com.viaversion.viaversion.util.Key;
|
import com.viaversion.viaversion.util.Key;
|
||||||
import com.viaversion.viaversion.util.Pair;
|
import com.viaversion.viaversion.util.Pair;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.*;
|
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> {
|
public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18, Protocol1_19To1_18_2> {
|
||||||
|
|
||||||
@ -349,11 +352,8 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
filter().handler((event, meta) -> {
|
filter().mapMetaType(Types1_19.META_TYPES::byId);
|
||||||
meta.setMetaType(Types1_19.META_TYPES.byId(meta.metaType().typeId()));
|
filter().metaType(Types1_19.META_TYPES.particleType).handler((event, meta) -> {
|
||||||
|
|
||||||
final MetaType type = meta.metaType();
|
|
||||||
if (type == Types1_19.META_TYPES.particleType) {
|
|
||||||
final Particle particle = (Particle) meta.getValue();
|
final Particle particle = (Particle) meta.getValue();
|
||||||
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
|
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
|
||||||
if (particle.getId() == particleMappings.id("vibration")) {
|
if (particle.getId() == particleMappings.id("vibration")) {
|
||||||
@ -368,18 +368,17 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
|
|||||||
}
|
}
|
||||||
|
|
||||||
rewriteParticle(particle);
|
rewriteParticle(particle);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
registerMetaTypeHandler(Types1_19.META_TYPES.itemType, Types1_19.META_TYPES.blockStateType, null, null);
|
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
|
// Convert to new block id
|
||||||
final int data = (int) meta.getValue();
|
final int data = (int) meta.getValue();
|
||||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
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
|
@Override
|
||||||
|
@ -174,12 +174,12 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
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);
|
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();
|
final int blockState = meta.value();
|
||||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||||
});
|
});
|
||||||
|
@ -106,8 +106,12 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
|
|||||||
meta.setTypeAndValue(Types1_20_3.META_TYPES.componentType, ComponentUtil.jsonToTag(meta.value()));
|
meta.setTypeAndValue(Types1_20_3.META_TYPES.componentType, ComponentUtil.jsonToTag(meta.value()));
|
||||||
} else if (type == Types1_20_2.META_TYPES.optionalComponentType) {
|
} else if (type == Types1_20_2.META_TYPES.optionalComponentType) {
|
||||||
meta.setTypeAndValue(Types1_20_3.META_TYPES.optionalComponentType, ComponentUtil.jsonToTag(meta.value()));
|
meta.setTypeAndValue(Types1_20_3.META_TYPES.optionalComponentType, ComponentUtil.jsonToTag(meta.value()));
|
||||||
} else if (type == Types1_20_2.META_TYPES.particleType) {
|
} else {
|
||||||
final Particle particle = (Particle) meta.getValue();
|
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();
|
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
|
||||||
if (particle.getId() == particleMappings.id("vibration")) {
|
if (particle.getId() == particleMappings.id("vibration")) {
|
||||||
// Change the type of the resource key argument
|
// Change the type of the resource key argument
|
||||||
@ -120,10 +124,6 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
|
|||||||
}
|
}
|
||||||
|
|
||||||
rewriteParticle(particle);
|
rewriteParticle(particle);
|
||||||
meta.setMetaType(Types1_20_3.META_TYPES.particleType);
|
|
||||||
} else {
|
|
||||||
meta.setMetaType(Types1_20_3.META_TYPES.byId(type.typeId()));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
registerMetaTypeHandler(
|
registerMetaTypeHandler(
|
||||||
@ -133,7 +133,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
|
|||||||
Types1_20_3.META_TYPES.particleType
|
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();
|
final int blockState = meta.value();
|
||||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||||
});
|
});
|
||||||
|
@ -17,7 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_20to1_19_4.packets;
|
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.Quaternion;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
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;
|
||||||
@ -123,11 +128,11 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_4
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
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);
|
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
|
// 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()) {
|
if (event.trackedEntity().hasSentMetadata() || event.hasExtraMeta()) {
|
||||||
return;
|
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));
|
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();
|
final Quaternion quaternion = meta.value();
|
||||||
meta.setValue(rotateY180(quaternion));
|
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();
|
final int blockState = meta.value();
|
||||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||||
});
|
});
|
||||||
|
@ -95,7 +95,7 @@ public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, Cl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
metadataRewriter.register();
|
super.registerPackets();
|
||||||
|
|
||||||
// Disconnect workaround (JSON!)
|
// Disconnect workaround (JSON!)
|
||||||
registerClientbound(State.LOGIN, 0x00, 0x00, wrapper -> {
|
registerClientbound(State.LOGIN, 0x00, 0x00, wrapper -> {
|
||||||
|
@ -17,11 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata;
|
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.EulerAngle;
|
||||||
import com.viaversion.viaversion.api.minecraft.Vector;
|
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.EntityType;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
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.ItemRewriter;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
import java.util.List;
|
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class MetadataRewriter1_9To1_8 extends EntityRewriter<ClientboundPackets1_8, Protocol1_9To1_8> {
|
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
|
@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());
|
MetaIndex metaIndex = MetaIndex.searchIndex(type, metadata.id());
|
||||||
if (metaIndex == null) {
|
if (metaIndex == null) {
|
||||||
throw new Exception("Could not find valid metadata");
|
// Almost certainly bad data, remove it
|
||||||
|
event.cancel();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metaIndex.getNewType() == null) {
|
if (metaIndex.getNewType() == null) {
|
||||||
metadatas.remove(metadata);
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +78,7 @@ public class MetadataRewriter1_9To1_8 extends EntityRewriter<ClientboundPackets1
|
|||||||
}
|
}
|
||||||
int newIndex = MetaIndex.PLAYER_HAND.getNewIndex();
|
int newIndex = MetaIndex.PLAYER_HAND.getNewIndex();
|
||||||
MetaType metaType = MetaIndex.PLAYER_HAND.getNewType();
|
MetaType metaType = MetaIndex.PLAYER_HAND.getNewType();
|
||||||
metadatas.add(new Metadata(newIndex, metaType, val));
|
event.createExtraMeta(new Metadata(newIndex, metaType, val));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OptUUID:
|
case OptUUID:
|
||||||
@ -129,8 +135,7 @@ public class MetadataRewriter1_9To1_8 extends EntityRewriter<ClientboundPackets1
|
|||||||
metadata.setValue(((Number) value).intValue());
|
metadata.setValue(((Number) value).intValue());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
metadatas.remove(metadata);
|
throw new RuntimeException("Unhandled MetaDataType: " + metaIndex.getNewType());
|
||||||
throw new Exception("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.IntTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.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.DimensionData;
|
||||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||||
import com.viaversion.viaversion.api.data.entity.TrackedEntity;
|
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.entities.EntityType;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
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.protocol.remapper.PacketHandlers;
|
||||||
import com.viaversion.viaversion.api.rewriter.RewriterBase;
|
import com.viaversion.viaversion.api.rewriter.RewriterBase;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
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.data.entity.DimensionDataImpl;
|
||||||
import com.viaversion.viaversion.rewriter.meta.MetaFilter;
|
import com.viaversion.viaversion.rewriter.meta.MetaFilter;
|
||||||
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent;
|
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 TrackedEntity entity = tracker(connection).entity(entityId);
|
||||||
final EntityType type = entity != null ? entity.entityType() : null;
|
final EntityType type = entity != null ? entity.entityType() : null;
|
||||||
for (final Metadata metadata : metadataList.toArray(EMPTY_ARRAY)) { // Copy the list to allow mutation
|
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;
|
MetaHandlerEvent event = null;
|
||||||
for (final MetaFilter filter : metadataFilters) {
|
for (final MetaFilter filter : metadataFilters) {
|
||||||
if (!filter.isFiltered(type, metadata)) {
|
if (!filter.isFiltered(type, metadata)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (event == null) {
|
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);
|
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 (event != null && event.hasExtraMeta()) {
|
||||||
if (extraMeta != null) {
|
|
||||||
// Finally, add newly created meta
|
// 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
|
@Override
|
||||||
public int newEntityId(int id) {
|
public int newEntityId(int id) {
|
||||||
return typeMappings != null ? typeMappings.getNewIdOrDefault(id, id) : 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) {
|
protected void rewriteParticle(Particle particle) {
|
||||||
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
|
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
|
||||||
int id = particle.getId();
|
int id = particle.getId();
|
||||||
|
@ -20,20 +20,24 @@ package com.viaversion.viaversion.rewriter.meta;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectFunction;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class MetaFilter {
|
public class MetaFilter {
|
||||||
private final MetaHandler handler;
|
private final MetaHandler handler;
|
||||||
private final EntityType type;
|
private final EntityType type;
|
||||||
|
private final MetaType metaType;
|
||||||
private final int index;
|
private final int index;
|
||||||
private final boolean filterFamily;
|
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");
|
Preconditions.checkNotNull(handler, "MetaHandler cannot be null");
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.metaType = metaType;
|
||||||
this.filterFamily = filterFamily;
|
this.filterFamily = filterFamily;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
@ -57,6 +61,15 @@ public class MetaFilter {
|
|||||||
return type;
|
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.
|
* Returns the metadata handler.
|
||||||
*
|
*
|
||||||
@ -86,7 +99,8 @@ public class MetaFilter {
|
|||||||
// Check if no specific index is filtered or the indexes are equal
|
// 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
|
// 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)
|
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) {
|
private boolean matchesType(@Nullable EntityType type) {
|
||||||
@ -101,6 +115,7 @@ public class MetaFilter {
|
|||||||
if (index != that.index) return false;
|
if (index != that.index) return false;
|
||||||
if (filterFamily != that.filterFamily) return false;
|
if (filterFamily != that.filterFamily) return false;
|
||||||
if (!handler.equals(that.handler)) return false;
|
if (!handler.equals(that.handler)) return false;
|
||||||
|
if (!Objects.equals(metaType, that.metaType)) return false;
|
||||||
return Objects.equals(type, that.type);
|
return Objects.equals(type, that.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +123,7 @@ public class MetaFilter {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = handler.hashCode();
|
int result = handler.hashCode();
|
||||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||||
|
result = 31 * result + (metaType != null ? metaType.hashCode() : 0);
|
||||||
result = 31 * result + index;
|
result = 31 * result + index;
|
||||||
result = 31 * result + (filterFamily ? 1 : 0);
|
result = 31 * result + (filterFamily ? 1 : 0);
|
||||||
return result;
|
return result;
|
||||||
@ -118,6 +134,7 @@ public class MetaFilter {
|
|||||||
return "MetaFilter{" +
|
return "MetaFilter{" +
|
||||||
"type=" + type +
|
"type=" + type +
|
||||||
", filterFamily=" + filterFamily +
|
", filterFamily=" + filterFamily +
|
||||||
|
", metaType=" + metaType +
|
||||||
", index=" + index +
|
", index=" + index +
|
||||||
", handler=" + handler +
|
", handler=" + handler +
|
||||||
'}';
|
'}';
|
||||||
@ -126,6 +143,7 @@ public class MetaFilter {
|
|||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
private final EntityRewriter<?, ?> rewriter;
|
private final EntityRewriter<?, ?> rewriter;
|
||||||
private EntityType type;
|
private EntityType type;
|
||||||
|
private MetaType metaType;
|
||||||
private int index = -1;
|
private int index = -1;
|
||||||
private boolean filterFamily;
|
private boolean filterFamily;
|
||||||
private MetaHandler handler;
|
private MetaHandler handler;
|
||||||
@ -134,9 +152,43 @@ public class MetaFilter {
|
|||||||
this.rewriter = rewriter;
|
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) {
|
public Builder type(EntityType type) {
|
||||||
Preconditions.checkArgument(this.type == null);
|
Preconditions.checkArgument(this.type == null);
|
||||||
this.type = type;
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,13 +198,6 @@ public class MetaFilter {
|
|||||||
return this;
|
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) {
|
public Builder handlerNoRegister(MetaHandler handler) {
|
||||||
Preconditions.checkArgument(this.handler == null);
|
Preconditions.checkArgument(this.handler == null);
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
@ -172,6 +217,17 @@ public class MetaFilter {
|
|||||||
register();
|
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.
|
* Sets a handler to remove metadata at the given index without affecting any other indexes and registers the filter.
|
||||||
* Should always be called last.
|
* Should always be called last.
|
||||||
@ -243,7 +299,7 @@ public class MetaFilter {
|
|||||||
* @return created meta filter
|
* @return created meta filter
|
||||||
*/
|
*/
|
||||||
public MetaFilter build() {
|
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
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
/* Uncomment if metatype classes changed
|
/* Uncomment if metatype classes changed
|
||||||
filter().handler((event, meta) -> {
|
filter().mapMetaType(typeId -> {
|
||||||
int id = meta.metaType().typeId();
|
int id = typeId;
|
||||||
if (id >= SomeAddedIndex) {
|
if (id >= SomeAddedIndex) {
|
||||||
id++;
|
id++;
|
||||||
}
|
}
|
||||||
meta.setMetaType(Types1_20_3.META_TYPES.byId(id));
|
return Types1_20_3.META_TYPES.byId(id);
|
||||||
});*/
|
});*/
|
||||||
|
|
||||||
// Registers registry type id changes
|
// Registers registry type id changes
|
||||||
@ -101,7 +101,7 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Minecarts are special
|
// 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();
|
final int blockState = meta.value();
|
||||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||||
});
|
});
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren