Skip to content

Commit

Permalink
Merge pull request #49 from ViaVersion/update/via
Browse files Browse the repository at this point in the history
Updated Via API usage
  • Loading branch information
RaphiMC authored Oct 19, 2023
2 parents 3b81f9c + f79660e commit 4c3abc8
Show file tree
Hide file tree
Showing 44 changed files with 358 additions and 353 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repositories {
}

dependencies {
compileOnly "com.viaversion:viaversion:4.9.0-23w40a-SNAPSHOT"
compileOnly "com.viaversion:viaversion:4.9.0-23w42a-SNAPSHOT"
compileOnly "org.yaml:snakeyaml:2.2"
compileOnly "com.google.guava:guava:32.1.3-jre"
compileOnly "io.netty:netty-handler:4.1.100.Final"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

import com.google.common.collect.Lists;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import net.raphimc.vialegacy.api.model.IdAndData;
import net.raphimc.vialegacy.api.protocol.StatelessProtocol;
import net.raphimc.vialegacy.api.splitter.PreNettySplitter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.types;

import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.types.minecraft.OldMetaType;
import com.viaversion.viaversion.api.type.types.metadata.OldMetaType;

public class MetadataType extends OldMetaType {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.minecraft.MetaListType;
import com.viaversion.viaversion.api.type.types.metadata.MetaListType;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1.types;

import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.types.minecraft.OldMetaType;
import com.viaversion.viaversion.api.type.types.metadata.OldMetaType;

public class MetadataType extends OldMetaType {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.minecraft.MetaListType;
import com.viaversion.viaversion.api.type.types.metadata.MetaListType;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.viaversion.viaversion.api.minecraft.chunks.*;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.CustomByteType;
import com.viaversion.viaversion.api.type.types.minecraft.BaseChunkType;
import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.api.model.IdAndData;
import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.chunks.NibbleArray1_1;
Expand All @@ -32,9 +32,9 @@
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

public class Chunk1_1Type extends Type<Chunk> {
public class ChunkType1_1 extends Type<Chunk> {

public Chunk1_1Type() {
public ChunkType1_1() {
super(Chunk.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
public class Types1_1 {

public static Type<BlockChangeRecord[]> BLOCK_CHANGE_RECORD_ARRAY = new BlockChangeRecordArrayType();
public static Type<Chunk> CHUNK = new Chunk1_1Type();
public static Type<Chunk> CHUNK = new ChunkType1_1();

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Environment;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.chunks.*;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
Expand All @@ -36,7 +37,6 @@
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import net.raphimc.vialegacy.ViaLegacy;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialegacy.api.data.BlockList1_6;
Expand Down Expand Up @@ -67,7 +67,7 @@
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.types.Types1_6_4;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.metadata.MetaIndex1_8to1_7_6;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Chunk1_7_6Type;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ChunkType1_7_6;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6;

import java.util.ArrayList;
Expand Down Expand Up @@ -145,7 +145,7 @@ public void register() {
wrapper.user().get(DimensionTracker.class).setDimension(wrapper.get(Type.BYTE, 1));
final EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
entityTracker.setPlayerID(wrapper.get(Type.INT, 0));
entityTracker.getTrackedEntities().put(entityTracker.getPlayerID(), new TrackedLivingEntity(entityTracker.getPlayerID(), new Location(8, 64, 8), Entity1_10Types.EntityType.PLAYER));
entityTracker.getTrackedEntities().put(entityTracker.getPlayerID(), new TrackedLivingEntity(entityTracker.getPlayerID(), new Location(8, 64, 8), EntityTypes1_10.EntityType.PLAYER));
});
}
});
Expand Down Expand Up @@ -178,7 +178,7 @@ public void register() {
wrapper.user().get(ChestStateTracker.class).clear();
final EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
entityTracker.getTrackedEntities().clear();
entityTracker.getTrackedEntities().put(entityTracker.getPlayerID(), new TrackedLivingEntity(entityTracker.getPlayerID(), new Location(8, 64, 8), Entity1_10Types.EntityType.PLAYER));
entityTracker.getTrackedEntities().put(entityTracker.getPlayerID(), new TrackedLivingEntity(entityTracker.getPlayerID(), new Location(8, 64, 8), EntityTypes1_10.EntityType.PLAYER));
}
});
}
Expand All @@ -201,7 +201,7 @@ public void register() {
final double y = wrapper.get(Type.INT, 2) / 32.0D;
final double z = wrapper.get(Type.INT, 3) / 32.0D;
final EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.getTrackedEntities().put(entityId, new TrackedLivingEntity(entityId, new Location(x, y, z), Entity1_10Types.EntityType.PLAYER));
tracker.getTrackedEntities().put(entityId, new TrackedLivingEntity(entityId, new Location(x, y, z), EntityTypes1_10.EntityType.PLAYER));
});
}
});
Expand All @@ -222,7 +222,7 @@ public void register() {
final double x = wrapper.get(Type.INT, 1) / 32.0D;
final double y = wrapper.get(Type.INT, 2) / 32.0D;
final double z = wrapper.get(Type.INT, 3) / 32.0D;
tracker.getTrackedEntities().put(entityId, new TrackedEntity(entityId, new Location(x, y, z), Entity1_10Types.ObjectType.ITEM.getType()));
tracker.getTrackedEntities().put(entityId, new TrackedEntity(entityId, new Location(x, y, z), EntityTypes1_10.ObjectType.ITEM.getType()));
});
}
});
Expand All @@ -249,14 +249,14 @@ public void register() {
final EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
final int entityId = wrapper.get(Type.INT, 0);
final byte typeId = wrapper.get(Type.BYTE, 0);
final Entity1_10Types.EntityType type;
final EntityTypes1_10.EntityType type;
if (typeId == 70 || typeId == 71 || typeId == 74) {
type = Entity1_10Types.ObjectType.FALLING_BLOCK.getType();
wrapper.set(Type.BYTE, 0, (byte) Entity1_10Types.ObjectType.FALLING_BLOCK.getId());
type = EntityTypes1_10.ObjectType.FALLING_BLOCK.getType();
wrapper.set(Type.BYTE, 0, (byte) EntityTypes1_10.ObjectType.FALLING_BLOCK.getId());
} else if (typeId == 10 || typeId == 11 || typeId == 12) {
type = Entity1_10Types.ObjectType.MINECART.getType();
type = EntityTypes1_10.ObjectType.MINECART.getType();
} else {
type = Entity1_10Types.getTypeFromId(typeId, true);
type = EntityTypes1_10.getTypeFromId(typeId, true);
}
final double x = wrapper.get(Type.INT, 1) / 32.0D;
final double y = wrapper.get(Type.INT, 2) / 32.0D;
Expand All @@ -274,8 +274,8 @@ public void register() {
if (typeId == 70) throwerEntityId = 12; // sand
if (typeId == 71) throwerEntityId = 13; // gravel
if (typeId == 74) throwerEntityId = 122; // dragon egg
if (typeId == Entity1_10Types.ObjectType.FISHIHNG_HOOK.getId()) {
final Optional<AbstractTrackedEntity> nearestEntity = entityTracker.getNearestEntity(location, 2.0D, e -> e.getEntityType().isOrHasParent(Entity1_10Types.EntityType.PLAYER));
if (typeId == EntityTypes1_10.ObjectType.FISHIHNG_HOOK.getId()) {
final Optional<AbstractTrackedEntity> nearestEntity = entityTracker.getNearestEntity(location, 2.0D, e -> e.getEntityType().isOrHasParent(EntityTypes1_10.EntityType.PLAYER));
throwerEntityId = nearestEntity.map(AbstractTrackedEntity::getEntityId).orElseGet(entityTracker::getPlayerID);
}
wrapper.set(Type.INT, 4, throwerEntityId);
Expand All @@ -286,7 +286,7 @@ public void register() {
}

entityTracker.getTrackedEntities().put(entityId, new TrackedEntity(entityId, location, type));
final Entity1_10Types.ObjectType objectType = Entity1_10Types.ObjectType.findById(typeId).orElse(null);
final EntityTypes1_10.ObjectType objectType = EntityTypes1_10.ObjectType.findById(typeId).orElse(null);
if (objectType == null) return;

float pitch;
Expand Down Expand Up @@ -334,7 +334,7 @@ public void register() {
final double y = wrapper.get(Type.INT, 2) / 32.0D;
final double z = wrapper.get(Type.INT, 3) / 32.0D;
final List<Metadata> metadataList = wrapper.get(Types1_3_1.METADATA_LIST, 0);
final Entity1_10Types.EntityType entityType = Entity1_10Types.getTypeFromId(type, false);
final EntityTypes1_10.EntityType entityType = EntityTypes1_10.getTypeFromId(type, false);
final EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.getTrackedEntities().put(entityId, new TrackedLivingEntity(entityId, new Location(x, y, z), entityType));
tracker.updateEntityMetadata(entityId, metadataList);
Expand Down Expand Up @@ -459,7 +459,7 @@ public void register() {

if (!load) {
final Chunk chunk = new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], null, new ArrayList<>());
wrapper.write(new Chunk1_7_6Type(wrapper.user().get(ClientWorld.class)), chunk);
wrapper.write(new ChunkType1_7_6(wrapper.user().get(ClientWorld.class)), chunk);
} else {
wrapper.cancel();
}
Expand Down Expand Up @@ -496,7 +496,7 @@ public void register() {
}
}
}
wrapper.write(new Chunk1_7_6Type(clientWorld), chunk);
wrapper.write(new ChunkType1_7_6(clientWorld), chunk);
});
}
});
Expand Down Expand Up @@ -807,7 +807,7 @@ private void handleEntityMetadata(final int entityId, final List<Metadata> metad
if (index == MetaIndex1_8to1_7_6.ENTITY_FLAGS) {
if ((metadata.<Byte>value() & 4) != 0) { // entity mount
final Optional<AbstractTrackedEntity> oNearbyEntity = tracker.getNearestEntity(entity.getLocation(), 1.0D, e -> {
return e.getEntityType().isOrHasParent(Entity1_10Types.EntityType.MINECART_RIDEABLE) || e.getEntityType().isOrHasParent(Entity1_10Types.EntityType.PIG) || e.getEntityType().isOrHasParent(Entity1_10Types.EntityType.BOAT);
return e.getEntityType().isOrHasParent(EntityTypes1_10.EntityType.MINECART_RIDEABLE) || e.getEntityType().isOrHasParent(EntityTypes1_10.EntityType.PIG) || e.getEntityType().isOrHasParent(EntityTypes1_10.EntityType.BOAT);
});

if (oNearbyEntity.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
*/
package net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.model;

import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
import net.raphimc.vialegacy.api.model.Location;

public abstract class AbstractTrackedEntity {

private int entityId;
private Location location;
private Entity1_10Types.EntityType entityType;
private EntityTypes1_10.EntityType entityType;

private boolean isRiding;

public AbstractTrackedEntity(final int entityId, final Location location, final Entity1_10Types.EntityType entityType) {
public AbstractTrackedEntity(final int entityId, final Location location, final EntityTypes1_10.EntityType entityType) {
this.entityId = entityId;
this.location = location;
this.entityType = entityType;
Expand All @@ -50,11 +50,11 @@ public void setLocation(Location location) {
this.location = location;
}

public Entity1_10Types.EntityType getEntityType() {
public EntityTypes1_10.EntityType getEntityType() {
return this.entityType;
}

public void setEntityType(Entity1_10Types.EntityType entityType) {
public void setEntityType(EntityTypes1_10.EntityType entityType) {
this.entityType = entityType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/
package net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.model;

import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
import net.raphimc.vialegacy.api.model.Location;

public class TrackedEntity extends AbstractTrackedEntity {

public TrackedEntity(int entityId, Location location, Entity1_10Types.EntityType entityType) {
public TrackedEntity(int entityId, Location location, EntityTypes1_10.EntityType entityType) {
super(entityId, location, entityType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.model;

import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import net.raphimc.vialegacy.api.model.Location;
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.sound.SoundEmulation;
Expand All @@ -42,7 +42,7 @@ public class TrackedLivingEntity extends AbstractTrackedEntity {
public int wolfHealth;
public boolean wolfIsAngry;

public TrackedLivingEntity(int entityId, Location location, Entity1_10Types.EntityType entityType) {
public TrackedLivingEntity(int entityId, Location location, EntityTypes1_10.EntityType entityType) {
super(entityId, location, entityType);
}

Expand All @@ -53,7 +53,7 @@ public void tick(EntityTracker tracker) {
tracker.playSound(this.getEntityId(), SoundType.IDLE);
}

if (this.getEntityType().isOrHasParent(Entity1_10Types.EntityType.ENTITY_AGEABLE)) {
if (this.getEntityType().isOrHasParent(EntityTypes1_10.EntityType.ENTITY_AGEABLE)) {
if (this.growingAge < 0) {
this.growingAge++;
} else if (this.growingAge > 0) {
Expand Down Expand Up @@ -84,7 +84,7 @@ public void updateMetadata(List<Metadata> metadataList) {
public void applyPitch(EntityTracker tracker, ConfiguredSound sound) {
float pitch;

if (this.getEntityType().isOrHasParent(Entity1_10Types.EntityType.ENTITY_AGEABLE) && this.growingAge < 0) {
if (this.getEntityType().isOrHasParent(EntityTypes1_10.EntityType.ENTITY_AGEABLE) && this.growingAge < 0) {
pitch = (tracker.RND.nextFloat() - tracker.RND.nextFloat()) * 0.2F + 1.5F;
} else {
pitch = (tracker.RND.nextFloat() - tracker.RND.nextFloat()) * 0.2F + 1.0F;
Expand Down
Loading

0 comments on commit 4c3abc8

Please sign in to comment.