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;
|
2021-12-15 14:26:42 +01:00
|
|
|
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;
|
2021-12-15 14:26:42 +01:00
|
|
|
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
|
|
|
|
2022-08-01 16:14:37 +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));
|
2021-12-15 14:26:42 +01:00
|
|
|
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")
|
2021-12-15 14:26:42 +01:00
|
|
|
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
|
2021-12-15 14:26:42 +01:00
|
|
|
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")
|
2021-12-15 14:26:42 +01:00
|
|
|
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")
|
2021-12-15 14:26:42 +01:00
|
|
|
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")
|
2021-12-15 14:26:42 +01:00
|
|
|
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);
|
2021-12-15 14:26:42 +01:00
|
|
|
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
|
|
|
}
|