Advertisement
jayhillx

pink chicken issues

Aug 22nd, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.92 KB | None | 0 0
  1. =======================================================================================================================================
  2. PinkChickenEntity
  3. public class PinkChickenEntity extends AnimalEntity {
  4.  
  5. private static final Ingredient TEMPTATION_ITEMS = Ingredient.fromItems(Items.WHEAT_SEEDS, Items.MELON_SEEDS, Items.PUMPKIN_SEEDS, Items.BEETROOT_SEEDS);
  6. public float wingRotation;
  7. public float destPos;
  8. public float oFlapSpeed;
  9. public float oFlap;
  10. public float wingRotDelta = 1.0F;
  11. public int timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
  12. public boolean chickenJockey;
  13.  
  14. public PinkChickenEntity(EntityType<? extends AnimalEntity> type, World worldIn) {
  15. super(type, worldIn);
  16. this.setPathPriority(PathNodeType.WATER, 0.0F);
  17. }
  18.  
  19. @Override
  20. protected void registerGoals() {
  21. this.goalSelector.addGoal(0, new SwimGoal(this));
  22. this.goalSelector.addGoal(1, new PanicGoal(this, 1.4D));
  23. this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D));
  24. this.goalSelector.addGoal(3, new TemptGoal(this, 1.0D, false, TEMPTATION_ITEMS));
  25. this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1D));
  26. this.goalSelector.addGoal(5, new WaterAvoidingRandomWalkingGoal(this, 1.0D));
  27. this.goalSelector.addGoal(6, new LookAtGoal(this, PlayerEntity.class, 6.0F));
  28. this.goalSelector.addGoal(7, new LookRandomlyGoal(this));
  29. }
  30.  
  31. @Override
  32. protected float getStandingEyeHeight(Pose poseIn, EntitySize sizeIn) {
  33. return this.isChild() ? sizeIn.height * 0.85F : sizeIn.height * 0.92F;
  34. }
  35.  
  36. @Override
  37. protected void registerAttributes() {
  38. super.registerAttributes();
  39. this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(4.0D);
  40. this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.25D);
  41. }
  42.  
  43. public void livingTick() {
  44. super.livingTick();
  45. this.oFlap = this.wingRotation;
  46. this.oFlapSpeed = this.destPos;
  47. this.destPos = (float)((double)this.destPos + (double)(this.onGround ? -1 : 4) * 0.3D);
  48. this.destPos = MathHelper.clamp(this.destPos, 0.0F, 1.0F);
  49. if (!this.onGround && this.wingRotDelta < 1.0F) {
  50. this.wingRotDelta = 1.0F;
  51. }
  52.  
  53. this.wingRotDelta = (float)((double)this.wingRotDelta * 0.9D);
  54. Vec3d vec3d = this.getMotion();
  55. if (!this.onGround && vec3d.y < 0.0D) {
  56. this.setMotion(vec3d.mul(1.0D, 0.6D, 1.0D));
  57. }
  58.  
  59. this.wingRotation += this.wingRotDelta * 2.0F;
  60. if (!this.world.isRemote && this.isAlive() && !this.isChild() && !this.isChickenJockey() && --this.timeUntilNextEgg <= 0) {
  61. this.playSound(SoundEvents.ENTITY_CHICKEN_EGG, 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
  62. this.entityDropItem(ModItem.PINK_EGG.get());
  63. this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
  64. }
  65.  
  66. }
  67.  
  68. @Override
  69. public boolean onLivingFall(float distance, float damageMultiplier) {
  70. return false;
  71. }
  72.  
  73. @Override
  74. protected SoundEvent getAmbientSound() {
  75. return SoundEvents.ENTITY_CHICKEN_AMBIENT;
  76. }
  77.  
  78. @Override
  79. protected SoundEvent getHurtSound(DamageSource damageSourceIn) {
  80. return SoundEvents.ENTITY_CHICKEN_HURT;
  81. }
  82.  
  83. @Override
  84. protected SoundEvent getDeathSound() {
  85. return SoundEvents.ENTITY_CHICKEN_DEATH;
  86. }
  87.  
  88. @Override
  89. protected void playStepSound(BlockPos pos, BlockState blockIn) {
  90. this.playSound(SoundEvents.ENTITY_CHICKEN_STEP, 0.15F, 1.0F);
  91. }
  92.  
  93. @Nullable
  94. @Override
  95. public PinkChickenEntity createChild(AgeableEntity ageable) {
  96. return ModEntity.PINK_CHICKEN.get().create(this.world);
  97. }
  98.  
  99. @Override
  100. public boolean isBreedingItem(ItemStack stack) {
  101. return TEMPTATION_ITEMS.test(stack);
  102. }
  103.  
  104. @Override
  105. protected int getExperiencePoints(PlayerEntity player) {
  106. return this.isChickenJockey() ? 10 : super.getExperiencePoints(player);
  107. }
  108.  
  109. @Override
  110. public void readAdditional(CompoundNBT compound) {
  111. super.readAdditional(compound);
  112. this.chickenJockey = compound.getBoolean("IsChickenJockey");
  113. if (compound.contains("EggLayTime")) {
  114. this.timeUntilNextEgg = compound.getInt("EggLayTime");
  115. }
  116.  
  117. }
  118.  
  119. @Override
  120. public void writeAdditional(CompoundNBT compound) {
  121. super.writeAdditional(compound);
  122. compound.putBoolean("IsChickenJockey", this.chickenJockey);
  123. compound.putInt("EggLayTime", this.timeUntilNextEgg);
  124. }
  125.  
  126. @Override
  127. public boolean canDespawn(double distanceToClosestPlayer) {
  128. return this.isChickenJockey() && !this.isBeingRidden();
  129. }
  130.  
  131. @Override
  132. public void updatePassenger(Entity passenger) {
  133. super.updatePassenger(passenger);
  134. float f = MathHelper.sin(this.renderYawOffset * ((float)Math.PI / 180F));
  135. float f1 = MathHelper.cos(this.renderYawOffset * ((float)Math.PI / 180F));
  136. float f2 = 0.1F;
  137. float f3 = 0.0F;
  138. passenger.setPosition(this.getPosX() + (double)(0.1F * f), this.getPosYHeight(0.5D) + passenger.getYOffset() + 0.0D, this.getPosZ() - (double)(0.1F * f1));
  139. if (passenger instanceof LivingEntity) {
  140. ((LivingEntity)passenger).renderYawOffset = this.renderYawOffset;
  141. }
  142.  
  143. }
  144.  
  145. public boolean isChickenJockey() {
  146. return this.chickenJockey;
  147. }
  148.  
  149. public void setChickenJockey(boolean jockey) {
  150. this.chickenJockey = jockey;
  151. }
  152. }
  153. =======================================================================================================================================
  154. PinkChickenModel
  155. @OnlyIn(Dist.CLIENT)
  156. public class PinkChickenModel<T extends PinkChickenEntity> extends AgeableModel<T> {
  157. private final ModelRenderer head;
  158. private final ModelRenderer body;
  159. private final ModelRenderer rightLeg;
  160. private final ModelRenderer leftLeg;
  161. private final ModelRenderer rightWing;
  162. private final ModelRenderer leftWing;
  163. private final ModelRenderer bill;
  164. private final ModelRenderer chin;
  165.  
  166. public PinkChickenModel() {
  167. int i = 16;
  168. this.head = new ModelRenderer(this, 0, 0);
  169. this.head.addBox(-2.0F, -6.0F, -2.0F, 4.0F, 6.0F, 3.0F, 0.0F);
  170. this.head.setRotationPoint(0.0F, 15.0F, -4.0F);
  171. this.bill = new ModelRenderer(this, 14, 0);
  172. this.bill.addBox(-2.0F, -4.0F, -4.0F, 4.0F, 2.0F, 2.0F, 0.0F);
  173. this.bill.setRotationPoint(0.0F, 15.0F, -4.0F);
  174. this.chin = new ModelRenderer(this, 14, 4);
  175. this.chin.addBox(-1.0F, -2.0F, -3.0F, 2.0F, 2.0F, 2.0F, 0.0F);
  176. this.chin.setRotationPoint(0.0F, 15.0F, -4.0F);
  177. this.body = new ModelRenderer(this, 0, 9);
  178. this.body.addBox(-3.0F, -4.0F, -3.0F, 6.0F, 8.0F, 6.0F, 0.0F);
  179. this.body.setRotationPoint(0.0F, 16.0F, 0.0F);
  180. this.rightLeg = new ModelRenderer(this, 26, 0);
  181. this.rightLeg.addBox(-1.0F, 0.0F, -3.0F, 3.0F, 5.0F, 3.0F);
  182. this.rightLeg.setRotationPoint(-2.0F, 19.0F, 1.0F);
  183. this.leftLeg = new ModelRenderer(this, 26, 0);
  184. this.leftLeg.addBox(-1.0F, 0.0F, -3.0F, 3.0F, 5.0F, 3.0F);
  185. this.leftLeg.setRotationPoint(1.0F, 19.0F, 1.0F);
  186. this.rightWing = new ModelRenderer(this, 24, 13);
  187. this.rightWing.addBox(0.0F, 0.0F, -3.0F, 1.0F, 4.0F, 6.0F);
  188. this.rightWing.setRotationPoint(-4.0F, 13.0F, 0.0F);
  189. this.leftWing = new ModelRenderer(this, 24, 13);
  190. this.leftWing.addBox(-1.0F, 0.0F, -3.0F, 1.0F, 4.0F, 6.0F);
  191. this.leftWing.setRotationPoint(4.0F, 13.0F, 0.0F);
  192. }
  193.  
  194. @Override
  195. protected Iterable<ModelRenderer> getHeadParts() {
  196. return ImmutableList.of(this.head, this.bill, this.chin);
  197. }
  198.  
  199. @Override
  200. protected Iterable<ModelRenderer> getBodyParts() {
  201. return ImmutableList.of(this.body, this.rightLeg, this.leftLeg, this.rightWing, this.leftWing);
  202. }
  203.  
  204. public void setRotationAngles(T entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
  205. this.head.rotateAngleX = headPitch * ((float)Math.PI / 180F);
  206. this.head.rotateAngleY = netHeadYaw * ((float)Math.PI / 180F);
  207. this.bill.rotateAngleX = this.head.rotateAngleX;
  208. this.bill.rotateAngleY = this.head.rotateAngleY;
  209. this.chin.rotateAngleX = this.head.rotateAngleX;
  210. this.chin.rotateAngleY = this.head.rotateAngleY;
  211. this.body.rotateAngleX = ((float)Math.PI / 2F);
  212. this.rightLeg.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount;
  213. this.leftLeg.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.4F * limbSwingAmount;
  214. this.rightWing.rotateAngleZ = ageInTicks;
  215. this.leftWing.rotateAngleZ = -ageInTicks;
  216. }
  217. }
  218. =======================================================================================================================================
  219. PinkChickenRenderer
  220. @OnlyIn(Dist.CLIENT)
  221. public class PinkChickenRenderer extends MobRenderer<PinkChickenEntity, PinkChickenModel<PinkChickenEntity>> {
  222. private static final ResourceLocation PINK_CHICKEN_TEXTURES = new ResourceLocation(MysticsBiomes.MOD_ID, "textures/entity/pink_chicken.png");
  223.  
  224. public PinkChickenRenderer(EntityRendererManager renderManagerIn) {
  225. super(renderManagerIn, new PinkChickenModel<>(),0.7F);
  226. }
  227.  
  228. @Override
  229. public ResourceLocation getEntityTexture(PinkChickenEntity entity) {
  230. return PINK_CHICKEN_TEXTURES;
  231. }
  232.  
  233. protected float handleRotationFloat(ChickenEntity livingBase, float partialTicks) {
  234. float f = MathHelper.lerp(partialTicks, livingBase.oFlap, livingBase.wingRotation);
  235. float f1 = MathHelper.lerp(partialTicks, livingBase.oFlapSpeed, livingBase.destPos);
  236. return (MathHelper.sin(f) + 1.0F) * f1;
  237. }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement