diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/demonVillage/DemonVillagePath.java b/src/main/java/WayofTime/alchemicalWizardry/common/demonVillage/DemonVillagePath.java index 37b4e933..a8add995 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/demonVillage/DemonVillagePath.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/demonVillage/DemonVillagePath.java @@ -15,6 +15,10 @@ public class DemonVillagePath public int zi; public ForgeDirection dir; public int length; + + public boolean canGoDown = true; + public boolean tunnelIfObstructed = true; + public boolean createBridgeInAirIfObstructed = false; public DemonVillagePath(int xi, int yi, int zi, ForgeDirection dir, int length) { @@ -25,22 +29,54 @@ public class DemonVillagePath this.length = length; } - public Int3 constructFullPath(TEDemonPortal portal, World world, int clearance) + public Int3AndBool constructFullPath(TEDemonPortal portal, World world, int clearance) { int xPos = this.xi; int yPos = this.yi; int zPos = this.zi; int rad = this.getRoadRadius(); + int value = 0; + + int finalYPos = this.constructPartialPath(portal, world, clearance, xPos - rad * dir.offsetX, yPos, zPos - rad * dir.offsetZ, dir, length + rad, false); for (int i = -rad; i <= rad; i++) { - this.constructPartialPath(portal, world, clearance, xPos - rad * dir.offsetX + i * dir.offsetZ, yPos, zPos - rad * dir.offsetZ + i * dir.offsetX, dir, length + 2 * rad); + value = Math.max(this.constructPartialPath(portal, world, clearance, xPos - rad * dir.offsetX + i * dir.offsetZ, yPos, zPos - rad * dir.offsetZ + i * dir.offsetX, dir, length + 2 * rad, true), value); + System.out.println("" + (length + 2 * rad) + ", " + value + ""); } + + Int3 position = new Int3(xPos, finalYPos, zPos); - return this.getFinalLocation(world, clearance); + boolean bool = value >= length + 2 * rad; + + return new Int3AndBool(position, bool); + } + + public class Int3AndBool + { + public Int3 coords; + public boolean bool; + public Int3AndBool(Int3 int3, boolean bool) + { + this.coords = int3; + this.bool = bool; + } } - public void constructPartialPath(TEDemonPortal portal, World world, int clearance, int xi, int yi, int zi, ForgeDirection dir, int length) + /** + * + * @param portal + * @param world + * @param clearance + * @param xi + * @param yi + * @param zi + * @param dir + * @param length + * @param doConstruct + * @return length if doConstruct, yPos if !doConstruct + */ + public int constructPartialPath(TEDemonPortal portal, World world, int clearance, int xi, int yi, int zi, ForgeDirection dir, int length, boolean doConstruct) { int xPos = xi; int yPos = yi; @@ -51,6 +87,8 @@ public class DemonVillagePath int xOffset = i * dir.offsetX; int zOffset = i * dir.offsetZ; + boolean completed = false; + for (int yOffset = 0; yOffset <= clearance; yOffset++) { int sign = 1; @@ -60,10 +98,14 @@ public class DemonVillagePath if (!block1.isReplaceable(world, xPos + xOffset, yPos + sign * yOffset, zPos + zOffset) && this.isBlockReplaceable(block1) && highBlock1.isReplaceable(world, xPos + xOffset, yPos + sign * yOffset + 1, zPos + zOffset)) { - world.setBlock(xPos + xOffset, yPos + sign * yOffset, zPos + zOffset, portal.getRoadBlock(), portal.getRoadMeta(), 3); + if(doConstruct) + { + world.setBlock(xPos + xOffset, yPos + sign * yOffset, zPos + zOffset, portal.getRoadBlock(), portal.getRoadMeta(), 3); + } yPos += sign * yOffset; + completed = true; break; - } else + } else if(canGoDown) { sign = -1; Block block2 = world.getBlock(xPos + xOffset, yPos + sign * yOffset, zPos + zOffset); @@ -71,13 +113,66 @@ public class DemonVillagePath if (!block2.isReplaceable(world, xPos + xOffset, yPos + sign * yOffset, zPos + zOffset) && this.isBlockReplaceable(block1) && highBlock2.isReplaceable(world, xPos + xOffset, yPos + sign * yOffset + 1, zPos + zOffset)) { - world.setBlock(xPos + xOffset, yPos + sign * yOffset, zPos + zOffset, portal.getRoadBlock(), portal.getRoadMeta(), 3); + if(doConstruct) + { + world.setBlock(xPos + xOffset, yPos + sign * yOffset, zPos + zOffset, portal.getRoadBlock(), portal.getRoadMeta(), 3); + } yPos += sign * yOffset; + completed = true; break; } } } + + if(!completed) + { + boolean returnAmount = true; + if(createBridgeInAirIfObstructed) + { + Block block1 = world.getBlock(xPos + xOffset, yPos, zPos + zOffset); + + if (block1.isReplaceable(world, xPos + xOffset, yPos, zPos + zOffset) || !this.isBlockReplaceable(block1)) + { + returnAmount = false; + + if(doConstruct) + { + world.setBlock(xPos + xOffset, yPos, zPos + zOffset, portal.getRoadBlock(), portal.getRoadMeta(), 3); + } + }else + { + returnAmount = true; + } + + }else if(this.tunnelIfObstructed) + { + Block block1 = world.getBlock(xPos + xOffset, yPos, zPos + zOffset); + + if (!block1.isReplaceable(world, xPos + xOffset, yPos, zPos + zOffset) || this.isBlockReplaceable(block1)) + { + returnAmount = false; + + if(doConstruct) + { + world.setBlock(xPos + xOffset, yPos, zPos + zOffset, portal.getRoadBlock(), portal.getRoadMeta(), 3); + world.setBlockToAir(xPos + xOffset, yPos + 1, zPos + zOffset); + world.setBlockToAir(xPos + xOffset, yPos + 2, zPos + zOffset); + world.setBlockToAir(xPos + xOffset, yPos + 3, zPos + zOffset); + } + }else + { + returnAmount = true; + } + } + + if(returnAmount) + { + return doConstruct ? i : yPos; + } + } } + + return doConstruct ? length : yPos; } public Int3 getFinalLocation(World world, int clearance) diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/demonVillage/tileEntity/TEDemonPortal.java b/src/main/java/WayofTime/alchemicalWizardry/common/demonVillage/tileEntity/TEDemonPortal.java index 3b3064f0..15b9a58c 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/demonVillage/tileEntity/TEDemonPortal.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/demonVillage/tileEntity/TEDemonPortal.java @@ -1,14 +1,19 @@ package WayofTime.alchemicalWizardry.common.demonVillage.tileEntity; -import WayofTime.alchemicalWizardry.AlchemicalWizardry; -import WayofTime.alchemicalWizardry.common.Int3; -import WayofTime.alchemicalWizardry.common.block.BlockTeleposer; -import WayofTime.alchemicalWizardry.common.demonVillage.*; -import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.DemonPacketRegistry; -import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.DemonType; -import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.demon.IHoardDemon; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; +import java.util.Set; + import net.minecraft.block.Block; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.EntityLivingBase; @@ -19,13 +24,22 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.ForgeDirection; +import WayofTime.alchemicalWizardry.AlchemicalWizardry; +import WayofTime.alchemicalWizardry.common.Int3; +import WayofTime.alchemicalWizardry.common.block.BlockTeleposer; +import WayofTime.alchemicalWizardry.common.demonVillage.BuildingSchematic; +import WayofTime.alchemicalWizardry.common.demonVillage.DemonBuilding; +import WayofTime.alchemicalWizardry.common.demonVillage.DemonCrosspath; +import WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath; +import WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath.Int3AndBool; +import WayofTime.alchemicalWizardry.common.demonVillage.GridSpace; +import WayofTime.alchemicalWizardry.common.demonVillage.GridSpaceHolder; +import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.DemonPacketRegistry; +import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.DemonType; +import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.demon.IHoardDemon; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.util.*; -import java.util.Map.Entry; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; public class TEDemonPortal extends TileEntity { @@ -202,6 +216,7 @@ public class TEDemonPortal extends TileEntity public void notifyDemons(EntityLivingBase demon, EntityLivingBase target, double radius) //TODO { + this.lockdownTimer = 1000; for(IHoardDemon thrallDemon : this.hoardList) { if(thrallDemon instanceof EntityCreature) @@ -288,6 +303,13 @@ public class TEDemonPortal extends TileEntity this.houseCooldown = TEDemonPortal.buildingGridDelay; this.roadCooldown = TEDemonPortal.roadGridDelay; this.demonHoardCooldown = TEDemonPortal.demonHoardDelay; + + this.createRandomRoad(); + + if (this.createRandomBuilding(DemonBuilding.BUILDING_PORTAL, tier) >= 1) + { + this.buildingStage = 0; + } isInitialized = true; } @@ -312,6 +334,7 @@ public class TEDemonPortal extends TileEntity if(buildingStage >= 0 && buildingStage <=2) { AlchemicalWizardry.logger.info("BuildingStage = " + buildingStage); + AlchemicalWizardry.logger.info("Tier = " + this.tier); this.createPortalBuilding(buildingStage, nextDemonPortalName, tier); buildingStage++; return; @@ -894,11 +917,11 @@ public class TEDemonPortal extends TileEntity return new Int3(0, 0, 0); } - public void createGriddedRoad(int gridXi, int yi, int gridZi, ForgeDirection dir, int gridLength, boolean convertStarter) //Total grid length + public int createGriddedRoad(int gridXi, int yi, int gridZi, ForgeDirection dir, int gridLength, boolean convertStarter) //Total grid length { if (gridLength == 0 || gridLength == 1) { - return; + return 0; } if (convertStarter) @@ -922,7 +945,8 @@ public class TEDemonPortal extends TileEntity { DemonVillagePath path = new DemonVillagePath(xCoord + initGridX * 5, initY, zCoord + initGridZ * 5, dir, 6); - Int3 next = path.constructFullPath(this, worldObj, this.getRoadStepClearance()); + Int3AndBool temp = path.constructFullPath(this, worldObj, this.getRoadStepClearance()); + Int3 next = temp.coords; if (next != null) { @@ -930,6 +954,11 @@ public class TEDemonPortal extends TileEntity if(printDebug) AlchemicalWizardry.logger.info("" + initY); } + + if(!temp.bool) + { + return index; + } initGridX += dir.offsetX; initGridZ += dir.offsetZ; @@ -939,6 +968,8 @@ public class TEDemonPortal extends TileEntity this.setGridSpace(initGridX, initGridZ, new GridSpace(GridSpace.ROAD, initY)); } } + + return gridLength - 1; } public void expandAreaInNegX() @@ -1330,6 +1361,10 @@ public class TEDemonPortal extends TileEntity 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(); }