Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. public void onWorldTick(WorldTickEvent event) {
  2. if (event.side.isServer()) {
  3. World world = event.world;
  4. HashSet<Item> items = new HashSet<Item>();
  5. items.add(Items.bone);
  6. items.add(Items.book);
  7. items.add(Items.feather);
  8.  
  9. ArrayList<EntityItem> foundEntityItems = new ArrayList<EntityItem>();
  10.  
  11. if (!world.isRemote) {
  12. if (bookSpawnDelay > 0) bookSpawnDelay--;
  13. else {
  14. List<Entity> entitiesInWorld = world.loadedEntityList;
  15.  
  16. for(Entity entityInWorld : entitiesInWorld) {
  17. if(entityInWorld instanceof EntityItem) {
  18. EntityItem entityItemInWorld = (EntityItem)entityInWorld;
  19. if(entityItemInWorld.getEntityItem().getItem() == Items.book) {
  20. items.remove(Items.book);
  21. AxisAlignedBB areaBound = new AxisAlignedBB(
  22. entityItemInWorld.posX - 3, entityItemInWorld.posY - 3, entityItemInWorld.posZ - 3,
  23. entityItemInWorld.posX + 3, entityItemInWorld.posY + 3, entityItemInWorld.posZ + 3
  24. );
  25. List<Entity> entitiesWithinBound = world.getEntitiesWithinAABBExcludingEntity(entityItemInWorld, areaBound);
  26.  
  27. for(Item item : items) {
  28. for(Entity entityWithinBound : entitiesWithinBound) {
  29. if(entityWithinBound instanceof EntityItem) {
  30. EntityItem entityItemWithinBound = (EntityItem)entityWithinBound;
  31. if(entityItemWithinBound.getEntityItem().getItem() == item) {
  32. items.remove(item);
  33. foundEntityItems.add(entityItemWithinBound);
  34. if(items.isEmpty()) {
  35. for(EntityItem foundEntityItem : foundEntityItems) {
  36. ItemStack foundItemStack = foundEntityItem.getEntityItem();
  37. bookSpawnDelay += 20;
  38. foundItemStack.stackSize--;
  39. if (foundItemStack.stackSize == 0) {
  40. world.removeEntity(foundEntityItem);
  41. foundEntityItems.remove(foundEntityItem);
  42. }
  43. double x = entityItemInWorld.posX;
  44. double y = entityItemInWorld.posY;
  45. double z = entityItemInWorld.posZ;
  46. LogHelper.info("Items is empty!");
  47.  
  48. if(foundEntityItems.isEmpty()) {
  49. LogHelper.info("Found Entity Items is empty!");
  50. WorldServer worldServer = (WorldServer) world;
  51. worldServer.spawnParticle(EnumParticleTypes.SMOKE_LARGE,
  52. false, x + 0.5D, y + 1.0D, z + 0.5D, 1, 0.0D,
  53. 0.0D, 0.0D, 0.0D, new int[0]);
  54. world.spawnEntityInWorld(new EntityItem(world, x, y, z, new ItemStack(ARKCraftItems.info_book)));
  55. world.spawnEntityInWorld(new EntityItem(world, x, y, z,
  56. new ItemStack(ARKCraftItems.info_book)));
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64.  
  65. }
  66. }
  67. }
  68.  
  69.  
  70.  
  71. }
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement