@SubscribeEvent public void onBlockPlaceEvent(BlockEvent.PlaceEvent event) { float blocker = RadiationShieldRegistry.getBlocker(event.block); if (blocker >= 0.99f) { return; } World world = event.blockSnapshot.world; DRRadiationManager radiationManager = DRRadiationManager.getManager(world); Map<GlobalCoordinate, DRRadiationManager.RadiationSource> radiationSources = radiationManager.getRadiationSources(); if (radiationSources.isEmpty()) { return; } int x = event.blockSnapshot.x; int y = event.blockSnapshot.y; int z = event.blockSnapshot.z; for (Map.Entry<GlobalCoordinate, DRRadiationManager.RadiationSource> entry : radiationSources.entrySet()) { DRRadiationManager.RadiationSource source = entry.getValue(); float radius = source.getRadius(); GlobalCoordinate gc = entry.getKey(); Coordinate c = gc.getCoordinate(); if (Math.abs(c.getX() - x) < radius && Math.abs(c.getY() - y) < radius && Math.abs(c.getZ() - z) < radius) { Logging.logDebug("Add blocker at: " + x + "," + y + "," + z); QuadTree radiationTree = source.getRadiationTree(world, c.getX(), c.getY(), c.getZ()); radiationTree.addBlocker(x, y, z, blocker); } } }
public Collection<GlobalCoordinate> findProtectors( int x, int y, int z, int dimension, int radius) { List<GlobalCoordinate> protectors = new ArrayList<GlobalCoordinate>(); for (GlobalCoordinate coordinate : protectorIdByCoordinate.keySet()) { if (coordinate.getDimension() == dimension) { Coordinate c = coordinate.getCoordinate(); if (Math.abs(x - c.getX()) <= (16 + radius + 1) && Math.abs(y - c.getY()) <= (16 + radius + 1) && Math.abs(z - c.getZ()) <= (16 + radius + 1)) { protectors.add(coordinate); } } } return protectors; }
@Override public void writeToNBT(NBTTagCompound tagCompound) { NBTTagList lst = new NBTTagList(); for (GlobalCoordinate destination : protectorIdByCoordinate.keySet()) { NBTTagCompound tc = new NBTTagCompound(); Coordinate c = destination.getCoordinate(); tc.setInteger("x", c.getX()); tc.setInteger("y", c.getY()); tc.setInteger("z", c.getZ()); tc.setInteger("dim", destination.getDimension()); Integer id = protectorIdByCoordinate.get(new GlobalCoordinate(c, destination.getDimension())); tc.setInteger("id", id); lst.appendTag(tc); } tagCompound.setTag("blocks", lst); tagCompound.setInteger("lastId", lastId); }