Posted December 23, 20213 yr I was looking all day into minecraft vanilla mobs code, so I could make one myself. My idea is: A mob that disguises itself as an Armor Standing with a full set of armor (being it iron, diamond...), and that if the player is close enough or attacks the "Armor Standing", it starts moving and attacking the player. I ended up with a code much like Endermans code, but still not complete. The lack of detailed documentation of the functions and classes leads up to hours of trying to understand what each class do, what they represent, how do you have to use them etc etc. Anyways, here is what I have: ... public class RiftAnimatedArmor extends Monster implements NeutralMob { private static final EntityDataAccessor<Integer> DATA_REMAINING_ANGER_TIME = SynchedEntityData.defineId(Bee.class, EntityDataSerializers.INT); private static final UniformInt PERSISTENT_ANGER_TIME = TimeUtil.rangeOfSeconds(20, 39); private UUID persistentAngerTarget; private static final boolean DISGUISED = true; protected int xpReward = 200; public RiftAnimatedArmor(EntityType<? extends RiftAnimatedArmor> entityType, Level level) { super(entityType, level); this.setPathfindingMalus(BlockPathTypes.LAVA, 0); } public static AttributeSupplier.Builder createAttributes() { return Monster.createMonsterAttributes() .add(Attributes.MAX_HEALTH, 33.0D) .add(Attributes.MOVEMENT_SPEED, (double)0.1F) .add(Attributes.ATTACK_DAMAGE, 5) .add(Attributes.FOLLOW_RANGE, 20); } protected void registerGoals() { this.goalSelector.addGoal(8, new LookAtPlayerGoal(this, Player.class, 8.0F)); this.goalSelector.addGoal(8, new RandomLookAroundGoal(this)); this.addBehaviourGoals(); } protected void addBehaviourGoals() { this.targetSelector.addGoal(2, new HurtByTargetGoal(this)); this.goalSelector.addGoal(2, new MeleeAttackGoal(this, 1.0D, false)); this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, Endermite.class, true, false)); this.goalSelector.addGoal(7, new WaterAvoidingRandomStrollGoal(this, 1.0D)); } public void setTarget(@Nullable LivingEntity entity) { super.setTarget(entity); } boolean CloseToPlayer(Player player) { return player.distanceToSqr(this) <= 3; } public void aiStep() { if (!this.level.isClientSide) { this.updatePersistentAnger((ServerLevel)this.level, true); } super.aiStep(); } @Override protected int getExperienceReward(Player player) { return super.getExperienceReward(player); } // TODO getAmbientSound() // TODO getDeathSound() // TODO getHurtSound() // TODO getStepSound() public boolean doHurtTarget(Entity entity) { boolean flag = entity.hurt(DamageSource.mobAttack(this), (float)((int)this.getAttributeValue(Attributes.ATTACK_DAMAGE))); if (flag) { this.doEnchantDamageEffects(this, entity); if (entity instanceof LivingEntity) { ((LivingEntity) entity).addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 2*20, 0)); } } return flag; } public int getRemainingPersistentAngerTime() { return this.entityData.get(DATA_REMAINING_ANGER_TIME); } public void setRemainingPersistentAngerTime(int time) { this.entityData.set(DATA_REMAINING_ANGER_TIME, time); } @Nullable public UUID getPersistentAngerTarget() { return this.persistentAngerTarget; } public void setPersistentAngerTarget(@Nullable UUID uuid) { this.persistentAngerTarget = uuid; } public void startPersistentAngerTimer() { this.setRemainingPersistentAngerTime(PERSISTENT_ANGER_TIME.sample(this.random)); } public class AnimatedArmorUndisguiseIfCloseToPlayer extends Goal { private final RiftAnimatedArmor animatedArmor; @Nullable private LivingEntity target; public AnimatedArmorUndisguiseIfCloseToPlayer(RiftAnimatedArmor animatedArmor) { this.animatedArmor = animatedArmor; } public boolean canUse() { this.target = this.animatedArmor.getTarget(); if (!(this.target instanceof Player)) { return false; } else { return CloseToPlayer((Player)this.target); } } // TODO public void start() { this.animatedArmor.getNavigation().stop(); } } How would I implement this mob? And please if someone knows a good source of documentation please tell me.
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.