Skip to content

Commit

Permalink
Add equality methods for all dynamic registry value classes
Browse files Browse the repository at this point in the history
  • Loading branch information
booky10 committed Aug 6, 2024
1 parent 7b152ff commit 2f45e9e
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.BiFunction;

import static com.github.retrooper.packetevents.protocol.chat.ChatTypeDecoration.Parameter.CONTENT;
Expand Down Expand Up @@ -147,6 +148,21 @@ public Style getStyle() {
return this.style;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ChatTypeDecoration)) return false;
ChatTypeDecoration that = (ChatTypeDecoration) obj;
if (!this.translationKey.equals(that.translationKey)) return false;
if (!this.parameters.equals(that.parameters)) return false;
return this.style.equals(that.style);
}

@Override
public int hashCode() {
return Objects.hash(this.translationKey, this.parameters, this.style);
}

public enum Parameter {

SENDER("sender", (component, type) -> type.getName()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class StaticChatType extends AbstractMappedEntity implements ChatType {

private final ChatTypeDecoration chatDecoration;
Expand Down Expand Up @@ -92,4 +94,21 @@ public ChatTypeDecoration getNarrationDecoration() {
public @Nullable NarrationPriority getNarrationPriority() {
return this.narrationPriority;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticChatType)) return false;
if (!super.equals(obj)) return false;
StaticChatType that = (StaticChatType) obj;
if (!this.chatDecoration.equals(that.chatDecoration)) return false;
if (!Objects.equals(this.overlayDecoration, that.overlayDecoration)) return false;
if (!this.narrationDecoration.equals(that.narrationDecoration)) return false;
return this.narrationPriority == that.narrationPriority;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.chatDecoration, this.overlayDecoration, this.narrationDecoration, this.narrationPriority);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class StaticWolfVariant extends AbstractMappedEntity implements WolfVariant {

private final ResourceLocation wildTexture;
Expand Down Expand Up @@ -79,4 +81,21 @@ public ResourceLocation getAngryTexture() {
public MappedEntitySet<Biome> getBiomes() {
return this.biomes;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticWolfVariant)) return false;
if (!super.equals(obj)) return false;
StaticWolfVariant that = (StaticWolfVariant) obj;
if (!this.wildTexture.equals(that.wildTexture)) return false;
if (!this.tameTexture.equals(that.tameTexture)) return false;
if (!this.angryTexture.equals(that.angryTexture)) return false;
return this.biomes.equals(that.biomes);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.wildTexture, this.tameTexture, this.angryTexture, this.biomes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class StaticEnchantmentType extends AbstractMappedEntity implements EnchantmentType {

private final Component description;
Expand Down Expand Up @@ -81,4 +83,21 @@ public MappedEntitySet<EnchantmentType> getExclusiveSet() {
public StaticComponentMap getEffects() {
return this.effects;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticEnchantmentType)) return false;
if (!super.equals(obj)) return false;
StaticEnchantmentType that = (StaticEnchantmentType) obj;
if (!this.description.equals(that.description)) return false;
if (!this.definition.equals(that.definition)) return false;
if (!this.exclusiveSet.equals(that.exclusiveSet)) return false;
return this.effects.equals(that.effects);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.description, this.definition, this.exclusiveSet, this.effects);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jetbrains.annotations.Nullable;

import java.util.Map;
import java.util.Objects;

public class StaticTrimMaterial extends AbstractMappedEntity implements TrimMaterial {

Expand Down Expand Up @@ -85,4 +86,22 @@ public Map<ArmorMaterial, String> getOverrideArmorMaterials() {
public Component getDescription() {
return this.description;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticTrimMaterial)) return false;
if (!super.equals(obj)) return false;
StaticTrimMaterial that = (StaticTrimMaterial) obj;
if (Float.compare(that.itemModelIndex, this.itemModelIndex) != 0) return false;
if (!this.assetName.equals(that.assetName)) return false;
if (!this.ingredient.equals(that.ingredient)) return false;
if (!this.overrideArmorMaterials.equals(that.overrideArmorMaterials)) return false;
return this.description.equals(that.description);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.assetName, this.ingredient, this.itemModelIndex, this.overrideArmorMaterials, this.description);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class StaticTrimPattern extends AbstractMappedEntity implements TrimPattern {

private final ResourceLocation assetId;
Expand Down Expand Up @@ -76,4 +78,21 @@ public Component getDescription() {
public boolean isDecal() {
return this.decal;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticTrimPattern)) return false;
if (!super.equals(obj)) return false;
StaticTrimPattern that = (StaticTrimPattern) obj;
if (this.decal != that.decal) return false;
if (!this.assetId.equals(that.assetId)) return false;
if (!this.templateItem.equals(that.templateItem)) return false;
return this.description.equals(that.description);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.assetId, this.templateItem, this.description, this.decal);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.BiFunction;

/**
Expand Down Expand Up @@ -129,4 +130,18 @@ public boolean isEmpty() {
public @Nullable List<T> getEntities() {
return this.entities;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof MappedEntitySet)) return false;
MappedEntitySet<?> that = (MappedEntitySet<?>) obj;
if (!Objects.equals(this.tagKey, that.tagKey)) return false;
return Objects.equals(this.entities, that.entities);
}

@Override
public int hashCode() {
return Objects.hash(this.tagKey, this.entities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.github.retrooper.packetevents.protocol.sound.Sound;
import net.kyori.adventure.util.Index;

import java.util.Objects;
import java.util.Optional;
import java.util.OptionalInt;

Expand Down Expand Up @@ -161,6 +162,30 @@ public Optional<Sound> getAmbientSound() {
return this.ambientSound;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof BiomeEffects)) return false;
BiomeEffects that = (BiomeEffects) obj;
if (this.fogColor != that.fogColor) return false;
if (this.waterColor != that.waterColor) return false;
if (this.waterFogColor != that.waterFogColor) return false;
if (this.skyColor != that.skyColor) return false;
if (!this.foliageColor.equals(that.foliageColor)) return false;
if (!this.grassColor.equals(that.grassColor)) return false;
if (this.grassColorModifier != that.grassColorModifier) return false;
if (!this.particle.equals(that.particle)) return false;
if (!this.ambientSound.equals(that.ambientSound)) return false;
if (!this.moodSound.equals(that.moodSound)) return false;
if (!this.additionsSound.equals(that.additionsSound)) return false;
return this.music.equals(that.music);
}

@Override
public int hashCode() {
return Objects.hash(this.fogColor, this.waterColor, this.waterFogColor, this.skyColor, this.foliageColor, this.grassColor, this.grassColorModifier, this.particle, this.ambientSound, this.moodSound, this.additionsSound, this.music);
}

public enum GrassColorModifier {

NONE("none"),
Expand Down Expand Up @@ -261,6 +286,22 @@ public int getBlockSearchExtent() {
public double getSoundOffset() {
return this.soundOffset;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof MoodSettings)) return false;
MoodSettings that = (MoodSettings) obj;
if (this.tickDelay != that.tickDelay) return false;
if (this.blockSearchExtent != that.blockSearchExtent) return false;
if (Double.compare(that.soundOffset, this.soundOffset) != 0) return false;
return this.sound.equals(that.sound);
}

@Override
public int hashCode() {
return Objects.hash(this.sound, this.tickDelay, this.blockSearchExtent, this.soundOffset);
}
}

public static final class AdditionsSettings {
Expand Down Expand Up @@ -294,6 +335,20 @@ public Sound getSound() {
public double getTickChance() {
return this.tickChance;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof AdditionsSettings)) return false;
AdditionsSettings that = (AdditionsSettings) obj;
if (Double.compare(that.tickChance, this.tickChance) != 0) return false;
return this.sound.equals(that.sound);
}

@Override
public int hashCode() {
return Objects.hash(this.sound, this.tickChance);
}
}

public static final class MusicSettings {
Expand Down Expand Up @@ -343,5 +398,21 @@ public int getMaxDelay() {
public boolean isReplaceMusic() {
return this.replaceMusic;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof MusicSettings)) return false;
MusicSettings that = (MusicSettings) obj;
if (this.minDelay != that.minDelay) return false;
if (this.maxDelay != that.maxDelay) return false;
if (this.replaceMusic != that.replaceMusic) return false;
return this.sound.equals(that.sound);
}

@Override
public int hashCode() {
return Objects.hash(this.sound, this.minDelay, this.maxDelay, this.replaceMusic);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class StaticBiome extends AbstractMappedEntity implements Biome {

private final boolean precipitation;
Expand Down Expand Up @@ -150,4 +152,26 @@ public float getDownfall() {
public BiomeEffects getEffects() {
return this.effects;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticBiome)) return false;
if (!super.equals(obj)) return false;
StaticBiome that = (StaticBiome) obj;
if (this.precipitation != that.precipitation) return false;
if (Float.compare(that.temperature, this.temperature) != 0) return false;
if (Float.compare(that.downfall, this.downfall) != 0) return false;
if (this.temperatureModifier != that.temperatureModifier) return false;
if (this.category != that.category) return false;
if (!Objects.equals(this.depth, that.depth)) return false;
if (!Objects.equals(this.scale, that.scale)) return false;
return this.effects.equals(that.effects);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.precipitation, this.temperature,
this.temperatureModifier, this.downfall, this.category, this.depth, this.scale, this.effects);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class StaticDamageType extends AbstractMappedEntity implements DamageType {
private String messageId;
private DamageScaling scaling;
Expand Down Expand Up @@ -70,4 +72,22 @@ public DamageEffects getEffects() {
public DeathMessageType getDeathMessageType() {
return this.deathMessageType;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticDamageType)) return false;
if (!super.equals(obj)) return false;
StaticDamageType that = (StaticDamageType) obj;
if (Float.compare(that.exhaustion, this.exhaustion) != 0) return false;
if (!this.messageId.equals(that.messageId)) return false;
if (this.scaling != that.scaling) return false;
if (this.effects != that.effects) return false;
return this.deathMessageType == that.deathMessageType;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.messageId, this.scaling, this.exhaustion, this.effects, this.deathMessageType);
}
}
Loading

0 comments on commit 2f45e9e

Please sign in to comment.