ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/common/blocks/functional/LampBlock.java

44 lines
1.6 KiB
Java

package de.ellpeck.actuallyadditions.common.blocks.functional;
import de.ellpeck.actuallyadditions.common.blocks.ActuallyBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
public class ColoredLampBlock extends ActuallyBlock {
private static final BooleanProperty LIT = BlockStateProperties.LIT;
public ColoredLampBlock() {
super(Properties.create(Material.ROCK));
this.setDefaultState(this.stateContainer.getBaseState().with(LIT, false));
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(LIT);
}
@Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
if (!state.get(LIT)) {
worldIn.setBlockState(pos, state.getBlock().getDefaultState().with(LIT, true));
}
return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
}
@Override
public int getLightValue(BlockState state, IBlockReader world, BlockPos pos) {
return state.get(LIT) ? 15 : 0;
}
}