Advertisement
Guest User

Slab with rotation

a guest
Nov 27th, 2021
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.mcreator.askir.block;
  2.  
  3. import net.minecraftforge.registries.ObjectHolder;
  4. import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
  5. import net.minecraftforge.api.distmarker.OnlyIn;
  6. import net.minecraftforge.api.distmarker.Dist;
  7.  
  8. import net.minecraft.state.properties.SlabType;
  9. import net.minecraft.loot.LootContext;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.item.Item;
  12. import net.minecraft.item.BlockItem;
  13. import net.minecraft.client.renderer.RenderTypeLookup;
  14. import net.minecraft.client.renderer.RenderType;
  15. import net.minecraft.block.material.Material;
  16. import net.minecraft.block.SoundType;
  17. import net.minecraft.block.SlabBlock;
  18. import net.minecraft.block.BlockState;
  19. import net.minecraft.block.Block;
  20.  
  21. import net.minecraft.world.IBlockReader;
  22. import net.minecraft.util.math.vector.Vector3d;
  23. import net.minecraft.util.math.shapes.VoxelShapes;
  24. import net.minecraft.util.math.shapes.VoxelShape;
  25. import net.minecraft.util.math.shapes.ISelectionContext;
  26. import net.minecraft.util.math.BlockPos;
  27. import net.minecraft.util.Rotation;
  28. import net.minecraft.util.Mirror;
  29. import net.minecraft.util.Direction;
  30. import net.minecraft.state.StateContainer;
  31. import net.minecraft.state.DirectionProperty;
  32. import net.minecraft.item.BlockItemUseContext;
  33. import net.minecraft.block.HorizontalBlock;
  34.  
  35. import net.mcreator.askir.itemgroup.AskirModToolsItemGroup;
  36. import net.mcreator.askir.AskirModElements;
  37.  
  38. import java.util.List;
  39. import java.util.Collections;
  40.  
  41. @AskirModElements.ModElement.Tag
  42. public class LetsgoBlock extends AskirModElements.ModElement {
  43. @ObjectHolder("askir:letsgo")
  44. public static final Block block = null;
  45. public LetsgoBlock(AskirModElements instance) {
  46. super(instance, 606);
  47. }
  48.  
  49. @Override
  50. public void initElements() {
  51. elements.blocks.add(() -> new CustomBlock());
  52. elements.items
  53. .add(() -> new BlockItem(block, new Item.Properties().group(AskirModToolsItemGroup.tab)).setRegistryName(block.getRegistryName()));
  54. }
  55.  
  56. @Override
  57. @OnlyIn(Dist.CLIENT)
  58. public void clientLoad(FMLClientSetupEvent event) {
  59. RenderTypeLookup.setRenderLayer(block, RenderType.getCutout());
  60. }
  61. public static class CustomBlock extends SlabBlock {
  62. public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
  63. public CustomBlock() {
  64. super(Block.Properties.create(Material.ROCK).sound(SoundType.GROUND).hardnessAndResistance(1f, 10f).setLightLevel(s -> 0).notSolid()
  65. .setOpaque((bs, br, bp) -> false));
  66. this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.NORTH));
  67. setRegistryName("letsgo");
  68. }
  69.  
  70. @Override
  71. public boolean propagatesSkylightDown(BlockState state, IBlockReader reader, BlockPos pos) {
  72. return true;
  73. }
  74.  
  75. @Override
  76. public int getOpacity(BlockState state, IBlockReader worldIn, BlockPos pos) {
  77. return 0;
  78. }
  79.  
  80. @Override
  81. public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) {
  82. Vector3d offset = state.getOffset(world, pos);
  83. switch ((Direction) state.get(FACING)) {
  84. case SOUTH :
  85. default :
  86. return VoxelShapes.or(makeCuboidShape(16, 0, 8, 0, 8, 0)).withOffset(offset.x, offset.y, offset.z);
  87. case NORTH :
  88. return VoxelShapes.or(makeCuboidShape(0, 0, 8, 16, 8, 16)).withOffset(offset.x, offset.y, offset.z);
  89. case EAST :
  90. return VoxelShapes.or(makeCuboidShape(8, 0, 0, 0, 8, 16)).withOffset(offset.x, offset.y, offset.z);
  91. case WEST :
  92. return VoxelShapes.or(makeCuboidShape(8, 0, 16, 16, 8, 0)).withOffset(offset.x, offset.y, offset.z);
  93. }
  94. }
  95.  
  96. @Override
  97. protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
  98. builder.add(FACING);
  99. }
  100.  
  101. public BlockState rotate(BlockState state, Rotation rot) {
  102. return state.with(FACING, rot.rotate(state.get(FACING)));
  103. }
  104.  
  105. public BlockState mirror(BlockState state, Mirror mirrorIn) {
  106. return state.rotate(mirrorIn.toRotation(state.get(FACING)));
  107. }
  108.  
  109. @Override
  110. public BlockState getStateForPlacement(BlockItemUseContext context) {
  111. ;
  112. return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite());
  113. }
  114.  
  115. @Override
  116. public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
  117. List<ItemStack> dropsOriginal = super.getDrops(state, builder);
  118. if (!dropsOriginal.isEmpty())
  119. return dropsOriginal;
  120. return Collections.singletonList(new ItemStack(this, state.get(TYPE) == SlabType.DOUBLE ? 2 : 1));
  121. }
  122. }
  123. }
  124.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement