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

97 lines
3.8 KiB
Java
Raw Normal View History

2020-05-05 19:43:27 +02:00
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
2021-12-04 15:40:09 +01:00
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraTimer;
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.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.renderer.RenderType;
2021-12-04 15:40:09 +01:00
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.entity.player.Player;
2020-05-05 19:43:27 +02:00
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
2021-12-04 15:40:09 +01:00
import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.InteractionResult;
2020-05-05 19:43:27 +02:00
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
2021-12-04 15:40:09 +01:00
import net.minecraft.level.IBlockReader;
import net.minecraft.level.Level;
import net.minecraft.level.server.ServerLevel;
2020-05-05 19:43:27 +02:00
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.Random;
import java.util.function.Function;
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 = makeCuboidShape(1, 0, 1, 15, 15, 15);
public BlockAuraTimer() {
2021-12-04 15:40:09 +01:00
super("aura_timer", BlockEntityAuraTimer::new, Properties.from(Blocks.SMOOTH_STONE));
2020-05-05 19:43:27 +02:00
this.setDefaultState(this.getDefaultState().with(BlockStateProperties.POWERED, false));
}
@Override
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
}
@Override
2021-12-04 15:40:09 +01:00
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
2020-05-05 19:43:27 +02:00
return SHAPE;
}
@Override
@OnlyIn(Dist.CLIENT)
2021-12-04 15:40:09 +01:00
public Tuple<BlockEntityType<BlockEntityAuraTimer>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityAuraTimer>>>> getTESR() {
2020-05-05 19:43:27 +02:00
return new Tuple<>(ModTileEntities.AURA_TIMER, () -> RenderAuraTimer::new);
}
@Override
public Supplier<RenderType> getRenderType() {
2020-09-22 03:17:02 +02:00
return RenderType::getCutout;
2020-05-05 19:43:27 +02:00
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(BlockStateProperties.POWERED);
}
@Override
2021-12-04 15:40:09 +01:00
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult p_225533_6_) {
2020-05-05 19:43:27 +02:00
return Helper.putStackOnTile(player, handIn, pos, 0, true);
}
@Override
public boolean canProvidePower(BlockState state) {
return true;
}
@Override
2021-12-04 15:40:09 +01:00
public int getWeakPower(BlockState state, IBlockReader level, BlockPos pos, Direction side) {
2020-05-05 19:43:27 +02:00
return state.get(BlockStateProperties.POWERED) ? 15 : 0;
}
@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);
2020-05-05 19:43:27 +02:00
if (state.get(BlockStateProperties.POWERED))
2021-12-04 15:40:09 +01:00
levelIn.setBlockState(pos, state.with(BlockStateProperties.POWERED, false));
2020-05-05 19:43:27 +02:00
}
}