mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Closes #1073
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:
parent
dca3098631
commit
a571c70457
2 changed files with 31 additions and 5 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
||||
|
@ -101,6 +103,31 @@ public final class StackUtil{
|
|||
else for(ItemStack s : stacks) if (!s.isEmpty()) return false;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue