Skip to content

Commit

Permalink
Fix item filter not dropping buffered items when destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
Rearth committed Dec 5, 2024
1 parent 3dca9b7 commit 89c22c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.enums.BlockFace;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
Expand Down Expand Up @@ -103,6 +104,23 @@ public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos po
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return getOutlineShape(state, world, pos, context);
}

@Override
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {

if (!world.isClient) {
var entity = (ItemFilterBlockEntity) world.getBlockEntity(pos);
var stacks = entity.inventory.heldStacks;
for (var stack : stacks) {
if (!stack.isEmpty()) {
var itemEntity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack);
world.spawnEntity(itemEntity);
}
}
}

return super.onBreak(world, pos, state, player);
}

static {
BOUNDING_SHAPES = new VoxelShape[Direction.values().length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

public class ItemFilterBlockEntity extends BlockEntity implements InventoryProvider, ExtendedScreenHandlerFactory, BlockEntityTicker<ItemFilterBlockEntity> {

protected final FilterBlockInventory inventory = new FilterBlockInventory(1);
public final FilterBlockInventory inventory = new FilterBlockInventory(1);

protected FilterData filterSettings = new FilterData(false, true, new HashMap<>());
protected BlockApiCache<Storage<ItemVariant>, Direction> lookupCache;
Expand Down Expand Up @@ -160,7 +160,7 @@ public void markDirty() {
public record FilterData(boolean useNbt, boolean useWhitelist, Map<Integer, ItemStack> items) {
}

protected class FilterBlockInventory extends SimpleInventory implements SidedInventory {
public class FilterBlockInventory extends SimpleInventory implements SidedInventory {

public FilterBlockInventory(int size) {
super(size);
Expand Down

0 comments on commit 89c22c3

Please sign in to comment.