Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Solved] -> 1.14 Bounding Box not working


GyuGya_55
 Share

Recommended Posts

Solution for the next gen who stumble upon this thread. Solution provided by Simon_kungen:

 

public VoxelShape getShape(BlockState state, IBlockReader reader, BlockPos position, ISelectionContext context)
    {
        return Block.makeCuboidShape(xMin, yMin, zMin, xMax, yMax, zMax); //all decimals
    }

 

 

 

 

The boundingbox of my block isn't what I set it. I'm a newby and after 2 days of trying I still couldn't find the problem. I would really appreciate if someone could halp me out a bit.

 

Here is the blocks class.

package com.gyugya55.mymod.blocks;

import javax.annotation.Nullable;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB;
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.minecraft.world.World;

public class Abacus extends Block
{
	
	public Abacus()
	{
		super(Properties.create(Material.WOOD)
						.sound(SoundType.WOOD)
						.hardnessAndResistance(0.1f,0.5f)
						.lightValue(0)
				);
		setRegistryName("abacus");
	}
	
	@Override
	public BlockRenderLayer getRenderLayer()
	{
		return BlockRenderLayer.CUTOUT_MIPPED;
	}
	
    @Override
    public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) {
        if (entity != null) {
            world.setBlockState(pos, state.with(BlockStateProperties.FACING, getFacingFromEntity(pos, entity)), 2);
        }
    }
    
    public static Direction getFacingFromEntity(BlockPos clickedBlock, LivingEntity entity) {
        return Direction.getFacingFromVector((float) (entity.posX - clickedBlock.getX()), (float) (entity.posY - clickedBlock.getY()), (float) (entity.posZ - clickedBlock.getZ()));
    }

    @Override
    protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
        builder.add(BlockStateProperties.FACING);
    }
    
    @Override
    public boolean isNormalCube(BlockState state, IBlockReader reader, BlockPos position)
    {
    	return false;
    }
	
	public VoxelShape getCollisionShape(BlockState state, IBlockReader reader, BlockPos position, ISelectionContext context) 
	{
        return Block.makeCuboidShape(
                0D, 	//x
                0D, 	//y down
                7D,		//z
                16D,	//x
                10.5D,	//y up
                9D	//z
                );
    }
	
	public AxisAlignedBB getBoundingBox() 
	{
		return new AxisAlignedBB( 0D,  0D, 7D, 16D, 10.5D, 9D );
	}
	
	
}

 

 

So this is the current bounding box of my object.

1689730787_Kpernyfelvtel(8).thumb.png.06b5ff50e75c974283480444b79ba363.png

 

 

And this is what im trying to achive.1346043751_Kpernyfelvtel(9).thumb.png.665c6bb58e849f2af60bcec52ef595bd.png

Edited by GyuGya_55
Link to comment
Share on other sites

Some images would help understand the problem.

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

1 hour ago, GyuGya_55 said:

The boundingbox of my block isn't what I set it. I'm a newby and after 2 days of trying I still couldn't find the problem. I would really appreciate if someone could halp me out a bit.

Minecraft has three different methods for the bounding box that all call getShape. So just override getShape

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

6 minutes ago, GyuGya_55 said:

ony the BoundingBox not.

getBoundingBox isn't a method in the Block class. Whenever you override a method in a super class put the @Override annotation above the method. It will tell you if you are actually overriding the method.

Also...

9 hours ago, Animefan8888 said:

Minecraft has three different methods for the bounding box that all call getShape. So just override getShape

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Quote

getBoundingBox isn't a method in the Block class. Whenever you override a method in a super class put the @Override annotation above the method. It will tell you if you are actually overriding the method.

Minecraft has three different methods for the bounding box that all call getShape. So just override getShape

 

I tried to do it like this:

public static final AxisAlignedBB AABB = new AxisAlignedBB(
				0D, 	//x
				0D, 	//y down
				7D,		//z
				16D,	//x
				10.5D,	//y up
				9D	//z
				);
	
	@Override
	public VoxelShape getShape(BlockState state, IBlockReader reader, BlockPos position, ISelectionContext context) {
		return VoxelShapes.create(AABB);
	}

 

But now I don't have any hitboxes. 798883727_Kpernyfelvtel(11).thumb.png.dba22b72c62b5ca4c0e971ff08da1239.png

Edited by GyuGya_55
Link to comment
Share on other sites

24 minutes ago, GyuGya_55 said:

7D

Im pretty confident its on a 0-1 decimal scale so 7 is pretty big.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

7 hours ago, Animefan8888 said:

Im pretty confident its on a 0-1 decimal scale so 7 is pretty big.

When dealing with AABBs? Yes.

VoxelShape on the other hand, ranges 0-16. The VoxelShape.create method that takes in an AABB multiplies it all by 16.

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

