Make all valid books work with shift-clicking and hopper insertion
This commit is contained in:
@@ -3,7 +3,6 @@ package electroblob.wizardry.inventory;
|
|||||||
import electroblob.wizardry.Settings;
|
import electroblob.wizardry.Settings;
|
||||||
import electroblob.wizardry.Wizardry;
|
import electroblob.wizardry.Wizardry;
|
||||||
import electroblob.wizardry.block.BlockBookshelf;
|
import electroblob.wizardry.block.BlockBookshelf;
|
||||||
import electroblob.wizardry.item.ItemSpellBook;
|
|
||||||
import electroblob.wizardry.registry.WizardryItems;
|
import electroblob.wizardry.registry.WizardryItems;
|
||||||
import electroblob.wizardry.tileentity.TileEntityBookshelf;
|
import electroblob.wizardry.tileentity.TileEntityBookshelf;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
@@ -83,7 +82,7 @@ public class ContainerBookshelf extends Container {
|
|||||||
int minSlotId = 0;
|
int minSlotId = 0;
|
||||||
int maxSlotId = BlockBookshelf.SLOT_COUNT - 1;
|
int maxSlotId = BlockBookshelf.SLOT_COUNT - 1;
|
||||||
|
|
||||||
if(!(stack.getItem() instanceof ItemSpellBook)) return ItemStack.EMPTY;
|
if(!isBook(stack)) return ItemStack.EMPTY;
|
||||||
|
|
||||||
if(!this.mergeItemStack(stack, minSlotId, maxSlotId + 1, false)){
|
if(!this.mergeItemStack(stack, minSlotId, maxSlotId + 1, false)){
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
@@ -106,6 +105,11 @@ public class ContainerBookshelf extends Container {
|
|||||||
return remainder;
|
return remainder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns true if the given stack counts as a book and can be placed in a bookshelf, false if not. */
|
||||||
|
public static boolean isBook(ItemStack stack){
|
||||||
|
return validItems.contains(stack.getItem()) || Settings.containsMetaItem(Wizardry.settings.bookItems, stack);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given item to the set of items that can be put in a bookshelf. This method should be called from the
|
* Adds the given item to the set of items that can be put in a bookshelf. This method should be called from the
|
||||||
* {@code init()} phase.
|
* {@code init()} phase.
|
||||||
@@ -149,7 +153,7 @@ public class ContainerBookshelf extends Container {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(ItemStack stack){
|
public boolean isItemValid(ItemStack stack){
|
||||||
return validItems.contains(stack.getItem()) || Settings.containsMetaItem(Wizardry.settings.bookItems, stack);
|
return isBook(stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package electroblob.wizardry.tileentity;
|
|||||||
|
|
||||||
import electroblob.wizardry.Wizardry;
|
import electroblob.wizardry.Wizardry;
|
||||||
import electroblob.wizardry.block.BlockBookshelf;
|
import electroblob.wizardry.block.BlockBookshelf;
|
||||||
|
import electroblob.wizardry.inventory.ContainerBookshelf;
|
||||||
import electroblob.wizardry.item.ItemSpellBook;
|
import electroblob.wizardry.item.ItemSpellBook;
|
||||||
import electroblob.wizardry.util.NBTExtras;
|
import electroblob.wizardry.util.NBTExtras;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
@@ -136,8 +137,8 @@ public class TileEntityBookshelf extends TileEntity implements IInventory, ITick
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValidForSlot(int slotNumber, ItemStack itemstack){
|
public boolean isItemValidForSlot(int slotNumber, ItemStack stack){
|
||||||
return itemstack.isEmpty() || itemstack.getItem() instanceof ItemSpellBook; // TODO: Add a whitelist
|
return stack.isEmpty() || ContainerBookshelf.isBook(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user