Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.mcreator.askir.block;
- import net.minecraftforge.registries.ObjectHolder;
- import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
- import net.minecraftforge.api.distmarker.OnlyIn;
- import net.minecraftforge.api.distmarker.Dist;
- import net.minecraft.state.properties.SlabType;
- import net.minecraft.loot.LootContext;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.Item;
- import net.minecraft.item.BlockItem;
- import net.minecraft.client.renderer.RenderTypeLookup;
- import net.minecraft.client.renderer.RenderType;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.SoundType;
- import net.minecraft.block.SlabBlock;
- import net.minecraft.block.BlockState;
- import net.minecraft.block.Block;
- import net.minecraft.world.IBlockReader;
- import net.minecraft.util.math.vector.Vector3d;
- import net.minecraft.util.math.shapes.VoxelShapes;
- import net.minecraft.util.math.shapes.VoxelShape;
- import net.minecraft.util.math.shapes.ISelectionContext;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.Rotation;
- import net.minecraft.util.Mirror;
- import net.minecraft.util.Direction;
- import net.minecraft.state.StateContainer;
- import net.minecraft.state.DirectionProperty;
- import net.minecraft.item.BlockItemUseContext;
- import net.minecraft.block.HorizontalBlock;
- import net.mcreator.askir.itemgroup.AskirModToolsItemGroup;
- import net.mcreator.askir.AskirModElements;
- import java.util.List;
- import java.util.Collections;
- @AskirModElements.ModElement.Tag
- public class LetsgoBlock extends AskirModElements.ModElement {
- @ObjectHolder("askir:letsgo")
- public static final Block block = null;
- public LetsgoBlock(AskirModElements instance) {
- super(instance, 606);
- }
- @Override
- public void initElements() {
- elements.blocks.add(() -> new CustomBlock());
- elements.items
- .add(() -> new BlockItem(block, new Item.Properties().group(AskirModToolsItemGroup.tab)).setRegistryName(block.getRegistryName()));
- }
- @Override
- @OnlyIn(Dist.CLIENT)
- public void clientLoad(FMLClientSetupEvent event) {
- RenderTypeLookup.setRenderLayer(block, RenderType.getCutout());
- }
- public static class CustomBlock extends SlabBlock {
- public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
- public CustomBlock() {
- super(Block.Properties.create(Material.ROCK).sound(SoundType.GROUND).hardnessAndResistance(1f, 10f).setLightLevel(s -> 0).notSolid()
- .setOpaque((bs, br, bp) -> false));
- this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.NORTH));
- setRegistryName("letsgo");
- }
- @Override
- public boolean propagatesSkylightDown(BlockState state, IBlockReader reader, BlockPos pos) {
- return true;
- }
- @Override
- public int getOpacity(BlockState state, IBlockReader worldIn, BlockPos pos) {
- return 0;
- }
- @Override
- public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) {
- Vector3d offset = state.getOffset(world, pos);
- switch ((Direction) state.get(FACING)) {
- case SOUTH :
- default :
- return VoxelShapes.or(makeCuboidShape(16, 0, 8, 0, 8, 0)).withOffset(offset.x, offset.y, offset.z);
- case NORTH :
- return VoxelShapes.or(makeCuboidShape(0, 0, 8, 16, 8, 16)).withOffset(offset.x, offset.y, offset.z);
- case EAST :
- return VoxelShapes.or(makeCuboidShape(8, 0, 0, 0, 8, 16)).withOffset(offset.x, offset.y, offset.z);
- case WEST :
- return VoxelShapes.or(makeCuboidShape(8, 0, 16, 16, 8, 0)).withOffset(offset.x, offset.y, offset.z);
- }
- }
- @Override
- protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
- builder.add(FACING);
- }
- public BlockState rotate(BlockState state, Rotation rot) {
- return state.with(FACING, rot.rotate(state.get(FACING)));
- }
- public BlockState mirror(BlockState state, Mirror mirrorIn) {
- return state.rotate(mirrorIn.toRotation(state.get(FACING)));
- }
- @Override
- public BlockState getStateForPlacement(BlockItemUseContext context) {
- ;
- return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite());
- }
- @Override
- public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
- List<ItemStack> dropsOriginal = super.getDrops(state, builder);
- if (!dropsOriginal.isEmpty())
- return dropsOriginal;
- return Collections.singletonList(new ItemStack(this, state.get(TYPE) == SlabType.DOUBLE ? 2 : 1));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement