Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. package com.drnickenstein.testmod.entities;
  2.  
  3. import com.drnickenstein.testmod.init.EntityTypesInit;
  4. import com.drnickenstein.testmod.init.SoundInit;
  5.  
  6. import net.minecraft.block.BlockState;
  7. import net.minecraft.entity.AgeableEntity;
  8. import net.minecraft.entity.EntityType;
  9. import net.minecraft.entity.ILivingEntityData;
  10. import net.minecraft.entity.LivingEntity;
  11. import net.minecraft.entity.SharedMonsterAttributes;
  12. import net.minecraft.entity.SpawnReason;
  13. import net.minecraft.entity.ai.goal.FollowOwnerGoal;
  14. import net.minecraft.entity.ai.goal.LookAtGoal;
  15. import net.minecraft.entity.ai.goal.SwimGoal;
  16. import net.minecraft.entity.ai.goal.WaterAvoidingRandomWalkingGoal;
  17. import net.minecraft.entity.monster.CreeperEntity;
  18. import net.minecraft.entity.passive.TameableEntity;
  19. import net.minecraft.entity.player.PlayerEntity;
  20. import net.minecraft.nbt.CompoundNBT;
  21. import net.minecraft.potion.EffectInstance;
  22. import net.minecraft.potion.Effects;
  23. import net.minecraft.util.DamageSource;
  24. import net.minecraft.util.SoundEvent;
  25. import net.minecraft.util.math.BlockPos;
  26. import net.minecraft.world.World;
  27.  
  28. public class Humadillo extends TameableEntity
  29. {
  30.  
  31. //private int timer;
  32.  
  33. public Humadillo(EntityType<? extends TameableEntity> type, World worldIn)
  34. {
  35. super(type, worldIn);
  36.  
  37. }
  38.  
  39.  
  40.  
  41.  
  42. @SuppressWarnings({ "unchecked", "rawtypes" })
  43. @Override
  44. protected void registerGoals()
  45. {
  46.  
  47. super.registerGoals();
  48.  
  49. this.goalSelector.addGoal(0, new FollowOwnerGoal(this, 1.5D, 25.0f, 50.0f, false));
  50. this.goalSelector.addGoal(1, new Humadillo.AvoidEntityGoal(this, CreeperEntity.class, 24.0F, 1.5D, 1.5D));
  51. this.goalSelector.addGoal(2, new SwimGoal(this));
  52. this.goalSelector.addGoal(3, new WaterAvoidingRandomWalkingGoal(this, 1.0D));
  53. this.goalSelector.addGoal(4, new LookAtGoal(this, PlayerEntity.class, 5.0f));
  54.  
  55. }
  56.  
  57.  
  58.  
  59. @Override
  60. protected void registerAttributes()
  61. {
  62.  
  63.  
  64. super.registerAttributes();
  65. this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue((double)0.3F);
  66. if (this.isTamed())
  67. {
  68. this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20.0D);
  69. }
  70. else
  71. {
  72. this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20.0D);
  73. }
  74. this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue((double)0.20f);
  75. }
  76.  
  77. public void setTamed(boolean tamed)
  78. {
  79. super.setTamed(tamed);
  80. if (tamed)
  81. {
  82. this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20.0D);
  83. this.setHealth(20.0F);
  84. }
  85. else
  86. {
  87. this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20.0D);
  88. }
  89.  
  90. this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(4.0D);
  91. }
  92.  
  93. @SuppressWarnings("unused")
  94. @Override
  95. protected void damageEntity(DamageSource damageSrc, float damageAmount)
  96. {
  97.  
  98.  
  99. this.addPotionEffect(new EffectInstance(Effects.RESISTANCE, 400, 1, false, true));
  100. this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.0f);
  101. int i = 0;
  102. long time = System.currentTimeMillis();
  103. while(time != time+5000)
  104. {
  105. i++;
  106. }
  107. if(time < 1)
  108. {
  109. this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.20f);
  110. }
  111.  
  112. }
  113.  
  114. @Override
  115. public AgeableEntity createChild(AgeableEntity ageable) {
  116. Humadillo entity = new Humadillo(EntityTypesInit.HUMADILLO.get(), this.world);
  117. entity.onInitialSpawn(this.world, this.world.getDifficultyForLocation(new BlockPos(entity)),
  118. SpawnReason.BREEDING, (ILivingEntityData) null, (CompoundNBT) null);
  119. entity.setGlowing(true);
  120. return entity;
  121.  
  122. }
  123.  
  124. @Override
  125. public boolean canTrample(BlockState state, BlockPos pos, float fallDistance) {
  126.  
  127. return true;
  128. }
  129. @Override
  130. public boolean canBeLeashedTo(PlayerEntity player)
  131. {
  132.  
  133. return true;
  134. }
  135.  
  136. class AvoidEntityGoal<T extends LivingEntity> extends net.minecraft.entity.ai.goal.AvoidEntityGoal<T> {
  137. @SuppressWarnings("unused")
  138. private final Humadillo humadillo;
  139.  
  140. public AvoidEntityGoal(Humadillo humadilloIn, Class<T> p_i47251_3_, float p_i47251_4_, double p_i47251_5_, double p_i47251_7_) {
  141. super(humadilloIn, p_i47251_3_, p_i47251_4_, p_i47251_5_, p_i47251_7_);
  142. this.humadillo = humadilloIn;
  143. }
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement