Skip to content

Commit

Permalink
make bookcases have enchantment power
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Dec 27, 2024
1 parent 0188da7 commit 9cab28a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ run-data

repo
/src/main/generated/.cache/
/src/generated/resources/.cache/
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -14,6 +15,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

import java.util.stream.IntStream;

public class BookcaseBlock extends BCFacingEntityBlock {
private static final VoxelShape NORTH_SHAPE = ShapeUtil.combine(
Shapes.box(0.0625, 0, 0.5, 0.9375, 0.0625, 0.9375),
Expand Down Expand Up @@ -61,4 +64,14 @@ public int getAnalogOutputSignal(BlockState state, Level level, BlockPos pos) {
}
return super.getAnalogOutputSignal(state, level, pos);
}

@Override
public float getEnchantPowerBonus(BlockState state, LevelReader level, BlockPos pos) {
BlockEntity blockEntity = level.getBlockEntity(pos);
if (!(blockEntity instanceof BookcaseBlockEntity bcbe)) return super.getEnchantPowerBonus(state, level, pos);
return super.getEnchantPowerBonus(state, level, pos) + 0.125f * IntStream.range(0, bcbe.getContainerSize())
.mapToObj(bcbe::getItem)
.filter(e -> !e.isEmpty())
.count();
}
}

0 comments on commit 9cab28a

Please sign in to comment.