Fixed tool table system bugging when multiple stacks of the same item are present

This commit is contained in:
Ellpeck 2015-09-22 23:48:27 +02:00
parent 29b2101563
commit c20a7b969e
4 changed files with 34 additions and 10 deletions

View file

@ -14,6 +14,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.ActuallyAdditions;
import ellpeck.actuallyadditions.inventory.GuiHandler;
import ellpeck.actuallyadditions.tile.TileEntityInventoryBase;
import ellpeck.actuallyadditions.tile.TileEntityToolTable;
import ellpeck.actuallyadditions.util.INameableItem;
import ellpeck.actuallyadditions.util.ModUtil;
@ -96,7 +97,17 @@ public class BlockToolTable extends BlockContainerBase implements INameableItem{
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int par6){
this.dropInventory(world, x, y, z);
if(!world.isRemote){
TileEntity aTile = world.getTileEntity(x, y, z);
if(aTile instanceof TileEntityInventoryBase){
TileEntityInventoryBase tile = (TileEntityInventoryBase)aTile;
if(tile.getSizeInventory() > 0){
for(int i = 0; i < tile.getSizeInventory()-1; i++){
this.dropSlotFromInventory(i, tile, world, x, y, z);
}
}
}
}
super.breakBlock(world, x, y, z, block, par6);
}

View file

@ -64,8 +64,9 @@ public class TooltipEvent{
if(page.getItemStackForPage() != null && page.getItemStackForPage().isItemEqual(stack)){
int keyCode = KeyBinds.keybindOpenBooklet.getKeyCode();
if(!ConfigBoolValues.NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled() || Minecraft.getMinecraft().thePlayer.inventory.hasItem(InitItems.itemLexicon)){
if(ConfigBoolValues.SHOW_NEED_BOOKLET_FOR_KEYBIND_INFO.isEnabled()){
event.toolTip.add(EnumChatFormatting.GOLD+StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".keyToSeeRecipe", keyCode > 0 && keyCode < Keyboard.KEYBOARD_SIZE ? "'"+Keyboard.getKeyName(keyCode)+"'" : "[NONE]"));
}
if(Keyboard.isKeyDown(KeyBinds.keybindOpenBooklet.getKeyCode())){
GuiBooklet book = new GuiBooklet();
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));

View file

@ -52,9 +52,14 @@ public class ContainerToolTable extends Container{
if(this.inventory instanceof TileEntityToolTable){
TileEntityToolTable table = (TileEntityToolTable)this.inventory;
ToolTableHandler.Recipe recipe = ToolTableHandler.getRecipeFromSlots(table.slots);
if(recipe != null){
ItemStack[] stacks = recipe.itemsNeeded.clone();
for(int i = 0; i < TileEntityToolTable.INPUT_SLOT_AMOUNT; i++){
if(ItemUtil.contains(recipe.itemsNeeded, table.getStackInSlot(i))){
int place = ItemUtil.getPlaceAt(stacks, table.getStackInSlot(i));
if(place != -1){
table.decrStackSize(i, 1);
stacks[place] = null;
}
}
}

View file

@ -60,11 +60,18 @@ public class ItemUtil{
* Returns true if array contains stack or if both contain null
*/
public static boolean contains(ItemStack[] array, ItemStack stack){
for(ItemStack aStack : array){
if((stack == null && aStack == null) || (stack != null && aStack != null && aStack.isItemEqual(stack))){
return true;
return getPlaceAt(array, stack) != -1;
}
/**
* Returns the place of stack in array, -1 if not present
*/
public static int getPlaceAt(ItemStack[] array, ItemStack stack){
for(int i = 0; i < array.length; i++){
if((stack == null && array[i] == null) || (stack != null && array[i] != null && array[i].isItemEqual(stack))){
return i;
}
}
return false;
return -1;
}
}