注:1.16.5的实体教程和本文基本类似,只是一些类中的函数名称有所不同。
我们今天在1.18.1的模组中添加一个生物实体
1.新建entity文件夹 -> 文件夹中新建一个model文件夹,一个render文件夹,一个我们的生物类(以EntityRe8Dimi.java为例)
我们本次要制作一个boss类怪物,类似于凋零,具有boss血条
EntityRe8Dimi.java
package com.joy187.re8joymod.entity;
import java.util.Random;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import com.joy187.re8joymod.init.EntityInit;
import com.mojang.blaze3d.vertex.PoseStack.Pose;
import net.minecraft.client.renderer.EffectInstance;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerBossEvent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.BossEvent;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal;
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.IronGolem;
import net.minecraft.world.entity.boss.wither.WitherBoss;
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.monster.Ravager;
import net.minecraft.world.entity.monster.ZombifiedPiglin;
import net.minecraft.world.entity.npc.AbstractVillager;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.minecraftforge.client.event.RenderGameOverlayEvent.BossInfo;
//我们的boss继承自劫掠兽
public class EntityRe8Dimi extends Ravager {
//boss血条信息
private final ServerBossEvent bossInfo = (ServerBossEvent)(new ServerBossEvent(this.getDisplayName(), BossEvent.BossBarColor.PURPLE, BossEvent.BossBarOverlay.PROGRESS)).setDarkenScreen(true);
private static final EntityDataAccessor DATA_ID_INV = SynchedEntityData.defineId(EntityRe8Dimi.class, EntityDataSerializers.INT);
//我们的boss不攻击类型为不死亡灵类的生物(凋零骷髅一类)
private static final Predicate LIVING_ENTITY_SELECTOR = (p_31504_) -> {
return p_31504_.getMobType() != MobType.UNDEAD && p_31504_.attackable();
};
public EntityRe8Dimi(EntityType |