Jump to content

Custom hitbox for my mob


WorldsEnder

Recommended Posts

The bounding box is the hitbox.  Minecraft doesn't distinguish between them as far as I know.

 

For blocks there's a separate bounding box (where the player runs into it) and hit box (where the mouse can highlight the block), but this has to do with blocks that the player can walk through needing a collision box for interactions separate from the physics.

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

No idea.

 

All I know about is this.setSize(width, height);

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

I don't think it will work if you pass 0 to every argument. I also think there's another function you need to override: getCollisionBox(Entity). Alternatively, you could try modifying the field this.boundingBox. I'd be glad to help, though, as I need the answer to this problem myself.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

Okay, I've found critical point of code that leads us to no control over this thing...:

EntityRenderer: line 304ff.

                        float f2 = entity.getCollisionBorderSize();
->                     AxisAlignedBB axisalignedbb = entity.boundingBox.expand((double)f2, (double)f2, (double)f2);
                        MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);

                        if (axisalignedbb.isVecInside(vec3))
                        {
                            if (0.0D < d2 || d2 == 0.0D)
                            {
                                this.pointedEntity = entity;
                                d2 = 0.0D;
                            }
                        }
                        else if (movingobjectposition != null)
                        {
                            double d3 = vec3.distanceTo(movingobjectposition.hitVec);

                            if (d3 < d2 || d2 == 0.0D)
                            {
                                this.pointedEntity = entity;
                                d2 = d3;
                            }
                        }

This leads us to the problem. As a modder I don't know how to influence the entity.boundingBox as it is declared final in Entity...

I am not used to make a request so if one of you is more experienced in requesting something from the dev-team, pls do it. All they have to do is to swap this special line of code from entity.boundingBox to entity.getBoundingBox() or entity.getCollisionBox(). Either of them would do fine.

Link to comment
Share on other sites

The entity.boundingBox is final, but you can alter it in your constructor. As a standard, it's initialized with an AABB with "no box" (look at Entity.java, line 253)

So if you don't alter it, you can just override getCollisionBorderSize()  and return anything you wish.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

So I did this:

public EntityFelyne(World par1World) {
	super(par1World);
	this.boundingBox.setBounds(0D, 0D, 0D, 0D, 0D, 0D);
}

@Override
public AxisAlignedBB getCollisionBox(Entity par1Entity) {
	return boundingBox;
}

@Override
public AxisAlignedBB getBoundingBox() {
	return boundingBox;
}

Still, when I enter debug mode.... box[-33.80000001192093, 66.0, 140.19999998807907 -> -33.19999998807907, 67.79999995231628, 140.80000001192093]; and this is totally the zone I can hit the entity in. Anything you wanna say about this?

Link to comment
Share on other sites

So I did this:

public EntityFelyne(World par1World) {
	super(par1World);
	this.boundingBox.setBounds(0D, 0D, 0D, 0D, 0D, 0D);
}

@Override
public AxisAlignedBB getCollisionBox(Entity par1Entity) {
	return boundingBox;
}

@Override
public AxisAlignedBB getBoundingBox() {
	return boundingBox;
}

Still, when I enter debug mode.... box[-33.80000001192093, 66.0, 140.19999998807907 -> -33.19999998807907, 67.79999995231628, 140.80000001192093]; and this is totally the zone I can hit the entity in. Anything you wanna say about this?

You're setting all the bounds to 0... it seems doubtful that that would work...

 

Also, apparently setPosition(x,y,z) changes the bounding box... according to the "width" and "height". So you'll have to override that too.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

I've overridden setPosition:

/EDIT wrong solution:

 

@Override
public void setPosition(double par1, double par2, double par3) {
	AxisAlignedBB b = this.boundingBox;
                double minFromPosx = this.posX - b.minX;
                double minFromPosy = this.posY - b.minY;
                double minFromPosz = this.posZ - b.minZ;
                double maxFromPosx = b.maxX - this.posX;
                double maxFromPosx = b.maxY - this.posY;
                double maxFromPosx = b.minZ - this.posZ;
	this.posX = par1;
	this.posY = par2;
	this.posZ = par3;
                this.boundingBox.setBounds(posX - minFromPosx, posY - minFromPosy , posZ - minFromPosz, posX + maxFromPosx, posY + maxFromPosy, posZ + maxFromPosz);
}

 

:-\ it doesn't really work at all...  Now I have weird glitches were the entity is not where it belongs to and I can't really explain why :(

 

EDIT: fixed it, works fine now

EDIT2: I did not tell the truth... it does not work all the time... will inspect that

EDIT3: finally... I found a solution to keep the boundingBox centered on your entity (at least x and z -axis). No more wishes I guess:

@Override
public void setPosition(double par1, double par2, double par3) {
	AxisAlignedBB b = this.boundingBox;
	double boxSX = b.maxX - b.minX;
	double boxSY = b.maxY - b.minY;
	double boxSZ = b.maxZ - b.minZ;
	this.boundingBox.setBounds(posX - boxSX/2D, posY, posZ - boxSZ/2D, posX + boxSX/2D, posY + boxSY, posZ + boxSZ/2D);
}

  • Thanks 1
Link to comment
Share on other sites

  • 6 years later...
4 hours ago, java coder123 said:

so i am pretty new at coding and I really want to implement this in my mod,  but I don't understand what I should put in for all the Variables

this is a post from 7 years ago, use the latest versions of Forge and start your own thread. 

 

And if you don't know Java, learn that first before diving into Forge, this isn't a forum for learning Java.

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • 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;     }  
  • Topics

×
×
  • Create New...

Important Information

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