Not sure if you figured it out, but here is my solution: I did a more mechanical approach to this. I made four VoxelShape variables due to my block being centred to the side of a block and then I checked which direction the blockstate were and did a switch statement to return the correct orientation:

 

//double x1,       double y1,       double z1,        double x2,        double y2,         double z2
protected static final VoxelShape SHAPE_WEST = Block.makeCuboidShape(10.0D, 1.0D, 5.0D, 16.0D, 11.0D, 11.0D);
protected static final VoxelShape SHAPE_EAST = Block.makeCuboidShape(0.0D, 1.0D, 5.0D, 6.0D, 11.0D, 11.0D);
protected static final VoxelShape SHAPE_NORTH = Block.makeCuboidShape(5.0D, 1.0D, 10.0D, 11.0D, 11.0D, 16.0D);
protected static final VoxelShape SHAPE_SOUTH = Block.makeCuboidShape(5.0D, 1.0D, 0.0D, 11.0D, 11.0D, 6.0D);

 

@Override
public VoxelShape getShape(BlockState state, IBlockReader blockReader, BlockPos pos, ISelectionContext selectionContext)
{
    switch (state.get(HORIZONTAL_FACING)) {
        case WEST:
            return SHAPE_WEST;

        case EAST:
            return SHAPE_EAST;

        case SOUTH:
            return SHAPE_SOUTH;

        default: case NORTH:
            return SHAPE_NORTH;
    }
}

 

Because of your block being centred in the middle you only need to make two VoxelShape variables, one is for west and east and the other for north and south.

 

