thaumcraft.api.WorldCoordinates Java Examples

The following examples show how to use thaumcraft.api.WorldCoordinates. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VisNetHandler.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
public static ArrayList<Object[]> findClosestNodes(TileVisNode target,
		TileVisNode parent, ArrayList<Object[]> in) {
	
	if (cache.size() > 512 || cache.contains(new WorldCoordinates(parent))) return in;
	cache.add(new WorldCoordinates(parent));
	
	for (WeakReference<TileVisNode> childWR : parent.getChildren()) {
		TileVisNode child = childWR.get();

		if (child != null && !child.equals(target) && !child.equals(parent)) {
			float r2 = inRange(child.getWorldObj(), child.getLocation(),
					target.getLocation(), target.getRange());
			if (r2 > 0) {
				in.add(new Object[] { child, r2 });
			}
			
			in = findClosestNodes(target, child, in);
		}
	}
	return in;
}
 
Example #2
Source File: VisNetHandler.java    From Chisel-2 with GNU General Public License v2.0 6 votes vote down vote up
public static ArrayList<Object[]> findClosestNodes(TileVisNode target,
		TileVisNode parent, ArrayList<Object[]> in) {
	
	if (cache.size() > 512 || cache.contains(new WorldCoordinates(parent))) return in;
	cache.add(new WorldCoordinates(parent));
	
	for (WeakReference<TileVisNode> childWR : parent.getChildren()) {
		TileVisNode child = childWR.get();

		if (child != null && !child.equals(target) && !child.equals(parent)) {
			float r2 = inRange(child.getWorldObj(), child.getLocation(),
					target.getLocation(), target.getRange());
			if (r2 > 0) {
				in.add(new Object[] { child, r2 });
			}
			
			in = findClosestNodes(target, child, in);
		}
	}
	return in;
}
 
Example #3
Source File: TileVisNode.java    From GardenCollection with MIT License 6 votes vote down vote up
public void removeThisNode() {
	for (WeakReference<TileVisNode> n:getChildren()) {
		if (n!=null && n.get()!=null) {
			n.get().removeThisNode();
		}
	}	
	
	children = new ArrayList<WeakReference<TileVisNode>>();
	if (VisNetHandler.isNodeValid(this.getParent())) {
		this.getParent().get().nodeRefresh=true;
	}
	this.setParent(null);
	this.parentChanged();
	
	if (this.isSource()) {
		HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = VisNetHandler.sources.get(worldObj.provider.dimensionId);
		if (sourcelist==null) {
			sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
		}
		sourcelist.remove(getLocation());
		VisNetHandler.sources.put( worldObj.provider.dimensionId, sourcelist );
	}
	
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
 
Example #4
Source File: TileVisNode.java    From Chisel-2 with GNU General Public License v2.0 6 votes vote down vote up
public void removeThisNode() {
	for (WeakReference<TileVisNode> n:getChildren()) {
		if (n!=null && n.get()!=null) {
			n.get().removeThisNode();
		}
	}	
	
	children = new ArrayList<WeakReference<TileVisNode>>();
	if (VisNetHandler.isNodeValid(this.getParent())) {
		this.getParent().get().nodeRefresh=true;
	}
	this.setParent(null);
	this.parentChanged();
	
	if (this.isSource()) {
		HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = VisNetHandler.sources.get(worldObj.provider.dimensionId);
		if (sourcelist==null) {
			sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
		}
		sourcelist.remove(getLocation());
		VisNetHandler.sources.put( worldObj.provider.dimensionId, sourcelist );
	}
	
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
 
Example #5
Source File: VisNetHandler.java    From GardenCollection with MIT License 6 votes vote down vote up
public static ArrayList<Object[]> findClosestNodes(TileVisNode target,
		TileVisNode parent, ArrayList<Object[]> in) {
	
	if (cache.size() > 512 || cache.contains(new WorldCoordinates(parent))) return in;
	cache.add(new WorldCoordinates(parent));
	
	for (WeakReference<TileVisNode> childWR : parent.getChildren()) {
		TileVisNode child = childWR.get();

		if (child != null && !child.equals(target) && !child.equals(parent)) {
			float r2 = inRange(child.getWorldObj(), child.getLocation(),
					target.getLocation(), target.getRange());
			if (r2 > 0) {
				in.add(new Object[] { child, r2 });
			}
			
			in = findClosestNodes(target, child, in);
		}
	}
	return in;
}
 
Example #6
Source File: TileVisNode.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 6 votes vote down vote up
public void removeThisNode() {
	for (WeakReference<TileVisNode> n:getChildren()) {
		if (n!=null && n.get()!=null) {
			n.get().removeThisNode();
		}
	}	
	
	children = new ArrayList<WeakReference<TileVisNode>>();
	if (VisNetHandler.isNodeValid(this.getParent())) {
		this.getParent().get().nodeRefresh=true;
	}
	this.setParent(null);
	this.parentChanged();
	
	if (this.isSource()) {
		HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = VisNetHandler.sources.get(worldObj.provider.dimensionId);
		if (sourcelist==null) {
			sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
		}
		sourcelist.remove(getLocation());
		VisNetHandler.sources.put( worldObj.provider.dimensionId, sourcelist );
	}
	
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
 
Example #7
Source File: TileVisNode.java    From AdvancedMod with GNU General Public License v3.0 6 votes vote down vote up
public void removeThisNode() {
	for (WeakReference<TileVisNode> n:getChildren()) {
		if (n!=null && n.get()!=null) {
			n.get().removeThisNode();
		}
	}	
	
	children = new ArrayList<WeakReference<TileVisNode>>();
	if (VisNetHandler.isNodeValid(this.getParent())) {
		this.getParent().get().nodeRefresh=true;
	}
	this.setParent(null);
	this.parentChanged();
	
	if (this.isSource()) {
		HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = VisNetHandler.sources.get(worldObj.provider.dimensionId);
		if (sourcelist==null) {
			sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
		}
		sourcelist.remove(getLocation());
		VisNetHandler.sources.put( worldObj.provider.dimensionId, sourcelist );
	}
	
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
 
Example #8
Source File: VisNetHandler.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 6 votes vote down vote up
public static ArrayList<Object[]> findClosestNodes(TileVisNode target,
		TileVisNode parent, ArrayList<Object[]> in) {
	
	if (cache.size() > 512 || cache.contains(new WorldCoordinates(parent))) return in;
	cache.add(new WorldCoordinates(parent));
	
	for (WeakReference<TileVisNode> childWR : parent.getChildren()) {
		TileVisNode child = childWR.get();

		if (child != null && !child.equals(target) && !child.equals(parent)) {
			float r2 = inRange(child.getWorldObj(), child.getLocation(),
					target.getLocation(), target.getRange());
			if (r2 > 0) {
				in.add(new Object[] { child, r2 });
			}
			
			in = findClosestNodes(target, child, in);
		}
	}
	return in;
}
 
Example #9
Source File: TileVisNode.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
public void removeThisNode() {
	for (WeakReference<TileVisNode> n:getChildren()) {
		if (n!=null && n.get()!=null) {
			n.get().removeThisNode();
		}
	}	
	
	children = new ArrayList<WeakReference<TileVisNode>>();
	if (VisNetHandler.isNodeValid(this.getParent())) {
		this.getParent().get().nodeRefresh=true;
	}
	this.setParent(null);
	this.parentChanged();
	
	if (this.isSource()) {
		HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = VisNetHandler.sources.get(worldObj.provider.dimensionId);
		if (sourcelist==null) {
			sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
		}
		sourcelist.remove(getLocation());
		VisNetHandler.sources.put( worldObj.provider.dimensionId, sourcelist );
	}
	
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
 
Example #10
Source File: TileEssentiaCompressor.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
private List<WorldCoordinates> searchAndGetSources() {
    WorldCoordinates thisCoordinates = new WorldCoordinates(this);
    Map<WorldCoordinates, List<WorldCoordinates>> teSources = new HashMap<WorldCoordinates, List<WorldCoordinates>>();
    getSourcesField(teSources);
    if(!teSources.containsKey(thisCoordinates)) {
        searchSources();
        getSourcesField(teSources);
        if(teSources.containsKey(thisCoordinates)) {
            return searchAndGetSources();
        }
        return new ArrayList<WorldCoordinates>();
    }
    List<WorldCoordinates> result = teSources.get(thisCoordinates);
    ((Map<WorldCoordinates, List<WorldCoordinates>>) injEssentiaHandler.getField("sources")).remove(thisCoordinates);
    return result;
}
 
Example #11
Source File: TileEssentiaCompressor.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
private boolean doDrain(Aspect a, List<WorldCoordinates> coordinates) {
    for (WorldCoordinates coordinate : coordinates) {
        TileEntity sourceTile = worldObj.getTileEntity(coordinate.x, coordinate.y, coordinate.z);
        if ((sourceTile == null) || (!(sourceTile instanceof IAspectSource))) {
            continue;
        }
        if(sourceTile instanceof TileEssentiaCompressor) continue;
        IAspectSource as = (IAspectSource)sourceTile;
        AspectList contains = as.getAspects();
        if(contains == null || contains.visSize() > al.visSize()) continue;
        if(!canAccept(a)) continue;
        if (as.takeFromContainer(a, 1)) {
            PacketHandler.INSTANCE.sendToAllAround(new PacketFXEssentiaSource(xCoord, yCoord + 1, zCoord,
                    (byte)(xCoord - coordinate.x), (byte)(yCoord - coordinate.y + 1), (byte)(zCoord - coordinate.z),
                    a.getColor()), new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord + 1, zCoord, 32.0D));
            return true;
        }
    }
    return false;
}
 
Example #12
Source File: VisNetHandler.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
public static void addSource(World world, TileVisNode vs) {
	HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
			.get(world.provider.dimensionId);
	if (sourcelist == null) {
		sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
	}
	sourcelist.put(vs.getLocation(), new WeakReference(vs));
	sources.put(world.provider.dimensionId, sourcelist);
	nearbyNodes.clear();
}
 
Example #13
Source File: VisNetHandler.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
/**
 * This method drains vis from a relay or source near the passed in
 * location. The amount received can be less than the amount requested so
 * take that into account.
 * 
 * @param world
 * @param x the x position of the draining block or entity
 * @param y the y position of the draining block or entity
 * @param z the z position of the draining block or entity
 * @param aspect what aspect to drain
 * @param amount how much to drain
 * @return how much was actually drained
 */
public static int drainVis(World world, int x, int y, int z, Aspect aspect, int amount) {

	int drainedAmount = 0;

	WorldCoordinates drainer = new WorldCoordinates(x, y, z,
			world.provider.dimensionId);
	if (!nearbyNodes.containsKey(drainer)) {
		calculateNearbyNodes(world, x, y, z);
	}

	ArrayList<WeakReference<TileVisNode>> nodes = nearbyNodes.get(drainer);
	if (nodes!=null && nodes.size()>0)
	for (WeakReference<TileVisNode> noderef : nodes) {
		
		TileVisNode node = noderef.get();
		
		if (node == null) continue;

		int a = node.consumeVis(aspect, amount);
		drainedAmount += a;
		amount -= a;
		if (a>0) {
			int color = Aspect.getPrimalAspects().indexOf(aspect);
			generateVisEffect(world.provider.dimensionId, x, y, z, node.xCoord, node.yCoord, node.zCoord, color);				
		}
		if (amount <= 0) {
			break;
		}
	}
	
	return drainedAmount;
}
 
Example #14
Source File: VisNetHandler.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method drains vis from a relay or source near the passed in
 * location. The amount received can be less than the amount requested so
 * take that into account.
 * 
 * @param world
 * @param x the x position of the draining block or entity
 * @param y the y position of the draining block or entity
 * @param z the z position of the draining block or entity
 * @param aspect what aspect to drain
 * @param amount how much to drain
 * @return how much was actually drained
 */
public static int drainVis(World world, int x, int y, int z, Aspect aspect, int amount) {

	int drainedAmount = 0;

	WorldCoordinates drainer = new WorldCoordinates(x, y, z,
			world.provider.dimensionId);
	if (!nearbyNodes.containsKey(drainer)) {
		calculateNearbyNodes(world, x, y, z);
	}

	ArrayList<WeakReference<TileVisNode>> nodes = nearbyNodes.get(drainer);
	if (nodes!=null && nodes.size()>0)
	for (WeakReference<TileVisNode> noderef : nodes) {
		
		TileVisNode node = noderef.get();
		
		if (node == null) continue;

		int a = node.consumeVis(aspect, amount);
		drainedAmount += a;
		amount -= a;
		if (a>0) {
			int color = Aspect.getPrimalAspects().indexOf(aspect);
			generateVisEffect(world.provider.dimensionId, x, y, z, node.xCoord, node.yCoord, node.zCoord, color);				
		}
		if (amount <= 0) {
			break;
		}
	}
	
	return drainedAmount;
}
 
Example #15
Source File: VisNetHandler.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static void addSource(World world, TileVisNode vs) {
	HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
			.get(world.provider.dimensionId);
	if (sourcelist == null) {
		sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
	}
	sourcelist.put(vs.getLocation(), new WeakReference(vs));
	sources.put(world.provider.dimensionId, sourcelist);
	nearbyNodes.clear();
}
 
Example #16
Source File: VisNetHandler.java    From GardenCollection with MIT License 5 votes vote down vote up
public static void addSource(World world, TileVisNode vs) {
	HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
			.get(world.provider.dimensionId);
	if (sourcelist == null) {
		sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
	}
	sourcelist.put(vs.getLocation(), new WeakReference(vs));
	sources.put(world.provider.dimensionId, sourcelist);
	nearbyNodes.clear();
}
 
Example #17
Source File: VisNetHandler.java    From GardenCollection with MIT License 5 votes vote down vote up
/**
 * This method drains vis from a relay or source near the passed in
 * location. The amount received can be less than the amount requested so
 * take that into account.
 * 
 * @param world
 * @param x the x position of the draining block or entity
 * @param y the y position of the draining block or entity
 * @param z the z position of the draining block or entity
 * @param aspect what aspect to drain
 * @param amount how much to drain
 * @return how much was actually drained
 */
public static int drainVis(World world, int x, int y, int z, Aspect aspect, int amount) {

	int drainedAmount = 0;

	WorldCoordinates drainer = new WorldCoordinates(x, y, z,
			world.provider.dimensionId);
	if (!nearbyNodes.containsKey(drainer)) {
		calculateNearbyNodes(world, x, y, z);
	}

	ArrayList<WeakReference<TileVisNode>> nodes = nearbyNodes.get(drainer);
	if (nodes!=null && nodes.size()>0)
	for (WeakReference<TileVisNode> noderef : nodes) {
		
		TileVisNode node = noderef.get();
		
		if (node == null) continue;

		int a = node.consumeVis(aspect, amount);
		drainedAmount += a;
		amount -= a;
		if (a>0) {
			int color = Aspect.getPrimalAspects().indexOf(aspect);
			generateVisEffect(world.provider.dimensionId, x, y, z, node.xCoord, node.yCoord, node.zCoord, color);				
		}
		if (amount <= 0) {
			break;
		}
	}
	
	return drainedAmount;
}
 
Example #18
Source File: TileEssentiaCompressor.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean searchForEssentia(List<WorldCoordinates> coordinates) {
    if(ticksExisted % 10 != 0) return prevFound;
    for (Aspect a : Aspect.aspects.values()) {
        if (doDrain(a, coordinates)) {
            al.add(a, 1);
            worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
            markDirty();
            return true;
        }
    }
    return false;
}
 
Example #19
Source File: VisNetHandler.java    From Chisel-2 with GNU General Public License v2.0 5 votes vote down vote up
public static void addSource(World world, TileVisNode vs) {
	HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
			.get(world.provider.dimensionId);
	if (sourcelist == null) {
		sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
	}
	sourcelist.put(vs.getLocation(), new WeakReference(vs));
	sources.put(world.provider.dimensionId, sourcelist);
	nearbyNodes.clear();
}
 
Example #20
Source File: TileEssentiaCompressor.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void updateEntity() {
    super.updateEntity();
    ticksExisted++;

    if(!worldObj.isRemote) {
        if(isMultiblockFormed()) {
            checkMultiblock();
        }

        if(!isMultiblockFormed()) return;

        if (isMasterTile() && (prevFound || (ticksExisted % 100) == 0)) {
            List<WorldCoordinates> coords = searchAndGetSources();
            if (coords == null || coords.isEmpty()) {
                prevFound = false;
            } else {
                prevFound = searchForEssentia(coords);
            }
        }

        if(isMasterTile() && ((incSize < MAX_SIZE && (ticksExisted % 40) == 0) || (coordPedestal != null))) {
            consumeElements();
        }
    } else {
        if(isMasterTile() && isMultiblockFormed()) {
            playLightningEffects();
            playVortexEffects();
            if(al.visSize() > 0) {
                playEssentiaEffects();
            }
        }
    }

    if(isMasterTile() && isMultiblockFormed()) {
        vortexEntities();
    }
}
 
Example #21
Source File: TileEssentiaCompressor.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void searchSources() {
    WorldCoordinates thisCoord = new WorldCoordinates(xCoord, yCoord, zCoord, worldObj.provider.dimensionId);
    List<WorldCoordinates> coords = new LinkedList<WorldCoordinates>();
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        unsafe_search(thisCoord, direction, coords);
    }

    ((Map<WorldCoordinates, List<WorldCoordinates>>) injEssentiaHandler.getField("sources")).put(thisCoord, coords);
}
 
Example #22
Source File: TileEssentiaCompressor.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void unsafe_search(WorldCoordinates coord, ForgeDirection direction, List<WorldCoordinates> out) {
    ((HashMap<WorldCoordinates, Long>) injEssentiaHandler.getField("sourcesDelay")).remove(coord);
    injEssentiaHandler.invokeMethod("getSources", new Class[]{ World.class, WorldCoordinates.class, ForgeDirection.class, int.class }, worldObj, coord, direction, 5);
    List<WorldCoordinates> coords = ((Map<WorldCoordinates, List<WorldCoordinates>>) injEssentiaHandler.getField("sources")).get(coord);
    if(coords != null) {
        out.addAll(((Map<WorldCoordinates, List<WorldCoordinates>>) injEssentiaHandler.getField("sources")).get(coord));
        ((Map<WorldCoordinates, List<WorldCoordinates>>) injEssentiaHandler.getField("sources")).remove(coord);
    }
}
 
Example #23
Source File: VisNetHandler.java    From AdvancedMod with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method drains vis from a relay or source near the passed in
 * location. The amount received can be less than the amount requested so
 * take that into account.
 * 
 * @param world
 * @param x the x position of the draining block or entity
 * @param y the y position of the draining block or entity
 * @param z the z position of the draining block or entity
 * @param aspect what aspect to drain
 * @param amount how much to drain
 * @return how much was actually drained
 */
public static int drainVis(World world, int x, int y, int z, Aspect aspect, int amount) {

	int drainedAmount = 0;

	WorldCoordinates drainer = new WorldCoordinates(x, y, z,
			world.provider.dimensionId);
	if (!nearbyNodes.containsKey(drainer)) {
		calculateNearbyNodes(world, x, y, z);
	}

	ArrayList<WeakReference<TileVisNode>> nodes = nearbyNodes.get(drainer);
	if (nodes!=null && nodes.size()>0)
	for (WeakReference<TileVisNode> noderef : nodes) {
		
		TileVisNode node = noderef.get();
		
		if (node == null) continue;

		int a = node.consumeVis(aspect, amount);
		drainedAmount += a;
		amount -= a;
		if (a>0) {
			int color = Aspect.getPrimalAspects().indexOf(aspect);
			generateVisEffect(world.provider.dimensionId, x, y, z, node.xCoord, node.yCoord, node.zCoord, color);				
		}
		if (amount <= 0) {
			break;
		}
	}
	
	return drainedAmount;
}
 
Example #24
Source File: VisNetHandler.java    From AdvancedMod with GNU General Public License v3.0 5 votes vote down vote up
public static void addSource(World world, TileVisNode vs) {
	HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
			.get(world.provider.dimensionId);
	if (sourcelist == null) {
		sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
	}
	sourcelist.put(vs.getLocation(), new WeakReference(vs));
	sources.put(world.provider.dimensionId, sourcelist);
	nearbyNodes.clear();
}
 
Example #25
Source File: VisNetHandler.java    From Chisel-2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method drains vis from a relay or source near the passed in
 * location. The amount received can be less than the amount requested so
 * take that into account.
 * 
 * @param world
 * @param x the x position of the draining block or entity
 * @param y the y position of the draining block or entity
 * @param z the z position of the draining block or entity
 * @param aspect what aspect to drain
 * @param amount how much to drain
 * @return how much was actually drained
 */
public static int drainVis(World world, int x, int y, int z, Aspect aspect, int amount) {

	int drainedAmount = 0;

	WorldCoordinates drainer = new WorldCoordinates(x, y, z,
			world.provider.dimensionId);
	if (!nearbyNodes.containsKey(drainer)) {
		calculateNearbyNodes(world, x, y, z);
	}

	ArrayList<WeakReference<TileVisNode>> nodes = nearbyNodes.get(drainer);
	if (nodes!=null && nodes.size()>0)
	for (WeakReference<TileVisNode> noderef : nodes) {
		
		TileVisNode node = noderef.get();
		
		if (node == null) continue;

		int a = node.consumeVis(aspect, amount);
		drainedAmount += a;
		amount -= a;
		if (a>0) {
			int color = Aspect.getPrimalAspects().indexOf(aspect);
			generateVisEffect(world.provider.dimensionId, x, y, z, node.xCoord, node.yCoord, node.zCoord, color);				
		}
		if (amount <= 0) {
			break;
		}
	}
	
	return drainedAmount;
}
 
Example #26
Source File: TileVisNode.java    From AdvancedMod with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return the WorldCoordinates location of where this node is located
 */
public WorldCoordinates getLocation() {
	return new WorldCoordinates(this);
}
 
Example #27
Source File: VisNetHandler.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
private static void calculateNearbyNodes(World world, int x, int y, int z) {

		HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
				.get(world.provider.dimensionId);
		if (sourcelist == null) {
			sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
			return;
		}

		ArrayList<WeakReference<TileVisNode>> cn = new ArrayList<WeakReference<TileVisNode>>();
		WorldCoordinates drainer = new WorldCoordinates(x, y, z,
				world.provider.dimensionId);

		ArrayList<Object[]> nearby = new ArrayList<Object[]>();

		for (WeakReference<TileVisNode> root : sourcelist.values()) {
			
			if (!isNodeValid(root))
				continue;

			TileVisNode source = root.get();
			
			TileVisNode closest = null;
			float range = Float.MAX_VALUE;

			float r = inRange(world, drainer, source.getLocation(),
					source.getRange());
			if (r > 0) {
				range = r;
				closest = source;
			}
			
			ArrayList<WeakReference<TileVisNode>> children = new ArrayList<WeakReference<TileVisNode>>();
			children = getAllChildren(source,children);
			
			for (WeakReference<TileVisNode> child : children) {
				TileVisNode n = child.get();
				if (n != null && !n.equals(root)) {
					
					float r2 = inRange(n.getWorldObj(), n.getLocation(),
							drainer, n.getRange());
					if (r2 > 0 && r2 < range) {
						range = r2;
						closest = n;
					}
				}
			}

			if (closest != null) {
				
				cn.add(new WeakReference(closest));
			}
		}

		nearbyNodes.put(drainer, cn);
	}
 
Example #28
Source File: VisNetHandler.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
private static float inRange(World world, WorldCoordinates cc1,
		WorldCoordinates cc2, int range) {
	float distance = cc1.getDistanceSquaredToWorldCoordinates(cc2);
	return distance > range * range ? -1 : distance;
}
 
Example #29
Source File: VisNetHandler.java    From Chisel-2 with GNU General Public License v2.0 4 votes vote down vote up
public static WeakReference<TileVisNode> addNode(World world, TileVisNode vn) {
	WeakReference ref = new WeakReference(vn);

	HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
			.get(world.provider.dimensionId);
	if (sourcelist == null) {
		sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
		return null;
	}

	ArrayList<Object[]> nearby = new ArrayList<Object[]>();

	for (WeakReference<TileVisNode> root : sourcelist.values()) {
		if (!isNodeValid(root))
			continue;

		TileVisNode source = root.get();

		float r = inRange(world, vn.getLocation(), source.getLocation(),
				vn.getRange());
		if (r > 0) {
			nearby.add(new Object[] { source, r - vn.getRange() * 2 });
		}
		
		nearby = findClosestNodes(vn, source, nearby);
		cache.clear();
	}

	float dist = Float.MAX_VALUE;
	TileVisNode closest = null;
	if (nearby.size() > 0) {
		for (Object[] o : nearby) {
			if ((Float) o[1] < dist &&
				(vn.getAttunement() == -1 || ((TileVisNode) o[0]).getAttunement() == -1 || 
					vn.getAttunement() == ((TileVisNode) o[0]).getAttunement())//) {
				 && canNodeBeSeen(vn,(TileVisNode)o[0])) {
				dist = (Float) o[1];
				closest = (TileVisNode) o[0];					
			}
		}
	}
	if (closest != null) {
		closest.getChildren().add(ref);
		nearbyNodes.clear();
		return new WeakReference(closest);
	}

	return null;
}
 
Example #30
Source File: VisNetHandler.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public static WeakReference<TileVisNode> addNode(World world, TileVisNode vn) {
	WeakReference ref = new WeakReference(vn);

	HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
			.get(world.provider.dimensionId);
	if (sourcelist == null) {
		sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
		return null;
	}

	ArrayList<Object[]> nearby = new ArrayList<Object[]>();

	for (WeakReference<TileVisNode> root : sourcelist.values()) {
		if (!isNodeValid(root))
			continue;

		TileVisNode source = root.get();

		float r = inRange(world, vn.getLocation(), source.getLocation(),
				vn.getRange());
		if (r > 0) {
			nearby.add(new Object[] { source, r - vn.getRange() * 2 });
		}
		
		nearby = findClosestNodes(vn, source, nearby);
		cache.clear();
	}

	float dist = Float.MAX_VALUE;
	TileVisNode closest = null;
	if (nearby.size() > 0) {
		for (Object[] o : nearby) {
			if ((Float) o[1] < dist &&
				(vn.getAttunement() == -1 || ((TileVisNode) o[0]).getAttunement() == -1 || 
					vn.getAttunement() == ((TileVisNode) o[0]).getAttunement())//) {
				 && canNodeBeSeen(vn,(TileVisNode)o[0])) {
				dist = (Float) o[1];
				closest = (TileVisNode) o[0];					
			}
		}
	}
	if (closest != null) {
		closest.getChildren().add(ref);
		nearbyNodes.clear();
		return new WeakReference(closest);
	}

	return null;
}