Skip to content

Commit

Permalink
Merge pull request #26 from ViaVersion/fix/vv-usage
Browse files Browse the repository at this point in the history
Updated VV API usage
  • Loading branch information
RaphiMC authored Jan 13, 2024
2 parents 660cdf3 + 3d9feb2 commit d9be3ff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,19 @@

public class Protocol1_14to3D_Shareware extends BackwardsProtocol<ClientboundPackets3D_Shareware, ClientboundPackets1_14, ServerboundPackets3D_Shareware, ServerboundPackets1_14> {

public static final BackwardsMappings MAPPINGS = new BackwardsMappings("3D_Shareware", "1.14");
public static final BackwardsMappings MAPPINGS = new BackwardsMappings("3D_Shareware", "1.14", Protocol1_14To1_13_2.class);
private static final int SERVERSIDE_VIEW_DISTANCE = 64;

private BlockItemPackets3D_Shareware blockItemPackets;
private final BlockItemPackets3D_Shareware blockItemPackets = new BlockItemPackets3D_Shareware(this);

public Protocol1_14to3D_Shareware() {
super(ClientboundPackets3D_Shareware.class, ClientboundPackets1_14.class, ServerboundPackets3D_Shareware.class, ServerboundPackets1_14.class);
}

@Override
protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_14To1_13_2.class, MAPPINGS::load);
super.registerPackets();

this.blockItemPackets = new BlockItemPackets3D_Shareware(this);
this.blockItemPackets.register();
new EntityPackets3D_Shareware(this).registerPackets();
final SoundRewriter<ClientboundPackets3D_Shareware> soundRewriter = new SoundRewriter<>(this);
soundRewriter.registerSound(ClientboundPackets3D_Shareware.SOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,23 @@

public class Protocol1_16to20w14infinite extends BackwardsProtocol<ClientboundPackets20w14infinite, ClientboundPackets1_16, ServerboundPackets20w14infinite, ServerboundPackets1_16> {

public static final BackwardsMappings MAPPINGS = new BackwardsMappings("20w14infinite", "1.16");
public static final BackwardsMappings MAPPINGS = new BackwardsMappings("20w14infinite", "1.16", Protocol1_16To1_15_2.class);
private static final UUID ZERO_UUID = new UUID(0, 0);

private BlockItemPackets20w14infinite blockItemPackets;
private TagRewriter<ClientboundPackets20w14infinite> tagRewriter;
private MetadataRewriter1_16to20w14infinite metadataRewriter;
private final BlockItemPackets20w14infinite blockItemPackets = new BlockItemPackets20w14infinite(this);
private final MetadataRewriter1_16to20w14infinite metadataRewriter = new MetadataRewriter1_16to20w14infinite(this);
private final TagRewriter<ClientboundPackets20w14infinite> tagRewriter = new TagRewriter<>(this);

public Protocol1_16to20w14infinite() {
super(ClientboundPackets20w14infinite.class, ClientboundPackets1_16.class, ServerboundPackets20w14infinite.class, ServerboundPackets1_16.class);
}

@Override
protected void registerPackets() {
this.metadataRewriter = new MetadataRewriter1_16to20w14infinite(this);
metadataRewriter.register();
tagRewriter = new TagRewriter<>(this);

this.executeAsyncAfterLoaded(Protocol1_16To1_15_2.class, () -> {
MAPPINGS.load();
this.onMappingDataLoaded();
});
super.registerPackets();

tagRewriter.register(ClientboundPackets20w14infinite.TAGS, RegistryType.ENTITY);
new StatisticsRewriter<>(this).register(ClientboundPackets20w14infinite.STATISTICS);
this.blockItemPackets = new BlockItemPackets20w14infinite(this);
this.blockItemPackets.register();
EntityPackets20w14infinite.register(this);
final SoundRewriter<ClientboundPackets20w14infinite> soundRewriter = new SoundRewriter<>(this);
soundRewriter.registerSound(ClientboundPackets20w14infinite.SOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@
*/
package net.raphimc.viaaprilfools.protocols.protocol1_16to20w14infinite.metadata;

import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
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;

import java.util.List;

public class MetadataRewriter1_16to20w14infinite extends EntityRewriter<ClientboundPackets20w14infinite, Protocol1_16to20w14infinite> {

public MetadataRewriter1_16to20w14infinite(Protocol1_16to20w14infinite protocol) {
Expand All @@ -38,37 +33,21 @@ public MetadataRewriter1_16to20w14infinite(Protocol1_16to20w14infinite protocol)
}

@Override
public EntityType typeFromId(int type) {
return EntityTypes1_16.getTypeFromId(type);
}

@Override
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
if (metadata.metaType() == Types1_14.META_TYPES.itemType) {
metadata.setValue(this.protocol.getItemRewriter().handleItemToClient(metadata.value()));
} else if (metadata.metaType() == Types1_14.META_TYPES.blockStateType) {
int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (metadata.metaType() == Types1_14.META_TYPES.particleType) {
rewriteParticle((Particle) metadata.getValue());
}
protected void registerRewrites() {
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.blockStateType, null, Types1_14.META_TYPES.particleType);

if (type == null) return;

if (type.isOrHasParent(EntityTypes1_16.MINECART_ABSTRACT)
&& metadata.id() == 10) {
filter().type(EntityTypes1_16.MINECART_ABSTRACT).index(10).handler((event, meta) -> {
// Convert to new block id
int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
int data = (int) meta.getValue();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});

filter().type(EntityTypes1_16.ABSTRACT_ARROW).removeIndex(8);
}

if (type.isOrHasParent(EntityTypes1_16.ABSTRACT_ARROW)) {
if (metadata.id() == 8) {
metadatas.remove(metadata);
} else if (metadata.id() > 8) {
metadata.setId(metadata.id() - 1);
}
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_16.getTypeFromId(type);
}

}

0 comments on commit d9be3ff

Please sign in to comment.