Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. package com.mod.drakania.ChestFinder;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.item.Item;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.tileentity.TileEntity;
  10. import net.minecraft.world.ChunkCoordIntPair;
  11. import net.minecraft.world.World;
  12.  
  13. public class ItemTileEntityFinder extends Item {
  14.  
  15. @Override
  16.  
  17. public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean held) {
  18.  
  19. if(held) {
  20.  
  21. List<TileEntity> tiles = world.loadedTileEntityList;
  22.  
  23. ArrayList<TileEntity> tilesNear = new ArrayList<TileEntity>();
  24.  
  25. ChunkCoordIntPair entityChunk = world.getChunkFromBlockCoords((int)entity.posX, (int)entity.posZ).getChunkCoordIntPair();
  26.  
  27. for(TileEntity tile : tiles) {
  28.  
  29. ChunkCoordIntPair tileChunk = world.getChunkFromBlockCoords(tile.xCoord, tile.zCoord).getChunkCoordIntPair();
  30.  
  31. if(tileChunk.chunkXPos >= entityChunk.chunkXPos - 2 &&
  32.  
  33. tileChunk.chunkXPos <= entity.chunkCoordX + 2 &&
  34.  
  35. tileChunk.chunkZPos >= entity.chunkCoordZ - 2 &&
  36.  
  37. tileChunk.chunkZPos <= entity.chunkCoordZ + 2) {
  38.  
  39. tilesNear.add(tile);
  40.  
  41. }
  42.  
  43. }
  44.  
  45. }
  46.  
  47. }
  48.  
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement