| 1 | package net.minecraft.world.entity.monster.piglin;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.server.level.ServerLevel;
|
| 6 | import net.minecraft.sounds.SoundEvent;
|
| 7 | import net.minecraft.sounds.SoundEvents;
|
| 8 | import net.minecraft.util.RandomSource;
|
| 9 | import net.minecraft.util.profiling.Profiler;
|
| 10 | import net.minecraft.util.profiling.ProfilerFiller;
|
| 11 | import net.minecraft.world.DifficultyInstance;
|
| 12 | import net.minecraft.world.damagesource.DamageSource;
|
| 13 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 14 | import net.minecraft.world.entity.EntityType;
|
| 15 | import net.minecraft.world.entity.EquipmentSlot;
|
| 16 | import net.minecraft.world.entity.LivingEntity;
|
| 17 | import net.minecraft.world.entity.SpawnGroupData;
|
| 18 | import net.minecraft.world.entity.ai.Brain;
|
| 19 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 20 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 21 | import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
| 22 | import net.minecraft.world.entity.ai.sensing.SensorType;
|
| 23 | import net.minecraft.world.entity.monster.Monster;
|
| 24 | import net.minecraft.world.item.ItemStack;
|
| 25 | import net.minecraft.world.item.Items;
|
| 26 | import net.minecraft.world.level.Level;
|
| 27 | import net.minecraft.world.level.ServerLevelAccessor;
|
| 28 | import net.minecraft.world.level.block.state.BlockState;
|
| 29 | import org.jspecify.annotations.Nullable;
|
| 30 |
|
| 31 | public class PiglinBrute extends AbstractPiglin {
|
| 32 | private static final int MAX_HEALTH = 50;
|
| 33 | private static final float MOVEMENT_SPEED_WHEN_FIGHTING = 0.35F;
|
| 34 | private static final int ATTACK_DAMAGE = 7;
|
| 35 | private static final double TARGETING_RANGE = 12.0;
|
| 36 | public static final Brain.Provider<PiglinBrute> BRAIN_PROVIDER = Brain.provider(
|
| 37 | List.of(MemoryModuleType.NEAREST_VISIBLE_ADULT_PIGLINS),
|
| 38 | List.of(SensorType.NEAREST_LIVING_ENTITIES, SensorType.NEAREST_PLAYERS, SensorType.NEAREST_ITEMS, SensorType.HURT_BY, SensorType.PIGLIN_BRUTE_SPECIFIC_SENSOR),
|
| 39 | PiglinBruteAi::getActivities
|
| 40 | );
|
| 41 |
|
| 42 | public PiglinBrute(final EntityType<? extends PiglinBrute> type, final Level level) {
|
| 43 | super(type, level);
|
| 44 | this.xpReward = 20;
|
| 45 | }
|
| 46 |
|
| 47 | public static AttributeSupplier.Builder createAttributes() {
|
| 48 | return Monster.createMonsterAttributes()
|
| 49 | .add(Attributes.MAX_HEALTH, 50.0)
|
| 50 | .add(Attributes.MOVEMENT_SPEED, 0.35F)
|
| 51 | .add(Attributes.ATTACK_DAMAGE, 7.0)
|
| 52 | .add(Attributes.FOLLOW_RANGE, 12.0);
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | public @Nullable SpawnGroupData finalizeSpawn(
|
| 57 | final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, final @Nullable SpawnGroupData groupData
|
| 58 | ) {
|
| 59 | PiglinBruteAi.initMemories(this);
|
| 60 | this.populateDefaultEquipmentSlots(level.getRandom(), difficulty);
|
| 61 | return super.finalizeSpawn(level, difficulty, spawnReason, groupData);
|
| 62 | }
|
| 63 |
|
| 64 | @Override
|
| 65 | protected void populateDefaultEquipmentSlots(final RandomSource random, final DifficultyInstance difficulty) {
|
| 66 | this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.GOLDEN_AXE));
|
| 67 | }
|
| 68 |
|
| 69 | @Override
|
| 70 | protected Brain<PiglinBrute> makeBrain(final Brain.Packed packedBrain) {
|
| 71 | return BRAIN_PROVIDER.makeBrain(this, packedBrain);
|
| 72 | }
|
| 73 |
|
| 74 | @Override
|
| 75 | public Brain<PiglinBrute> getBrain() {
|
| 76 | return super.getBrain();
|
| 77 | }
|
| 78 |
|
| 79 | @Override
|
| 80 | public boolean canHunt() {
|
| 81 | return false;
|
| 82 | }
|
| 83 |
|
| 84 | @Override
|
| 85 | public boolean wantsToPickUp(final ServerLevel level, final ItemStack itemStack) {
|
| 86 | return itemStack.is(Items.GOLDEN_AXE) ? super.wantsToPickUp(level, itemStack) : false;
|
| 87 | }
|
| 88 |
|
| 89 | @Override
|
| 90 | protected void customServerAiStep(final ServerLevel level) {
|
| 91 | ProfilerFiller profiler = Profiler.get();
|
| 92 | profiler.push("piglinBruteBrain");
|
| 93 | this.getBrain().tick(level, this);
|
| 94 | profiler.pop();
|
| 95 | PiglinBruteAi.updateActivity(this);
|
| 96 | PiglinBruteAi.maybePlayActivitySound(this);
|
| 97 | super.customServerAiStep(level);
|
| 98 | }
|
| 99 |
|
| 100 | @Override
|
| 101 | public PiglinArmPose getArmPose() {
|
| 102 | return this.isAggressive() && this.isHoldingMeleeWeapon() ? PiglinArmPose.ATTACKING_WITH_MELEE_WEAPON : PiglinArmPose.DEFAULT;
|
| 103 | }
|
| 104 |
|
| 105 | @Override
|
| 106 | public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
|
| 107 | boolean wasHurt = super.hurtServer(level, source, damage);
|
| 108 | if (wasHurt && source.getEntity() instanceof LivingEntity sourceEntity) {
|
| 109 | PiglinBruteAi.wasHurtBy(level, this, sourceEntity);
|
| 110 | }
|
| 111 |
|
| 112 | return wasHurt;
|
| 113 | }
|
| 114 |
|
| 115 | @Override
|
| 116 | protected SoundEvent getAmbientSound() {
|
| 117 | return SoundEvents.PIGLIN_BRUTE_AMBIENT;
|
| 118 | }
|
| 119 |
|
| 120 | @Override
|
| 121 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 122 | return SoundEvents.PIGLIN_BRUTE_HURT;
|
| 123 | }
|
| 124 |
|
| 125 | @Override
|
| 126 | protected SoundEvent getDeathSound() {
|
| 127 | return SoundEvents.PIGLIN_BRUTE_DEATH;
|
| 128 | }
|
| 129 |
|
| 130 | @Override
|
| 131 | protected void playStepSound(final BlockPos pos, final BlockState blockState) {
|
| 132 | this.playSound(SoundEvents.PIGLIN_BRUTE_STEP, 0.15F, 1.0F);
|
| 133 | }
|
| 134 |
|
| 135 | protected void playAngrySound() {
|
| 136 | this.makeSound(SoundEvents.PIGLIN_BRUTE_ANGRY);
|
| 137 | }
|
| 138 |
|
| 139 | @Override
|
| 140 | protected void playConvertedSound() {
|
| 141 | this.makeSound(SoundEvents.PIGLIN_BRUTE_CONVERTED_TO_ZOMBIFIED);
|
| 142 | }
|
| 143 | }
|
| 144 |
|