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-15 14:26:42 +01:00
|
|
|
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;
|
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;
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2021-12-15 14:26:42 +01:00
|
|
|
private static final VoxelShape SHAPE = box(1, 0, 1, 15, 15, 15);
|
2020-05-05 19:43:27 +02:00
|
|
|
|
|
|
|
public BlockAuraTimer() {
|
2021-12-15 14:26:42 +01:00
|
|
|
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
|
2021-12-15 14:26:42 +01:00
|
|
|
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
|
2020-05-05 19:43:27 +02:00
|
|
|
return SHAPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Supplier<RenderType> getRenderType() {
|
2021-12-15 14:26:42 +01:00
|
|
|
return RenderType::cutout;
|
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
|
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
|
2021-12-15 14:26:42 +01:00
|
|
|
public boolean isSignalSource(BlockState state) {
|
2020-05-05 19:43:27 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
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
|
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);
|
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() {
|
|
|
|
BlockEntityRenderers.register(ModTileEntities.AURA_TIMER, RenderAuraTimer::new);
|
|
|
|
}
|
2020-05-05 19:43:27 +02:00
|
|
|
}
|