Guest User

Untitled

a guest
May 17th, 2017
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.28 KB | None | 0 0
  1. package com.TheRPGAdventurer.server.entity.breeds;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Random;
  5. import java.util.Set;
  6.  
  7. import javax.annotation.Nullable;
  8.  
  9. import com.TheRPGAdventurer.RealmOfTheDragonsSoundEvents;
  10. import com.TheRPGAdventurer.server.entity.EntityTameableDragon;
  11. import net.minecraft.block.Block;
  12. import net.minecraft.entity.EnumCreatureAttribute;
  13. import net.minecraft.init.Items;
  14. import net.minecraft.init.SoundEvents;
  15. import net.minecraft.item.Item;
  16. import net.minecraft.util.DamageSource;
  17. import net.minecraft.util.SoundEvent;
  18. import net.minecraft.util.math.BlockPos;
  19. import net.minecraft.world.World;
  20. import net.minecraft.world.biome.Biome;
  21.  
  22. /**
  23. * Base class for dragon breeds.
  24. *
  25. */
  26. public abstract class DragonBreed {
  27.  
  28. private final String skin;
  29. private final int color;
  30. private final Set<String> immunities = new HashSet<>();
  31. private final Set<Block> breedBlocks = new HashSet<>();
  32. private final Set<Biome> biomes = new HashSet<>();
  33. protected final Random rand = new Random();
  34.  
  35. DragonBreed(String skin, int color) {
  36. this.skin = skin;
  37. this.color = color;
  38.  
  39. // ignore suffocation damage
  40. addImmunity(DamageSource.drown);
  41. addImmunity(DamageSource.inWall);
  42.  
  43. // assume that cactus needles don't do much damage to animals with horned scales
  44. addImmunity(DamageSource.cactus);
  45.  
  46. // ignore damage from vanilla ender dragon
  47. addImmunity(DamageSource.dragonBreath);
  48. }
  49.  
  50. public String getSkin() {
  51. return skin;
  52. }
  53.  
  54. public EnumCreatureAttribute getCreatureAttribute() {
  55. return EnumCreatureAttribute.UNDEFINED;
  56. }
  57.  
  58. public int getColor() {
  59. return color;
  60. }
  61.  
  62. public float getColorR() {
  63. return ((color >> 16) & 0xFF) / 255f;
  64. }
  65.  
  66. public float getColorG() {
  67. return ((color >> 8) & 0xFF) / 255f;
  68. }
  69.  
  70. public float getColorB() {
  71. return (color & 0xFF) / 255f;
  72. }
  73.  
  74. protected final void addImmunity(DamageSource dmg) {
  75. immunities.add(dmg.damageType);
  76. }
  77.  
  78. public boolean isImmuneToDamage(DamageSource dmg) {
  79. if (immunities.isEmpty()) {
  80. return false;
  81. }
  82.  
  83. return immunities.contains(dmg.damageType);
  84. }
  85. //disabled
  86. protected final void addHabitatBlock(Block block) {
  87. breedBlocks.add(block);
  88. }
  89. //disabled
  90. public boolean isHabitatBlock(Block block) {
  91. return breedBlocks.contains(block);
  92. }
  93. //disabled
  94. protected final void addHabitatBiome(Biome biome) {
  95. biomes.add(biome);
  96. }
  97. //disabled
  98. public boolean isHabitatBiome(Biome biome) {
  99. return biomes.contains(biome);
  100. }
  101. //disabled the original mod used this to change the egg's breed on whatever environment it is on but It doesn't fit on me.
  102. public boolean isHabitatEnvironment(EntityTameableDragon dragon) {
  103. return false;
  104. }
  105.  
  106. public Item[] getFoodItems() {
  107. return new Item[] { Items.PORKCHOP, Items.BEEF, Items.CHICKEN, Items.ROTTEN_FLESH,
  108. Items.WHEAT, Items.BEETROOT, Items.RABBIT, Items.CARROT, Items.COOKED_FISH,
  109. Items.COOKED_BEEF, Items.COOKED_CHICKEN, Items.COOKED_MUTTON, Items.COOKED_PORKCHOP,
  110. Items.COOKED_RABBIT};
  111. }
  112.  
  113. public Item getBreedingItem() {
  114. return Items.FISH;
  115. }
  116.  
  117. public void onUpdate(EntityTameableDragon dragon) {
  118. placeFootprintBlocks(dragon);
  119. }
  120.  
  121. protected void placeFootprintBlocks(EntityTameableDragon dragon) {
  122. // only apply on server
  123. if (!dragon.isServer()) {
  124. return;
  125. }
  126.  
  127. // only apply on adult dragons that don't fly
  128. if (!dragon.isAdult() || dragon.isFlying()) {
  129. return;
  130. }
  131.  
  132. // only apply if footprints are enabled
  133. float footprintChance = getFootprintChance();
  134. if (footprintChance == 0) {
  135. return;
  136. }
  137.  
  138. // footprint loop, from EntitySnowman.onLivingUpdate with slight tweaks
  139. World world = dragon.worldObj;
  140. for (int i = 0; i < 4; i++) {
  141. // place only if randomly selected
  142. if (world.rand.nextFloat() > footprintChance) {
  143. continue;
  144. }
  145.  
  146. // get footprint position
  147. double bx = dragon.posX + (i % 2 * 2 - 1) * 0.25;
  148. double by = dragon.posY + 0.5;
  149. double bz = dragon.posZ + (i / 2 % 2 * 2 - 1) * 0.25;
  150. BlockPos pos = new BlockPos(bx, by, bz);
  151.  
  152. // footprints can only be placed on empty space
  153. if (world.isAirBlock(pos)) {
  154. continue;
  155. }
  156.  
  157. placeFootprintBlock(dragon, pos);
  158. }
  159. }
  160.  
  161. protected void placeFootprintBlock(EntityTameableDragon dragon, BlockPos blockPos) {
  162.  
  163. }
  164.  
  165. protected float getFootprintChance() {
  166. return 0;
  167. }
  168.  
  169. public abstract void onEnable(EntityTameableDragon dragon);
  170.  
  171. public abstract void onDisable(EntityTameableDragon dragon);
  172.  
  173. public abstract void onDeath(EntityTameableDragon dragon);
  174.  
  175. public SoundEvent getLivingSound() {
  176. if (rand.nextInt(3) == 0) {
  177. return RealmOfTheDragonsSoundEvents.ENTITY_DRAGON_GROWL;
  178. } else {
  179. return RealmOfTheDragonsSoundEvents.ENTITY_DRAGON_BREATHE;
  180. }
  181. }
  182.  
  183. public SoundEvent getHurtSound() {
  184. return SoundEvents.ENTITY_ENDERDRAGON_HURT;
  185. }
  186.  
  187. public SoundEvent getDeathSound() {
  188. return RealmOfTheDragonsSoundEvents.ENTITY_DRAGON_DEATH;
  189. }
  190.  
  191. public SoundEvent getWingsSound() {
  192. return SoundEvents.ENTITY_ENDERDRAGON_FLAP;
  193. }
  194.  
  195. public SoundEvent getStepSound() {
  196. return RealmOfTheDragonsSoundEvents.ENTITY_DRAGON_STEP;
  197. }
  198.  
  199. public SoundEvent getEatSound() {
  200. return SoundEvents.ENTITY_GENERIC_EAT;
  201. }
  202.  
  203. public SoundEvent getAttackSound() {
  204. return SoundEvents.ENTITY_GENERIC_EAT;
  205. }
  206.  
  207. public float getSoundPitch(SoundEvent sound) {
  208. return 1;
  209. }
  210.  
  211. public float getSoundVolume(SoundEvent sound) {
  212. return 1;
  213. }
  214.  
  215. }
Advertisement
Add Comment
Please, Sign In to add comment