NaturesAura/src/main/java/de/ellpeck/naturesaura/blocks/BlockAuraTimer.java

84 lines
3.4 KiB
Java
Raw Normal View History

2020-05-05 19:43:27 +02:00
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
2021-12-04 15:40:09 +01:00
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraTimer;
2021-12-19 15:32:45 +01:00
import de.ellpeck.naturesaura.blocks.tiles.ModBlockEntities;
2020-05-05 19:43:27 +02:00
import de.ellpeck.naturesaura.blocks.tiles.render.RenderAuraTimer;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider;
2021-12-15 16:24:53 +01:00
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
2022-06-27 15:24:04 +02:00
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
2020-05-05 19:43:27 +02:00
public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockState, ITESRProvider<BlockEntityAuraTimer> {
2020-05-05 19:43:27 +02:00
2022-06-27 15:24:04 +02:00
private static final VoxelShape SHAPE = Block.box(1, 0, 1, 15, 15, 15);
2020-05-05 19:43:27 +02:00
public BlockAuraTimer() {
2021-12-19 15:32:45 +01:00
super("aura_timer", BlockEntityAuraTimer.class, Properties.copy(Blocks.SMOOTH_STONE));
this.registerDefaultState(this.defaultBlockState().setValue(BlockStateProperties.POWERED, false));
2020-05-05 19:43:27 +02:00
}
@Override
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
}
@Override
2023-02-15 23:45:50 +01:00
@SuppressWarnings("deprecation")
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
2022-06-27 15:24:04 +02:00
return BlockAuraTimer.SHAPE;
2020-05-05 19:43:27 +02:00
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
2020-05-05 19:43:27 +02:00
builder.add(BlockStateProperties.POWERED);
}
@Override
2023-02-15 23:45:50 +01:00
@SuppressWarnings("deprecation")
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult p_225533_6_) {
2020-05-05 19:43:27 +02:00
return Helper.putStackOnTile(player, handIn, pos, 0, true);
}
@Override
2023-02-15 23:45:50 +01:00
@SuppressWarnings("deprecation")
public boolean isSignalSource(BlockState state) {
2020-05-05 19:43:27 +02:00
return true;
}
@Override
2023-02-15 23:45:50 +01:00
@SuppressWarnings("deprecation")
public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction side) {
return state.getValue(BlockStateProperties.POWERED) ? 15 : 0;
2020-05-05 19:43:27 +02:00
}
@Override
2022-06-27 15:24:04 +02:00
public void tick(BlockState state, ServerLevel levelIn, BlockPos pos, RandomSource random) {
2021-12-04 15:40:09 +01:00
super.tick(state, levelIn, pos, random);
if (state.getValue(BlockStateProperties.POWERED))
levelIn.setBlockAndUpdate(pos, state.setValue(BlockStateProperties.POWERED, false));
2020-05-05 19:43:27 +02:00
}
2021-12-15 16:24:53 +01:00
@Override
public void registerTESR() {
2021-12-19 15:32:45 +01:00
BlockEntityRenderers.register(ModBlockEntities.AURA_TIMER, RenderAuraTimer::new);
2021-12-15 16:24:53 +01:00
}
2020-05-05 19:43:27 +02:00
}