Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
200
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @SubscribeEvent
  2. public void onWorldTick(WorldTickEvent event) {
  3. if (event.side.isServer()) {
  4. LogHelper.info("[OnWorldTick] The Side is on the server!");
  5. World world = event.world;
  6. final Set<Item> remainingInputs = new HashSet<>(INPUTS); // Create a mutable copy of the input set to track which items have been found
  7.  
  8. if (!world.isRemote) {
  9. if (bookSpawnDelay > 0) bookSpawnDelay--;
  10. else {
  11. LogHelper.info("The world is not remote.");
  12. List<Entity> entitiesInWorld = world.loadedEntityList;
  13. for(Entity entityInWorld : entitiesInWorld) {
  14. LogHelper.info("Found an Entity in the world!");
  15. ArrayList<EntityItem> foundEntityItems = new ArrayList<EntityItem>();
  16. if(entityInWorld instanceof EntityItem) {
  17. EntityItem entityItemInWorld = (EntityItem)entityInWorld;
  18. if(entityItemInWorld.getEntityItem().getItem() == Items.book) {
  19. LogHelper.info("Found an Entity in the world that is a book!");
  20. remainingInputs.remove(Items.book);
  21. AxisAlignedBB areaBound = entityItemInWorld.getEntityBoundingBox().expand(3, 3, 3);
  22. List<Entity> entitiesWithinBound = world.getEntitiesWithinAABBExcludingEntity(entityItemInWorld, areaBound);
  23. for (Entity entityWithinBound : entitiesWithinBound) {
  24. if (entityWithinBound instanceof EntityItem) {
  25. EntityItem entityItemWithinBound = (EntityItem) entityWithinBound;
  26. if (entityItemWithinBound.getEntityItem().getItem() == Items.bone) {
  27. LogHelper.info("Found an Entity near the book that is a bone!");
  28. remainingInputs.remove(Items.bone);
  29. if(!remainingInputs.contains(entityItemWithinBound)) foundEntityItems.add(entityItemWithinBound);
  30. } else if (entityItemWithinBound.getEntityItem().getItem() == Items.feather) {
  31. LogHelper.info("Found an Entity near the book that is a feather!");
  32. remainingInputs.remove(Items.feather);
  33. if(!remainingInputs.contains(entityItemWithinBound)) foundEntityItems.add(entityItemWithinBound);
  34. }
  35. if (remainingInputs.isEmpty()) {
  36. LogHelper.info("All items have been found. The Items hashmap is empty.");
  37. for (EntityItem foundEntityItem : foundEntityItems) {
  38. ItemStack foundItemStack = foundEntityItem.getEntityItem();
  39. bookSpawnDelay += 20;
  40. foundItemStack.stackSize--;
  41. if (foundItemStack.stackSize <= 0) {
  42. LogHelper.info("Deleting the Item: " + foundItemStack.getItem().toString());
  43. world.removeEntity(foundEntityItem);
  44. }
  45. double x = entityItemInWorld.posX;
  46. double y = entityItemInWorld.posY;
  47. double z = entityItemInWorld.posZ;
  48.  
  49. WorldServer worldServer = (WorldServer) world;
  50. worldServer.spawnParticle(EnumParticleTypes.SMOKE_LARGE, false,
  51. x + 0.5D, y + 1.0D, z + 0.5D, 1, 0.0D, 0.0D, 0.0D, 0.0D,
  52. new int[0]);
  53. world.spawnEntityInWorld(new EntityItem(world, x, y, z,
  54. new ItemStack(ARKCraftItems.info_book)));
  55.  
  56. }
  57. }
  58.  
  59. }
  60. }
  61.  
  62. }
  63. }
  64. }
  65.  
  66.  
  67.  
  68. }
  69. }
  70. }
  71. }
Advertisement
RAW Paste Data Copied
Advertisement