Skip to content

Commit

Permalink
Merge pull request #1003 from booky10/fix/registry-element-equality
Browse files Browse the repository at this point in the history
Fix registry element equality check
  • Loading branch information
booky10 authored Sep 23, 2024
2 parents 7218c36 + 2baaf18 commit be24877
Show file tree
Hide file tree
Showing 24 changed files with 74 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_19_1;
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 All @@ -37,7 +38,7 @@

import static com.github.retrooper.packetevents.util.adventure.AdventureIndexUtil.indexValueOrThrow;

public interface ChatType extends MappedEntity, CopyableEntity<ChatType> {
public interface ChatType extends MappedEntity, CopyableEntity<ChatType>, DeepComparableEntity {

@UnknownNullability("only nullable for 1.19")
ChatTypeDecoration getChatDecoration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public ChatType copy(@Nullable TypesBuilderData newData) {
return this.narrationPriority;
}

@Override
public boolean deepEquals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticChatType)) return false;
Expand All @@ -107,6 +108,7 @@ public boolean deepEquals(Object obj) {
return this.narrationPriority == that.narrationPriority;
}

@Override
public int deepHashCode() {
return Objects.hash(super.hashCode(), this.chatDecoration, this.overlayDecoration, this.narrationDecoration, this.narrationPriority);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public MappedEntitySet<Biome> getBiomes() {
return this.biomes;
}

@Override
public boolean deepEquals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticWolfVariant)) return false;
Expand All @@ -93,6 +94,7 @@ public boolean deepEquals(Object obj) {
return this.biomes.equals(that.biomes);
}

@Override
public int deepHashCode() {
return Objects.hash(super.hashCode(), this.wildTexture, this.tameTexture, this.angryTexture, this.biomes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.github.retrooper.packetevents.protocol.entity.wolfvariant;

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.mapper.MappedEntitySet;
import com.github.retrooper.packetevents.protocol.nbt.NBT;
Expand All @@ -31,7 +32,7 @@
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
import org.jetbrains.annotations.Nullable;

public interface WolfVariant extends MappedEntity, CopyableEntity<WolfVariant> {
public interface WolfVariant extends MappedEntity, CopyableEntity<WolfVariant>, DeepComparableEntity {

ResourceLocation getWildTexture();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.github.retrooper.packetevents.protocol.item.banner;

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 All @@ -29,7 +30,7 @@
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;

public interface BannerPattern extends MappedEntity, CopyableEntity<BannerPattern> {
public interface BannerPattern extends MappedEntity, CopyableEntity<BannerPattern>, DeepComparableEntity {

ResourceLocation getAssetId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public String getTranslationKey() {
return this.translationKey;
}

@Override
public boolean deepEquals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticBannerPattern)) return false;
Expand All @@ -64,6 +65,7 @@ public boolean deepEquals(Object obj) {
return this.translationKey.equals(that.translationKey);
}

@Override
public int deepHashCode() {
return Objects.hash(super.hashCode(), this.assetId, this.translationKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.github.retrooper.packetevents.protocol.component.StaticComponentMap;
import com.github.retrooper.packetevents.protocol.item.enchantment.EnchantmentDefinition;
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.mapper.MappedEntitySet;
import com.github.retrooper.packetevents.protocol.nbt.NBT;
Expand All @@ -35,7 +36,7 @@

import java.util.Optional;

public interface EnchantmentType extends MappedEntity, CopyableEntity<EnchantmentType> {
public interface EnchantmentType extends MappedEntity, CopyableEntity<EnchantmentType>, DeepComparableEntity {

Component getDescription();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public StaticComponentMap getEffects() {
return this.effects;
}

@Override
public boolean deepEquals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticEnchantmentType)) return false;
Expand All @@ -95,6 +96,7 @@ public boolean deepEquals(Object obj) {
return this.effects.equals(that.effects);
}

@Override
public int deepHashCode() {
return Objects.hash(super.hashCode(), this.description, this.definition, this.exclusiveSet, this.effects);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.github.retrooper.packetevents.protocol.item.jukebox;

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 All @@ -32,7 +33,8 @@
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;

public interface IJukeboxSong extends MappedEntity, CopyableEntity<IJukeboxSong> {
public interface IJukeboxSong extends MappedEntity, CopyableEntity<IJukeboxSong>, DeepComparableEntity {

Sound getSound();

Component getDescription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void setComparatorOutput(int comparatorOutput) {
this.comparatorOutput = comparatorOutput;
}

@Override
public boolean deepEquals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof JukeboxSong)) return false;
Expand All @@ -112,6 +113,7 @@ public boolean deepEquals(Object obj) {
return this.description.equals(that.description);
}

@Override
public int deepHashCode() {
return Objects.hash(super.hashCode(), this.sound, this.description, this.lengthInSeconds, this.comparatorOutput);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public Component getDescription() {
return this.description;
}

@Override
public boolean deepEquals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticTrimMaterial)) return false;
Expand All @@ -99,6 +100,7 @@ public boolean deepEquals(Object obj) {
return this.description.equals(that.description);
}

@Override
public int deepHashCode() {
return Objects.hash(super.hashCode(), this.assetName, this.ingredient, this.itemModelIndex, this.overrideArmorMaterials, this.description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
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 All @@ -39,7 +40,7 @@
import java.util.HashMap;
import java.util.Map;

public interface TrimMaterial extends MappedEntity, CopyableEntity<TrimMaterial> {
public interface TrimMaterial extends MappedEntity, CopyableEntity<TrimMaterial>, DeepComparableEntity {

String getAssetName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public boolean isDecal() {
return this.decal;
}

@Override
public boolean deepEquals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticTrimPattern)) return false;
Expand All @@ -90,6 +91,7 @@ public boolean deepEquals(Object obj) {
return this.description.equals(that.description);
}

@Override
public int deepHashCode() {
return Objects.hash(super.hashCode(), this.assetId, this.templateItem, this.description, this.decal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
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.NBTByte;
Expand All @@ -34,7 +35,7 @@
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;

public interface TrimPattern extends MappedEntity, CopyableEntity<TrimPattern> {
public interface TrimPattern extends MappedEntity, CopyableEntity<TrimPattern>, DeepComparableEntity {

ResourceLocation getAssetId();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.github.retrooper.packetevents.protocol.mapper;

public interface DeepComparableEntity {

boolean deepEquals(Object obj);

int deepHashCode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.github.retrooper.packetevents.protocol.world.biome;

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.NBTByte;
Expand All @@ -35,7 +36,7 @@

import static com.github.retrooper.packetevents.util.adventure.AdventureIndexUtil.indexValueOrThrow;

public interface Biome extends MappedEntity, CopyableEntity<Biome> {
public interface Biome extends MappedEntity, CopyableEntity<Biome>, DeepComparableEntity {

boolean hasPrecipitation();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public BiomeEffects getEffects() {
return this.effects;
}

@Override
public boolean deepEquals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticBiome)) return false;
Expand All @@ -168,6 +169,7 @@ public boolean deepEquals(Object obj) {
return this.effects.equals(that.effects);
}

@Override
public int deepHashCode() {
return Objects.hash(super.hashCode(), this.precipitation, this.temperature,
this.temperatureModifier, this.downfall, this.category, this.depth, this.scale, this.effects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.github.retrooper.packetevents.protocol.world.damagetype;

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 All @@ -32,7 +33,7 @@

import static com.github.retrooper.packetevents.util.adventure.AdventureIndexUtil.indexValueOrThrow;

public interface DamageType extends MappedEntity, CopyableEntity<DamageType> {
public interface DamageType extends MappedEntity, CopyableEntity<DamageType>, DeepComparableEntity {
String getMessageId();

DamageScaling getScaling();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public DeathMessageType getDeathMessageType() {
return this.deathMessageType;
}

@Override
public boolean deepEquals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticDamageType)) return false;
Expand All @@ -85,6 +86,7 @@ public boolean deepEquals(Object obj) {
return this.deathMessageType == that.deathMessageType;
}

@Override
public int deepHashCode() {
return Objects.hash(super.hashCode(), this.messageId, this.scaling, this.exhaustion, this.effects, this.deathMessageType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.github.retrooper.packetevents.PacketEvents;
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.NBTByte;
Expand All @@ -36,7 +37,7 @@

import java.util.OptionalLong;

public interface DimensionType extends MappedEntity, CopyableEntity<DimensionType> {
public interface DimensionType extends MappedEntity, CopyableEntity<DimensionType>, DeepComparableEntity {

OptionalLong getFixedTime();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public int getMonsterSpawnBlockLightLimit() {
return this.monsterSpawnBlockLightLimit;
}

@Override
public boolean deepEquals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticDimensionType)) return false;
Expand All @@ -212,6 +213,7 @@ public boolean deepEquals(Object obj) {
return Objects.equals(this.monsterSpawnLightLevel, that.monsterSpawnLightLevel);
}

@Override
public int deepHashCode() {
return Objects.hash(super.hashCode(), this.fixedTime, this.hasSkyLight, this.hasCeiling, this.ultraWarm, this.natural, this.coordinateScale, this.bedWorking, this.respawnAnchorWorking, this.minY, this.height, this.logicalHeight, this.infiniburnTag, this.effectsLocation, this.ambientLight, this.piglinSafe, this.hasRaids, this.monsterSpawnLightLevel, this.monsterSpawnBlockLightLimit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.github.retrooper.packetevents.protocol.world.painting;

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 All @@ -30,7 +31,7 @@
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;

public interface PaintingVariant extends MappedEntity, CopyableEntity<PaintingVariant> {
public interface PaintingVariant extends MappedEntity, CopyableEntity<PaintingVariant>, DeepComparableEntity {

int getWidth();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public ResourceLocation getAssetId() {
return this.assetId;
}

@Override
public boolean deepEquals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticPaintingVariant)) return false;
Expand All @@ -72,6 +73,7 @@ public boolean deepEquals(Object obj) {
return this.assetId.equals(that.assetId);
}

@Override
public int deepHashCode() {
return Objects.hash(super.hashCode(), this.width, this.height, this.assetId);
}
Expand Down
Loading

0 comments on commit be24877

Please sign in to comment.