Search in sources :

Example 1 with GridSpaceHolder

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

the class TEDemonPortal method createGSH.

public GridSpaceHolder createGSH() {
    GridSpaceHolder grid = new GridSpaceHolder();
    grid.area = this.area;
    grid.negXRadius = this.negXRadius;
    grid.negZRadius = this.negZRadius;
    grid.posXRadius = this.posXRadius;
    grid.posZRadius = this.posZRadius;
    return grid;
}
Also used : GridSpaceHolder(WayofTime.alchemicalWizardry.common.demonVillage.GridSpaceHolder)

Example 2 with GridSpaceHolder

use of WayofTime.alchemicalWizardry.common.demonVillage.GridSpaceHolder 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 3 with GridSpaceHolder

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

the class TEDemonPortal method createPortalBuilding.

/**
 * The Stage is at what point the portal is in reacting to the creation of the Demon Portal.
 * Stage == 0 means just the saving
 * Stage == 1 means to telepose the portal
 * Stage == 2 means the teleposition is complete and that the building may be constructed
 */
public void createPortalBuilding(int stage, String name, int tier) {
    for (DemonBuilding build : TEDemonPortal.buildingList) {
        if (build.buildingType != DemonBuilding.BUILDING_PORTAL || build.buildingTier != tier) {
            continue;
        }
        if (build.getName().equals(this.nextDemonPortalName)) {
            int x = 0;
            int z = 0;
            GridSpace home = this.getGridSpace(x, z);
            int yLevel = home.getYLevel();
            GridSpaceHolder grid = this.createGSH();
            ForgeDirection chosenDirection = this.nextDemonPortalDirection;
            Int3 portalSpace = build.getDoorSpace(chosenDirection);
            int yOffset = portalSpace.yCoord;
            switch(stage) {
                case 0:
                    break;
                case 1:
                    int yDestination = yLevel + yOffset;
                    if (yCoord != yDestination) {
                        BlockTeleposer.swapBlocks(this, worldObj, worldObj, xCoord, yCoord, zCoord, xCoord, yDestination, zCoord);
                    } else {
                    // Nuthin - just as a reminder that we can now increment properly
                    }
                    break;
                case 2:
                    build.destroyAllInField(worldObj, xCoord + (x) * 5, yLevel, zCoord + (z) * 5, chosenDirection.getOpposite());
                    build.buildAll(this, worldObj, xCoord + (x) * 5, yLevel, zCoord + (z) * 5, chosenDirection.getOpposite(), true);
                    build.setAllGridSpaces(x, z, yLevel, chosenDirection.getOpposite(), GridSpace.MAIN_PORTAL, grid);
                    this.loadGSH(grid);
                    break;
            }
            return;
        }
    }
}
Also used : Int3(WayofTime.alchemicalWizardry.api.Int3) DemonBuilding(WayofTime.alchemicalWizardry.common.demonVillage.DemonBuilding) GridSpaceHolder(WayofTime.alchemicalWizardry.common.demonVillage.GridSpaceHolder) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) GridSpace(WayofTime.alchemicalWizardry.common.demonVillage.GridSpace)

Aggregations

GridSpaceHolder (WayofTime.alchemicalWizardry.common.demonVillage.GridSpaceHolder)3 Int3 (WayofTime.alchemicalWizardry.api.Int3)2 DemonBuilding (WayofTime.alchemicalWizardry.common.demonVillage.DemonBuilding)2 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)2 DemonVillagePath (WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath)1 Int3AndBool (WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath.Int3AndBool)1 GridSpace (WayofTime.alchemicalWizardry.common.demonVillage.GridSpace)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