Jump to content

[1.18.2] MultiPart Entitys hitboxes do not work


No132

Recommended Posts

I made a custom multipart entity,but after some time it just stops taking damage. I think I done everything corectly (I can post a code if needed). I think there is some kind of problem with getDimensions method, can someone help me?

Link to comment
Share on other sites

Here is the Parent Class 

ublic class ParentEntity extends Monster {
    private final ParentEntityCopy[] copyarr = new ParentEntityCopy[1];
    private int tostart = 0;
    public ParentEntity(EntityType<? extends Monster> type, Level level) {
        super(type, level);
        this.noCulling = true;
        for (int i = 0; i < copyarr.length; i++) {
            copyarr[i] = new ParentEntityCopy(this);
        }
    }
    @Override
    protected void registerGoals() {
        this.goalSelector.addGoal(0, new FloatGoal(this));
        this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.0D, false));
    }

    public static AttributeSupplier.Builder registerAttributes() {
        return Monster.createMobAttributes()
                .add(Attributes.MAX_HEALTH, 10.0D)
                .add(Attributes.ARMOR, 10.0D)
                .add(Attributes.ATTACK_DAMAGE, 10.0D)
                .add(Attributes.MOVEMENT_SPEED, 1D)
                .add(Attributes.FOLLOW_RANGE, 64.0D);
    }
    @Override
    public void tick() {
        super.tick();
        for (int i = 0; i < copyarr.length; i++) {
            ParentEntityCopy copy = copyarr[i];
            copy.tick();
            if (tostart == 0){
                copy.setPos(getX(),getY(),getZ());
            }
        }
        tostart = 1;

    }
    @Override
    public boolean hurt(DamageSource pSource, float pAmount) {
        return super.hurt(pSource, pAmount);
    }
    @Override
    public void remove(RemovalReason reason) {
        super.remove(reason);
        if (this.level instanceof ServerLevel) {
            for (ParentEntityCopy part : copyarr) {
                part.remove(RemovalReason.KILLED);
            }
        }
    }
    @Nullable
    @Override
    public PartEntity<?>[] getParts() {
        return copyarr;
    }

    @Override
    public boolean isMultipartEntity() {
        return true;
    }
}

 

Link to comment
Share on other sites

Here is ParentEntityCopy 

public class ParentEntityCopy extends PartEntity<ParentEntity> {
    public static final ResourceLocation RENDERER = new ResourceLocation(MOD_ID.MOD_ID,"textures/entity/ParentEntity.png");
    public EntityDimensions Size;
    public ParentEntityCopy(ParentEntity parent) {
        super(parent);
        this.setSize(EntityDimensions.scalable(1.8F, 3F));
        setInvisible(false);
        setInvulnerable(false);
    }
    @OnlyIn(Dist.CLIENT)
    public ResourceLocation renderer() {
        return RENDERER;
    }
    protected void setSize(EntityDimensions size) {
        this.Size = size;
        refreshDimensions();
    }
    @Override
    public boolean isPickable() {
        return true;
    }
    @Override
    public EntityDimensions getDimensions(Pose poseIn) {
        return Size;
    }

    @Override
    protected void defineSynchedData() {
    }
    @Override
    protected void readAdditionalSaveData(CompoundTag pCompound) {
    }
    @Override
    public void tick() {
        super.tick();
        moveTo(getX(), getY(), getZ());
        this.tickCount++;
        yRotO = getYRot();
        xRotO = getXRot();
    }
    @Override
    protected void addAdditionalSaveData(CompoundTag pCompound) {
    }
    @Override
    public boolean hurt(DamageSource source, float amount) {
        System.out.println("Hurt method called!");
        return super.hurt(source, amount);
    }
    @Override
    public void setRot(float yaw, float pitch) {
        super.setRot(yaw, pitch);
    }
}

 

Link to comment
Share on other sites

I know nothing about multipart entities, but your ParentEntityCopy.hurt() does nothing.

Your part entity is just a basic entity that has no health attribute.

Compare your code with DragonEntityPart.hurt() that forwards the damage to the parent which does have a health attribute.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

The Code prints "Hurt method called!", also even if I add getParent().hurt(DamageSourse.Anvil,1000); that will not work, also part entity has no health by default.I looked at the code at debug mode and the method just do not called.

Link to comment
Share on other sites

54 minutes ago, No132 said:

The Code prints "Hurt method called!",

So? That doesn't mean the rest of the code does anything useful.

Your super call just marks the part entity as hurt which means it will flash red. But it doesn't have any health to actually damage.

Quote

also even if I add getParent().hurt(DamageSourse.Anvil,1000); that will not work,

Why not? "It does not work" is not a bug report.

Quote

also part entity has no health by default.

That's what I said is your problem.

Quote

I looked at the code at debug mode and the method just do not called.

What code?

If you looked a the code in a debugger you can step through it and see what is being called and what conditional statement stops it reaching the code you expect.

 

All in all, your "question" is unanswerable. It is full of  undefined "it/that/the"s.

 

Finally, when I went back to  look at the code you posted to see if I could guess what you are talking about, I noticed this:

Quote

public static final ResourceLocation RENDERER = new ResourceLocation(MOD_ID.MOD_ID,"textures/entity/ParentEntity.png");

That will crash at runtime because uppercase characters are not allowed in ResourceLocations.

So that class you posted cannot possibly be code that is actually getting used.

Edited by warjort
  • Confused 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Ok,

Quote

Why not? "It does not work" is not a bug report.

That line do not gets called so yes It does not work.

Quote

also part entity has no health by default.

That's what I said is your problem.

It can not have health or everything will crash,so its not a problem(

Quote

All in all, your "question" is unanswerable. It is full of  undefined "it/that/the"s.

Yeah it just do not works becouse minecraft do not want to call hurt method and I dont know what do with this

Quote

That will crash at runtime because uppercase characters are not allowed in ResourceLocations.

So that class you posted cannot possibly be code that is actually getting used.

My bad, I changed the Names of the classes and resourse locations when I was posting to make it more readable.

Also can I ask does this code works by you? Maybe the problem not in the code.

Link to comment
Share on other sites

What code? All you post are snippets of java out of context. Which you now admit is not the real code.

If you want help you need to put the full real code on github. So we can see everything that is relevant. And maybe try it for ourselves.

 

But as I said originally, I know virtually nothing about multipart entities. I have never written one.

I only answered because it was obvious your hurt() method didn't do anything.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Quote

What code? All you post are snippets of java out of context. Which you now admit is not the real code.

Snippets? I didnt knew this word before,sorry for my bad Englisch.

Quote

But as I said originally, I know virtually nothing about multipart entities. I have never written one.

I only answered because it was obvious your hurt() method didn't do anything.

So if you know nothing,then why do you come  and write answers here? And my hurt method actually does something you can go and paste this to your entity hurt method.

Write if you will ever have some useful information about this  problem. Thanks.

Edited by No132
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



×
×
  • Create New...

Important Information

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