mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 11:36:43 +01:00
Fixed spellbook still consuming items even if you haven't crafted anything
This commit is contained in:
parent
f59c1833e3
commit
4dffafda01
2 changed files with 31 additions and 21 deletions
|
@ -78,10 +78,12 @@ public class ContainerSpellBook extends Container {
|
|||
if (!crafted.isEmpty()) {
|
||||
current = SpellRegistry.instance().enchantStack(current, crafted);
|
||||
|
||||
resultSlot.setCrafted(true);
|
||||
player.playSound(SoundEvents.BLOCK_NOTE_CHIME, 1, 1);
|
||||
} else {
|
||||
current = SpellRegistry.instance().disenchantStack(current);
|
||||
|
||||
resultSlot.setCrafted(false);
|
||||
player.playSound(SoundEvents.BLOCK_NOTE_BASS, 1, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ public class SlotEnchantingResult extends SlotEnchanting {
|
|||
|
||||
private IPageUnlockListener listener;
|
||||
|
||||
private boolean crafted;
|
||||
|
||||
public SlotEnchantingResult(IPageUnlockListener listener, IPageOwner owner, InventorySpellBook craftMatric, IInventory inventory, int index, int xPosition, int yPosition) {
|
||||
super(inventory, index, xPosition, yPosition);
|
||||
this.owner = owner;
|
||||
|
@ -31,35 +33,41 @@ public class SlotEnchantingResult extends SlotEnchanting {
|
|||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setCrafted(boolean crafted) {
|
||||
this.crafted = crafted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onTake(EntityPlayer player, ItemStack stack) {
|
||||
onCrafting(stack);
|
||||
if (crafted) {
|
||||
onCrafting(stack);
|
||||
|
||||
ItemStack current = craftMatrix.getCraftResultMatrix().getStackInSlot(0);
|
||||
craftMatrix.getCraftResultMatrix().setInventorySlotContents(0, stack);
|
||||
ItemStack current = craftMatrix.getCraftResultMatrix().getStackInSlot(0);
|
||||
craftMatrix.getCraftResultMatrix().setInventorySlotContents(0, stack);
|
||||
|
||||
NonNullList<ItemStack> remaining = Unicopia.getCraftingManager().getRemainingItems(craftMatrix, player.world);
|
||||
NonNullList<ItemStack> remaining = Unicopia.getCraftingManager().getRemainingItems(craftMatrix, player.world);
|
||||
|
||||
craftMatrix.getCraftResultMatrix().setInventorySlotContents(0, current);
|
||||
craftMatrix.getCraftResultMatrix().setInventorySlotContents(0, current);
|
||||
|
||||
for (int i = 0; i < remaining.size(); ++i) {
|
||||
current = craftMatrix.getStackInSlot(i);
|
||||
ItemStack remainder = remaining.get(i);
|
||||
for (int i = 0; i < remaining.size(); ++i) {
|
||||
current = craftMatrix.getStackInSlot(i);
|
||||
ItemStack remainder = remaining.get(i);
|
||||
|
||||
if (!current.isEmpty()) {
|
||||
if (current.getCount() < stack.getCount()) {
|
||||
craftMatrix.setInventorySlotContents(i, ItemStack.EMPTY);
|
||||
} else {
|
||||
craftMatrix.decrStackSize(i, stack.getCount());
|
||||
}
|
||||
|
||||
if (!remainder.isEmpty()) {
|
||||
if (craftMatrix.getStackInSlot(i).isEmpty()) {
|
||||
craftMatrix.setInventorySlotContents(i, remainder);
|
||||
if (!current.isEmpty()) {
|
||||
if (current.getCount() < stack.getCount()) {
|
||||
craftMatrix.setInventorySlotContents(i, ItemStack.EMPTY);
|
||||
} else {
|
||||
remainder.setCount(stack.getCount());
|
||||
if (!player.inventory.addItemStackToInventory(remainder)) {
|
||||
player.dropItem(remainder, true);
|
||||
craftMatrix.decrStackSize(i, stack.getCount());
|
||||
}
|
||||
|
||||
if (!remainder.isEmpty()) {
|
||||
if (craftMatrix.getStackInSlot(i).isEmpty()) {
|
||||
craftMatrix.setInventorySlotContents(i, remainder);
|
||||
} else {
|
||||
remainder.setCount(stack.getCount());
|
||||
if (!player.inventory.addItemStackToInventory(remainder)) {
|
||||
player.dropItem(remainder, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue