Skip to content

Commit

Permalink
Check for deep equals before using vanilla registry element
Browse files Browse the repository at this point in the history
Could potentially solve #962, although I can't reproduce that issue

This may be caused by two different changes to packetevents:
1. We did a little memory optimization so only elements different to the vanilly registry get stored
2. We fixed an issue where some elements would not equal the "same" vanilla element

This could cause every custom element to just never be registered, so we now do explicit deep-equals checks before saving the vanilla element instead
  • Loading branch information
booky10 committed Sep 21, 2024
1 parent f1f4ffe commit 4d7314e
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.github.retrooper.packetevents.protocol.item.trimpattern.TrimPattern;
import com.github.retrooper.packetevents.protocol.item.trimpattern.TrimPatterns;
import com.github.retrooper.packetevents.protocol.mapper.CopyableEntity;
import com.github.retrooper.packetevents.protocol.mapper.DeepComparableEntity;
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
import com.github.retrooper.packetevents.protocol.nbt.NBT;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
Expand Down Expand Up @@ -142,7 +143,7 @@ public interface NbtEntryDecoder<T> {
}

@ApiStatus.Internal
public static final class RegistryEntry<T extends MappedEntity & CopyableEntity<T>> {
public static final class RegistryEntry<T extends MappedEntity & CopyableEntity<T> & DeepComparableEntity> {

private final IRegistry<T> baseRegistry;
private final NbtEntryDecoder<T> decoder;
Expand Down Expand Up @@ -186,7 +187,7 @@ private void handleElement(
if (element.getData() != null) {
// data was provided, use registry element sent over network
T value = this.decoder.decode(element.getData(), version, data);
if (!value.equals(copiedBaseEntry)) {
if (!value.deepEquals(copiedBaseEntry)) {
// only define decoded value if it doesn't match the base
// registry value this ensures we don't save everything twice,
// if it has been already stored in memory
Expand Down

0 comments on commit 4d7314e

Please sign in to comment.