mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-06-02 04:03:36 +02:00
58 lines
1.7 KiB
Java
58 lines
1.7 KiB
Java
package de.ellpeck.prettypipes.network;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.nbt.ListTag;
|
|
import net.minecraftforge.common.util.INBTSerializable;
|
|
|
|
import java.util.Objects;
|
|
import java.util.UUID;
|
|
|
|
public class NetworkLock implements INBTSerializable<CompoundTag> {
|
|
|
|
// identify locks by UUID since network locks can't be identified by location and locked item alone
|
|
// (two locks could be set for the same item and the same amount if it exists twice in the chest)
|
|
private UUID lockId = UUID.randomUUID();
|
|
public NetworkLocation location;
|
|
public ItemStack stack;
|
|
|
|
public NetworkLock(NetworkLocation location, ItemStack stack) {
|
|
this.location = location;
|
|
this.stack = stack;
|
|
}
|
|
|
|
public NetworkLock(CompoundTag nbt) {
|
|
this.deserializeNBT(nbt);
|
|
}
|
|
|
|
@Override
|
|
public CompoundTag serializeNBT() {
|
|
CompoundTag nbt = new CompoundTag();
|
|
nbt.putUniqueId("id", this.lockId);
|
|
nbt.put("location", this.location.serializeNBT());
|
|
nbt.put("stack", this.stack.write(new CompoundTag()));
|
|
return nbt;
|
|
}
|
|
|
|
@Override
|
|
public void deserializeNBT(CompoundTag nbt) {
|
|
this.lockId = nbt.getUniqueId("id");
|
|
this.location = new NetworkLocation(nbt.getCompound("location"));
|
|
this.stack = ItemStack.read(nbt.getCompound("stack"));
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (o instanceof NetworkLock) {
|
|
NetworkLock that = (NetworkLock) o;
|
|
return this.lockId.equals(that.lockId);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(this.lockId);
|
|
}
|
|
}
|