Skip to content

Commit

Permalink
Update Via API usage (#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael authored and kennytv committed May 14, 2024
1 parent 4d6c6a2 commit 8f92d55
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ public void register() {

public PacketHandler getFallingBlockHandler() {
return wrapper -> {
final Optional<EntityTypes1_12.ObjectType> type = EntityTypes1_12.ObjectType.findById(wrapper.get(Types.BYTE, 0));
if (type.isPresent() && type.get() == EntityTypes1_12.ObjectType.FALLING_BLOCK) {
final EntityTypes1_12.ObjectType type = EntityTypes1_12.ObjectType.findById(wrapper.get(Types.BYTE, 0));
if (type == EntityTypes1_12.ObjectType.FALLING_BLOCK) {
final int objectData = wrapper.get(Types.INT, 0);

final IdAndData block = handleBlock(objectData & 4095, objectData >> 12 & 15);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public void register() {

// Track Entity
handler(getObjectTrackerHandler());
handler(getObjectRewriter(id -> EntityTypes1_11.ObjectType.findById(id).orElse(null)));
handler(getObjectRewriter(EntityTypes1_11.ObjectType::findById));

handler(protocol.getItemRewriter().getFallingBlockHandler());
}
});

registerTracker(ClientboundPackets1_9_3.ADD_EXPERIENCE_ORB, EntityTypes1_10.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_10.EntityType.WEATHER);
registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_10.EntityType.LIGHTNING_BOLT);

protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public void register() {

// Track Entity
handler(getObjectTrackerHandler());
handler(getObjectRewriter(id -> EntityTypes1_11.ObjectType.findById(id).orElse(null)));
handler(getObjectRewriter(EntityTypes1_11.ObjectType::findById));
}
});

registerTracker(ClientboundPackets1_9_3.ADD_EXPERIENCE_ORB, EntityTypes1_11.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_11.EntityType.WEATHER);
registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_11.EntityType.LIGHTNING_BOLT);

protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() {
@Override
Expand Down Expand Up @@ -110,7 +110,7 @@ public void register() {
@Override
protected void registerRewrites() {
// Handle non-existing firework metadata (index 7 entity id for boosting)
filter().type(EntityTypes1_11.EntityType.FIREWORK).cancel(7);
filter().type(EntityTypes1_11.EntityType.FIREWORK_ROCKET).cancel(7);

// Handle non-existing pig metadata (index 14 - boost time)
filter().type(EntityTypes1_11.EntityType.PIG).cancel(14);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private boolean isLlama(UserConnection user) {
if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) {
EntityTracker entTracker = user.getEntityTracker(Protocol1_11To1_10.class);
StoredEntityData entityData = entTracker.entityData(tracker.getEntityId());
return entityData != null && entityData.type().is(EntityTypes1_11.EntityType.LIAMA);
return entityData != null && entityData.type().is(EntityTypes1_11.EntityType.LLAMA);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public void register() {

// Track Entity
handler(getObjectTrackerHandler());
handler(getObjectRewriter(id -> EntityTypes1_11.ObjectType.findById(id).orElse(null)));
handler(getObjectRewriter(EntityTypes1_11.ObjectType::findById));

handler(protocol.getItemRewriter().getFallingBlockHandler());
}
});

registerTracker(ClientboundPackets1_9_3.ADD_EXPERIENCE_ORB, EntityTypes1_11.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_11.EntityType.WEATHER);
registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_11.EntityType.LIGHTNING_BOLT);

protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() {
@Override
Expand Down Expand Up @@ -189,16 +189,16 @@ protected void registerRewrites() {
mapEntityTypeWithData(EntityTypes1_11.EntityType.SKELETON_HORSE, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(4)));
mapEntityTypeWithData(EntityTypes1_11.EntityType.ZOMBIE_HORSE, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(3)));
// New mobs
mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOCATION_FANGS, EntityTypes1_11.EntityType.SHULKER);
mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOCATION_ILLAGER, EntityTypes1_11.EntityType.VILLAGER).plainName();
mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOKER_FANGS, EntityTypes1_11.EntityType.SHULKER);
mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOKER, EntityTypes1_11.EntityType.VILLAGER).plainName();
mapEntityTypeWithData(EntityTypes1_11.EntityType.VEX, EntityTypes1_11.EntityType.BAT).plainName();
mapEntityTypeWithData(EntityTypes1_11.EntityType.VINDICATOR, EntityTypes1_11.EntityType.VILLAGER).plainName().spawnMetadata(storage -> storage.add(new EntityData(13, EntityDataTypes1_9.VAR_INT, 4))); // Base Profession
mapEntityTypeWithData(EntityTypes1_11.EntityType.LLAMA, EntityTypes1_11.EntityType.HORSE).plainName().spawnMetadata(storage -> storage.add(getHorseMetaType(1)));
mapEntityTypeWithData(EntityTypes1_11.EntityType.LLAMA_SPIT, EntityTypes1_11.EntityType.SNOWBALL);

