| 1 | package net.minecraft.world.entity.animal.squid;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.particles.ParticleOptions;
|
| 5 | import net.minecraft.core.particles.ParticleTypes;
|
| 6 | import net.minecraft.network.syncher.EntityDataAccessor;
|
| 7 | import net.minecraft.network.syncher.EntityDataSerializers;
|
| 8 | import net.minecraft.network.syncher.SynchedEntityData;
|
| 9 | import net.minecraft.server.level.ServerLevel;
|
| 10 | import net.minecraft.sounds.SoundEvent;
|
| 11 | import net.minecraft.sounds.SoundEvents;
|
| 12 | import net.minecraft.util.RandomSource;
|
| 13 | import net.minecraft.world.damagesource.DamageSource;
|
| 14 | import net.minecraft.world.entity.AgeableMob;
|
| 15 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 16 | import net.minecraft.world.entity.EntityType;
|
| 17 | import net.minecraft.world.entity.EntityTypes;
|
| 18 | import net.minecraft.world.entity.LivingEntity;
|
| 19 | import net.minecraft.world.level.Level;
|
| 20 | import net.minecraft.world.level.ServerLevelAccessor;
|
| 21 | import net.minecraft.world.level.block.Blocks;
|
| 22 | import net.minecraft.world.level.storage.ValueInput;
|
| 23 | import net.minecraft.world.level.storage.ValueOutput;
|
| 24 | import org.jspecify.annotations.Nullable;
|
| 25 |
|
| 26 | public class GlowSquid extends Squid {
|
| 27 | private static final EntityDataAccessor<Integer> DATA_DARK_TICKS_REMAINING = SynchedEntityData.defineId(GlowSquid.class, EntityDataSerializers.INT);
|
| 28 | private static final int DEFAULT_DARK_TICKS_REMAINING = 0;
|
| 29 |
|
| 30 | public GlowSquid(final EntityType<? extends GlowSquid> type, final Level level) {
|
| 31 | super(type, level);
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | protected ParticleOptions getInkParticle() {
|
| 36 | return ParticleTypes.GLOW_SQUID_INK;
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
|
| 41 | super.defineSynchedData(entityData);
|
| 42 | entityData.define(DATA_DARK_TICKS_REMAINING, 0);
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | public @Nullable AgeableMob getBreedOffspring(final ServerLevel level, final AgeableMob partner) {
|
| 47 | return EntityTypes.GLOW_SQUID.create(level, EntitySpawnReason.BREEDING);
|
| 48 | }
|
| 49 |
|
| 50 | @Override
|
| 51 | protected SoundEvent getSquirtSound() {
|
| 52 | return SoundEvents.GLOW_SQUID_SQUIRT;
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | protected SoundEvent getAmbientSound() {
|
| 57 | return SoundEvents.GLOW_SQUID_AMBIENT;
|
| 58 | }
|
| 59 |
|
| 60 | @Override
|
| 61 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 62 | return SoundEvents.GLOW_SQUID_HURT;
|
| 63 | }
|
| 64 |
|
| 65 | @Override
|
| 66 | protected SoundEvent getDeathSound() {
|
| 67 | return SoundEvents.GLOW_SQUID_DEATH;
|
| 68 | }
|
| 69 |
|
| 70 | @Override
|
| 71 | protected void addAdditionalSaveData(final ValueOutput output) {
|
| 72 | super.addAdditionalSaveData(output);
|
| 73 | output.putInt("DarkTicksRemaining", this.getDarkTicksRemaining());
|
| 74 | }
|
| 75 |
|
| 76 | @Override
|
| 77 | protected void readAdditionalSaveData(final ValueInput input) {
|
| 78 | super.readAdditionalSaveData(input);
|
| 79 | this.setDarkTicks(input.getIntOr("DarkTicksRemaining", 0));
|
| 80 | }
|
| 81 |
|
| 82 | @Override
|
| 83 | public void aiStep() {
|
| 84 | super.aiStep();
|
| 85 | int darkTicks = this.getDarkTicksRemaining();
|
| 86 | if (darkTicks > 0) {
|
| 87 | this.setDarkTicks(darkTicks - 1);
|
| 88 | }
|
| 89 |
|
| 90 | this.level().addParticle(ParticleTypes.GLOW, this.getRandomX(0.6), this.getRandomY(), this.getRandomZ(0.6), 0.0, 0.0, 0.0);
|
| 91 | }
|
| 92 |
|
| 93 | @Override
|
| 94 | public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
|
| 95 | boolean hurt = super.hurtServer(level, source, damage);
|
| 96 | if (hurt) {
|
| 97 | this.setDarkTicks(100);
|
| 98 | }
|
| 99 |
|
| 100 | return hurt;
|
| 101 | }
|
| 102 |
|
| 103 | private void setDarkTicks(final int ticks) {
|
| 104 | this.entityData.set(DATA_DARK_TICKS_REMAINING, ticks);
|
| 105 | }
|
| 106 |
|
| 107 | public int getDarkTicksRemaining() {
|
| 108 | return this.entityData.get(DATA_DARK_TICKS_REMAINING);
|
| 109 | }
|
| 110 |
|
| 111 | public static boolean checkGlowSquidSpawnRules(
|
| 112 | final EntityType<? extends LivingEntity> type,
|
| 113 | final ServerLevelAccessor level,
|
| 114 | final EntitySpawnReason spawnReason,
|
| 115 | final BlockPos pos,
|
| 116 | final RandomSource random
|
| 117 | ) {
|
| 118 | return pos.getY() <= level.getSeaLevel() - 33 && level.getRawBrightness(pos, 0) == 0 && level.getBlockState(pos).is(Blocks.WATER);
|
| 119 | }
|
| 120 | }
|
| 121 |
|