mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 19:46:42 +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()) {
|
if (!crafted.isEmpty()) {
|
||||||
current = SpellRegistry.instance().enchantStack(current, crafted);
|
current = SpellRegistry.instance().enchantStack(current, crafted);
|
||||||
|
|
||||||
|
resultSlot.setCrafted(true);
|
||||||
player.playSound(SoundEvents.BLOCK_NOTE_CHIME, 1, 1);
|
player.playSound(SoundEvents.BLOCK_NOTE_CHIME, 1, 1);
|
||||||
} else {
|
} else {
|
||||||
current = SpellRegistry.instance().disenchantStack(current);
|
current = SpellRegistry.instance().disenchantStack(current);
|
||||||
|
|
||||||
|
resultSlot.setCrafted(false);
|
||||||
player.playSound(SoundEvents.BLOCK_NOTE_BASS, 1, 1);
|
player.playSound(SoundEvents.BLOCK_NOTE_BASS, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ public class SlotEnchantingResult extends SlotEnchanting {
|
||||||
|
|
||||||
private IPageUnlockListener listener;
|
private IPageUnlockListener listener;
|
||||||
|
|
||||||
|
private boolean crafted;
|
||||||
|
|
||||||
public SlotEnchantingResult(IPageUnlockListener listener, IPageOwner owner, InventorySpellBook craftMatric, IInventory inventory, int index, int xPosition, int yPosition) {
|
public SlotEnchantingResult(IPageUnlockListener listener, IPageOwner owner, InventorySpellBook craftMatric, IInventory inventory, int index, int xPosition, int yPosition) {
|
||||||
super(inventory, index, xPosition, yPosition);
|
super(inventory, index, xPosition, yPosition);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
|
@ -31,35 +33,41 @@ public class SlotEnchantingResult extends SlotEnchanting {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCrafted(boolean crafted) {
|
||||||
|
this.crafted = crafted;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onTake(EntityPlayer player, ItemStack stack) {
|
public ItemStack onTake(EntityPlayer player, ItemStack stack) {
|
||||||
onCrafting(stack);
|
if (crafted) {
|
||||||
|
onCrafting(stack);
|
||||||
|
|
||||||
ItemStack current = craftMatrix.getCraftResultMatrix().getStackInSlot(0);
|
ItemStack current = craftMatrix.getCraftResultMatrix().getStackInSlot(0);
|
||||||
craftMatrix.getCraftResultMatrix().setInventorySlotContents(0, stack);
|
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) {
|
for (int i = 0; i < remaining.size(); ++i) {
|
||||||
current = craftMatrix.getStackInSlot(i);
|
current = craftMatrix.getStackInSlot(i);
|
||||||
ItemStack remainder = remaining.get(i);
|
ItemStack remainder = remaining.get(i);
|
||||||
|
|
||||||
if (!current.isEmpty()) {
|
if (!current.isEmpty()) {
|
||||||
if (current.getCount() < stack.getCount()) {
|
if (current.getCount() < stack.getCount()) {
|
||||||
craftMatrix.setInventorySlotContents(i, ItemStack.EMPTY);
|
craftMatrix.setInventorySlotContents(i, ItemStack.EMPTY);
|
||||||
} else {
|
|
||||||
craftMatrix.decrStackSize(i, stack.getCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!remainder.isEmpty()) {
|
|
||||||
if (craftMatrix.getStackInSlot(i).isEmpty()) {
|
|
||||||
craftMatrix.setInventorySlotContents(i, remainder);
|
|
||||||
} else {
|
} else {
|
||||||
remainder.setCount(stack.getCount());
|
craftMatrix.decrStackSize(i, stack.getCount());
|
||||||
if (!player.inventory.addItemStackToInventory(remainder)) {
|
}
|
||||||
player.dropItem(remainder, true);
|
|
||||||
|
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