Jump to content

marinz

Members
  • Posts

    67
  • Joined

  • Last visited

Posts posted by marinz

  1. Randomly placing different variants of rock. This is my rock block class

    package com.tzs.asm.blocks;
    
    import java.util.stream.Stream;
    
    import net.minecraft.block.AbstractBlock;
    import net.minecraft.block.Block;
    import net.minecraft.block.BlockState;
    import net.minecraft.block.SoundType;
    import net.minecraft.block.material.Material;
    import net.minecraft.block.material.MaterialColor;
    import net.minecraft.item.BlockItemUseContext;
    import net.minecraft.state.DirectionProperty;
    import net.minecraft.state.StateContainer.Builder;
    import net.minecraft.state.properties.BlockStateProperties;
    import net.minecraft.util.Direction;
    import net.minecraft.util.Mirror;
    import net.minecraft.util.Rotation;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.math.shapes.IBooleanFunction;
    import net.minecraft.util.math.shapes.ISelectionContext;
    import net.minecraft.util.math.shapes.VoxelShape;
    import net.minecraft.util.math.shapes.VoxelShapes;
    import net.minecraft.world.IBlockReader;
    import net.minecraft.world.IWorld;
    
    public class rockBlock extends Block {
    	
    	public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
    	
    	
    	
    	public rockBlock() {
    		super(AbstractBlock.Properties.of(Material.STONE, MaterialColor.COLOR_GRAY).speedFactor(0.3f)
    				.friction(0.5f).harvestLevel(1).sound(SoundType.STONE).noOcclusion());
    		
    		this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
    	}
    	
    	@SuppressWarnings("deprecation")
    	@Override
    	public BlockState mirror(BlockState state, Mirror mirrorIn) {
    		return state.rotate(mirrorIn.getRotation(state.getValue(FACING)));
    	}
    	
    	@Override
    	public BlockState rotate(BlockState state, IWorld world, BlockPos pos, Rotation direction) {
    		return state.setValue(FACING, direction.rotate(state.getValue(FACING)));
    	}
    	
    	@Override
    	public BlockState getStateForPlacement(BlockItemUseContext context) {
    		return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
    	}
    	
    	@Override
    	protected void createBlockStateDefinition(Builder<Block, BlockState> builder) {
    		super.createBlockStateDefinition(builder);
    		builder.add(FACING);
    	}
    	
    	private static final VoxelShape rockN = Stream.of(
    			Block.box(8.450000000000001, 0, 5.275, 9.450000000000001, 0.40000000000000036, 5.975),
    			Block.box(6.850000000000001, 0, 5.975, 9.850000000000001, 1, 10.975),
    			Block.box(5.850000000000001, 0, 8.575, 6.850000000000001, 0.40000000000000036, 10.674999999999999),
    			Block.box(7.350000000000001, 0, 6.775, 9.350000000000001, 0.40000000000000036, 9.775)
    			).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get();
    	
    	private static final VoxelShape rockE = Stream.of(
    			Block.box(10.025000000000002, 0, 8.45, 10.725000000000001, 0.40000000000000036, 9.45),
    			Block.box(5.025000000000002, 0, 6.85, 10.025000000000002, 1, 9.85),
    			Block.box(5.325000000000003, 0, 5.85, 7.4250000000000025, 0.40000000000000036, 6.85),
    			Block.box(6.225000000000001, 0, 7.35, 9.225000000000001, 0.40000000000000036, 9.35)
    			).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get();
    	
    	private static final VoxelShape rockS = Stream.of(
    			Block.box(6.5500000000000025, 0, 10.025, 7.5500000000000025, 0.40000000000000036, 10.725),
    			Block.box(6.150000000000002, 0, 5.025, 9.150000000000002, 1, 10.025),
    			Block.box(9.150000000000002, 0, 5.325000000000001, 10.150000000000002, 0.40000000000000036, 7.425000000000001),
    			Block.box(6.650000000000002, 0, 6.225, 8.650000000000002, 0.40000000000000036, 9.225)
    			).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get();
    	
    	private static final VoxelShape rockW = Stream.of(
    			Block.box(5.275000000000002, 0, 6.550000000000001, 5.975000000000001, 0.40000000000000036, 7.550000000000001),
    			Block.box(5.975000000000001, 0, 6.15, 10.975000000000001, 1, 9.15),
    			Block.box(8.575000000000001, 0, 9.15, 10.675, 0.40000000000000036, 10.15),
    			Block.box(6.775000000000002, 0, 6.65, 9.775000000000002, 0.40000000000000036, 8.65)
    			).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get();
    
    	@Override
    	public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
    	    switch(state.getValue(FACING)) {
    		case EAST:
    			return rockE;
    		case SOUTH:
    			return rockS;
    		case WEST:
    			return rockW;
    		default:
    			return rockN;
    	    }
    	}
    }

     

  2. So if I just do this it should work:

    {
         "variants": {
              "facing=north": {"model": "asm:block/rock1"},
              "facing=east": {"model": "asm:block/rock1", "y": 90},
              "facing=south": {"model": "asm:block/rock1", "y": 180},
              "facing=west": {"model": "asm:block/rock1", "y": 270},
       		  "facing=north": {"model": "asm:block/rock2"},
              "facing=east": {"model": "asm:block/rock2", "y": 90},
              "facing=south": {"model": "asm:block/rock2", "y": 180},
              "facing=west": {"model": "asm:block/rock2", "y": 270}
         }
    }

     

  3. I did it and it works but there is another question. My block is rock, I have 1 model for it and I did the facing, but I would like to add more variants(few more models so when I click with rock item on ground it puts a random model) with facing and that to spawn in every biome.

  4. I've made a block smaller then 16x16 but the bounding box or hitbox(I don't know what it's actually called) is still 16x16 or full cube block. How do I change that. Do I have to make seperate class for that block or can I just do something with this code below.

    public class BlockInit{
    	
    	public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, asmMain.MODID);
    
    	public static final RegistryObject<Block> ROCK = BLOCKS.register("rock",
    			() -> new Block(AbstractBlock.Properties.of(Material.STONE, MaterialColor.COLOR_GRAY).speedFactor(0.3f)
    					.friction(0.5f).harvestLevel(1).sound(SoundType.STONE).noOcclusion()));
    
    }

     

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.