Advertisement
Guest User

Untitled

a guest
May 19th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.67 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. private final Set<Item> dropitems = new HashSet<>();
  35.  
  36. DragonBreed(String skin, int color) {
  37. this.skin = skin;
  38. this.color = color;
  39.  
  40. // ignore suffocation damage
  41. addImmunity(DamageSource.drown);
  42. addImmunity(DamageSource.inWall);
  43.  
  44. // assume that cactus needles don't do much damage to animals with horned scales
  45. addImmunity(DamageSource.cactus);
  46.  
  47. // ignore damage from vanilla ender dragon
  48. addImmunity(DamageSource.dragonBreath);
  49. }
  50.  
  51. public String getSkin() {
  52. return skin;
  53. }
  54.  
  55. public EnumCreatureAttribute getCreatureAttribute() {
  56. return EnumCreatureAttribute.UNDEFINED;
  57. }
  58.  
  59. public int getColor() {
  60. return color;
  61. }
  62.  
  63. public float getColorR() {
  64. return ((color >> 16) & 0xFF) / 255f;
  65. }
  66.  
  67. public float getColorG() {
  68. return ((color >> 8) & 0xFF) / 255f;
  69. }
  70.  
  71. public float getColorB() {
  72. return (color & 0xFF) / 255f;
  73. }
  74.  
  75. protected final void addImmunity(DamageSource dmg) {
  76. immunities.add(dmg.damageType);
  77. }
  78.  
  79. public boolean isImmuneToDamage(DamageSource dmg) {
  80. if (immunities.isEmpty()) {
  81. return false;
  82. }
  83.  
  84. return immunities.contains(dmg.damageType);
  85. }
  86. //disabled
  87. protected final void addHabitatBlock(Block block) {
  88. breedBlocks.add(block);
  89. }
  90. //disabled
  91. public boolean isHabitatBlock(Block block) {
  92. return breedBlocks.contains(block);
  93. }
  94. //disabled
  95. protected final void addHabitatBiome(Biome biome) {
  96. biomes.add(biome);
  97. }
  98. //disabled
  99. public boolean isHabitatBiome(Biome biome) {
  100. return biomes.contains(biome);
  101. }
  102. //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.
  103. public boolean isHabitatEnvironment(EntityTameableDragon dragon) {
  104. return false;
  105. }
  106.  
  107. public Item[] getFoodItems() {
  108. return new Item[] { Items.PORKCHOP, Items.BEEF, Items.CHICKEN, Items.ROTTEN_FLESH,
  109. Items.WHEAT, Items.BEETROOT, Items.RABBIT, Items.CARROT, Items.COOKED_FISH,
  110. Items.COOKED_BEEF, Items.COOKED_CHICKEN, Items.COOKED_MUTTON, Items.COOKED_PORKCHOP,
  111. Items.COOKED_RABBIT};
  112. }
  113.  
  114. public Item getBreedingItem() {
  115. return Items.FISH;
  116. }
  117.  
  118. public void onUpdate(EntityTameableDragon dragon) {
  119. placeFootprintBlocks(dragon);
  120. }
  121.  
  122. protected void placeFootprintBlocks(EntityTameableDragon dragon) {
  123. // only apply on server
  124. if (!dragon.isServer()) {
  125. return;
  126. }
  127.  
  128. // only apply on adult dragons that don't fly
  129. if (!dragon.isAdult() || dragon.isFlying()) {
  130. return;
  131. }
  132.  
  133. // only apply if footprints are enabled
  134. float footprintChance = getFootprintChance();
  135. if (footprintChance == 0) {
  136. return;
  137. }
  138.  
  139. // footprint loop, from EntitySnowman.onLivingUpdate with slight tweaks
  140. World world = dragon.worldObj;
  141. for (int i = 0; i < 4; i++) {
  142. // place only if randomly selected
  143. if (world.rand.nextFloat() > footprintChance) {
  144. continue;
  145. }
  146.  
  147. // get footprint position
  148. double bx = dragon.posX + (i % 2 * 2 - 1) * 0.25;
  149. double by = dragon.posY + 0.5;
  150. double bz = dragon.posZ + (i / 2 % 2 * 2 - 1) * 0.25;
  151. BlockPos pos = new BlockPos(bx, by, bz);
  152.  
  153. // footprints can only be placed on empty space
  154. if (world.isAirBlock(pos)) {
  155. continue;
  156. }
  157.  
  158. placeFootprintBlock(dragon, pos);
  159. }
  160. }
  161.  
  162. protected void placeFootprintBlock(EntityTameableDragon dragon, BlockPos blockPos) {
  163.  
  164. }
  165.  
  166. protected float getFootprintChance() {
  167. return 0;
  168. }
  169.  
  170. public abstract void onEnable(EntityTameableDragon dragon);
  171.  
  172. public abstract void onDisable(EntityTameableDragon dragon);
  173.  
  174. public abstract void onDeath(EntityTameableDragon dragon);
  175.  
  176. public SoundEvent getLivingSound() {
  177. if (rand.nextInt(3) == 0) {
  178. return RealmOfTheDragonsSoundEvents.ENTITY_DRAGON_GROWL;
  179. } else {
  180. return RealmOfTheDragonsSoundEvents.ENTITY_DRAGON_BREATHE;
  181. }
  182. }
  183.  
  184. public SoundEvent getHurtSound() {
  185. return SoundEvents.ENTITY_ENDERDRAGON_HURT;
  186. }
  187.  
  188. public SoundEvent getDeathSound() {
  189. return RealmOfTheDragonsSoundEvents.ENTITY_DRAGON_DEATH;
  190. }
  191.  
  192. public SoundEvent getWingsSound() {
  193. return SoundEvents.ENTITY_ENDERDRAGON_FLAP;
  194. }
  195.  
  196. public SoundEvent getStepSound() {
  197. return RealmOfTheDragonsSoundEvents.ENTITY_DRAGON_STEP;
  198. }
  199.  
  200. public SoundEvent getEatSound() {
  201. return SoundEvents.ENTITY_GENERIC_EAT;
  202. }
  203.  
  204. public SoundEvent getAttackSound() {
  205. return SoundEvents.ENTITY_GENERIC_EAT;
  206. }
  207.  
  208. public float getSoundPitch(SoundEvent sound) {
  209. return 1;
  210. }
  211.  
  212. public float getSoundVolume(SoundEvent sound) {
  213. return 1;
  214. }
  215.  
  216. }
  217. package com.TheRPGAdventurer.server.entity.breeds;
  218.  
  219. import java.util.HashSet;
  220. import java.util.Random;
  221. import java.util.Set;
  222.  
  223. import javax.annotation.Nullable;
  224.  
  225. import com.TheRPGAdventurer.RealmOfTheDragonsSoundEvents;
  226. import com.TheRPGAdventurer.server.entity.EntityTameableDragon;
  227. import net.minecraft.block.Block;
  228. import net.minecraft.entity.EnumCreatureAttribute;
  229. import net.minecraft.init.Items;
  230. import net.minecraft.init.SoundEvents;
  231. import net.minecraft.item.Item;
  232. import net.minecraft.util.DamageSource;
  233. import net.minecraft.util.SoundEvent;
  234. import net.minecraft.util.math.BlockPos;
  235. import net.minecraft.world.World;
  236. import net.minecraft.world.biome.Biome;
  237.  
  238. /**
  239. * Base class for dragon breeds.
  240. *
  241. */
  242. public abstract class DragonBreed {
  243.  
  244. private final String skin;
  245. private final int color;
  246. private final Set<String> immunities = new HashSet<>();
  247. private final Set<Block> breedBlocks = new HashSet<>();
  248. private final Set<Biome> biomes = new HashSet<>();
  249. protected final Random rand = new Random();
  250. private final Set<Item> dropitems = new HashSet<>();
  251.  
  252. DragonBreed(String skin, int color) {
  253. this.skin = skin;
  254. this.color = color;
  255.  
  256. // ignore suffocation damage
  257. addImmunity(DamageSource.drown);
  258. addImmunity(DamageSource.inWall);
  259.  
  260. // assume that cactus needles don't do much damage to animals with horned scales
  261. addImmunity(DamageSource.cactus);
  262.  
  263. // ignore damage from vanilla ender dragon
  264. addImmunity(DamageSource.dragonBreath);
  265. }
  266.  
  267. public String getSkin() {
  268. return skin;
  269. }
  270.  
  271. public EnumCreatureAttribute getCreatureAttribute() {
  272. return EnumCreatureAttribute.UNDEFINED;
  273. }
  274.  
  275. public int getColor() {
  276. return color;
  277. }
  278.  
  279. public float getColorR() {
  280. return ((color >> 16) & 0xFF) / 255f;
  281. }
  282.  
  283. public float getColorG() {
  284. return ((color >> 8) & 0xFF) / 255f;
  285. }
  286.  
  287. public float getColorB() {
  288. return (color & 0xFF) / 255f;
  289. }
  290.  
  291. protected final void addImmunity(DamageSource dmg) {
  292. immunities.add(dmg.damageType);
  293. }
  294.  
  295. public boolean isImmuneToDamage(DamageSource dmg) {
  296. if (immunities.isEmpty()) {
  297. return false;
  298. }
  299.  
  300. return immunities.contains(dmg.damageType);
  301. }
  302. //disabled
  303. protected final void addHabitatBlock(Block block) {
  304. breedBlocks.add(block);
  305. }
  306. //disabled
  307. public boolean isHabitatBlock(Block block) {
  308. return breedBlocks.contains(block);
  309. }
  310. //disabled
  311. protected final void addHabitatBiome(Biome biome) {
  312. biomes.add(biome);
  313. }
  314. //disabled
  315. public boolean isHabitatBiome(Biome biome) {
  316. return biomes.contains(biome);
  317. }
  318. //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.
  319. public boolean isHabitatEnvironment(EntityTameableDragon dragon) {
  320. return false;
  321. }
  322.  
  323. public Item[] getFoodItems() {
  324. return new Item[] { Items.PORKCHOP, Items.BEEF, Items.CHICKEN, Items.ROTTEN_FLESH,
  325. Items.WHEAT, Items.BEETROOT, Items.RABBIT, Items.CARROT, Items.COOKED_FISH,
  326. Items.COOKED_BEEF, Items.COOKED_CHICKEN, Items.COOKED_MUTTON, Items.COOKED_PORKCHOP,
  327. Items.COOKED_RABBIT};
  328. }
  329.  
  330. public Item getBreedingItem() {
  331. return Items.FISH;
  332. }
  333.  
  334. public void onUpdate(EntityTameableDragon dragon) {
  335. placeFootprintBlocks(dragon);
  336. }
  337.  
  338. protected void placeFootprintBlocks(EntityTameableDragon dragon) {
  339. // only apply on server
  340. if (!dragon.isServer()) {
  341. return;
  342. }
  343.  
  344. // only apply on adult dragons that don't fly
  345. if (!dragon.isAdult() || dragon.isFlying()) {
  346. return;
  347. }
  348.  
  349. // only apply if footprints are enabled
  350. float footprintChance = getFootprintChance();
  351. if (footprintChance == 0) {
  352. return;
  353. }
  354.  
  355. // footprint loop, from EntitySnowman.onLivingUpdate with slight tweaks
  356. World world = dragon.worldObj;
  357. for (int i = 0; i < 4; i++) {
  358. // place only if randomly selected
  359. if (world.rand.nextFloat() > footprintChance) {
  360. continue;
  361. }
  362.  
  363. // get footprint position
  364. double bx = dragon.posX + (i % 2 * 2 - 1) * 0.25;
  365. double by = dragon.posY + 0.5;
  366. double bz = dragon.posZ + (i / 2 % 2 * 2 - 1) * 0.25;
  367. BlockPos pos = new BlockPos(bx, by, bz);
  368.  
  369. // footprints can only be placed on empty space
  370. if (world.isAirBlock(pos)) {
  371. continue;
  372. }
  373.  
  374. placeFootprintBlock(dragon, pos);
  375. }
  376. }
  377.  
  378. protected void placeFootprintBlock(EntityTameableDragon dragon, BlockPos blockPos) {
  379.  
  380. }
  381.  
  382. protected float getFootprintChance() {
  383. return 0;
  384. }
  385.  
  386. public abstract void onEnable(EntityTameableDragon dragon);
  387.  
  388. public abstract void onDisable(EntityTameableDragon dragon);
  389.  
  390. public abstract void onDeath(EntityTameableDragon dragon);
  391.  
  392. public SoundEvent getLivingSound() {
  393. if (rand.nextInt(3) == 0) {
  394. return RealmOfTheDragonsSoundEvents.ENTITY_DRAGON_GROWL;
  395. } else {
  396. return RealmOfTheDragonsSoundEvents.ENTITY_DRAGON_BREATHE;
  397. }
  398. }
  399.  
  400. public SoundEvent getHurtSound() {
  401. return SoundEvents.ENTITY_ENDERDRAGON_HURT;
  402. }
  403.  
  404. public SoundEvent getDeathSound() {
  405. return RealmOfTheDragonsSoundEvents.ENTITY_DRAGON_DEATH;
  406. }
  407.  
  408. public SoundEvent getWingsSound() {
  409. return SoundEvents.ENTITY_ENDERDRAGON_FLAP;
  410. }
  411.  
  412. public SoundEvent getStepSound() {
  413. return RealmOfTheDragonsSoundEvents.ENTITY_DRAGON_STEP;
  414. }
  415.  
  416. public SoundEvent getEatSound() {
  417. return SoundEvents.ENTITY_GENERIC_EAT;
  418. }
  419.  
  420. public SoundEvent getAttackSound() {
  421. return SoundEvents.ENTITY_GENERIC_EAT;
  422. }
  423.  
  424. public float getSoundPitch(SoundEvent sound) {
  425. return 1;
  426. }
  427.  
  428. public float getSoundVolume(SoundEvent sound) {
  429. return 1;
  430. }
  431.  
  432. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement