So I have a signed book and I am trying to unsign it by changing the ItemType to WRITTABLE_BOOK by creating a ItemStackSnapshot of a WRITTABLE_BOOK and then copying over the Keys and values over from the original signed book. However something odd happens
Signed book
Unsigned book with copied key+value from the signed book
Am I doing something wrong as the value is directly copied over?
here is my code
Slot slot;
ItemStack book = slot.peek().get();
ItemStackSnapshot snapshot = ItemTypes.WRITABLE_BOOK.getTemplate();
for(Key<? extends BaseValue<? extends Object>> key : book.getKeys()){
snapshot = addTo(snapshot, book, key);
}
slot.set(snapshot.createStack());
return CommandResult.success();
}
private <T extends Object> ItemStackSnapshot addTo(ItemStackSnapshot snapshot, ItemStack book, Key<? extends BaseValue<? extends Object>> key){
Key<? extends BaseValue<T>> key2 = (Key<? extends BaseValue<T>>)key;
Optional<T> opValue = book.get(key2);
if(!opValue.isPresent()){
return snapshot;
}
Optional<ItemStackSnapshot> opSnapshot = snapshot.with(key2, opValue.get());
if(opSnapshot.isPresent()){
return opSnapshot.get();
}
return snapshot;
}