mapObjectType(EntityTypes1_11.ObjectType.LIAMA_SPIT, EntityTypes1_11.ObjectType.SNOWBALL, -1);
mapObjectType(EntityTypes1_11.ObjectType.LLAMA_SPIT, EntityTypes1_11.ObjectType.SNOWBALL, -1);
// Replace with endertorchthingies
mapObjectType(EntityTypes1_11.ObjectType.EVOCATION_FANGS, EntityTypes1_11.ObjectType.FALLING_BLOCK, 198 | 1 << 12);
mapObjectType(EntityTypes1_11.ObjectType.EVOKER_FANGS, EntityTypes1_11.ObjectType.FALLING_BLOCK, 198 | 1 << 12);

// Handle ElderGuardian & target metadata
filter().type(EntityTypes1_11.EntityType.GUARDIAN).index(12).handler((event, meta) -> {
Expand Down Expand Up @@ -232,7 +232,7 @@ protected void registerRewrites() {
});

// Handle Evocation Illager
filter().type(EntityTypes1_11.EntityType.EVOCATION_ILLAGER).index(12).handler((event, meta) -> {
filter().type(EntityTypes1_11.EntityType.EVOKER).index(12).handler((event, meta) -> {
event.setIndex(13);
meta.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Byte) meta.getValue()).intValue()); // Change the profession for the states
});
Expand All @@ -243,7 +243,7 @@ protected void registerRewrites() {
});

// Handle VindicationIllager
filter().type(EntityTypes1_11.EntityType.VINDICATION_ILLAGER).index(12).handler((event, meta) -> {
filter().type(EntityTypes1_11.EntityType.VINDICATOR).index(12).handler((event, meta) -> {
event.setIndex(13);
meta.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Number) meta.getValue()).intValue() == 1 ? 2 : 4);
});
Expand Down Expand Up @@ -283,7 +283,7 @@ protected void registerRewrites() {
});

