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

92 lines
3.6 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;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
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.ICustomRenderType;
import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
2020-05-05 19:43:27 +02:00
import net.minecraft.util.Tuple;
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.entity.BlockEntityType;
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
import java.util.Random;
import java.util.function.Supplier;
2021-12-04 15:40:09 +01:00
public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockState, ITESRProvider<BlockEntityAuraTimer>, ICustomRenderType {
2020-05-05 19:43:27 +02:00
private static final VoxelShape SHAPE = box(1, 0, 1, 15, 15, 15);
2020-05-05 19:43:27 +02:00
public BlockAuraTimer() {
super("aura_timer", BlockEntityAuraTimer::new, 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
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
2020-05-05 19:43:27 +02:00
return SHAPE;
}
@Override
public Tuple<BlockEntityType<? extends BlockEntityAuraTimer>, Supplier<BlockEntityRendererProvider<BlockEntityAuraTimer>>> getTESR() {
2020-05-05 19:43:27 +02:00
return new Tuple<>(ModTileEntities.AURA_TIMER, () -> RenderAuraTimer::new);
}
@Override
public Supplier<RenderType> getRenderType() {
return RenderType::cutout;
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
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
public boolean isSignalSource(BlockState state) {
2020-05-05 19:43:27 +02:00
return true;
}
@Override
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
2021-12-04 15:40:09 +01:00
public void tick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
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
}
}