Jump to content

1.16.5 How to change block hitbox


marinz

Recommended Posts

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()));

}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Is this what you are talking about?

{
  "variants": {
    "": [
      {
        "model": "minecraft:block/stone"
      },
      {
        "model": "minecraft:block/stone_mirrored"
      },
      {
        "model": "minecraft:block/stone",
        "y": 180
      },
      {
        "model": "minecraft:block/stone_mirrored",
        "y": 180
      }
    ]
  }
}

 

Link to comment
Share on other sites

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}
     }
}

 

Link to comment
Share on other sites

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;
	    }
	}
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Sup,i use forge 47.2.30 for 1.20.1 and i got this crash error :  https://pastebin.com/SMxVrV3E May someone help me ? Thank you !
    • 🎰 Mainkan Slot Online dengan Hanya 5 Ribu Via Dana, Proses Cepat! 🎰 Buka pintu ke dunia hiburan tanpa batas di UANG69 Slot Online! Bersiaplah untuk merasakan sensasi kemenangan di ujung jari Anda dengan taruhan serendah 5 ribu rupiah saja, melalui metode pembayaran yang mudah via Dana! ⚡ Proses Cepat, Nikmati Keuntungan dalam Sekejap ⚡ Bergabunglah dengan komunitas slot paling dinamis dan terpanas, dengan puluhan permainan slot yang menakjubkan, serta kesempatan untuk memenangkan jackpot besar! Rasakan gemerlapnya Las Vegas langsung dari kenyamanan rumah Anda sendiri. 🔥 Keunggulan UANG69 Slot Online: 🔥 ✅ Taruhan Serendah 5 Ribu Rupiah ✅ Metode Pembayaran Mudah via Dana ✅ Proses Cepat, Penarikan Lancar ✅ Puluhan Permainan Slot Terbaik ✅ Jackpot Besar Menanti untuk Dimenangkan Bergabunglah dengan UANG69 hari ini dan jadilah bagian dari petualangan slot yang tak terlupakan. Nikmati keseruan, kemenangan, dan hiburan di ujung jari Anda! Jangan lewatkan kesempatan ini, bergabunglah sekarang dan mulailah memenangkan hadiah besar! 💰💎🎉
    • Hello, I am trying to play Minecraft (premium version) with the All Of Create mod from CurseForge. When I launch it from the Minecraft launcher I get an error "The game has stopped working" Error code: 1. I tried to create a modpack, without mods, and launch it (in case there was any incompatibility) but it doesn't work either.... Error with mod: https://paste.ee/p/zzvJY I hope someone can help me. Thanks in advance.
    • Jika Anda mencari maxwin secepat kilat, maka Slot Kilat77 adalah tempatnya! Dengan koleksi slot terbaik yang dirancang untuk memberikan kemenangan instan, setiap putaran di Slot Kilat77 adalah kesempatan untuk memenangkan hadiah besar dalam sekejap. Bergabunglah sekarang dan rasakan sensasi kemenangan kilat di setiap gulungan. Jadi, jangan ragu lagi, mari bergabung dan raih maxwin secepat kilat hanya di Slot Kilat77!
    • Jos77 adalah pilihan terbaik untuk meraih maxwin hari ini! Dengan koleksi permainan slot terbaik dan peluang kemenangan yang tinggi, setiap putaran di Jos77 adalah kesempatan untuk memenangkan hadiah besar. Bergabunglah sekarang dan rasakan sensasi kemenangan yang luar biasa di setiap gulungan. Jadi, jangan lewatkan kesempatan untuk menjadi pemenang hari ini di Jos77 Mulailah petualangan slot Anda sekarang di Jos77 dan temukan sendiri mengapa kami adalah pilihan utama para pencari maxwin. Dengan grafis yang memukau, fitur bonus yang menggiurkan, dan dukungan pelanggan yang luar biasa, kami siap membawa pengalaman bermain Anda ke level berikutnya. Tidak peduli apakah Anda seorang pemula atau ahli slot, Jos77 menyediakan lingkungan yang ramah dan menyenangkan bagi semua pemain. Jadi, bersiaplah untuk meraih maxwin dan nikmati kesuksesan Anda di Jos77 hari ini!  
  • Topics

×
×
  • Create New...

Important Information

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