Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Jul 25, 2024
1 parent f290af7 commit 7a9bf5f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,7 @@ public void register() {
wrapper.cancel();
}
if (tracker.clientEntityId() == entityId) {
tracker.getEntityData().removeIf(first -> entityData.stream().anyMatch(second -> first.id() == second.id()));
for (final EntityData data : entityData) {
final Object value = data.value();
if (value instanceof Item item) {
tracker.getEntityData().add(new EntityData(data.id(), data.dataType(), item.copy()));
} else {
tracker.getEntityData().add(new EntityData(data.id(), data.dataType(), value));
}
}
tracker.updateEntityData(entityData);
}
});
}
Expand Down Expand Up @@ -346,15 +338,7 @@ public void register() {
map(Types.SHORT); // Current item
map(Types1_8.ENTITY_DATA_LIST, Types1_7_6_10.ENTITY_DATA_LIST); // Entity data

handler(wrapper -> {
addTrackedEntity(wrapper, wrapper.get(Types.VAR_INT, 0), EntityTypes1_8.EntityType.PLAYER);

final List<EntityData> entityDataList = wrapper.get(Types1_7_6_10.ENTITY_DATA_LIST, 0);
handleEntityData(wrapper.get(Types.VAR_INT, 0), entityDataList, wrapper.user());

final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_7_6_10.class);
tracker.setEntityData(entityDataList);
});
handler(getTrackerAndDataHandler(Types1_7_6_10.ENTITY_DATA_LIST, EntityTypes1_8.EntityType.PLAYER));
}
});
protocol.registerClientbound(ClientboundPackets1_8.SET_EQUIPPED_ITEM, new PacketHandlers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public void register() {
wrapper.send(Protocol1_8To1_7_6_10.class);
wrapper.cancel();

if (tracker.getEntityData().isEmpty()) {
return;
}
// 1.8 clients do keep entity data after respawn, 1.7 clients don't
final PacketWrapper setEntityData = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_ENTITY_DATA, wrapper.user());
setEntityData.write(Types.VAR_INT, tracker.clientEntityId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
Expand Down Expand Up @@ -186,12 +187,20 @@ public void setClientEntityGameMode(int clientEntityGameMode) {
this.clientEntityGameMode = clientEntityGameMode;
}

public List<EntityData> getEntityData() {
return entityData;
public void updateEntityData(List<EntityData> entityData) {
entityData.removeIf(first -> entityData.stream().anyMatch(second -> first.id() == second.id()));
for (final EntityData data : entityData) {
final Object value = data.value();
if (value instanceof Item item) {
entityData.add(new EntityData(data.id(), data.dataType(), item.copy()));
} else {
entityData.add(new EntityData(data.id(), data.dataType(), value));
}
}
}

public void setEntityData(List<EntityData> entityData) {
this.entityData = entityData;
public List<EntityData> getEntityData() {
return entityData;
}

}

0 comments on commit 7a9bf5f

Please sign in to comment.