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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

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