Jump to content

Recommended Posts

Posted (edited)

I've created a new mob by essentially copying the Bat and removing it's wings. The mob works fine, however the mob's hitbox is too large compared to the Bat. In the picture you can see the difference
Image here
 

This is the model class i'm using

package com.antiblaze.entities.models;

import com.antiblaze.entities.AntiBlazeEntity;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.entity.model.RendererModel;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

/**
 * AntiBlaze Model
 * @author JimiIT92
 */
@OnlyIn(Dist.CLIENT)
public class AntiBlazeModel<T extends AntiBlazeEntity> extends EntityModel<T> {

    /**
     * AntiBlaze Head Model
     */
    private final RendererModel antiBlazeHead;
    /**
     * AntiBlaze Body Model
     */
    private final RendererModel antiBlazeBody;

    /**
     * Constructor. Initialize the Model
     */
    public AntiBlazeModel() {
        this.textureWidth = 64;
        this.textureHeight = 64;
        this.antiBlazeHead = new RendererModel(this, 0, 0);
        this.antiBlazeHead.addBox(-3.0F, -3.0F, -3.0F, 6, 6, 6);
        RendererModel renderermodel = new RendererModel(this, 24, 0);
        renderermodel.addBox(-4.0F, -6.0F, -2.0F, 3, 4, 1);
        this.antiBlazeHead.addChild(renderermodel);
        RendererModel renderermodel1 = new RendererModel(this, 24, 0);
        renderermodel1.mirror = true;
        renderermodel1.addBox(1.0F, -6.0F, -2.0F, 3, 4, 1);
        this.antiBlazeHead.addChild(renderermodel1);
        this.antiBlazeBody = new RendererModel(this, 0, 16);
        this.antiBlazeBody.addBox(-3.0F, 4.0F, -3.0F, 6, 12, 6);
        this.antiBlazeBody.setTextureOffset(0, 34).addBox(-5.0F, 16.0F, 0.0F, 10, 6, 1);
    }

    /**
     * Render the Model
     * @param entityIn Entity to render
     * @param limbSwing Limb Swing
     * @param limbSwingAmount Limb Swing Amount
     * @param ageInTicks Age in Ticks
     * @param netHeadYaw Net Head Yea
     * @param headPitch Head Pitch
     * @param scale Scale
     */
    public void render(T entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
        this.setRotationAngles(entityIn, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
        this.antiBlazeHead.render(scale);
        this.antiBlazeBody.render(scale);
    }

    /**
     * Set Model rotation and angles
     * @param entityIn Entity to render
     * @param limbSwing Limb Swing
     * @param limbSwingAmount Limb Swing Amount
     * @param ageInTicks Age in Ticks
     * @param netHeadYaw Net Head Yea
     * @param headPitch Head Pitch
     * @param scale Scale
     */
    public void setRotationAngles(T entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
        this.antiBlazeHead.rotateAngleX = headPitch * ((float)Math.PI / 180F);
        this.antiBlazeHead.rotateAngleY = netHeadYaw * ((float)Math.PI / 180F);
        this.antiBlazeHead.rotateAngleZ = 0.0F;
        this.antiBlazeHead.setRotationPoint(0.0F, 0.0F, 0.0F);
        this.antiBlazeBody.rotateAngleX = ((float)Math.PI / 4F) + MathHelper.cos(ageInTicks * 0.1F) * 0.15F;
        this.antiBlazeBody.rotateAngleY = 0.0F;
    }
}


This is the entity class
 

package com.antiblaze.entities;

import com.antiblaze.entities.goals.AntiBlazeAttackGoal;
import com.antiblaze.settings.Settings;
import net.minecraft.block.BlockState;
import net.minecraft.entity.*;
import net.minecraft.entity.passive.AmbientEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

/**
 * AntiBlaze Entity
 * @author JimiIT92
 */
public class AntiBlazeEntity extends AmbientEntity {

