TheOnlyTails

RubySheepEntity Class

Jul 27th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.22 KB | None | 0 0
  1. package com.theonlytails.ruby.entities;
  2.  
  3. import com.theonlytails.ruby.init.ItemsRegistry;
  4. import com.theonlytails.ruby.init.RubyEntityTypes;
  5. import net.minecraft.block.BlockState;
  6. import net.minecraft.entity.*;
  7. import net.minecraft.entity.ai.attributes.Attributes;
  8. import net.minecraft.entity.ai.goal.*;
  9. import net.minecraft.entity.item.ItemEntity;
  10. import net.minecraft.entity.passive.SheepEntity;
  11. import net.minecraft.entity.player.PlayerEntity;
  12. import net.minecraft.item.DyeColor;
  13. import net.minecraft.item.Items;
  14. import net.minecraft.item.crafting.Ingredient;
  15. import net.minecraft.nbt.CompoundNBT;
  16. import net.minecraft.util.*;
  17. import net.minecraft.util.math.BlockPos;
  18. import net.minecraft.world.DifficultyInstance;
  19. import net.minecraft.world.IWorld;
  20. import net.minecraft.world.World;
  21. import net.minecraftforge.api.distmarker.Dist;
  22. import net.minecraftforge.api.distmarker.OnlyIn;
  23. import org.jetbrains.annotations.NotNull;
  24.  
  25. import javax.annotation.Nonnull;
  26. import javax.annotation.Nullable;
  27.  
  28. import static net.minecraft.entity.ai.attributes.AttributeModifierMap.MutableAttribute;
  29.  
  30. public class RubySheepEntity extends SheepEntity {
  31.     public static final Ingredient TEMPTATION_ITEMS = Ingredient.fromItems(ItemsRegistry.RUBY.get(), Items.WHEAT);
  32.     private EatGrassGoal eatGrassGoal;
  33.     private int rubySheepTimer;
  34.  
  35.     public RubySheepEntity(EntityType<? extends SheepEntity> type, World worldIn) {
  36.         super(type, worldIn);
  37.     }
  38.  
  39.     @Nonnull
  40.     public static MutableAttribute setCustomAttributes() {
  41.         // func_233666_p_() -> registerAttributes()
  42.         return MobEntity.func_233666_p_()
  43.                 .createMutableAttribute(Attributes.MAX_HEALTH, 10f)
  44.                 .createMutableAttribute(Attributes.MOVEMENT_SPEED, 0.23f);
  45.     }
  46.  
  47.     @Override
  48.     protected void registerGoals() {
  49.         super.registerGoals();
  50.         eatGrassGoal = new EatGrassGoal(this);
  51.         this.goalSelector.addGoal(0, new SwimGoal(this));
  52.         this.goalSelector.addGoal(1, new PanicGoal(this, 1.25D));
  53.         this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D));
  54.         this.goalSelector.addGoal(3, new TemptGoal(this, 1.1D, TEMPTATION_ITEMS, false));
  55.         this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1D));
  56.         this.goalSelector.addGoal(5, this.eatGrassGoal);
  57.         this.goalSelector.addGoal(6, new WaterAvoidingRandomWalkingGoal(this, 1.0D));
  58.         this.goalSelector.addGoal(7, new LookAtGoal(this, PlayerEntity.class, 6.0F));
  59.         this.goalSelector.addGoal(8, new LookRandomlyGoal(this));
  60.     }
  61.  
  62.     @Override
  63.     protected int getExperiencePoints(@Nonnull PlayerEntity player) {
  64.         return super.getExperiencePoints(player);
  65.     }
  66.  
  67.     @Nullable
  68.     @Override
  69.     public RubySheepEntity createChild(@Nonnull AgeableEntity ageable) {
  70.         return RubyEntityTypes.RUBY_SHEEP.get().create(world);
  71.     }
  72.  
  73.     @Nullable
  74.     @Override
  75.     protected SoundEvent getAmbientSound() {
  76.         return SoundEvents.ENTITY_SHEEP_AMBIENT;
  77.     }
  78.  
  79.     @Nullable
  80.     @Override
  81.     protected SoundEvent getDeathSound() {
  82.         return SoundEvents.ENTITY_SHEEP_DEATH;
  83.     }
  84.  
  85.     @Nullable
  86.     @Override
  87.     protected SoundEvent getHurtSound(@Nonnull DamageSource damageSourceIn) {
  88.         return SoundEvents.ENTITY_SHEEP_HURT;
  89.     }
  90.  
  91.     @Override
  92.     protected void playStepSound(@Nonnull BlockPos pos, @Nonnull BlockState blockIn) {
  93.         this.playSound(SoundEvents.ENTITY_SHEEP_STEP, 0.1f, 1f);
  94.     }
  95.  
  96.     @Override
  97.     protected void updateAITasks() {
  98.         this.rubySheepTimer = this.eatGrassGoal.getEatingGrassTimer();
  99.         super.updateAITasks();
  100.     }
  101.  
  102.     @Override
  103.     public void livingTick() {
  104.         if (this.world.isRemote) {
  105.             rubySheepTimer = Math.max(0, rubySheepTimer - 1);
  106.         }
  107.         super.livingTick();
  108.     }
  109.  
  110.     @OnlyIn(Dist.CLIENT)
  111.     @Override
  112.     public void handleStatusUpdate(byte id) {
  113.         if (id == 10) {
  114.             rubySheepTimer = 40;
  115.         } else {
  116.             super.handleStatusUpdate(id);
  117.         }
  118.     }
  119.  
  120.     @Override
  121.     public void shear(@NotNull SoundCategory category) {
  122.         this.world.playMovingSound(null, this, SoundEvents.ENTITY_SHEEP_SHEAR, category, 1.0F, 1.0F);
  123.         this.setSheared(true);
  124.         int i = 1 + this.rand.nextInt(3);
  125.  
  126.         for (int j = 0; j < i; ++j) {
  127.             ItemEntity itementity = this.entityDropItem(ItemsRegistry.RUBY_WOOL_ITEM.get(), 1);
  128.             if (itementity != null) {
  129.                 itementity.setMotion(itementity.getMotion().add((this.rand.nextFloat() - this.rand.nextFloat()) * 0.1F, this.rand.nextFloat() * 0.05F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.1F));
  130.             }
  131.         }
  132.     }
  133.  
  134.     @Nullable
  135.     @Override
  136.     public ILivingEntityData onInitialSpawn(@NotNull IWorld worldIn, @NotNull DifficultyInstance difficultyIn, @NotNull SpawnReason reason, @Nullable ILivingEntityData spawnDataIn, @Nullable CompoundNBT dataTag) {
  137.         this.setFleeceColor(DyeColor.WHITE);
  138.         return super.onInitialSpawn(worldIn, difficultyIn, reason, spawnDataIn, dataTag);
  139.     }
  140.  
  141.     @Override
  142.     public @NotNull ResourceLocation getLootTable() {
  143.         return new ResourceLocation("ruby", "loot_tables/entities/ruby_sheep");
  144.     }
  145. }
  146.  
Advertisement
Add Comment
Please, Sign In to add comment