| 1 | package net.minecraft.world.entity.monster.spider;
|
| 2 |
|
| 3 | import net.minecraft.server.level.ServerLevel;
|
| 4 | import net.minecraft.world.Difficulty;
|
| 5 | import net.minecraft.world.DifficultyInstance;
|
| 6 | import net.minecraft.world.effect.MobEffectInstance;
|
| 7 | import net.minecraft.world.effect.MobEffects;
|
| 8 | import net.minecraft.world.entity.Entity;
|
| 9 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 10 | import net.minecraft.world.entity.EntityType;
|
| 11 | import net.minecraft.world.entity.LivingEntity;
|
| 12 | import net.minecraft.world.entity.SpawnGroupData;
|
| 13 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 14 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 15 | import net.minecraft.world.level.Level;
|
| 16 | import net.minecraft.world.level.ServerLevelAccessor;
|
| 17 | import net.minecraft.world.phys.Vec3;
|
| 18 | import org.jspecify.annotations.Nullable;
|
| 19 |
|
| 20 | public class CaveSpider extends Spider {
|
| 21 | public CaveSpider(final EntityType<? extends CaveSpider> type, final Level level) {
|
| 22 | super(type, level);
|
| 23 | }
|
| 24 |
|
| 25 | public static AttributeSupplier.Builder createCaveSpider() {
|
| 26 | return Spider.createAttributes().add(Attributes.MAX_HEALTH, 12.0);
|
| 27 | }
|
| 28 |
|
| 29 | @Override
|
| 30 | public boolean doHurtTarget(final ServerLevel level, final Entity target) {
|
| 31 | if (super.doHurtTarget(level, target)) {
|
| 32 | if (target instanceof LivingEntity livingEntity) {
|
| 33 | int poisonTime = 0;
|
| 34 | if (this.level().getDifficulty() == Difficulty.NORMAL) {
|
| 35 | poisonTime = 7;
|
| 36 | } else if (this.level().getDifficulty() == Difficulty.HARD) {
|
| 37 | poisonTime = 15;
|
| 38 | }
|
| 39 |
|
| 40 | if (poisonTime > 0) {
|
| 41 | livingEntity.addEffect(new MobEffectInstance(MobEffects.POISON, poisonTime * 20, 0), this);
|
| 42 | }
|
| 43 | }
|
| 44 |
|
| 45 | return true;
|
| 46 | } else {
|
| 47 | return false;
|
| 48 | }
|
| 49 | }
|
| 50 |
|
| 51 | @Override
|
| 52 | public @Nullable SpawnGroupData finalizeSpawn(
|
| 53 | final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, final @Nullable SpawnGroupData groupData
|
| 54 | ) {
|
| 55 | return groupData;
|
| 56 | }
|
| 57 |
|
| 58 | @Override
|
| 59 | public Vec3 getVehicleAttachmentPoint(final Entity vehicle) {
|
| 60 | return vehicle.getBbWidth() <= this.getBbWidth() ? new Vec3(0.0, 0.21875 * this.getScale(), 0.0) : super.getVehicleAttachmentPoint(vehicle);
|
| 61 | }
|
| 62 | }
|
| 63 |
|