Skip to content

Commit

Permalink
fix: machine references do not work as item components
Browse files Browse the repository at this point in the history
Due to not implementing equals and hashCode

Closes #1254
  • Loading branch information
klikli-dev committed Nov 9, 2024
1 parent ef1f881 commit 1131bb2
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.common.util.INBTSerializable;

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

public class MachineReference implements INBTSerializable<CompoundTag> {
Expand Down Expand Up @@ -210,4 +211,39 @@ public BlockEntity getInsertBlockEntity(Level level) {
public boolean isValidFor(Level level) {
return this.getExtractBlockEntity(level) != null && this.getInsertBlockEntity(level) != null;
}

@Override
public boolean equals(Object obj) {
if(obj == this)
return true;

if (obj instanceof MachineReference) {
MachineReference other = (MachineReference) obj;
return this.extractGlobalPos.equals(other.extractGlobalPos) &&
this.extractRegistryName.equals(other.extractRegistryName) &&
this.extractChunkLoaded == other.extractChunkLoaded &&
this.extractFacing == other.extractFacing &&
this.insertGlobalPos.equals(other.insertGlobalPos) &&
this.insertRegistryName.equals(other.insertRegistryName) &&
this.insertChunkLoaded == other.insertChunkLoaded &&
this.insertFacing == other.insertFacing &&
this.customName.equals(other.customName);
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(
this.extractGlobalPos,
this.extractRegistryName,
this.extractChunkLoaded,
this.extractFacing,
this.insertGlobalPos,
this.insertRegistryName,
this.insertChunkLoaded,
this.insertFacing,
this.customName
);
}
}

0 comments on commit 1131bb2

Please sign in to comment.