Fish animation & egg

This commit is contained in:
paulevsGitch 2020-10-23 21:42:27 +03:00
parent e76577328c
commit 112783835e
5 changed files with 79 additions and 7 deletions

View file

@ -1,15 +1,20 @@
package ru.betterend.entity;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.passive.SchoolingFishEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.world.World;
public class EntityEndFish extends SchoolingFishEntity {
@ -25,7 +30,25 @@ public class EntityEndFish extends SchoolingFishEntity {
protected void initDataTracker() {
super.initDataTracker();
this.dataTracker.startTracking(VARIANT, (byte) this.getRandom().nextInt(VARIANTS));
this.dataTracker.startTracking(SCALE, (byte) this.getRandom().nextInt(255));
this.dataTracker.startTracking(SCALE, (byte) this.getRandom().nextInt(16));
}
@Override
public void writeCustomDataToTag(CompoundTag tag) {
super.writeCustomDataToTag(tag);
tag.putByte("Variant", (byte) getVariant());
tag.putByte("Scale", (byte) getScale());
}
@Override
public void readCustomDataFromTag(CompoundTag tag) {
super.readCustomDataFromTag(tag);
if (tag.contains("Variant")) {
this.dataTracker.set(VARIANT, tag.getByte("Variant"));
}
if (tag.contains("Scale")) {
this.dataTracker.set(SCALE, tag.getByte("Scale"));
}
}
@Override
@ -35,14 +58,40 @@ public class EntityEndFish extends SchoolingFishEntity {
@Override
protected SoundEvent getFlopSound() {
return null;
return SoundEvents.ENTITY_TROPICAL_FISH_FLOP;
}
@Override
protected SoundEvent getAmbientSound() {
return SoundEvents.ENTITY_SALMON_AMBIENT;
}
@Override
protected SoundEvent getDeathSound() {
return SoundEvents.ENTITY_SALMON_DEATH;
}
@Override
protected SoundEvent getHurtSound(DamageSource source) {
return SoundEvents.ENTITY_SALMON_HURT;
}
@Override
public void tick() {
super.tick();
if (random.nextInt(8) == 0 && getBlockState().isOf(Blocks.WATER)) {
double x = getX() + random.nextGaussian() * 0.2;
double y = getY() + random.nextGaussian() * 0.2;
double z = getZ() + random.nextGaussian() * 0.2;
world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0);
}
}
public static DefaultAttributeContainer.Builder createMobAttributes() {
return LivingEntity.createLivingAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 2.0D)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0D)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.5D);
.add(EntityAttributes.GENERIC_MAX_HEALTH, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.75);
}
public int getVariant() {
@ -50,6 +99,6 @@ public class EntityEndFish extends SchoolingFishEntity {
}
public float getScale() {
return ((int) this.dataTracker.get(SCALE) & 255) / 512F + 0.6F;
return this.dataTracker.get(SCALE) / 32F + 0.75F;
}
}