Merge pull request #18 from ViaVersion/update/via

Updated Via API usage
This commit is contained in:
RK_01 2023-10-19 18:34:24 +00:00 committed by GitHub
commit 0b6ebf7c77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 40 deletions

View File

@ -22,8 +22,8 @@ repositories {
}
dependencies {
compileOnly "com.viaversion:viaversion:4.9.0-23w40a-SNAPSHOT"
compileOnly("com.viaversion:viabackwards-common:4.9.0-23w40a-SNAPSHOT") {
compileOnly "com.viaversion:viaversion:4.9.0-23w42a-SNAPSHOT"
compileOnly("com.viaversion:viabackwards-common:4.9.0-23w42a-SNAPSHOT") {
exclude group: "com.viaversion", module: "viaversion"
}
compileOnly "org.yaml:snakeyaml:2.2"

View File

@ -33,13 +33,13 @@ public class BlockItemPackets3D_Shareware extends ItemRewriter<ClientboundPacket
@Override
protected void registerPackets() {
this.registerSetCooldown(ClientboundPackets3D_Shareware.COOLDOWN);
this.registerWindowItems(ClientboundPackets3D_Shareware.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
this.registerSetSlot(ClientboundPackets3D_Shareware.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
this.registerEntityEquipment(ClientboundPackets3D_Shareware.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
this.registerAdvancements(ClientboundPackets3D_Shareware.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
this.registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
this.registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
this.registerSpawnParticle(ClientboundPackets3D_Shareware.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.FLOAT);
this.registerWindowItems(ClientboundPackets3D_Shareware.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY);
this.registerSetSlot(ClientboundPackets3D_Shareware.SET_SLOT, Type.ITEM1_13_2);
this.registerEntityEquipment(ClientboundPackets3D_Shareware.ENTITY_EQUIPMENT, Type.ITEM1_13_2);
this.registerAdvancements(ClientboundPackets3D_Shareware.ADVANCEMENTS, Type.ITEM1_13_2);
this.registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.ITEM1_13_2);
this.registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
this.registerSpawnParticle(ClientboundPackets3D_Shareware.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.FLOAT);
this.protocol.registerClientbound(ClientboundPackets3D_Shareware.TRADE_LIST, new PacketHandlers() {
public void register() {
@ -48,10 +48,10 @@ public class BlockItemPackets3D_Shareware extends ItemRewriter<ClientboundPacket
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; ++i) {
BlockItemPackets3D_Shareware.this.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
BlockItemPackets3D_Shareware.this.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
BlockItemPackets3D_Shareware.this.handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
BlockItemPackets3D_Shareware.this.handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
if (wrapper.passthrough(Type.BOOLEAN)) {
BlockItemPackets3D_Shareware.this.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
BlockItemPackets3D_Shareware.this.handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
}
wrapper.passthrough(Type.BOOLEAN);

View File

@ -18,7 +18,6 @@
package net.raphimc.viaaprilfools.protocols.protocol1_14to3D_Shareware.packets;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
@ -81,7 +80,7 @@ public class EntityPackets3D_Shareware {
public void handleMetadata(final List<Metadata> metadataList) {
for (Metadata metadata : metadataList) {
if (metadata.metaType() == MetaType1_14.Slot) {
if (metadata.metaType() == Types1_14.META_TYPES.itemType) {
metadata.setValue(this.protocol.getItemRewriter().handleItemToClient(metadata.value()));
}
}

View File

@ -23,7 +23,7 @@ import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
@ -171,7 +171,7 @@ public class Protocol1_16to20w14infinite extends BackwardsProtocol<ClientboundPa
@Override
public void init(UserConnection userConnection) {
userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, Entity1_16Types.PLAYER));
userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, EntityTypes1_16.PLAYER));
}
@Override

View File

@ -18,11 +18,11 @@
package net.raphimc.viaaprilfools.protocols.protocol1_16to20w14infinite.metadata;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import net.raphimc.viaaprilfools.protocols.protocol1_16to20w14infinite.ClientboundPackets20w14infinite;
import net.raphimc.viaaprilfools.protocols.protocol1_16to20w14infinite.Protocol1_16to20w14infinite;
@ -33,36 +33,36 @@ public class MetadataRewriter1_16to20w14infinite extends EntityRewriter<Clientbo
public MetadataRewriter1_16to20w14infinite(Protocol1_16to20w14infinite protocol) {
super(protocol);
mapEntityType(Entity20w14infiniteTypes.ZOMBIE_PIGMAN, Entity1_16Types.ZOMBIFIED_PIGLIN);
mapTypes(Entity20w14infiniteTypes.values(), Entity1_16Types.class);
mapEntityType(Entity20w14infiniteTypes.ZOMBIE_PIGMAN, EntityTypes1_16.ZOMBIFIED_PIGLIN);
mapTypes(Entity20w14infiniteTypes.values(), EntityTypes1_16.class);
}
@Override
public EntityType typeFromId(int type) {
return Entity1_16Types.getTypeFromId(type);
return EntityTypes1_16.getTypeFromId(type);
}
@Override
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
if (metadata.metaType() == MetaType1_14.Slot) {
if (metadata.metaType() == Types1_14.META_TYPES.itemType) {
metadata.setValue(this.protocol.getItemRewriter().handleItemToClient(metadata.value()));
} else if (metadata.metaType() == MetaType1_14.BlockID) {
} else if (metadata.metaType() == Types1_14.META_TYPES.blockStateType) {
int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (metadata.metaType() == MetaType1_14.PARTICLE) {
} else if (metadata.metaType() == Types1_14.META_TYPES.particleType) {
rewriteParticle((Particle) metadata.getValue());
}
if (type == null) return;
if (type.isOrHasParent(Entity1_16Types.MINECART_ABSTRACT)
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(Entity1_16Types.ABSTRACT_ARROW)) {
if (type.isOrHasParent(EntityTypes1_16.ABSTRACT_ARROW)) {
if (metadata.id() == 8) {
metadatas.remove(metadata);
} else if (metadata.id() > 8) {

View File

@ -47,13 +47,13 @@ public class BlockItemPackets20w14infinite extends ItemRewriter<ClientboundPacke
@Override
protected void registerPackets() {
this.registerSetCooldown(ClientboundPackets20w14infinite.COOLDOWN);
this.registerWindowItems(ClientboundPackets20w14infinite.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
this.registerSetSlot(ClientboundPackets20w14infinite.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
this.registerWindowItems(ClientboundPackets20w14infinite.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY);
this.registerSetSlot(ClientboundPackets20w14infinite.SET_SLOT, Type.ITEM1_13_2);
this.registerTradeList(ClientboundPackets20w14infinite.TRADE_LIST);
this.registerAdvancements(ClientboundPackets20w14infinite.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
this.registerSpawnParticle(ClientboundPackets20w14infinite.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
this.registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
this.registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
this.registerAdvancements(ClientboundPackets20w14infinite.ADVANCEMENTS, Type.ITEM1_13_2);
this.registerSpawnParticle(ClientboundPackets20w14infinite.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.DOUBLE);
this.registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.ITEM1_13_2);
this.registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
final BlockRewriter<ClientboundPackets20w14infinite> blockRewriter = new BlockRewriter<>(this.protocol, Type.POSITION1_14);
blockRewriter.registerBlockAction(ClientboundPackets20w14infinite.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets20w14infinite.BLOCK_CHANGE);
@ -114,7 +114,7 @@ public class BlockItemPackets20w14infinite extends ItemRewriter<ClientboundPacke
handler(wrapper -> {
int slot = wrapper.read(Type.VAR_INT);
wrapper.write(Type.BYTE, (byte) slot);
handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
});
}
});
@ -122,7 +122,7 @@ public class BlockItemPackets20w14infinite extends ItemRewriter<ClientboundPacke
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketHandlers() {
@Override
public void register() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2)));
}
});
}

View File

@ -18,7 +18,7 @@
package net.raphimc.viaaprilfools.protocols.protocol1_16to20w14infinite.packets;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
@ -61,19 +61,19 @@ public class EntityPackets20w14infinite {
public static void register(Protocol1_16to20w14infinite protocol) {
MetadataRewriter1_16to20w14infinite metadataRewriter = protocol.get(MetadataRewriter1_16to20w14infinite.class);
metadataRewriter.registerTrackerWithData(ClientboundPackets20w14infinite.SPAWN_ENTITY, Entity1_16Types.FALLING_BLOCK);
metadataRewriter.registerTrackerWithData(ClientboundPackets20w14infinite.SPAWN_ENTITY, EntityTypes1_16.FALLING_BLOCK);
metadataRewriter.registerTracker(ClientboundPackets20w14infinite.SPAWN_MOB);
metadataRewriter.registerTracker(ClientboundPackets20w14infinite.SPAWN_PLAYER, Entity1_16Types.PLAYER);
metadataRewriter.registerTracker(ClientboundPackets20w14infinite.SPAWN_PLAYER, EntityTypes1_16.PLAYER);
metadataRewriter.registerMetadataRewriter(ClientboundPackets20w14infinite.ENTITY_METADATA, Types1_14.METADATA_LIST);
metadataRewriter.registerRemoveEntities(ClientboundPackets20w14infinite.DESTROY_ENTITIES);
// Spawn lightning -> Spawn entity
protocol.registerClientbound(ClientboundPackets20w14infinite.SPAWN_GLOBAL_ENTITY, ClientboundPackets1_16.SPAWN_ENTITY, wrapper -> {
final int entityId = wrapper.passthrough(Type.VAR_INT); // entity id
wrapper.user().getEntityTracker(Protocol1_16to20w14infinite.class).addEntity(entityId, Entity1_16Types.LIGHTNING_BOLT);
wrapper.user().getEntityTracker(Protocol1_16to20w14infinite.class).addEntity(entityId, EntityTypes1_16.LIGHTNING_BOLT);
wrapper.write(Type.UUID, UUID.randomUUID()); // uuid
wrapper.write(Type.VAR_INT, Entity1_16Types.LIGHTNING_BOLT.getId()); // entity type
wrapper.write(Type.VAR_INT, EntityTypes1_16.LIGHTNING_BOLT.getId()); // entity type
wrapper.read(Type.BYTE); // remove type
@ -117,7 +117,7 @@ public class EntityPackets20w14infinite {
map(Type.LONG); // Seed
map(Type.UNSIGNED_BYTE); // Max players
handler(wrapper -> {
wrapper.user().getEntityTracker(Protocol1_16to20w14infinite.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16Types.PLAYER);
wrapper.user().getEntityTracker(Protocol1_16to20w14infinite.class).addEntity(wrapper.get(Type.INT, 0), EntityTypes1_16.PLAYER);
final String type = wrapper.read(Type.STRING);// level type
wrapper.passthrough(Type.VAR_INT); // View distance