Search in sources :

Example 1 with ManagedLocation

use of net.tropicraft.core.common.town.ManagedLocation in project Tropicraft by Tropicraft.

the class TownKoaVillageGenHelper method hookTryGenVillage.

/* Takes coords that are assumed to be a beach, scans to find the ocean side and checks if theres enough ocean space to gen */
public static boolean hookTryGenVillage(BlockPos parCoords, World parWorld) {
    /*int x = MathHelper.floor_double(player.getX());
		int z = MathHelper.floor_double(player.getZ());
		int y = player.worldObj.getHeightValue(x, z);*/
    int directionTry = getBestGenDirection(parCoords, parWorld);
    if (directionTry != -1) {
        dbg("test success! dir: " + directionTry);
        BlockPos centerCoords = getCoordsFromAdjustedDirection(parCoords, directionTry);
        dbg("centerCoords: " + centerCoords);
        // make sure its at exact height
        centerCoords = new BlockPos(centerCoords.getX(), WorldProviderTropicraft.MID_HEIGHT + 1, centerCoords.getZ());
        TownKoaVillage village = new TownKoaVillage();
        WorldDataInstance storage = parWorld.getCapability(Tropicraft.WORLD_DATA_INSTANCE, null);
        if (storage != null) {
            int minDistBetweenVillages = 512;
            Iterator it = storage.lookupTickingManagedLocations.values().iterator();
            while (it.hasNext()) {
                ManagedLocation town = (ManagedLocation) it.next();
                if (Math.sqrt(town.spawn.distanceSq(parCoords)) < minDistBetweenVillages) {
                    // System.out.println("village to close to another, aborting");
                    return false;
                }
            }
            int newID = storage.getAndIncrementKoaIDVillage();
            // int newID = parWorld.rand.nextInt(9999);
            village.initData(newID, parWorld.provider.getDimension(), centerCoords);
            village.direction = directionTry;
            village.initFirstTime();
            storage.addTickingLocation(village);
            return true;
        } else {
        // dbg("ERROR: cant get world capability???");
        }
    } else {
    // System.out.println("test fail!");
    }
    return false;
}
Also used : ManagedLocation(net.tropicraft.core.common.town.ManagedLocation) Iterator(java.util.Iterator) BlockPos(net.minecraft.util.math.BlockPos) WorldDataInstance(net.tropicraft.core.common.capability.WorldDataInstance)

Aggregations

Iterator (java.util.Iterator)1 BlockPos (net.minecraft.util.math.BlockPos)1 WorldDataInstance (net.tropicraft.core.common.capability.WorldDataInstance)1 ManagedLocation (net.tropicraft.core.common.town.ManagedLocation)1