// Get rid of Liama metadata
filter().type(EntityTypes1_11.EntityType.LIAMA).handler((event, meta) -> {
filter().type(EntityTypes1_11.EntityType.LLAMA).handler((event, meta) -> {
StoredEntityData data = storedEntityData(event);
ChestedHorseStorage storage = data.get(ChestedHorseStorage.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public void register() {

// Track Entity
handler(getObjectTrackerHandler());
handler(getObjectRewriter(id -> EntityTypes1_12.ObjectType.findById(id).orElse(null)));
handler(getObjectRewriter(EntityTypes1_12.ObjectType::findById));

handler(protocol.getItemRewriter().getFallingBlockHandler());
}
});

registerTracker(ClientboundPackets1_12.ADD_EXPERIENCE_ORB, EntityTypes1_12.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_12.ADD_GLOBAL_ENTITY, EntityTypes1_12.EntityType.WEATHER);
registerTracker(ClientboundPackets1_12.ADD_GLOBAL_ENTITY, EntityTypes1_12.EntityType.LIGHTNING_BOLT);

protocol.registerClientbound(ClientboundPackets1_12.ADD_MOB, new PacketHandlers() {
@Override
Expand Down Expand Up @@ -196,10 +196,9 @@ protected void registerRewrites() {
});

// Handle Illager
filter().type(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).cancel(12);
filter().type(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).index(13).toIndex(12);
filter().type(EntityTypes1_12.EntityType.EVOKER).removeIndex(12);

filter().type(EntityTypes1_12.EntityType.ILLUSION_ILLAGER).index(0).handler((event, meta) -> {
filter().type(EntityTypes1_12.EntityType.ILLUSIONER).index(0).handler((event, meta) -> {
byte mask = (byte) meta.getValue();

if ((mask & 0x20) == 0x20) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected void registerRewrites() {
filter().type(EntityTypes1_13.EntityType.TRIDENT).index(8).toIndex(7);

// Rewrite Minecart blocks
filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> {
filter().type(EntityTypes1_13.EntityType.ABSTRACT_MINECART).index(9).handler((event, meta) -> {
int data = (int) meta.getValue();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ public void register() {
handler(getObjectTrackerHandler());

handler(wrapper -> {
Optional<EntityTypes1_13.ObjectType> optionalType = EntityTypes1_13.ObjectType.findById(wrapper.get(Types.BYTE, 0));
if (optionalType.isEmpty()) return;

EntityTypes1_13.ObjectType type = optionalType.get();
EntityTypes1_13.ObjectType type = EntityTypes1_13.ObjectType.findById(wrapper.get(Types.BYTE, 0));
if (type == EntityTypes1_13.ObjectType.FALLING_BLOCK) {
int blockState = wrapper.get(Types.INT, 0);
int combined = Protocol1_13To1_12_2.MAPPINGS.getNewBlockStateId(blockState);
Expand Down Expand Up @@ -308,8 +305,8 @@ protected void registerRewrites() {
filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(18); // Traveling

// Remove additional fish meta
filter().type(EntityTypes1_13.EntityType.ABSTRACT_FISHES).cancel(12);
filter().type(EntityTypes1_13.EntityType.ABSTRACT_FISHES).cancel(13);
filter().type(EntityTypes1_13.EntityType.ABSTRACT_FISH).cancel(12);
filter().type(EntityTypes1_13.EntityType.ABSTRACT_FISH).cancel(13);

// Remove phantom size
filter().type(EntityTypes1_13.EntityType.PHANTOM).cancel(12);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.viaversion.viabackwards.protocol.v1_14to1_13_2.rewriter;

import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.entities.storage.EntityReplacement;
import com.viaversion.viabackwards.api.entities.storage.EntityPositionHandler;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
Expand All @@ -36,7 +35,6 @@
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
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.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_13_2;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
Expand Down Expand Up @@ -141,8 +139,8 @@ public void register() {
int id = wrapper.get(Types.BYTE, 0);
int mappedId = newEntityId(id);
EntityTypes1_13.EntityType entityType = EntityTypes1_13.getTypeFromId(mappedId, false);
EntityTypes1_13.ObjectType objectType;
if (entityType.isOrHasParent(EntityTypes1_13.EntityType.MINECART_ABSTRACT)) {
EntityTypes1_13.ObjectType objectType = null;
if (entityType.isOrHasParent(EntityTypes1_13.EntityType.ABSTRACT_MINECART)) {
objectType = EntityTypes1_13.ObjectType.MINECART;
int data = switch (entityType) {
case CHEST_MINECART -> 1;
Expand All @@ -156,7 +154,12 @@ public void register() {
if (data != 0)
wrapper.set(Types.INT, 0, data);
} else {
objectType = EntityTypes1_13.ObjectType.fromEntityType(entityType).orElse(null);
for (final EntityTypes1_13.ObjectType type : EntityTypes1_13.ObjectType.values()) {
if (type.getType() == entityType) {
objectType = type;
break;
}
}
}

if (objectType == null) return;
Expand Down

0 comments on commit 8f92d55

Please sign in to comment.