Jump to content

[SOLVED] Create full block that damages like cactus


trollworkout

Recommended Posts

I created a block similar to cactus but is not dealing me any damage.

 

I added this

    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)

    {

        entityIn.attackEntityFrom(DamageSource.cactus, 1.0F);

    }

 

but doesn't seem to do anything.

 

Plus I added FULL_BLOCK_AABB collision for selection and collision bounding box but doesn't seem to have any effect.

 

Any thoughts?

 

Here is my code (it extends LogBlock which extends BlockLog vanilla log class)

 

package com.technorcery.common.blocks;

import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ThornLog extends LogBlock {


public ThornLog(String name) {
	super(name);
}

@Override
    public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos)
    {
        return FULL_BLOCK_AABB;
    }

    @SideOnly(Side.CLIENT)
@Override
    public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos)
    {
        return FULL_BLOCK_AABB;
    }


    @SideOnly(Side.CLIENT)
    @Override
    public BlockRenderLayer getBlockLayer()
    {
        return BlockRenderLayer.CUTOUT;
    }
    
    @Override
    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
    {
        entityIn.attackEntityFrom(DamageSource.cactus, 1.0F);
    }

}

 

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

OnEntityCollided is called when the entity is inside of a block if you use FULL_BLOCK_AABB then the entity wont be able to get inside of the block which is one reason why cactus is not a full block.

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

so I need to say isFullBlock false then to enable custom collisions?

 

I am not sure how to handle this.

 

Can I create collision bigger than 0 , 0 , 0 , 1 ,1 ,1 ? (ie 16 x 16 x 16 block)

 

I tried -0.0625 , 0 .  -0.0625 . 1.0625 1 1.0625 and othing happend  maybe cause I gotta say is full block false??

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

I found an old post saying to use getCollisionBoundingBoxFromPool but I have a feeling it was changed in newer versions of forge. Probably now is called addCollisionBoxToList ??

 

 

getCollisionBoundingBoxFromPool I think is now called getBoundingBox and is deprecated :D but i think that's the one that i need.

 

edit NVM

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

OK so I used F3  + B to see player bounding box and I tested even more.

 

Seems player does not go inside the block but if he does by accident or if pushed he takes damage.

 

So collision bounding box defines where the player stops . I need to make my collision bounding box bigger and my collision box smaller by 1 pixel. But seems collision bounding box = collision box. Let's see if there is a way to set them up differently.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

You need to have the collision box smaller (0,0,0,1,1,1), or else the player or any other

Entity

won't be able to collide with it.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

You need to have the collision box smaller (0,0,0,1,1,1), or else the player or any other

Entity

won't be able to collide with it.

 

how can i make a block that's bigger than normal block and deals damage like cactus then?

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

i tried negative numbers and i do collide with the block just fine. like i'm stopped pixels away outside a full block.

 

for ex

protected static final AxisAlignedBB COLLISION_AABB = new AxisAlignedBB(-0.0625D, 0.0D, -0.0625D, 1.0625D, 1.0D, 1.0625D);

 

this is 18 x 18 x 18 with 1 pixel all around a full block. if i set it as collision works fine!

 

is just

onEntityCollidedWithBlock < this function i don't think it works with collisions bigger than full block maybe because it checks to see if i'm inside the block but i never get inside it

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

yea you can I just did it

 

you need to use offsets

 

also my bounding box is 1 pixel bigger than normal in all directions 18 x 18 x 18..and i get damaged if i get close to 16  x 16 x 16

 

I figured this out kinda.

 

 

Also I remember reading you can in fact go a bit over but not by much like max 8?? pixels over a normal full block size.  This is from original forge documentation.  I guess you learned something too. haha

 

 

 

The problem is not going outside the block. The problem is that function that cactus use only checks to see if collision is inside a full cube and seems to ignore collision bigger than a full cube.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

The problem is not going outside the block. The problem is that function that cactus use only checks to see if collision is inside a full cube and seems to ignore collision bigger than a full cube.

 

Make it 0.001 units smaller than a full block, it only needs to be smaller than a full block for entities to collide with it.

Link to comment
Share on other sites

The problem is not going outside the block. The problem is that function that cactus use only checks to see if collision is inside a full cube and seems to ignore collision bigger than a full cube.

 

Make it 0.001 units smaller than a full block, it only needs to be smaller than a full block for entities to collide with it.

 

0.001 seems too fine . I m gonna fiddle with this.

 

You know if there is a way to rotate bounding box based on block rotation as well? I  want the top and bottom to have no damage only sides.

 

EDIT: AxisAlignedBB(0.005D, 0.0D, 0.005D, 0.995D, 1.0D, 0.995D); works fine.

 

my thorns go from 16 - 17 pixel (CUTOUT mode) but my block collision box  is 15.95 so it doesn't feel like i'm going inside the block and it pricks me.

 

i wanted to get damaged at 16 - 17 but this is fine to. i get damaged at 15.95 - 16 but feels natural.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

I'm guessing the only way to rotate collision for a pillar is have 3 collisions AABB EW SN and UPDOWN then simply check orientation and return different collisions depending on orientation??

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Fully functional i did what Leviathan suggested made my collision box be like  0.05  smaller on the sides plus damage entity function makes it so when I step too close I get damaged. Works perfect

 

Also since my block has a pillar like rotation i have 3 collisions X Y and Z and depending on the EnumAxis i return different collisions .

 

My normal collision top and bottom does not hurt only sides.

 

Result is 100% fully functional cactus like but FULL block that only sides hurt and is rotate-able.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

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.

×
×
  • Create New...

Important Information

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