54 lines
1.8 KiB
Java
54 lines
1.8 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import com.mojang.serialization.MapCodec;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.stats.Stat;
|
|
import net.minecraft.stats.Stats;
|
|
import net.minecraft.util.Mth;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
|
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
|
import net.minecraft.world.level.block.entity.TrappedChestBlockEntity;
|
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
public class TrappedChestBlock extends ChestBlock {
|
|
public static final MapCodec<TrappedChestBlock> CODEC = simpleCodec(TrappedChestBlock::new);
|
|
|
|
@Override
|
|
public MapCodec<TrappedChestBlock> codec() {
|
|
return CODEC;
|
|
}
|
|
|
|
public TrappedChestBlock(BlockBehaviour.Properties properties) {
|
|
super(() -> BlockEntityType.TRAPPED_CHEST, properties);
|
|
}
|
|
|
|
@Override
|
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
|
return new TrappedChestBlockEntity(pos, state);
|
|
}
|
|
|
|
@Override
|
|
protected Stat<ResourceLocation> getOpenChestStat() {
|
|
return Stats.CUSTOM.get(Stats.TRIGGER_TRAPPED_CHEST);
|
|
}
|
|
|
|
@Override
|
|
protected boolean isSignalSource(BlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
protected int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {
|
|
return Mth.clamp(ChestBlockEntity.getOpenCount(level, pos), 0, 15);
|
|
}
|
|
|
|
@Override
|
|
protected int getDirectSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {
|
|
return direction == Direction.UP ? state.getSignal(level, pos, direction) : 0;
|
|
}
|
|
}
|