    /**
     * Entity Spawn Position
     */
    private BlockPos spawnPosition;
    /**
     * Constructor. Initialize the AntiBlaze Entity
     * @param type Entity Type
     * @param world World Instance
     */
    public AntiBlazeEntity(EntityType<? extends AmbientEntity> type, World world) {
        super(type, world);
    }

    /**
     * Register the AntiBlaze Goals
     */
    @Override
    protected void registerGoals() {
        super.registerGoals();
        this.goalSelector.addGoal(Settings.ATTACK_GOAL_PRIORITY, new AntiBlazeAttackGoal(this, Settings.ATTACK_GOAL_SPEED, false));
    }

    /**
     * Register the AntiBlaze attributes
     */
    @Override
    protected void registerAttributes() {
        super.registerAttributes();
        this.getAttributes().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE);
        this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(6.0D);
        this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(Settings.ATTACK_DAMAGE.get());
    }

    /**
     * Returns the volume for the sounds this mob makes.
     * @return Mob's sound volume
     */
    @Override
    protected float getSoundVolume() {
        return 0.1F;
    }

    /**
     * Gets the pitch of living sounds in living entities.
     * @return Mob's pitch
     */
    @Override
    protected float getSoundPitch() {
        return super.getSoundPitch() * 0.95F;
    }

    /**
     * Returns whether this entity should push and be pushed by other entities when colliding.
     * @return True if the entity should push and be pushed by other entities when colliding, false otherwise
     */
    @Override
    public boolean canBePushed() {
        return false;
    }

    /**
     * Called on collision with an entity. Does nothing
     * @param entityIn Entity
     */
    protected void collideWithEntity(Entity entityIn) { }

    /**
     * Called on collision with nearest entity. Does nothing
     */
    protected void collideWithNearbyEntities() { }

    /**
     * Called to update the entity's position/logic
     */
    @Override
    public void tick() {
        super.tick();
        this.setMotion(this.getMotion().mul(1.0D, 0.6D, 1.0D));
    }

    /**
     * Update the AI Tasks
     */
    @Override
    protected void updateAITasks() {
        super.updateAITasks();
        if (this.spawnPosition != null && (!this.world.isAirBlock(this.spawnPosition) || this.spawnPosition.getY() < 1)) {
            this.spawnPosition = null;
        }

        if (this.spawnPosition == null || this.rand.nextInt(30) == 0 || this.spawnPosition.withinDistance(this.getPositionVec(), 2.0D)) {
            this.spawnPosition = new BlockPos(this.posX + (double)this.rand.nextInt(7) - (double)this.rand.nextInt(7), this.posY + (double)this.rand.nextInt(6) - 2.0D, this.posZ + (double)this.rand.nextInt(7) - (double)this.rand.nextInt(7));
        }
        double d0 = (double)this.spawnPosition.getX() + 0.5D - this.posX;
        double d1 = (double)this.spawnPosition.getY() + 0.1D - this.posY;
        double d2 = (double)this.spawnPosition.getZ() + 0.5D - this.posZ;
        Vec3d vec3d = this.getMotion();
        Vec3d vec3d1 = vec3d.add((Math.signum(d0) * 0.5D - vec3d.x) * (double)0.1F, (Math.signum(d1) * (double)0.7F - vec3d.y) * (double)0.1F, (Math.signum(d2) * 0.5D - vec3d.z) * (double)0.1F);
        this.setMotion(vec3d1);
        float f = (float)(MathHelper.atan2(vec3d1.z, vec3d1.x) * (double)(180F / (float)Math.PI)) - 90.0F;
        float f1 = MathHelper.wrapDegrees(f - this.rotationYaw);
        this.moveForward = 0.5F;
        this.rotationYaw += f1;
    }

    /**
     * Returns whether this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
     * prevent them from trampling crops
     * @return True if the entity will trigger Block.onEntityWalking, false otherwise
     */
    @Override
    protected boolean canTriggerWalking() {
        return false;
    }

