9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-19 15:09:25 +00:00

Fix hashcode

This commit is contained in:
XiaoMoMi
2024-09-07 01:05:13 +08:00
parent 3a8fb364fe
commit 262209eda8
2 changed files with 21 additions and 1 deletions

View File

@@ -23,6 +23,8 @@ import net.momirealms.customcrops.api.core.SynchronizedCompoundMap;
import net.momirealms.customcrops.api.core.block.CustomCropsBlock;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class CustomCropsBlockStateImpl implements CustomCropsBlockState {
private final SynchronizedCompoundMap compoundMap;
@@ -66,4 +68,21 @@ public class CustomCropsBlockStateImpl implements CustomCropsBlockState {
"}, " + compoundMap +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CustomCropsBlockStateImpl that = (CustomCropsBlockStateImpl) o;
return Objects.equals(compoundMap, that.compoundMap);
}
@Override
public int hashCode() {
Tag<?> id = compoundMap.get("id");
if (id != null) {
return 7 * id.hashCode() + 13 * owner.type().hashCode();
}
return owner.type().hashCode();
}
}

View File

@@ -412,7 +412,8 @@ public class BukkitWorldAdaptor extends AbstractWorldAdaptor<World> {
for (int j = 0; j < blockAmount; j++){
byte[] blockData = new byte[sectionData.readInt()];
sectionData.read(blockData);
CompoundMap block = readCompound(blockData).getValue();
CompoundTag tag = readCompound(blockData);
CompoundMap block = tag.getValue();
Key key = keyFunction.apply((String) block.get("type").getValue());
CompoundMap data = (CompoundMap) block.get("data").getValue();
CustomCropsBlock customBlock = InternalRegistries.BLOCK.get(key);