Skip to content

Commit

Permalink
Updated Via API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Oct 19, 2023
1 parent 26d149e commit 3afef18
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,7 +80,7 @@ public void register() {

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()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
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;
Expand Down Expand Up @@ -171,7 +171,7 @@ protected void onMappingDataLoaded() {

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -117,7 +117,7 @@ public void register() {
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
Expand Down

0 comments on commit 3afef18

Please sign in to comment.