Fix table on a stick

now mimics vanilla behavior and tries to add stacks back to inv before
dropping.
This commit is contained in:
Shadows_of_Fire 2017-07-07 13:51:44 -04:00
parent f0fd0b5364
commit fa31c65c9f

View file

@ -13,11 +13,13 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import invtweaks.api.container.InventoryContainer; import invtweaks.api.container.InventoryContainer;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.*; import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World; import net.minecraft.world.World;
@InventoryContainer @InventoryContainer
@ -107,19 +109,21 @@ public class ContainerCrafter extends Container{
public void onContainerClosed(EntityPlayer player){ public void onContainerClosed(EntityPlayer player){
super.onContainerClosed(player); super.onContainerClosed(player);
if(!this.world.isRemote){
for(int i = 0; i < 9; ++i){ for(int i = 0; i < 9; ++i){
ItemStack stack = this.craftMatrix.removeStackFromSlot(i); ItemStack stack = this.craftMatrix.removeStackFromSlot(i);
if(StackUtil.isValid(stack)){ if(StackUtil.isValid(stack)){
player.dropItem(stack, false); if(!player.addItemStackToInventory(stack))
} if(!this.world.isRemote) Block.spawnAsEntity(world, player.getPosition(), stack);
} }
} }
} }
@Override @Override
public void onCraftMatrixChanged(IInventory inv){ public void onCraftMatrixChanged(IInventory inv){
this.craftResult.setInventorySlotContents(0, CraftingManager.findMatchingRecipe(this.craftMatrix, this.world).getRecipeOutput()); IRecipe output = CraftingManager.findMatchingRecipe(this.craftMatrix, this.world);
ItemStack stack = ItemStack.EMPTY;
if(output != null) stack = output.getRecipeOutput();
this.craftResult.setInventorySlotContents(0, stack);
} }
@Override @Override