Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated VV API usage #26

Merged
merged 3 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}