Search in sources :

Example 1 with DemonVillagePath

use of WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath in project BloodMagic by WayofTime.

the class TEDemonPortal method createRandomHouse.

public int createRandomHouse(int buildingTier) {
    int next = rand.nextInt(4);
    ForgeDirection dir;
    switch(next) {
        case 0:
            dir = ForgeDirection.NORTH;
            break;
        case 1:
            dir = ForgeDirection.SOUTH;
            break;
        case 2:
            dir = ForgeDirection.EAST;
            break;
        case 3:
            dir = ForgeDirection.WEST;
            break;
        default:
            dir = ForgeDirection.NORTH;
    }
    // Second: 1 *
    Int3 space = this.findRoadSpaceFromDirection(dir, (rand.nextInt(negXRadius + negZRadius + posXRadius + posZRadius)) + 1);
    int x = space.xCoord;
    int z = space.zCoord;
    int yLevel = space.yCoord;
    if (printDebug)
        AlchemicalWizardry.logger.info("Road space - x: " + x + " z: " + z);
    GridSpaceHolder grid = this.createGSH();
    if (!this.getGridSpace(x, z).isRoadSegment()) {
        return 0;
    }
    List<ForgeDirection> directions = new ArrayList();
    for (int i = 2; i < 6; i++) {
        ForgeDirection testDir = ForgeDirection.getOrientation(i);
        if (this.getGridSpace(x + testDir.offsetX, z + testDir.offsetZ).isEmpty()) {
            directions.add(testDir);
        }
    }
    if (directions.isEmpty()) {
        return 0;
    }
    HashMap<ForgeDirection, List<DemonBuilding>> schemMap = new HashMap();
    for (ForgeDirection nextDir : directions) {
        for (DemonBuilding build : TEDemonPortal.buildingList) {
            if (build.buildingTier != buildingTier || build.buildingType != DemonBuilding.BUILDING_HOUSE) {
                continue;
            }
            Int3 offsetSpace = build.getGridOffsetFromRoad(nextDir, yLevel);
            int xOff = offsetSpace.xCoord;
            int zOff = offsetSpace.zCoord;
            if (build.isValid(grid, x + xOff, z + zOff, nextDir.getOpposite())) {
                if (schemMap.containsKey(nextDir)) {
                    schemMap.get(nextDir).add(build);
                } else {
                    schemMap.put(nextDir, new ArrayList());
                    schemMap.get(nextDir).add(build);
                }
            } else {
                if (printDebug)
                    AlchemicalWizardry.logger.info("This ISN'T valid!");
            }
        }
    }
    if (schemMap.keySet().isEmpty()) {
        return 0;
    }
    ForgeDirection chosenDirection = (ForgeDirection) schemMap.keySet().toArray()[new Random().nextInt(schemMap.keySet().size())];
    DemonBuilding build = schemMap.get(chosenDirection).get(new Random().nextInt(schemMap.get(chosenDirection).size()));
    Int3 offsetSpace = build.getGridOffsetFromRoad(chosenDirection, yLevel);
    int xOff = offsetSpace.xCoord;
    int zOff = offsetSpace.zCoord;
    build.destroyAllInField(worldObj, xCoord + (x + xOff) * 5, yLevel, zCoord + (z + zOff) * 5, chosenDirection.getOpposite());
    build.buildAll(this, worldObj, xCoord + (x + xOff) * 5, yLevel, zCoord + (z + zOff) * 5, chosenDirection.getOpposite(), true);
    build.setAllGridSpaces(x + xOff, z + zOff, yLevel, chosenDirection.getOpposite(), GridSpace.HOUSE, grid);
    this.loadGSH(grid);
    DemonVillagePath path = new DemonVillagePath(xCoord + (x) * 5, yLevel, zCoord + (z) * 5, chosenDirection, 2);
    Int3AndBool temp = path.constructFullPath(this, worldObj, this.getRoadStepClearance());
    return build.getNumberOfGridSpaces();
}
Also used : HashMap(java.util.HashMap) Int3(WayofTime.alchemicalWizardry.api.Int3) GridSpaceHolder(WayofTime.alchemicalWizardry.common.demonVillage.GridSpaceHolder) DemonBuilding(WayofTime.alchemicalWizardry.common.demonVillage.DemonBuilding) ArrayList(java.util.ArrayList) DemonVillagePath(WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath) Int3AndBool(WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath.Int3AndBool) Random(java.util.Random) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) NBTTagList(net.minecraft.nbt.NBTTagList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 2 with DemonVillagePath

use of WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath in project BloodMagic by WayofTime.

the class TEDemonPortal method createRoad.

public void createRoad(int xi, int yi, int zi, ForgeDirection dir, int length, boolean doesNotDrop) {
    int curX = xi;
    int curY = yi;
    int curZ = zi;
    int roadRadius = this.getRoadRadius();
    if (dir.offsetY != 0) {
        return;
    }
    DemonVillagePath path = new DemonVillagePath(xi, yi, zi, dir, length);
    path.constructFullPath(this, worldObj, this.getRoadStepClearance());
}
Also used : DemonVillagePath(WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath)

Example 3 with DemonVillagePath

use of WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath in project BloodMagic by WayofTime.

the class TEDemonPortal method createGriddedRoad.

public // Total grid length
int createGriddedRoad(// Total grid length
int gridXi, // Total grid length
int yi, // Total grid length
int gridZi, // Total grid length
ForgeDirection dir, // Total grid length
int gridLength, // Total grid length
boolean convertStarter) {
    if (gridLength == 0 || gridLength == 1) {
        return 0;
    }
    int initGridX = gridXi;
    int initGridZ = gridZi;
    int initY = yi;
    if (convertStarter) {
        this.setGridSpace(initGridX, initGridZ, new GridSpace(GridSpace.CROSSROAD, initY));
        DemonCrosspath crosspath = new DemonCrosspath(xCoord + initGridX * 5, initY, zCoord + initGridZ * 5);
        crosspath.createCrosspath(worldObj);
    }
    for (int index = 0; index < gridLength - 1; index++) {
        DemonVillagePath path = new DemonVillagePath(xCoord + initGridX * 5, initY, zCoord + initGridZ * 5, dir, 6);
        Int3AndBool temp = path.constructFullPath(this, worldObj, this.getRoadStepClearance());
        Int3 next = temp.coords;
        if (next != null) {
            initY = next.yCoord;
            if (printDebug)
                AlchemicalWizardry.logger.info("" + initY);
        }
        if (!temp.bool) {
            return index;
        }
        initGridX += dir.offsetX;
        initGridZ += dir.offsetZ;
        if (!this.getGridSpace(initGridX, initGridZ).isRoadSegment()) {
            this.setGridSpace(initGridX, initGridZ, new GridSpace(GridSpace.ROAD, initY));
        }
    }
    return gridLength - 1;
}
Also used : Int3AndBool(WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath.Int3AndBool) DemonCrosspath(WayofTime.alchemicalWizardry.common.demonVillage.DemonCrosspath) Int3(WayofTime.alchemicalWizardry.api.Int3) GridSpace(WayofTime.alchemicalWizardry.common.demonVillage.GridSpace) DemonVillagePath(WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath)

Aggregations

DemonVillagePath (WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath)3 Int3 (WayofTime.alchemicalWizardry.api.Int3)2 Int3AndBool (WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath.Int3AndBool)2 DemonBuilding (WayofTime.alchemicalWizardry.common.demonVillage.DemonBuilding)1 DemonCrosspath (WayofTime.alchemicalWizardry.common.demonVillage.DemonCrosspath)1 GridSpace (WayofTime.alchemicalWizardry.common.demonVillage.GridSpace)1 GridSpaceHolder (WayofTime.alchemicalWizardry.common.demonVillage.GridSpaceHolder)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Random (java.util.Random)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1