This fix means there is a clear underlying issue with the inventory
structure of AA...  This is going to be quite a big refactor.  Bleh.
This commit is contained in:
Shadows_of_Fire 2018-05-31 16:41:13 -04:00
parent dca3098631
commit a571c70457
2 changed files with 31 additions and 5 deletions

View file

@ -72,7 +72,7 @@ public class TileEntityBreaker extends TileEntityInventoryBase {
@Override
public boolean isItemValidForSlot(int i, ItemStack stack) {
return this.isPlacer;
return true;
}
private void doWork() {
@ -87,10 +87,9 @@ public class TileEntityBreaker extends TileEntityInventoryBase {
float chance = WorldUtil.fireFakeHarvestEventsForDropChance(drops, world, breakCoords);
if (chance > 0 && world.rand.nextFloat() <= chance) {
if (WorldUtil.addToInventory(slots, drops, false)) {
this.world.playEvent(2001, breakCoords, Block.getStateId(stateToBreak));
this.world.setBlockToAir(breakCoords);
WorldUtil.addToInventory(slots, drops, true);
if (StackUtil.canAddAll(slots, drops)) {
world.destroyBlock(breakCoords, false);
StackUtil.addAll(slots, drops);
this.markDirty();
}
}

View file

@ -11,11 +11,13 @@
package de.ellpeck.actuallyadditions.mod.util;
import java.util.Collection;
import java.util.List;
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.items.IItemHandler;
public final class StackUtil{
@ -102,5 +104,30 @@ public final class StackUtil{
return true;
}
public static boolean canAddAll(IItemHandler inv, List<ItemStack> stacks) {
int slotMax = inv.getSlots();
int counter = 0;
for(ItemStack s : stacks) {
for(int i = 0; i < slotMax; i++) {
s = inv.insertItem(i, s, true);
if(s.isEmpty()) break;
}
if(s.isEmpty()) counter++;
}
return counter == stacks.size();
}
public static void addAll(IItemHandler inv, List<ItemStack> stacks) {
int slotMax = inv.getSlots();
for(ItemStack s : stacks) {
for(int i = 0; i < slotMax; i++) {
s = inv.insertItem(i, s, false);
if(s.isEmpty()) break;
}
}
}
}