Jump to content

[SOLVED] [1.16.4] Change Block Hitbox/Outline


Lellian

Recommended Posts

Hello modders,

 

I am new to modding mc, and I have a problem with custom block hitboxes.

 

I have made a block (The little stone thing, currently called ExampleBlock to test this) with a custom model and it works just fine, but the model is quite a bit smaller than a full block, yet it still has the hitbox of a full block:

 

2021-01-15_23_35_44.png.7e52c4d172a7e612edbec387da587821.png

 

Now, I did a lot of googling and found that, to get a custom hitbox, you need to override getShape().

I did that. Unfortunately, it didn't change anything. I must still be missing something, but I don't know what it is. 

All I want is for the hitbox/outline to be smaller, it can remain a simple box.

 

The block file:

 

package lellian.mc.elementology.common.blocks;

import lellian.mc.elementology.common.EleRegistry;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraftforge.fml.RegistryObject;

import javax.annotation.Nonnull;

public class ExampleBlock extends Block {
    private static VoxelShape SHAPE = makeCuboidShape(4d, 0d, 4d, 12d, 4d, 12d);

    public static final RegistryObject<net.minecraft.block.Block> EXAMPLE_BLOCK = EleRegistry.registerBlock("example_block",
            () -> new Block(AbstractBlock.Properties
                    .create(Material.ROCK)
                    .hardnessAndResistance(3, 3)
                    .sound(SoundType.STONE)
                    .notSolid()));

    public ExampleBlock(Properties properties) {
        super(properties);
    }

    // Called for class loading.
    public static void register(){};

    @Nonnull
    @Override
    public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        return SHAPE;
    }
}

 

I'm not sure how relevant it is, but here is also:

 

The BlockStateProvider:

 

package lellian.mc.elementology.client.data;

import lellian.mc.elementology.common.Elementology;
import lellian.mc.elementology.common.blocks.EleSimpleBlocks;
import lellian.mc.elementology.common.blocks.ExampleBlock;
import lellian.mc.elementology.common.blocks.MortarAndPestleBlock;
import net.minecraft.block.Block;
import net.minecraft.block.SlabBlock;
import net.minecraft.data.DataGenerator;
import net.minecraftforge.client.model.generators.BlockStateProvider;
import net.minecraftforge.client.model.generators.ModelFile;
import net.minecraftforge.common.data.ExistingFileHelper;

public class EleBlockStateProvider extends BlockStateProvider {
    public EleBlockStateProvider(DataGenerator gen, ExistingFileHelper exFileHelper) {
        super(gen, Elementology.MOD_ID, exFileHelper);
    }

    @Override
    protected void registerStatesAndModels() {
        registerBlockWithBlockItem(EleSimpleBlocks.BLUE_MANA_CRYSTAL_ORE.get());
        registerBlockWithBlockItem(EleSimpleBlocks.GREEN_MANA_CRYSTAL_ORE.get());
        registerBlockWithBlockItem(EleSimpleBlocks.RED_MANA_CRYSTAL_ORE.get());
        registerBlockWithBlockItem(EleSimpleBlocks.WHITE_MANA_CRYSTAL_ORE.get());
        registerBlockWithBlockItem(EleSimpleBlocks.MANA_CRYSTAL_BLOCK.get());

        manualModel(ExampleBlock.EXAMPLE_BLOCK.get(), "example_block");
     //   manualModel(MortarAndPestleBlock.MORTAR_AND_PESTLE.get(), "mortar_and_pestle");
    }

    private void registerBlockWithBlockItem(Block block){
        simpleBlock(block);
        final ModelFile model = models().getExistingFile(block.getRegistryName());
        simpleBlockItem(block, model);
    }

    private void manualModel(Block b, String name) {
        final ModelFile model = models().getExistingFile(modLoc("block/" + name));
        simpleBlock(b, model);

        simpleBlockItem(b, model);
    }
}

 

and the model:

 

{
    "parent": "minecraft:block/block",
    "textures": {
		"0": "minecraft:block/stone",
		"particle": "minecraft:block/stone"
	},
	"elements": [
		{
			"from": [4, 0, 4],
			"to": [12, 4, 12],
			"rotation": {"angle": 0, "axis": "y", "origin": [12, 8, 12]},
			"faces": {
				"north": {"uv": [0, 0, 8, 1], "texture": "#0"},
				"east": {"uv": [0, 3, 8, 4], "texture": "#0"},
				"south": {"uv": [0, 2, 8, 3], "texture": "#0"},
				"west": {"uv": [0, 0, 8, 2], "texture": "#0"},
				"up": {"uv": [0, 0, 8, 8], "texture": "#0"},
				"down": {"uv": [0, 0, 8, 8], "texture": "#0"}
			}
		}
    ]
}    

 

Can somebody help me figure this out?

Any help/idea is appreciated!

 

 

Edited by Lellian
Link to comment
Share on other sites

31 minutes ago, poopoodice said:

You've never use ExampleBlock?

What do you mean?

ExampleBlock is the small stone thing you see in the picture. It gets registered just fine (Via a DeferredRegistry), I can place it and then you see what is in the picture. This is about the hitbox/outline of the block, which I want to be smaller.

Edited by Lellian
Link to comment
Share on other sites

1 hour ago, Lellian said:

() -> new Block(AbstractBlock.Properties

Cough.

1 hour ago, Lellian said:

public class ExampleBlock extends Block {

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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