diff --git a/1.7.2/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java b/1.7.2/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java index 90d93322..62edf13c 100644 --- a/1.7.2/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java +++ b/1.7.2/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java @@ -105,17 +105,19 @@ import WayofTime.alchemicalWizardry.common.summoning.SummoningHelperAW; import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorRegistry; import WayofTime.alchemicalWizardry.common.tileEntity.TEAltar; import WayofTime.alchemicalWizardry.common.tileEntity.TEConduit; +import WayofTime.alchemicalWizardry.common.tileEntity.TEDemonPortal; import WayofTime.alchemicalWizardry.common.tileEntity.TEHomHeart; import WayofTime.alchemicalWizardry.common.tileEntity.TEMasterStone; import WayofTime.alchemicalWizardry.common.tileEntity.TEOrientable; import WayofTime.alchemicalWizardry.common.tileEntity.TEPedestal; import WayofTime.alchemicalWizardry.common.tileEntity.TEPlinth; +import WayofTime.alchemicalWizardry.common.tileEntity.TESchematicSaver; import WayofTime.alchemicalWizardry.common.tileEntity.TESocket; +import WayofTime.alchemicalWizardry.common.tileEntity.TESpectralContainer; import WayofTime.alchemicalWizardry.common.tileEntity.TESpellEffectBlock; import WayofTime.alchemicalWizardry.common.tileEntity.TESpellEnhancementBlock; import WayofTime.alchemicalWizardry.common.tileEntity.TESpellModifierBlock; import WayofTime.alchemicalWizardry.common.tileEntity.TESpellParadigmBlock; -import WayofTime.alchemicalWizardry.common.tileEntity.TESpectralContainer; import WayofTime.alchemicalWizardry.common.tileEntity.TETeleposer; import WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable; import WayofTime.alchemicalWizardry.common.tileEntity.gui.GuiHandler; @@ -234,6 +236,10 @@ public class AlchemicalWizardry @EventHandler public void preInit(FMLPreInitializationEvent event) { + (new File("config/BloodMagic/schematics")).mkdirs(); + + TEDemonPortal.loadBuildingList(); + MinecraftForge.EVENT_BUS.register(new LifeBucketHandler()); BloodMagicConfiguration.init(new File(event.getModConfigurationDirectory(), "AWWayofTime.cfg")); @@ -506,7 +512,9 @@ public class AlchemicalWizardry GameRegistry.registerTileEntity(TESpellEffectBlock.class, "containerSpellEffectBlock"); GameRegistry.registerTileEntity(TESpellModifierBlock.class, "containerSpellModifierBlock"); GameRegistry.registerTileEntity(TESpellEnhancementBlock.class, "containerSpellEnhancementBlock"); - GameRegistry.registerTileEntity(TESpectralContainer.class,"spectralContainerTileEntity"); + GameRegistry.registerTileEntity(TESpectralContainer.class,"spectralContainerTileEntity"); + GameRegistry.registerTileEntity(TEDemonPortal.class, "containerDemonPortal"); + GameRegistry.registerTileEntity(TESchematicSaver.class, "containerSchematicSaver"); //GameRegistry.registerBlock(ModBlocks.blockSpellEffect,"blockSpellEffect"); ModBlocks.bloodRune.setHarvestLevel("pickaxe", 2); ModBlocks.speedRune.setHarvestLevel("pickaxe", 2); diff --git a/1.7.2/main/java/WayofTime/alchemicalWizardry/ModBlocks.java b/1.7.2/main/java/WayofTime/alchemicalWizardry/ModBlocks.java index 37042571..bb5625a4 100644 --- a/1.7.2/main/java/WayofTime/alchemicalWizardry/ModBlocks.java +++ b/1.7.2/main/java/WayofTime/alchemicalWizardry/ModBlocks.java @@ -1,16 +1,42 @@ package WayofTime.alchemicalWizardry; -import cpw.mods.fml.common.registry.GameRegistry; -import WayofTime.alchemicalWizardry.common.LifeEssence; -import WayofTime.alchemicalWizardry.common.block.*; +import net.minecraft.block.Block; +import WayofTime.alchemicalWizardry.common.block.ArmourForge; +import WayofTime.alchemicalWizardry.common.block.BlockAltar; +import WayofTime.alchemicalWizardry.common.block.BlockBloodLightSource; +import WayofTime.alchemicalWizardry.common.block.BlockConduit; +import WayofTime.alchemicalWizardry.common.block.BlockDemonPortal; +import WayofTime.alchemicalWizardry.common.block.BlockHomHeart; +import WayofTime.alchemicalWizardry.common.block.BlockMasterStone; +import WayofTime.alchemicalWizardry.common.block.BlockPedestal; +import WayofTime.alchemicalWizardry.common.block.BlockPlinth; +import WayofTime.alchemicalWizardry.common.block.BlockSchematicSaver; +import WayofTime.alchemicalWizardry.common.block.BlockSocket; +import WayofTime.alchemicalWizardry.common.block.BlockSpectralContainer; +import WayofTime.alchemicalWizardry.common.block.BlockSpellEffect; +import WayofTime.alchemicalWizardry.common.block.BlockSpellEnhancement; +import WayofTime.alchemicalWizardry.common.block.BlockSpellModifier; +import WayofTime.alchemicalWizardry.common.block.BlockSpellParadigm; +import WayofTime.alchemicalWizardry.common.block.BlockTeleposer; +import WayofTime.alchemicalWizardry.common.block.BlockWritingTable; +import WayofTime.alchemicalWizardry.common.block.BloodRune; +import WayofTime.alchemicalWizardry.common.block.BloodStoneBrick; +import WayofTime.alchemicalWizardry.common.block.EfficiencyRune; +import WayofTime.alchemicalWizardry.common.block.EmptySocket; +import WayofTime.alchemicalWizardry.common.block.ImperfectRitualStone; +import WayofTime.alchemicalWizardry.common.block.LargeBloodStoneBrick; +import WayofTime.alchemicalWizardry.common.block.LifeEssenceBlock; +import WayofTime.alchemicalWizardry.common.block.RitualStone; +import WayofTime.alchemicalWizardry.common.block.RuneOfSacrifice; +import WayofTime.alchemicalWizardry.common.block.RuneOfSelfSacrifice; +import WayofTime.alchemicalWizardry.common.block.SpectralBlock; +import WayofTime.alchemicalWizardry.common.block.SpeedRune; import WayofTime.alchemicalWizardry.common.items.ItemBloodRuneBlock; import WayofTime.alchemicalWizardry.common.items.ItemSpellEffectBlock; import WayofTime.alchemicalWizardry.common.items.ItemSpellEnhancementBlock; import WayofTime.alchemicalWizardry.common.items.ItemSpellModifierBlock; import WayofTime.alchemicalWizardry.common.items.ItemSpellParadigmBlock; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.creativetab.CreativeTabs; +import cpw.mods.fml.common.registry.GameRegistry; /** * Created with IntelliJ IDEA. @@ -52,6 +78,8 @@ public class ModBlocks public static Block blockSpellModifier; public static Block blockSpellEnhancement; public static Block blockSpectralContainer; + public static Block blockBuildingSchematicSaver; + public static Block blockDemonPortal; public static void init() { @@ -83,6 +111,8 @@ public class ModBlocks blockSpellModifier = new BlockSpellModifier(); blockSpellEnhancement = new BlockSpellEnhancement(); blockSpectralContainer = new BlockSpectralContainer(); + blockDemonPortal = new BlockDemonPortal(); + blockBuildingSchematicSaver = new BlockSchematicSaver(); blockLifeEssence = new LifeEssenceBlock(); } @@ -120,6 +150,8 @@ public class ModBlocks GameRegistry.registerBlock(ModBlocks.blockSpellEffect, ItemSpellEffectBlock.class,"AlchemicalWizardry" + (ModBlocks.blockSpellEffect.getUnlocalizedName())); GameRegistry.registerBlock(ModBlocks.blockSpectralContainer, "spectralContainer"); + GameRegistry.registerBlock(ModBlocks.blockDemonPortal, "demonPortalMain"); + GameRegistry.registerBlock(ModBlocks.blockBuildingSchematicSaver, "blockSchemSaver"); } diff --git a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/block/BlockSchematicSaver.java b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/block/BlockSchematicSaver.java new file mode 100644 index 00000000..9c85e4fa --- /dev/null +++ b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/block/BlockSchematicSaver.java @@ -0,0 +1,43 @@ +package WayofTime.alchemicalWizardry.common.block; + +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import WayofTime.alchemicalWizardry.AlchemicalWizardry; +import WayofTime.alchemicalWizardry.common.tileEntity.TEDemonPortal; +import WayofTime.alchemicalWizardry.common.tileEntity.TESchematicSaver; + +public class BlockSchematicSaver extends BlockContainer +{ + public BlockSchematicSaver() + { + super(Material.rock); + setHardness(2.0F); + setResistance(5.0F); + setCreativeTab(AlchemicalWizardry.tabBloodMagic); + this.setBlockName("schematicSaver"); + } + + @Override + public TileEntity createNewTileEntity(World var1, int var2) + { + return new TESchematicSaver(); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float what, float these, float are) + { + if(world.isRemote) + { + return false; + } + + TESchematicSaver tileEntity = (TESchematicSaver) world.getTileEntity(x, y, z); + + tileEntity.rightClickBlock(player, side); + + return false; + } +} diff --git a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/block/LifeEssenceBlock.java b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/block/LifeEssenceBlock.java index ca5a6925..34676410 100644 --- a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/block/LifeEssenceBlock.java +++ b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/block/LifeEssenceBlock.java @@ -16,8 +16,7 @@ public class LifeEssenceBlock extends BlockFluidClassic { super(AlchemicalWizardry.lifeEssenceFluid, Material.water); AlchemicalWizardry.lifeEssenceFluid.setBlock(this); - AlchemicalWizardry.lifeEssenceFluid.setFlowingIcon(blockIcon); - AlchemicalWizardry.lifeEssenceFluid.setStillIcon(blockIcon); + //setCreativeTab(AlchemicalWizardry.tabBloodMagic); this.setBlockName("lifeEssenceFluidBlock"); } @@ -34,6 +33,8 @@ public class LifeEssenceBlock extends BlockFluidClassic public void registerBlockIcons(IIconRegister iconRegister) { this.blockIcon = iconRegister.registerIcon("AlchemicalWizardry:lifeEssenceStill"); + AlchemicalWizardry.lifeEssenceFluid.setFlowingIcon(blockIcon); + AlchemicalWizardry.lifeEssenceFluid.setStillIcon(blockIcon); //this.getFluid().setIcons(blockIcon); } diff --git a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/BlockSet.java b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/BlockSet.java index 6f5895bf..17800940 100644 --- a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/BlockSet.java +++ b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/BlockSet.java @@ -43,6 +43,11 @@ public class BlockSet } } + public List getPositions() + { + return positions; + } + public void addPositionToBlock(int xOffset, int yOffset, int zOffset) { positions.add(new Int3(xOffset, yOffset, zOffset)); diff --git a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/BuildingSchematic.java b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/BuildingSchematic.java index 6a2d1125..ec58a6b0 100644 --- a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/BuildingSchematic.java +++ b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/BuildingSchematic.java @@ -5,6 +5,8 @@ import java.util.List; import net.minecraft.block.Block; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import WayofTime.alchemicalWizardry.common.Int3; public class BuildingSchematic { @@ -38,8 +40,29 @@ public class BuildingSchematic blockList.add(set); } - public void buildAll(World world, int xCoord, int yCoord, int zCoord) + public void buildAll(World world, int xCoord, int yCoord, int zCoord, ForgeDirection dir) { + for(BlockSet set : blockList) + { + set.buildAll(world, xCoord, yCoord, zCoord, dir); + } + } + + public GridSpaceHolder createGSH() + { + GridSpaceHolder holder = new GridSpaceHolder(); + for(BlockSet set : blockList) + { + for(Int3 coords : set.getPositions()) + { + int gridX = (int)((coords.xCoord+2*Math.signum(coords.xCoord))/5); + int gridZ = (int)((coords.zCoord+2*Math.signum(coords.zCoord))/5); + + holder.setGridSpace(gridX, gridZ, new GridSpace()); + } + } + + return holder; } } \ No newline at end of file diff --git a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/DemonBuilding.java b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/DemonBuilding.java new file mode 100644 index 00000000..f6b85f7c --- /dev/null +++ b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/DemonBuilding.java @@ -0,0 +1,45 @@ +package WayofTime.alchemicalWizardry.common.demonVillage; + +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public class DemonBuilding +{ + public BuildingSchematic schematic; + public GridSpaceHolder area; + public int buildingTier; + public int type; + + public DemonBuilding(BuildingSchematic schematic) + { + this.schematic = schematic; + this.type = 0; + this.buildingTier = 0; + this.area = this.createGSHForSchematic(schematic); + } + + public String getName() + { + return schematic.name; + } + + public boolean isValid(GridSpaceHolder master, int gridX, int gridZ, ForgeDirection dir) + { + return area.doesContainAll(master, gridX, gridZ, dir); + } + + public void buildAll(World world, int xCoord, int yCoord, int zCoord, ForgeDirection dir) + { + schematic.buildAll(world, xCoord, yCoord, zCoord, dir); + } + + public void setAllGridSpaces(int xInit, int zInit, int yLevel, ForgeDirection dir, int type, GridSpaceHolder master) + { + area.setAllGridSpaces(xInit, zInit, yLevel, dir, type, master); + } + + public GridSpaceHolder createGSHForSchematic(BuildingSchematic scheme) + { + return scheme.createGSH(); + } +} diff --git a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/DemonVillagePath.java b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/DemonVillagePath.java index ce8db055..01645f35 100644 --- a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/DemonVillagePath.java +++ b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/DemonVillagePath.java @@ -95,8 +95,9 @@ public class DemonVillagePath int sign = 1; Block block1 = world.getBlock(xPos + xOffset, yPos + sign*yOffset, zPos + zOffset); + Block highBlock1 = world.getBlock(xPos + xOffset, yPos + sign*yOffset + 1, zPos + zOffset); - if(!world.isAirBlock(xPos + xOffset, yPos + sign*yOffset, zPos + zOffset) && this.isBlockReplaceable(block1) && world.isAirBlock(xPos + xOffset, yPos + sign*yOffset + 1, zPos + zOffset)) + 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)) { yPos += sign*yOffset; break; @@ -104,8 +105,9 @@ public class DemonVillagePath { sign = -1; Block block2 = world.getBlock(xPos + xOffset, yPos + sign*yOffset, zPos + zOffset); + Block highBlock2 = world.getBlock(xPos + xOffset, yPos + sign*yOffset + 1, zPos + zOffset); - if(!world.isAirBlock(xPos + xOffset, yPos + sign*yOffset, zPos + zOffset) && this.isBlockReplaceable(block2) && world.isAirBlock(xPos + xOffset, yPos + sign*yOffset + 1, zPos + zOffset)) + 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)) { yPos += sign*yOffset; break; @@ -114,7 +116,7 @@ public class DemonVillagePath } } - return new Int3(xi,yi,zi); + return new Int3(xPos,yPos,zPos); } public int getRoadRadius() diff --git a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/GridSpace.java b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/GridSpace.java index e92b513c..22536880 100644 --- a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/GridSpace.java +++ b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/GridSpace.java @@ -69,4 +69,9 @@ public class GridSpace { return type == this.ROAD || type == this.CROSSROAD; } + + public boolean isBuilding() + { + return type == this.HOUSE; + } } diff --git a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/GridSpaceHolder.java b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/GridSpaceHolder.java new file mode 100644 index 00000000..a0cd2cb1 --- /dev/null +++ b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/demonVillage/GridSpaceHolder.java @@ -0,0 +1,232 @@ +package WayofTime.alchemicalWizardry.common.demonVillage; + +import net.minecraftforge.common.util.ForgeDirection; + +public class GridSpaceHolder +{ + public GridSpace[][] area; + public int negXRadius; //These variables indicate how much the grid has expanded from the 1x1 + public int posXRadius; //matrix in each direction + public int negZRadius; + public int posZRadius; + + public GridSpaceHolder() + { + area = new GridSpace[1][1]; + area[0][0] = new GridSpace(); + } + + public void expandAreaInNegX() + { + GridSpace[][] newGrid = new GridSpace[negXRadius + posXRadius + 2][negZRadius + posZRadius + 1]; + for(int i=0; i<=negZRadius + posZRadius; i++) + { + newGrid[0][i] = new GridSpace(); + } + + for(int i=0; i<=negXRadius + posXRadius; i++) + { + for(int j=0; j<=negZRadius + posZRadius; j++) + { + newGrid[i+1][j] = area[i][j]; + } + } + + area = newGrid; + negXRadius += 1; + } + + public void expandAreaInPosX() + { + GridSpace[][] newGrid = new GridSpace[negXRadius + posXRadius + 2][negZRadius + posZRadius + 1]; + + for(int i=0; i<=negZRadius + posZRadius; i++) + { + newGrid[negXRadius + posXRadius + 1][i] = new GridSpace(); + } + + for(int i=0; i<=negXRadius + posXRadius; i++) + { + for(int j=0; j<=negZRadius + posZRadius; j++) + { + newGrid[i][j] = area[i][j]; + } + } + + area = newGrid; + posXRadius += 1; + } + + public void expandAreaInNegZ() + { + GridSpace[][] newGrid = new GridSpace[negXRadius + posXRadius + 1][negZRadius + posZRadius + 2]; + + System.out.println("x " + newGrid.length + "z " + newGrid[0].length); + + for(int i=0; i<=negXRadius + posXRadius; i++) + { + newGrid[i][0] = new GridSpace(); + } + + for(int i=0; i<=negXRadius + posXRadius; i++) + { + for(int j=0; j<=negZRadius + posZRadius; j++) + { + newGrid[i][j+1] = area[i][j]; + } + } + + area = newGrid; + negZRadius += 1; + } + + public void expandAreaInPosZ() + { + GridSpace[][] newGrid = new GridSpace[negXRadius + posXRadius + 1][negZRadius + posZRadius + 2]; + + for(int i=0; i<=negXRadius + posXRadius; i++) + { + newGrid[i][negZRadius + posZRadius + 1] = new GridSpace(); + } + + for(int i=0; i<=negXRadius + posXRadius; i++) + { + for(int j=0; j<=negZRadius + posZRadius; j++) + { + newGrid[i][j] = area[i][j]; + } + } + + area = newGrid; + posZRadius += 1; + } + + public GridSpace getGridSpace(int x, int z) + { + if(x > posXRadius|| x < -negXRadius || z > posZRadius || z < -negZRadius) + { + return new GridSpace(); + }else + { + return (area[x + negXRadius][z + negZRadius]); + } + } + + public void setGridSpace(int x, int z, GridSpace space) + { + if(x > posXRadius) + { + this.expandAreaInPosX(); + this.setGridSpace(x, z, space); + return; + }else if(x < -negXRadius) + { + this.expandAreaInNegX(); + this.setGridSpace(x, z, space); + return; + }else if(z > posZRadius) + { + this.expandAreaInPosZ(); + this.setGridSpace(x, z, space); + return; + }else if(z < -negZRadius) + { + this.expandAreaInNegZ(); + this.setGridSpace(x, z, space); + return; + }else + { + area[x + negXRadius][z + negZRadius] = space; + } + } + + public boolean doesContainAll(GridSpaceHolder master, int xInit, int zInit, ForgeDirection dir) + { + if(master != null) + { + for(int i=-negXRadius; i<=posXRadius; i++) + { + for(int j=-negZRadius; j<=posZRadius; j++) + { + GridSpace thisSpace = this.getGridSpace(i, j); + if(thisSpace.isEmpty()) + { + continue; + } + + int xOff = 0; + int zOff = 0; + + switch(dir) + { + case SOUTH: + xOff = -i; + zOff = -j; + break; + case WEST: + xOff = j; + zOff = -i; + break; + case EAST: + xOff = -j; + zOff = i; + break; + default: + xOff = i; + zOff = j; + break; + } + if(!master.getGridSpace(xInit + xOff, zInit + zOff).isEmpty()) + { + return false; + } + } + } + return true; + } + return false; + } + + public void setAllGridSpaces(int xInit, int zInit, int yLevel, ForgeDirection dir, int type, GridSpaceHolder master) + { + if(master != null) + { + for(int i=-negXRadius; i<=posXRadius; i++) + { + for(int j=-negZRadius; j<=posZRadius; j++) + { + GridSpace thisSpace = this.getGridSpace(i, j); + if(thisSpace.isEmpty()) + { + continue; + } + + int xOff = 0; + int zOff = 0; + + switch(dir) + { + case SOUTH: + xOff = -i; + zOff = -j; + break; + case WEST: + xOff = j; + zOff = -i; + break; + case EAST: + xOff = -j; + zOff = i; + break; + default: + xOff = i; + zOff = j; + break; + } + + master.setGridSpace(xInit + xOff, zInit + zOff, new GridSpace(type, yLevel)); + } + } + } + } +} diff --git a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEDemonPortal.java b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEDemonPortal.java index cd2edece..70ad21b0 100644 --- a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEDemonPortal.java +++ b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEDemonPortal.java @@ -1,6 +1,8 @@ package WayofTime.alchemicalWizardry.common.tileEntity; import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -21,16 +23,18 @@ import net.minecraftforge.common.util.ForgeDirection; import WayofTime.alchemicalWizardry.ModBlocks; import WayofTime.alchemicalWizardry.common.Int3; 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.GridSpace; +import WayofTime.alchemicalWizardry.common.demonVillage.GridSpaceHolder; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class TEDemonPortal extends TileEntity { - public static List buildingList = new ArrayList(); + public static List buildingList = new ArrayList(); public Random rand = new Random(); private GridSpace[][] area; @@ -369,6 +373,180 @@ public class TEDemonPortal extends TileEntity return new Int3(0,0,0); } + public Int3 findEmptySpaceNearRoad(ForgeDirection dir, int amount, int closeness) + { + int index = 0; + if(dir == ForgeDirection.NORTH) + { + System.out.print("NORTH!"); + for(int i=0; i<= negZRadius + posZRadius; i++) + { + for(int j=0; j<= negXRadius + posXRadius; j++) + { + GridSpace space = area[j][i]; + if(space.isEmpty()) + { + int yLevel = this.findNearestRoadYLevel(j-negXRadius, i-negZRadius, closeness); + if(yLevel == -1) + { + continue; + } + index++; + if(index >= amount) + { + return new Int3(j-negXRadius,yLevel,i-negZRadius); + } + } + } + } + }else if(dir == ForgeDirection.SOUTH) + { + for(int i=negZRadius + posZRadius; i >= 0 ; i--) + { + for(int j=0; j<= negXRadius + posXRadius; j++) + { + GridSpace space = area[j][i]; + int yLevel = this.findNearestRoadYLevel(j-negXRadius, i-negZRadius, closeness); + if(yLevel == -1) + { + continue; + } + if(space.isEmpty()) + { + index++; + if(index >= amount) + { + return new Int3(j-negXRadius,yLevel,i-negZRadius); + } + } + } + } + }else if(dir == ForgeDirection.EAST) + { + for(int i=negXRadius + posXRadius; i >= 0; i--) + { + for(int j=0; j <= negZRadius + posZRadius ; j++) + { + GridSpace space = area[i][j]; + int yLevel = this.findNearestRoadYLevel(i-negXRadius, j-negZRadius, closeness); + if(yLevel == -1) + { + continue; + } + if(space.isEmpty()) + { + index++; + if(index >= amount) + { + return new Int3(i-negXRadius,yLevel,j-negZRadius); + } + } + } + } + }else if(dir == ForgeDirection.WEST) + { + for(int i=0; i <= negXRadius + posXRadius; i++) + { + for(int j=0; j <= negZRadius + posZRadius ; j++) + { + GridSpace space = area[i][j]; + int yLevel = this.findNearestRoadYLevel(i-negXRadius, j-negZRadius, closeness); + if(yLevel == -1) + { + continue; + } + if(space.isEmpty()) + { + index++; + if(index >= amount) + { + return new Int3(i-negXRadius,yLevel,j-negZRadius); + } + } + } + } + } + + return new Int3(0,0,0); + } + + public Int3 findEmptySpaceFromDirection(ForgeDirection dir, int amount) + { + int index = 0; + if(dir == ForgeDirection.NORTH) + { + System.out.print("NORTH!"); + for(int i=0; i<= negZRadius + posZRadius; i++) + { + for(int j=0; j<= negXRadius + posXRadius; j++) + { + GridSpace space = area[j][i]; + if(space.isEmpty()) + { + index++; + if(index >= amount) + { + return new Int3(j-negXRadius,space.getYLevel(),i-negZRadius); + } + } + } + } + }else if(dir == ForgeDirection.SOUTH) + { + for(int i=negZRadius + posZRadius; i >= 0 ; i--) + { + for(int j=0; j<= negXRadius + posXRadius; j++) + { + GridSpace space = area[j][i]; + if(space.isEmpty()) + { + index++; + if(index >= amount) + { + return new Int3(j-negXRadius,space.getYLevel(),i-negZRadius); + } + } + } + } + }else if(dir == ForgeDirection.EAST) + { + for(int i=negXRadius + posXRadius; i >= 0; i--) + { + for(int j=0; j <= negZRadius + posZRadius ; j++) + { + GridSpace space = area[i][j]; + if(space.isEmpty()) + { + index++; + if(index >= amount) + { + return new Int3(i-negXRadius,space.getYLevel(),j-negZRadius); + } + } + } + } + }else if(dir == ForgeDirection.WEST) + { + for(int i=0; i <= negXRadius + posXRadius; i++) + { + for(int j=0; j <= negZRadius + posZRadius ; j++) + { + GridSpace space = area[i][j]; + if(space.isEmpty()) + { + index++; + if(index >= amount) + { + return new Int3(i-negXRadius,space.getYLevel(),j-negZRadius); + } + } + } + } + } + + return new Int3(0,0,0); + } + public void createGriddedRoad(int gridXi, int yi, int gridZi, ForgeDirection dir, int gridLength, boolean convertStarter) //Total grid length { if(gridLength == 0 || gridLength == 1) @@ -402,6 +580,7 @@ public class TEDemonPortal extends TileEntity if(next != null) { initY = next.yCoord; + System.out.println("" + initY); } initGridX += dir.offsetX; @@ -540,12 +719,101 @@ public class TEDemonPortal extends TileEntity public void rightClickBlock(EntityPlayer player, int side) { - this.testGson(); + //this.testGson(); Int3 roadMarker = this.getNextRoadMarker(); this.initialize(); - this.createRandomRoad(); + if(ForgeDirection.getOrientation(side) == ForgeDirection.UP) + { + this.createRandomBuilding(); + }else + { + this.createRandomRoad(); + } + } + + public void createRandomBuilding() + { + 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; + } + + int length = 5; + + Int3 space = findEmptySpaceNearRoad(dir, 3*(rand.nextInt(negXRadius + negZRadius + posXRadius + posZRadius))+1, 2); + + int x = space.xCoord; + int z = space.zCoord; + int yLevel = space.yCoord; + + GridSpace newSpace = this.getGridSpace(x, z); + if(!newSpace.isEmpty()) + { + return; + } + + if(yLevel == -1) + { + return; + } + + GridSpaceHolder grid = this.createGSH(); + + ForgeDirection chosenDirection = ForgeDirection.NORTH; + + for(DemonBuilding build : TEDemonPortal.buildingList) + { + if(build.isValid(grid, x, z, chosenDirection)) + { + build.buildAll(worldObj, xCoord + x*5, yLevel, zCoord + z*5, chosenDirection); + build.setAllGridSpaces(x, z, yLevel, chosenDirection, GridSpace.HOUSE, grid); + this.loadGSH(grid); + } + } + + System.out.println("X: " + x + " Z: " + z + " Direction: " + dir.toString()); + } + + public int findNearestRoadYLevel(int xCoord, int zCoord, int maxDistance) + { + for(int l=1; l<=maxDistance; l++) + { + for(int i=-l; i<=l; i++) + { + for(int j=-l; j<=l; j++) + { + if(Math.abs(i)!=l && Math.abs(j)!=l) + { + continue; + } + + if(this.getGridSpace(xCoord + i, zCoord + j).isRoadSegment()) + { + return this.getGridSpace(xCoord + i, zCoord + j).getYLevel(); + } + } + } + } + + return -1; } public void testGson() @@ -651,4 +919,58 @@ public class TEDemonPortal extends TileEntity { return 1; } + + 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; + } + + public void loadGSH(GridSpaceHolder grid) + { + this.area = grid.area; + this.negXRadius = grid.negXRadius; + this.negZRadius = grid.negZRadius; + this.posXRadius = grid.posXRadius; + this.posZRadius = grid.posZRadius; + } + + public static void loadBuildingList() + { + String folder = "config/BloodMagic/schematics"; + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + File file = new File(folder); + File[] files = file.listFiles(); + BufferedReader br; + + try{ + for(File f : files) + { + br = new BufferedReader(new FileReader(f)); + BuildingSchematic schema = gson.fromJson(br, BuildingSchematic.class); + TEDemonPortal.buildingList.add(new DemonBuilding(schema)); + } + }catch(FileNotFoundException e) + { + e.printStackTrace(); + } +// +// try { +// br = new BufferedReader(new FileReader(folder + "test3.json")); +// BuildingSchematic schema = gson.fromJson(br, BuildingSchematic.class); +// TEDemonPortal.buildingList.add(new DemonBuilding(schema)); +// } catch (FileNotFoundException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } + + + } } diff --git a/1.7.2/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TESchematicSaver.java b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TESchematicSaver.java new file mode 100644 index 00000000..8558b667 --- /dev/null +++ b/1.7.2/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TESchematicSaver.java @@ -0,0 +1,158 @@ +package WayofTime.alchemicalWizardry.common.tileEntity; + +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import WayofTime.alchemicalWizardry.ModBlocks; +import WayofTime.alchemicalWizardry.common.demonVillage.BuildingSchematic; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class TESchematicSaver extends TileEntity +{ + public Block targetBlock = ModBlocks.largeBloodStoneBrick; + + public void rightClickBlock(EntityPlayer player, int side) + { + BuildingSchematic schematic = new BuildingSchematic(); + + int negX = this.getNegXLimit(); + int negY = this.getNegYLimit(); + int negZ = this.getNegZLimit(); + int posX = this.getPosXLimit(); + int posY = this.getPosYLimit(); + int posZ = this.getPosZLimit(); + + for(int i=-negX+1; i<=posX-1; i++) + { + for(int j=-negY+1; j<=posY-1; j++) + { + for(int k=-negZ+1; k<=posZ-1; k++) + { + int meta = worldObj.getBlockMetadata(xCoord + i, yCoord + j, zCoord + k); + Block block = worldObj.getBlock(xCoord + i, yCoord + j, zCoord + k); + + if(!block.isAir(worldObj, xCoord + i, yCoord + j, zCoord + k)) + { + schematic.addBlockWithMeta(block, meta, i, j, k); + } + + } + } + + System.out.println("" + i); + } + + System.out.println("I got here!"); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String json = gson.toJson(schematic); + System.out.println("Here, too!"); + Writer writer; + try + { + writer = new FileWriter("config/BloodMagic/schematics/" + new Random().nextInt() + ".json"); + writer.write(json); + writer.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public int getPosYLimit() + { + int i=1; + while(i<100) + { + if(targetBlock == (worldObj.getBlock(xCoord, yCoord + i, zCoord))) + { + return i; + } + + i++; + } + return 1; + } + + public int getNegYLimit() + { + int i=1; + while(i<100) + { + if(targetBlock == (worldObj.getBlock(xCoord, yCoord - i, zCoord))) + { + return i; + } + + i++; + } + return 1; + } + + public int getPosXLimit() + { + int i=1; + while(i<100) + { + if(targetBlock == (worldObj.getBlock(xCoord + i, yCoord, zCoord))) + { + return i; + } + + i++; + } + return 1; + } + + public int getNegXLimit() + { + int i=1; + while(i<100) + { + if(targetBlock == (worldObj.getBlock(xCoord - i, yCoord, zCoord))) + { + return i; + } + + i++; + } + return 1; + } + + public int getPosZLimit() + { + int i=1; + while(i<100) + { + if(targetBlock == (worldObj.getBlock(xCoord, yCoord, zCoord + i))) + { + return i; + } + + i++; + } + return 1; + } + + public int getNegZLimit() + { + int i=1; + while(i<100) + { + if(targetBlock == (worldObj.getBlock(xCoord, yCoord, zCoord - i))) + { + return i; + } + + i++; + } + return 1; + } +} \ No newline at end of file diff --git a/1.7.2/main/java/joshie/alchemicalWizardy/ShapedBloodOrbRecipe.java b/1.7.2/main/java/joshie/alchemicalWizardy/ShapedBloodOrbRecipe.java index 69939943..f508fe6a 100644 --- a/1.7.2/main/java/joshie/alchemicalWizardy/ShapedBloodOrbRecipe.java +++ b/1.7.2/main/java/joshie/alchemicalWizardy/ShapedBloodOrbRecipe.java @@ -23,8 +23,8 @@ public class ShapedBloodOrbRecipe implements IRecipe { private ItemStack output = null; private Object[] input = null; - private int width = 0; - private int height = 0; + public int width = 0; + public int height = 0; private boolean mirrored = true; public ShapedBloodOrbRecipe(Block result, Object... recipe) { diff --git a/1.7.2/main/java/joshie/alchemicalWizardy/nei/NEIBloodOrbShapedHandler.java b/1.7.2/main/java/joshie/alchemicalWizardy/nei/NEIBloodOrbShapedHandler.java index 15730eb3..95faa19b 100644 --- a/1.7.2/main/java/joshie/alchemicalWizardy/nei/NEIBloodOrbShapedHandler.java +++ b/1.7.2/main/java/joshie/alchemicalWizardy/nei/NEIBloodOrbShapedHandler.java @@ -107,8 +107,8 @@ public class NEIBloodOrbShapedHandler extends ShapedRecipeHandler { int width; int height; try { - width = ReflectionManager.getField(ShapedBloodOrbRecipe.class, Integer.class, recipe, 4); - height = ReflectionManager.getField(ShapedBloodOrbRecipe.class, Integer.class, recipe, 5); + width = recipe.width; + height = recipe.height; } catch (Exception e) { e.printStackTrace(); return null;