@Override
public VoxelShape getShape(BlockState state, IBlockReader blockReader, BlockPos pos, ISelectionContext selectionContext)
{
    switch (state.get(HORIZONTAL_FACING)) {

        case EAST:
        case WEST:
            return SHAPE_WEST_EAST;

        case NORTH:
        case SOUTH:
            return SHAPE_SOUTH_NORTH;
    }
}

 

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is an issue with JEI make sure you have latest version for 1.16.5 then contact the author.
    • I checked my list of mod and immersive portal wasn't even installed.    
    • Look at your image. You are showing  /Applications/Minecraft/Contents/mods Your mods folder is Take a screenshot of the contents of second one. Although we can guess, you have been downloading your mods into the first folder when you should be putting them in the second one.  
    • I play the world yesterday and it was fine, upon loading it today it crashed ╥_╥. Pls help.  [main/ERROR]: Exception caught during firing event: null     Index: 6     Listeners:         0: HIGH         1: ASM: class me.shedaniel.architectury.event.forge.EventHandlerImplClient event(Lnet/minecraftforge/client/event/RecipesUpdatedEvent;)V         2: NORMAL         3: ASM: class owmii.lib.client.wiki.Wiki collect(Lnet/minecraftforge/client/event/RecipesUpdatedEvent;)V         4: ASM: class com.blamejared.crafttweaker.impl.events.CTStateEventHandler onRecipesUpdated(Lnet/minecraftforge/client/event/RecipesUpdatedEvent;)V         5: ASM: mekanism.client.ClientTickHandler@43d9842f recipesUpdated(Lnet/minecraftforge/client/event/RecipesUpdatedEvent;)V         6: net.minecraftforge.eventbus.EventBus$$Lambda$2959/736640638@6d07c39b java.util.ConcurrentModificationException     at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)     at java.util.ArrayList$Itr.next(ArrayList.java:851)     at mezz.jei.load.PluginCaller.callOnPlugins(PluginCaller.java:21)     at mezz.jei.load.PluginLoader.<init>(PluginLoader.java:109)     at mezz.jei.startup.JeiStarter.start(JeiStarter.java:69)     at mezz.jei.startup.ClientLifecycleHandler.startJEI(ClientLifecycleHandler.java:147)     at mezz.jei.startup.ClientLifecycleHandler.setupJEI(ClientLifecycleHandler.java:140)     at mezz.jei.startup.ClientLifecycleHandler.lambda$new$3(ClientLifecycleHandler.java:106)     at mezz.jei.startup.ClientLifecycleHandler$$Lambda$29176/1547335276.accept(Unknown Source)     at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:247)     at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:239)     at net.minecraftforge.eventbus.EventBus$$Lambda$2959/736640638.invoke(Unknown Source)     at net.minecraftforge.eventbus.EventBus$$Lambda$3273/1859299978.invoke(Unknown Source)     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302)     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283)     at net.minecraftforge.client.ForgeHooksClient.onRecipesUpdated(ForgeHooksClient.java:772)     at net.minecraft.client.network.play.ClientPlayNetHandler.func_199525_a(ClientPlayNetHandler.java:1314)     at net.minecraft.network.play.server.SUpdateRecipesPacket.func_148833_a(SourceFile:27)     at net.minecraft.network.play.server.SUpdateRecipesPacket.func_148833_a(SourceFile:15)     at net.minecraft.network.PacketThreadUtil.func_225383_a(SourceFile:21)     at net.minecraft.network.PacketThreadUtil$$Lambda$34638/1869809823.run(Unknown Source)     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213166_h(SourceFile:144)     at net.minecraft.util.concurrent.RecursiveEventLoop.func_213166_h(SourceFile:23)     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213168_p(SourceFile:118)     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213160_bf(SourceFile:103)     at net.minecraft.client.Minecraft.func_195542_b(Minecraft.java:948)     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:607)     at net.minecraft.client.main.Main.main(Main.java:184)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at net.minecraftforge.fml.loading.FMLClientLaunchProvider.lambda$launchService$0(FMLClientLaunchProvider.java:37)     at net.minecraftforge.fml.loading.FMLClientLaunchProvider$$Lambda$502/1391735333.call(Unknown Source)     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54)     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72)     at cpw.mods.modlauncher.Launcher.run(Launcher.java:82)     at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)  [main/FATAL]: Error executing task on Client java.util.ConcurrentModificationException: null     at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901) ~[?:1.8.0_51]     at java.util.ArrayList$Itr.next(ArrayList.java:851) ~[?:1.8.0_51]     at mezz.jei.load.PluginCaller.callOnPlugins(PluginCaller.java:21) ~[?:7.7.1.152]     at mezz.jei.load.PluginLoader.<init>(PluginLoader.java:109) ~[?:7.7.1.152]     at mezz.jei.startup.JeiStarter.start(JeiStarter.java:69) ~[?:7.7.1.152]     at mezz.jei.startup.ClientLifecycleHandler.startJEI(ClientLifecycleHandler.java:147) ~[?:7.7.1.152]     at mezz.jei.startup.ClientLifecycleHandler.setupJEI(ClientLifecycleHandler.java:140) ~[?:7.7.1.152]     at mezz.jei.startup.ClientLifecycleHandler.lambda$new$3(ClientLifecycleHandler.java:106) ~[?:7.7.1.152]     at mezz.jei.startup.ClientLifecycleHandler$$Lambda$29176/1547335276.accept(Unknown Source) ~[?:?]     at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:247) ~[eventbus-4.0.0.jar:?]     at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:239) ~[eventbus-4.0.0.jar:?]     at net.minecraftforge.eventbus.EventBus$$Lambda$2959/736640638.invoke(Unknown Source) ~[?:?]     at net.minecraftforge.eventbus.EventBus$$Lambda$3273/1859299978.invoke(Unknown Source) ~[?:?]     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?]     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?]     at net.minecraftforge.client.ForgeHooksClient.onRecipesUpdated(ForgeHooksClient.java:772) ~[?:?]     at net.minecraft.client.network.play.ClientPlayNetHandler.func_199525_a(ClientPlayNetHandler.java:1314) ~[?:?]     at net.minecraft.network.play.server.SUpdateRecipesPacket.func_148833_a(SourceFile:27) ~[?:?]     at net.minecraft.network.play.server.SUpdateRecipesPacket.func_148833_a(SourceFile:15) ~[?:?]     at net.minecraft.network.PacketThreadUtil.func_225383_a(SourceFile:21) ~[?:?]     at net.minecraft.network.PacketThreadUtil$$Lambda$34638/1869809823.run(Unknown Source) ~[?:?]     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213166_h(SourceFile:144) [?:?]     at net.minecraft.util.concurrent.RecursiveEventLoop.func_213166_h(SourceFile:23) [?:?]     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213168_p(SourceFile:118) [?:?]     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213160_bf(SourceFile:103) [?:?]     at net.minecraft.client.Minecraft.func_195542_b(Minecraft.java:948) [?:?]     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:607) [?:?]     at net.minecraft.client.main.Main.main(Main.java:184) [?:?]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_51]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_51]     at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_51]     at net.minecraftforge.fml.loading.FMLClientLaunchProvider.lambda$launchService$0(FMLClientLaunchProvider.java:37) [forge-1.16.5-36.2.35.jar:36.2]     at net.minecraftforge.fml.loading.FMLClientLaunchProvider$$Lambda$502/1391735333.call(Unknown Source) [forge-1.16.5-36.2.35.jar:36.2]     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.1.3.jar:?]     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.1.3.jar:?]     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.1.3.jar:?]     at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.1.3.jar:?]     at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.1.3.jar:?]
    • NEVER MIND I AM STUPID I HAD EXTRACTED MODS IN MY MOD FOLDER IM SORRY
  • Topics

×
×
  • Create New...

Important Information

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