Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SubscribeEvent
- public void onWorldTick(WorldTickEvent event) {
- if (event.side.isServer()) {
- LogHelper.info("[OnWorldTick] The Side is on the server!");
- World world = event.world;
- final Set<Item> remainingInputs = new HashSet<>(INPUTS); // Create a mutable copy of the input set to track which items have been found
- if (!world.isRemote) {
- if (bookSpawnDelay > 0) bookSpawnDelay--;
- else {
- LogHelper.info("The world is not remote.");
- List<Entity> entitiesInWorld = world.loadedEntityList;
- for(Entity entityInWorld : entitiesInWorld) {
- LogHelper.info("Found an Entity in the world!");
- ArrayList<EntityItem> foundEntityItems = new ArrayList<EntityItem>();
- if(entityInWorld instanceof EntityItem) {
- EntityItem entityItemInWorld = (EntityItem)entityInWorld;
- if(entityItemInWorld.getEntityItem().getItem() == Items.book) {
- LogHelper.info("Found an Entity in the world that is a book!");
- remainingInputs.remove(Items.book);
- AxisAlignedBB areaBound = entityItemInWorld.getEntityBoundingBox().expand(3, 3, 3);
- List<Entity> entitiesWithinBound = world.getEntitiesWithinAABBExcludingEntity(entityItemInWorld, areaBound);
- for (Entity entityWithinBound : entitiesWithinBound) {
- if (entityWithinBound instanceof EntityItem) {
- EntityItem entityItemWithinBound = (EntityItem) entityWithinBound;
- if (entityItemWithinBound.getEntityItem().getItem() == Items.bone) {
- LogHelper.info("Found an Entity near the book that is a bone!");
- remainingInputs.remove(Items.bone);
- if(!remainingInputs.contains(entityItemWithinBound)) foundEntityItems.add(entityItemWithinBound);
- } else if (entityItemWithinBound.getEntityItem().getItem() == Items.feather) {
- LogHelper.info("Found an Entity near the book that is a feather!");
- remainingInputs.remove(Items.feather);
- if(!remainingInputs.contains(entityItemWithinBound)) foundEntityItems.add(entityItemWithinBound);
- }
- if (remainingInputs.isEmpty()) {
- LogHelper.info("All items have been found. The Items hashmap is empty.");
- for (EntityItem foundEntityItem : foundEntityItems) {
- ItemStack foundItemStack = foundEntityItem.getEntityItem();
- bookSpawnDelay += 20;
- foundItemStack.stackSize--;
- if (foundItemStack.stackSize <= 0) {
- LogHelper.info("Deleting the Item: " + foundItemStack.getItem().toString());
- world.removeEntity(foundEntityItem);
- }
- double x = entityItemInWorld.posX;
- double y = entityItemInWorld.posY;
- double z = entityItemInWorld.posZ;
- WorldServer worldServer = (WorldServer) world;
- worldServer.spawnParticle(EnumParticleTypes.SMOKE_LARGE, false,
- x + 0.5D, y + 1.0D, z + 0.5D, 1, 0.0D, 0.0D, 0.0D, 0.0D,
- new int[0]);
- world.spawnEntityInWorld(new EntityItem(world, x, y, z,
- new ItemStack(ARKCraftItems.info_book)));
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement