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

View file

@ -11,11 +11,13 @@
package de.ellpeck.actuallyadditions.mod.util; package de.ellpeck.actuallyadditions.mod.util;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem; import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraftforge.items.IItemHandler;
public final class StackUtil{ public final class StackUtil{
@ -101,6 +103,31 @@ public final class StackUtil{
else for(ItemStack s : stacks) if (!s.isEmpty()) return false; else for(ItemStack s : stacks) if (!s.isEmpty()) return false;
return true; 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;
}
}
}
} }