    /**
     * Return whether this entity should not trigger a pressure plate or a tripwire.
     * @return True if the entity should not trigger a pressure plate or a tripwire, false otherwise
     */
    public boolean doesEntityNotTriggerPressurePlate() {
        return true;
    }

    /**
     * Called on entity falling. Does nothing
     * @param distance Fall distance
     * @param damageMultiplier Damage Multiplier
     */
    public void fall(float distance, float damageMultiplier) { }

    /**
     * Update Fall State. Does nothing
     * @param y Pos Y
     * @param onGroundIn If is on ground
     * @param state BlockState the entity is falling
     * @param pos BlockPos the entity is falling
     */
    protected void updateFallState(double y, boolean onGroundIn, BlockState state, BlockPos pos) { }

    /**
     * Called when the entity is attacked.
     * @param source Damage Source
     * @param amount Damage Amount
     * @return True if the entity should be damaged, false otherwise
     */
    @Override
    public boolean attackEntityFrom(DamageSource source, float amount) {
        if(this.isInvulnerableTo(source)) {
            return false;
        }
        return super.attackEntityFrom(source, amount);
    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     * @param compound NBTTag Compound
     */
    @Override
    public void readAdditional(CompoundNBT compound) {
        super.readAdditional(compound);
    }

    /**
     * (abstract) Protected helper method to write subclass entity data to NBT.
     * @param compound NBTTag Compound
     */
    @Override
    public void writeAdditional(CompoundNBT compound) {
        super.writeAdditional(compound);
    }

    /**
     * Get the entity's eye height
     * @param poseIn Entity's pose
     * @param sizeIn Enttiy Size
     * @return Entity Eye Height
     */
    protected float getStandingEyeHeight(Pose poseIn, EntitySize sizeIn) {
        return sizeIn.height / 2.0F;
    }
}

 

and this is how i render

 

package com.antiblaze.entities.renderers;

import com.antiblaze.entities.AntiBlazeEntity;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

/**
 * AntiBlaze Rendered Class
 * @author JimiIT92
 */
@OnlyIn(Dist.CLIENT)
public class AntiBlazeRenderer<T extends AntiBlazeEntity, M extends EntityModel<T>> extends  MobRenderer<T, M> {

    /**
     * Constructor. Initialize the Render Manager
     * @param renderManagerIn Render Manager
     */
    public AntiBlazeRenderer(EntityRendererManager renderManagerIn, M model) {
        super(renderManagerIn, model, 0.25F);
    }

    /**
     * Return whether the name should be rendered.
     * @param entity Entity
     * @return True if the name should be rendered, false otherwise
     */
    @Override
    protected boolean canRenderName(T entity) {
        return entity.hasCustomName();
    }

    /**
     * Scale the Model before rendering
     * @param entitylivingbaseIn Entity to scale
     * @param partialTickTime Partial Tick Time
     */
    @Override
    protected void preRenderCallback(T entitylivingbaseIn, float partialTickTime) {
        GlStateManager.scalef(0.35F, 0.35F, 0.35F);
    }

    /**
     * Apply Rotations to the model
     * @param entityLiving Entity
     * @param ageInTicks Age in Ticks
     * @param rotationYaw Rotation Yaw
     * @param partialTicks Partial Ticks
     */
    @Override
    protected void applyRotations(T entityLiving, float ageInTicks, float rotationYaw, float partialTicks) {
        GlStateManager.translatef(0.0F, MathHelper.cos(ageInTicks * 0.3F) * 0.1F, 0.0F);
        super.applyRotations(entityLiving, ageInTicks, rotationYaw, partialTicks);
    }

    /**
     * Get the Entity Texture
     * @param entity Entity
     * @return Entity Texture
     */
    protected ResourceLocation getEntityTexture(T entity) {
        return null;
    }

}

 

Any idea on why this happens? :/

Edited by JimiIT92
Solved

Don't blame me if i always ask for your help. I just want to learn to be better :)

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.