Guest User

Entity Class

a guest
Apr 18th, 2020
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.21 KB | None | 0 0
  1. package com.lordloss.tutorial.entities;
  2.  
  3. import com.lordloss.tutorial.init.ModEntityTypes;
  4. import net.minecraft.client.renderer.entity.ChickenRenderer;
  5. import net.minecraft.client.renderer.entity.model.ChickenModel;
  6. import net.minecraft.entity.*;
  7. import net.minecraft.entity.ai.goal.*;
  8. import net.minecraft.entity.passive.AnimalEntity;
  9. import net.minecraft.entity.passive.ChickenEntity;
  10. import net.minecraft.entity.player.PlayerEntity;
  11. import net.minecraft.item.Items;
  12. import net.minecraft.item.crafting.Ingredient;
  13. import net.minecraft.nbt.CompoundNBT;
  14. import net.minecraft.util.math.AxisAlignedBB;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraft.util.math.MathHelper;
  17. import net.minecraft.world.World;
  18. import net.minecraftforge.api.distmarker.Dist;
  19. import net.minecraftforge.api.distmarker.OnlyIn;
  20.  
  21. import javax.annotation.Nullable;
  22.  
  23. public class ExampleEntity extends AnimalEntity {
  24.  
  25.     private EatGrassGoal eatGrassGoal;
  26.     private int exampleTimer;
  27.  
  28.  
  29.     public ExampleEntity(EntityType<? extends AnimalEntity> type, World worldIn) {
  30.         super(type, worldIn);
  31.         AxisAlignedBB aabb = this.getBoundingBox();
  32.         this.setBoundingBox(new AxisAlignedBB(aabb.minX - 0.5d, aabb.minY, aabb.minZ - 0.5d, aabb.maxX - 0.5d, aabb.maxY - 0.5d, aabb.maxZ - 0.5d));
  33.     }
  34.  
  35.  
  36.     @Override
  37.     public AgeableEntity createChild(AgeableEntity ageable) {
  38.         ExampleEntity entity = new ExampleEntity(ModEntityTypes.EXAMPLE_ENTITY.get(), this.world);
  39.         entity.onInitialSpawn(this.world, this.world.getDifficultyForLocation(new BlockPos(entity)),
  40.                 SpawnReason.BREEDING, (ILivingEntityData)null, (CompoundNBT)null);
  41.         return entity;
  42.     }
  43.  
  44.     @Override
  45.     protected void registerGoals() {
  46.         super.registerGoals();
  47.         this.eatGrassGoal = new EatGrassGoal(this);
  48.         this.goalSelector.addGoal(0, new SwimGoal(this));
  49.         this.goalSelector.addGoal(1, new PanicGoal(this, 1.25D));
  50.         this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D));
  51.         this.goalSelector.addGoal(3, new TemptGoal(this, 1.1D, Ingredient.fromItems(Items.WHEAT), false));
  52.         this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1D));
  53.         this.goalSelector.addGoal(5, this.eatGrassGoal);
  54.         this.goalSelector.addGoal(6, new WaterAvoidingRandomWalkingGoal(this, 1.0D));
  55.         this.goalSelector.addGoal(7, new LookAtGoal(this, PlayerEntity.class, 6.0F));
  56.         this.goalSelector.addGoal(8, new LookRandomlyGoal(this));
  57.     }
  58.  
  59.     @Override
  60.     protected void updateAITasks() {
  61.         this.exampleTimer = this.eatGrassGoal.getEatingGrassTimer();
  62.         super.updateAITasks();
  63.     }
  64.  
  65.     @Override
  66.     public void livingTick() {
  67.         if(this.world.isRemote) {
  68.             this.exampleTimer = Math.max(0, this.exampleTimer-1);
  69.         }
  70.         super.livingTick();
  71.     }
  72.  
  73.     @Override
  74.     protected void registerAttributes() {
  75.         super.registerAttributes();
  76.         this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(8.0D);
  77.         this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.2f);
  78.     }
  79.  
  80.     @OnlyIn(Dist.CLIENT)
  81.     public void handleStatusUpdate(byte id) {
  82.         if (id == 10) {
  83.             this.exampleTimer = 40;
  84.         } else {
  85.             super.handleStatusUpdate(id);
  86.         }
  87.  
  88.     }
  89.  
  90.     @OnlyIn(Dist.CLIENT)
  91.     public float getHeadRotationPointY(float p_70894_1_) {
  92.         if (this.exampleTimer <= 0) {
  93.             return 0.0F;
  94.         } else if (this.exampleTimer >= 4 && this.exampleTimer <= 36) {
  95.             return 1.0F;
  96.         } else {
  97.             return this.exampleTimer < 4 ? ((float)this.exampleTimer - p_70894_1_) / 4.0F : -((float)(this.exampleTimer - 40) - p_70894_1_) / 4.0F;
  98.         }
  99.     }
  100.  
  101.     @OnlyIn(Dist.CLIENT)
  102.     public float getHeadRotationAngleX(float p_70890_1_) {
  103.         if (this.exampleTimer > 4 && this.exampleTimer <= 36) {
  104.             float f = ((float)(this.exampleTimer - 4) - p_70890_1_) / 32.0F;
  105.             return ((float)Math.PI / 5F) + 0.21991149F * MathHelper.sin(f * 28.7F);
  106.         } else {
  107.             return this.exampleTimer > 0 ? ((float)Math.PI / 5F) : this.rotationPitch * ((float)Math.PI / 180F);
  108.         }
  109.     }
  110.  
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment