Search in sources :

Example 1 with TileEntityInventory

use of org.spongepowered.api.item.inventory.type.TileEntityInventory in project RedProtect by FabioZumbi12.

the class RPEconomy method getRegionValue.

public static long getRegionValue(Region r) {
    long regionCost = 0;
    World w = RedProtect.get().serv.getWorld(r.getWorld()).get();
    int maxX = r.getMaxMbrX();
    int minX = r.getMinMbrX();
    int maxZ = r.getMaxMbrZ();
    int minZ = r.getMinMbrZ();
    for (int x = minX; x < maxX; x++) {
        for (int y = 0; y < 256; y++) {
            for (int z = minZ; z < maxZ; z++) {
                BlockSnapshot b = w.createSnapshot(x, y, z);
                /*
		      Location<World> loc = new Location<World>(w, x, y, z);		      
		      Collection<Entity> ents = w.getEntities(ent-> ent.getLocation().getBlockPosition().equals(loc.getBlockPosition()));
		      for (Entity ent:ents){
		    	  if (ent instanceof Equipable){
		    		  Equipable equip = (Equipable) ent;
		    		  regionCost += getInvValue(equip.getInventory().slots());
		    	  }
		      }
		      */
                if (b.getState().getType().equals(BlockTypes.AIR)) {
                    continue;
                }
                if (b.getLocation().get().getTileEntity().isPresent()) {
                    TileEntity invTile = b.getLocation().get().getTileEntity().get();
                    if (invTile instanceof TileEntityInventory) {
                        TileEntityInventory<?> inv = (TileEntityInventory<?>) invTile;
                        regionCost += getInvValue(inv.slots());
                    }
                } else {
                    regionCost += RedProtect.get().cfgs.getBlockCost(b.getState().getType().getName());
                }
            }
        }
    }
    r.setValue(regionCost);
    return regionCost;
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) TileEntityInventory(org.spongepowered.api.item.inventory.type.TileEntityInventory) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World)

Aggregations

BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)1 TileEntityInventory (org.spongepowered.api.item.inventory.type.TileEntityInventory)1 World (org.spongepowered.api.world.World)1