Skip to content

Commit

Permalink
Work around schematicannon item requirement bug by using multiple Sta…
Browse files Browse the repository at this point in the history
…ckRequirements, fixes #155
  • Loading branch information
hlysine committed Sep 8, 2024
1 parent 12f1f79 commit e115afd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import javax.annotation.ParametersAreNonnullByDefault;

import java.util.Optional;
import java.util.stream.IntStream;

import static net.minecraft.world.level.block.state.properties.BlockStateProperties.*;

Expand Down Expand Up @@ -338,10 +339,13 @@ static BlockState getMaterial(BlockGetter reader, BlockPos targetPos) {
* Utility to get the required items for a layer of a block state.
*/
static ItemRequirement getRequiredItemsForLayer(BlockState state, IntegerProperty property) {
return new ItemRequirement(
ItemRequirement.ItemUseType.CONSUME,
new ItemStack(state.getBlock().asItem(), state.getValue(property))
);
int count = state.getValue(property);
if (count == 0)
return ItemRequirement.NONE;
return new ItemRequirement(IntStream.range(0, count).mapToObj($ -> new ItemRequirement.StackRequirement(
new ItemStack(state.getBlock().asItem()),
ItemRequirement.ItemUseType.CONSUME
)).toList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Optional;
import java.util.Set;
import java.util.stream.IntStream;

/**
* An interface with implementation for all multi-state copycats.
Expand Down Expand Up @@ -435,10 +436,10 @@ static ItemRequirement getRequiredItemsForParts(BlockState state, BooleanPropert
count++;
}
if (count == 0) return ItemRequirement.NONE;
return new ItemRequirement(
ItemRequirement.ItemUseType.CONSUME,
new ItemStack(state.getBlock().asItem(), count)
);
return new ItemRequirement(IntStream.range(0, count).mapToObj($ -> new ItemRequirement.StackRequirement(
new ItemStack(state.getBlock().asItem()),
ItemRequirement.ItemUseType.CONSUME
)).toList());
}

@Override
Expand Down

0 comments on commit e115afd

Please sign in to comment.