Jump to content

[SOLVED] (1.10.2) Suffocating in block when walking into it when using 'addCollisionBoxToList' method!


Recommended Posts

Posted (edited)

Hello everyone,

I have been trying to make a simple custom block that looks like a Jar. All models, render types and such are working perfectly. The only problem I'm having is that when I set the collision and bounding box size (It works) but when I walk into it when it's at head height, I suffocate into it. I have tried adjusting the size of the collision box and bounding box countless times, same results. I have also tried setting 'isFullBlock', 'isNormalBlockCube' and all other methods like that to  "return false". That did nothing either. I have no idea how to fix this, been at it for about 2 hours now. Here is my code for the block (CheeseJar.java) =)

package com.github.jameswilsonproductions.tutorial.blocks;

import com.github.jameswilsonproductions.tutorial.Reference;
import com.github.jameswilsonproductions.tutorial.Tutorial;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import javax.annotation.Nullable;
import java.util.List;

public class CheeseJar extends Block{
  
    private AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(0.0625 * 4, 0, 0.0625 * 4, 0.0625 * 12, 0.0625 * 11, 0.0625 * 12);
    private AxisAlignedBB COLLISION_BOX = new AxisAlignedBB(0.0625 * 4, 0, 0.0625 * 4, 0.0625 * 12, 0.0625 * 11, 0.0625 * 12);

    public CheeseJar() {
        super(Material.GLASS);

        setUnlocalizedName(Reference.TutorialBlocks.CHEESEJAR.getUnlocalizedName());
        setRegistryName(Reference.TutorialBlocks.CHEESEJAR.getRegistryName());
        setSoundType(SoundType.GLASS);
        setHardness(.13f);
        setCreativeTab(Tutorial.CREATIVE_TAB);
    }

    @Override
    public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) {
        return false;
    }

    @Override
    public boolean isOpaqueCube(IBlockState state) {
        return false;
    }

    @Override
    public BlockRenderLayer getBlockLayer(){
        return BlockRenderLayer.TRANSLUCENT;
    }

    @Override
    public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn) {
        super.addCollisionBoxToList(pos, entityBox, collidingBoxes, COLLISION_BOX);
    }

    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
        return BOUNDING_BOX;
    }
}

COLLISION_BOX and BOUNDING_BOX are the same is because I was experimenting. BOUNDING_BOX is usually 1 pixel bigger that COLLISION_BOX.

I have pasted all the code, as a I feel all the methods I'm using here, play a role in the problem Thanks for the help in advance! =)

Maybe if you want a picture in the IntelliJ dark theme too, here is an attached file.

8735ed4b0a71a9c0aebf5ad859a5714b.png

Edited by JamesWilsonProductions
Updated title. Added [SOLVED]

Who am I? Me?

I am NEW to Minecraft Modding, but NOT NEW to Java. I have recently found an interest in doing this, and I'm having much fun thus far!

I am interested in getting active within this community.

Nice to meet you fellow mod developer, hope you're having a wonderful and challenging day!

Posted
5 minutes ago, diesieben07 said:

If the block material is set to glass, it will never cause suffocation, unless you manually override causesSuffocation.

Please show where you register your Block.

 

(Also, holy cow all those errors... how can you code like that?)

Errors? What errors. If you're talking about the ruled out methods, those are the deprecated ones. Apparently I am still allowed to use them, as I couldn't find any alternative. This only applies to the Block class though.

Here is where I register the block:

package com.github.jameswilsonproductions.tutorial.init;

import com.github.jameswilsonproductions.tutorial.blocks.BlockCheese;
import com.github.jameswilsonproductions.tutorial.blocks.BlockJar;
import com.github.jameswilsonproductions.tutorial.blocks.CheeseJar;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.fml.common.registry.GameRegistry;


public class ModBlocks {
    public static Block cheeseJar;

    public static void init(){
        cheeseJar = new CheeseJar();
    }

    public static void register(){
        registerBlock(cheeseJar);
    }

    private static void registerBlock(Block block){
        GameRegistry.register(block);
        ItemBlock item = new ItemBlock(block);
        item.setRegistryName(block.getRegistryName());
        GameRegistry.register(item);
    }

    public static void registerRenders(){
        registerRender(cheeseJar);
    }

    private static void registerRender(Block block){
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory"));
    }
}

 

cb5008f5b8e4b05c985ccce9ca6f49e6.png

Who am I? Me?

I am NEW to Minecraft Modding, but NOT NEW to Java. I have recently found an interest in doing this, and I'm having much fun thus far!

I am interested in getting active within this community.

Nice to meet you fellow mod developer, hope you're having a wonderful and challenging day!

Posted (edited)
17 minutes ago, diesieben07 said:

These: 

  Reveal hidden contents

nXD0QWQ.png

 

Yes, Mojang seems to use deprecated in the sense of "don't call this, but overriding it is necessary still" here.

 

As for the suffocation, I misread Material.GLASS as having blocksMovement return false. It doesn't, so you need to override isFullCube in your Block class to return false (or causesSuffocation).

And what shall I do with isNormalCube? What is the difference between the two? And about those errors... I have no idea how to get rid of them, didn't even realize they were errors. Any ideas on that?

 

This is the message I get when I hover over the errors:

" Not annotated method overrides method annotated with @MethodsReturnNonnullByDefault

 

This inspection reports problems related to @Nullable and @NotNull annotations usage configured in Constant conditions & exceptions inspection. "

 

Worked like a charm btw! Thanks =)

Edited by JamesWilsonProductions

Who am I? Me?

I am NEW to Minecraft Modding, but NOT NEW to Java. I have recently found an interest in doing this, and I'm having much fun thus far!

I am interested in getting active within this community.

Nice to meet you fellow mod developer, hope you're having a wonderful and challenging day!

Posted
4 minutes ago, diesieben07 said:

isNormalCube is basically vanilla's version of isSideSolid, except for all sides at once.

 

The warnings you get from IntelliJ simply tell you that you are overriding a method which is said to never return null, but your method is not annotated to say that. I am not saying you need to annotate your method, my comment was going in the direction of it being annoying. If you don't use these inspections... turn them off!

Ah, I see! Thanks for the help here. Appreciate it alot! =)

Who am I? Me?

I am NEW to Minecraft Modding, but NOT NEW to Java. I have recently found an interest in doing this, and I'm having much fun thus far!

I am interested in getting active within this community.

Nice to meet you fellow mod developer, hope you're having a wonderful and challenging day!

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



×
×
  • Create New...

Important Information

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