Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

}

 

you need a separate class, take a look at vanilla Blocks (BrewingStandBlock) how they create the VoxelShape

  • Author

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.

  • Author

I am using eclipse, I tried every search option and open type and got nothing. Is there any other way to search I am not that familiar with that.

  • Author

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

 

  • Author

First how sould I do different models all with different facing but with one item

  • Author

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

 

  • Author

Now it just places the second model not the first one and is there a way to have seperated hit boxes cuz second model is not the same as the first one

  • Author

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

 

  • Author

yeah I get that but what to use exept 

8 minutes ago, diesieben07 said:

DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;

 

  • Author

Does that mean I have to make class for that property too? Is this good?

public static final VariantProperty VARIANT = new VariantProperty();

 

  • Author
1 minute ago, marinz said:

public static final VariantProperty VARIANT = new VariantProperty();

So this is good? What do I do next

  • Author

I don't know... I am sorry I'm trying to figure it out but It's not going anywhere

  • Author

Is this something?

public static final	VariantProperty VARIANT = VariantProperty.valueOf("variant");

 

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.