Jump to content

Recommended Posts

Posted (edited)

Hello! I have been working on a mod and one of the main things currently is my bullet entity.

It renders in-game and works but I cannot get the hitbox right.

Currently, I am using this:

 setSize(0.1F, 0.1F);

to set the bounding box size. However, it renders this box below the entity in game:

96995cfefaa3f443ab188287ce088177.png

As you can see the bullet(Yelllow square) is in the air and the bounding box is below it. Another small issue is that my bullet can be pushed and hurt. Any way to disable this?

RenderBullet.class & EntityBullet.class 

package codes.matthewp.nerdwarcraft.client;

import codes.matthewp.nerdwarcraft.entity.EntityBullet;
import net.minecraft.client.model.ModelZombie;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.registry.IRenderFactory;

import javax.annotation.Nonnull;

public class RenderBullet extends RenderLiving<EntityBullet> {

    public static ResourceLocation mobTexture = new ResourceLocation("warcraft:textures/entity/bullet.png");


    public static final Factory FACTORY = new Factory();

    public RenderBullet(RenderManager renderManager) {
        super(renderManager, new ModelBullet(), 0.f);
    }

    @Override
    @Nonnull
    protected ResourceLocation getEntityTexture(@Nonnull EntityBullet entity) {
        return mobTexture;
    }

    public static class Factory implements IRenderFactory<EntityBullet> {
        @Override
        public Render<? super EntityBullet> createRenderFor(RenderManager manager) {
            return new RenderBullet(manager);
        }

    }
}
package codes.matthewp.nerdwarcraft.entity;

import net.minecraft.entity.EntityLiving;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;

public class EntityBullet extends EntityLiving {

    public EntityBullet(World worldIn) {
        super(worldIn);
        setSize(0.1F, 0.1F);
    }

    public void entityInit() {
        super.entityInit();
    }

}

EDIT: Added ModelBullet.class

@SideOnly(Side.CLIENT)
public class ModelBullet extends ModelBase {

    public ModelRenderer bulletBody;

    public int textureWidth = 16;
    public int textureHeight = 16;


    public ModelBullet() {
        bulletBody = new ModelRenderer(this, 0, 0);
        bulletBody.addBox(0, 0, 0, 2, 1, 4);
        bulletBody.setTextureSize(textureWidth, textureHeight);
    }

    @Override
    public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
        renderBullet((EntityBullet) entityIn, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
    }

    private void renderBullet(EntityBullet parEnntity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
        bulletBody.render(0.01F);
    }
}

 

Edited by IMleader
Wrong code
Posted

Why does your bullet extends EntityLiving (unless you meant to do this)?

If your entity should not behave like animals or mobs, then it should not extends EntityLiving.

You should just extend Entity instead.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
42 minutes ago, DavidM said:

Why does your bullet extends EntityLiving (unless you meant to do this)?

If your entity should not behave like animals or mobs, then it should not extends EntityLiving.

You should just extend Entity instead.

Ah, forgot I left that there. I have switched it over, however now I don't know where to use my ModelBullet.class. It simply renders a small hitbox with no bullet. Any clue on the hitbox issue as well?

Posted

Modded projectiles should extend EntityArrow if they want synced movement accuracy. This is due to many class based (instanceof ArrowEntity) checks in vanilla that deal with packets and motion.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)
2 hours ago, Cadiboo said:

Modded projectiles should extend EntityArrow if they want synced movement accuracy. This is due to many class based (instanceof ArrowEntity) checks in vanilla that deal with packets and motion.

Switched. Still can't figure out how to get the bullet to render now, and even still, the hitbox issue.

 

Edit. Also, how can I apply the force bit? entity.addVelocity requires x,y,z not just simply movement forward 

Edited by IMleader
Additional question
Posted
22 minutes ago, IMleader said:

Edit. Also, how can I apply the force bit? entity.addVelocity requires x,y,z not just simply movement forward 

Use trigonometry to find the xyz values

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

The ones to pass into Entity#addVelocity. Look at ArrowEntity#shoot for vanilla's code

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.