Make spell books return to the slots they came from (provided the container isn't closed)

This commit is contained in:
Electroblob77
2020-04-09 20:08:28 +01:00
parent c5b5172481
commit d56cf37f2b
3 changed files with 111 additions and 7 deletions
@@ -39,6 +39,7 @@ import javax.annotation.Nullable;
import java.util.*;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* <i>"Where do you put random but useful bits and pieces? {@code WizardryUtilities} of course - the 'stuff that doesn't
@@ -810,6 +811,22 @@ public final class WizardryUtilities {
return copy;
}
/**
* Returns whether the two given item stacks can be merged, i.e. if they both contain the same (stackable) item,
* metadata and NBT. Importantly, the number of items in each stack need not be the same. No actual merging is
* performed by this method; the input stacks will not be modified.
* @param stack1 The first stack to be tested for mergeability
* @param stack2 The second stack to be tested for mergeability (order does not matter)
* @return True if the two stacks can be merged, false if not
*/
public static boolean canMerge(ItemStack stack1, ItemStack stack2){
return !stack1.isEmpty() && !stack2.isEmpty()
&& stack1.isStackable() && stack2.isStackable()
&& stack1.getItem() == stack2.getItem()
&& (!stack1.getHasSubtypes() || stack1.getMetadata() == stack2.getMetadata())
&& ItemStack.areItemStackTagsEqual(stack1, stack2);
}
/**
* Checks if the given player is opped on the given server. If the server is a singleplayer or LAN server, this
* means they have cheats enabled.