mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +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
|
@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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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{
|
||||||
|
|
||||||
|
@ -102,5 +104,30 @@ public final class StackUtil{
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue