Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 ItemChestFinder extends Item {
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. @Override
  22.  
  23. public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean held) {
  24.  
  25. if(held) {
  26. List<TileEntity> tiles = world.loadedTileEntityList;
  27.  
  28. ArrayList<TileEntity> tilesNear = new ArrayList<TileEntity>();
  29.  
  30. ChunkCoordIntPair entityChunk = world.getChunkFromBlockCoords((int)entity.posX, (int)entity.posZ).getChunkCoordIntPair();
  31.  
  32. for(TileEntity tile : tiles) {
  33.  
  34. ChunkCoordIntPair tileChunk = world.getChunkFromBlockCoords(tile.xCoord, tile.zCoord).getChunkCoordIntPair();
  35.  
  36. if(tileChunk.chunkXPos >= entityChunk.chunkXPos - 2 &&
  37.  
  38. tileChunk.chunkXPos <= entity.chunkCoordX + 2 &&
  39.  
  40. tileChunk.chunkZPos >= entity.chunkCoordZ - 2 &&
  41.  
  42. tileChunk.chunkZPos <= entity.chunkCoordZ + 2) {
  43.  
  44. tilesNear.add(tile);
  45.  
  46. }
  47.  
  48. }
  49.  
  50. }
Advertisement
RAW Paste Data Copied
Advertisement