Anti-comments sweep!

This commit is contained in:
Tombenpotter 2014-10-13 22:33:20 +02:00
parent e6a10f3f06
commit dea1f87078
454 changed files with 23594 additions and 26739 deletions

View file

@ -1,195 +1,195 @@
package WayofTime.alchemicalWizardry.common.demonVillage;
import java.util.ArrayList;
import java.util.List;
import WayofTime.alchemicalWizardry.common.Int3;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import WayofTime.alchemicalWizardry.common.Int3;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
public class BlockSet
import java.util.ArrayList;
import java.util.List;
public class BlockSet
{
protected String blockid;
protected int[] metadata;
protected List<Int3> positions;
public BlockSet()
{
this(Blocks.stone);
}
public BlockSet(String blockid)
{
this.blockid = blockid;
this.metadata = new int[4];
positions = new ArrayList();
}
public BlockSet(Block block)
{
this(BlockSet.getPairedIdForBlock(block));
}
public BlockSet(Block block, int meta)
{
this(block);
for(int i=0; i<metadata.length; i++)
{
metadata[i] = meta;
}
if(block instanceof BlockStairs)
{
int[] northSet = new int[]{2,3,0,1};
int[] eastSet = new int[]{1,0,2,3};
int[] southSet = new int[]{3,2,1,0};
int[] westSet = new int[]{0,1,3,2};
int[] northUpSet = new int[]{6,7,4,5};
int[] eastUpSet = new int[]{5,4,6,7};
int[] southUpSet = new int[]{7,6,5,4};
int[] westUpSet = new int[]{4,5,7,6};
switch(meta)
{
case 0:
metadata = westSet;
break;
case 1:
metadata = eastSet;
break;
case 2:
metadata = northSet;
break;
case 3:
metadata = southSet;
break;
case 4:
metadata = westUpSet;
break;
case 5:
metadata = eastUpSet;
break;
case 6:
metadata = northUpSet;
break;
case 7:
metadata = southUpSet;
break;
}
}
}
public List<Int3> getPositions()
{
return positions;
}
public void addPositionToBlock(int xOffset, int yOffset, int zOffset)
{
positions.add(new Int3(xOffset, yOffset, zOffset));
}
public Block getBlock()
{
return this.getBlockForString(blockid);
}
public static String getPairedIdForBlock(Block block)
{
UniqueIdentifier un = GameRegistry.findUniqueIdentifierFor(block);
String name = "";
if(un != null)
{
name = un.modId + ":" + un.name;
}
return name;
}
public static Block getBlockForString(String str)
{
String[] parts = str.split(":");
String modId = parts[0];
String name = parts[1];
return GameRegistry.findBlock(modId, name);
}
public int getMetaForDirection(ForgeDirection dir)
{
if(metadata.length < 4)
{
return 0;
}
switch(dir)
{
case NORTH:
return metadata[0];
case SOUTH:
return metadata[1];
case WEST:
return metadata[2];
case EAST:
return metadata[3];
default:
return 0;
}
}
public void buildAtIndex(World world, int xCoord, int yCoord, int zCoord, ForgeDirection dir, int index)
{
Block block = this.getBlock();
if(index >= positions.size() || block == null)
{
return;
}
Int3 position = positions.get(index);
int xOff = position.xCoord;
int yOff = position.yCoord;
int zOff = position.zCoord;
int meta = this.getMetaForDirection(dir);
switch(dir)
{
case NORTH:
break;
case SOUTH:
xOff *= -1;
zOff *= -1;
break;
case WEST:
int temp = zOff;
zOff = xOff * -1;
xOff = temp;
break;
case EAST:
int temp2 = zOff * -1;
zOff = xOff;
xOff = temp2;
break;
default:
}
world.setBlock(xCoord + xOff, yCoord + yOff, zCoord + zOff, block, meta, 3);
}
public void buildAll(World world, int xCoord, int yCoord, int zCoord, ForgeDirection dir)
{
for(int i=0; i<positions.size(); i++)
{
this.buildAtIndex(world, xCoord, yCoord, zCoord, dir, i);
}
}
public boolean isContained(Block block, int defaultMeta)
{
Block thisBlock = this.getBlock();
return thisBlock == null ? false : thisBlock.equals(block) && this.metadata[0] == defaultMeta;
}
protected String blockid;
protected int[] metadata;
protected List<Int3> positions;
public BlockSet()
{
this(Blocks.stone);
}
public BlockSet(String blockid)
{
this.blockid = blockid;
this.metadata = new int[4];
positions = new ArrayList();
}
public BlockSet(Block block)
{
this(BlockSet.getPairedIdForBlock(block));
}
public BlockSet(Block block, int meta)
{
this(block);
for (int i = 0; i < metadata.length; i++)
{
metadata[i] = meta;
}
if (block instanceof BlockStairs)
{
int[] northSet = new int[]{2, 3, 0, 1};
int[] eastSet = new int[]{1, 0, 2, 3};
int[] southSet = new int[]{3, 2, 1, 0};
int[] westSet = new int[]{0, 1, 3, 2};
int[] northUpSet = new int[]{6, 7, 4, 5};
int[] eastUpSet = new int[]{5, 4, 6, 7};
int[] southUpSet = new int[]{7, 6, 5, 4};
int[] westUpSet = new int[]{4, 5, 7, 6};
switch (meta)
{
case 0:
metadata = westSet;
break;
case 1:
metadata = eastSet;
break;
case 2:
metadata = northSet;
break;
case 3:
metadata = southSet;
break;
case 4:
metadata = westUpSet;
break;
case 5:
metadata = eastUpSet;
break;
case 6:
metadata = northUpSet;
break;
case 7:
metadata = southUpSet;
break;
}
}
}
public List<Int3> getPositions()
{
return positions;
}
public void addPositionToBlock(int xOffset, int yOffset, int zOffset)
{
positions.add(new Int3(xOffset, yOffset, zOffset));
}
public Block getBlock()
{
return this.getBlockForString(blockid);
}
public static String getPairedIdForBlock(Block block)
{
UniqueIdentifier un = GameRegistry.findUniqueIdentifierFor(block);
String name = "";
if (un != null)
{
name = un.modId + ":" + un.name;
}
return name;
}
public static Block getBlockForString(String str)
{
String[] parts = str.split(":");
String modId = parts[0];
String name = parts[1];
return GameRegistry.findBlock(modId, name);
}
public int getMetaForDirection(ForgeDirection dir)
{
if (metadata.length < 4)
{
return 0;
}
switch (dir)
{
case NORTH:
return metadata[0];
case SOUTH:
return metadata[1];
case WEST:
return metadata[2];
case EAST:
return metadata[3];
default:
return 0;
}
}
public void buildAtIndex(World world, int xCoord, int yCoord, int zCoord, ForgeDirection dir, int index)
{
Block block = this.getBlock();
if (index >= positions.size() || block == null)
{
return;
}
Int3 position = positions.get(index);
int xOff = position.xCoord;
int yOff = position.yCoord;
int zOff = position.zCoord;
int meta = this.getMetaForDirection(dir);
switch (dir)
{
case NORTH:
break;
case SOUTH:
xOff *= -1;
zOff *= -1;
break;
case WEST:
int temp = zOff;
zOff = xOff * -1;
xOff = temp;
break;
case EAST:
int temp2 = zOff * -1;
zOff = xOff;
xOff = temp2;
break;
default:
}
world.setBlock(xCoord + xOff, yCoord + yOff, zCoord + zOff, block, meta, 3);
}
public void buildAll(World world, int xCoord, int yCoord, int zCoord, ForgeDirection dir)
{
for (int i = 0; i < positions.size(); i++)
{
this.buildAtIndex(world, xCoord, yCoord, zCoord, dir, i);
}
}
public boolean isContained(Block block, int defaultMeta)
{
Block thisBlock = this.getBlock();
return thisBlock == null ? false : thisBlock.equals(block) && this.metadata[0] == defaultMeta;
}
}

View file

@ -1,183 +1,180 @@
package WayofTime.alchemicalWizardry.common.demonVillage;
import WayofTime.alchemicalWizardry.ModBlocks;
import WayofTime.alchemicalWizardry.common.Int3;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import WayofTime.alchemicalWizardry.ModBlocks;
import WayofTime.alchemicalWizardry.common.Int3;
public class BuildingSchematic
public class BuildingSchematic
{
public String name;
public int doorX;
public int doorZ;
public int doorY;
public int buildingTier;
public int buildingType;
public List<BlockSet> blockList;
public BuildingSchematic()
{
this("");
}
public BuildingSchematic(String name)
{
this.name = name;
blockList = new ArrayList();
this.doorX = 0;
this.doorZ = 0;
this.doorY = 0;
this.buildingTier = 0;
this.buildingType = DemonBuilding.BUILDING_HOUSE;
}
public void addBlockWithMeta(Block block, int meta, int xOffset, int yOffset, int zOffset)
{
for(BlockSet set : blockList)
{
if(set.isContained(block, meta))
{
set.addPositionToBlock(xOffset, yOffset, zOffset);
return;
}
}
BlockSet set = new BlockSet(block, meta);
set.addPositionToBlock(xOffset, yOffset, zOffset);
blockList.add(set);
}
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(GridSpace.HOUSE,0));
}
}
return holder;
}
public Int3 getGridSpotOfDoor()
{
int gridX = (int)((doorX+2*Math.signum(doorX))/5);
int gridZ = (int)((doorZ+2*Math.signum(doorZ))/5);
return new Int3(gridX, doorY, gridZ);
}
public List<Int3> getGriddedPositions(ForgeDirection dir)
{
List<Int3> positionList = new ArrayList();
for(BlockSet blockSet : blockList)
{
for(Int3 pos : blockSet.getPositions())
{
int xOff = pos.xCoord;
int zOff = pos.zCoord;
switch(dir)
{
case SOUTH:
xOff *= -1;
zOff *= -1;
break;
case WEST:
int temp = zOff;
zOff = xOff * -1;
xOff = temp;
break;
case EAST:
int temp2 = zOff * -1;
zOff = xOff;
xOff = temp2;
break;
default:
}
Int3 nextPos = new Int3(xOff, 0, zOff);
if(!positionList.contains(nextPos))
{
positionList.add(nextPos);
}
}
}
return positionList;
}
public void destroyAllInField(World world, int xCoord, int yCoord, int zCoord, ForgeDirection dir)
{
GridSpaceHolder grid = this.createGSH(); //GridSpaceHolder is not aware of the buildings - need to use the schematic
List<Int3> positionList = getGriddedPositions(dir);
for(int i=this.getMinY(); i<=this.getMaxY(); i++)
{
for(Int3 pos : positionList)
{
Block block = world.getBlock(xCoord + pos.xCoord, yCoord + i, zCoord + pos.zCoord);
if(block != ModBlocks.blockDemonPortal)
{
world.setBlockToAir(xCoord + pos.xCoord, yCoord + i, zCoord + pos.zCoord);
}
}
//grid.destroyAllInGridSpaces(world, xCoord, yCoord + i, zCoord, dir); //Deprecated method
}
}
public int getMinY()
{
int min = 0;
for(BlockSet set : blockList)
{
for(Int3 pos : set.getPositions())
{
if(pos.yCoord < min)
{
min = pos.yCoord;
}
}
}
return min;
}
public int getMaxY()
{
int max = 0;
for(BlockSet set : blockList)
{
for(Int3 pos : set.getPositions())
{
if(pos.yCoord > max)
{
max = pos.yCoord;
}
}
}
return max;
}
public String name;
public int doorX;
public int doorZ;
public int doorY;
public int buildingTier;
public int buildingType;
public List<BlockSet> blockList;
public BuildingSchematic()
{
this("");
}
public BuildingSchematic(String name)
{
this.name = name;
blockList = new ArrayList();
this.doorX = 0;
this.doorZ = 0;
this.doorY = 0;
this.buildingTier = 0;
this.buildingType = DemonBuilding.BUILDING_HOUSE;
}
public void addBlockWithMeta(Block block, int meta, int xOffset, int yOffset, int zOffset)
{
for (BlockSet set : blockList)
{
if (set.isContained(block, meta))
{
set.addPositionToBlock(xOffset, yOffset, zOffset);
return;
}
}
BlockSet set = new BlockSet(block, meta);
set.addPositionToBlock(xOffset, yOffset, zOffset);
blockList.add(set);
}
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(GridSpace.HOUSE, 0));
}
}
return holder;
}
public Int3 getGridSpotOfDoor()
{
int gridX = (int) ((doorX + 2 * Math.signum(doorX)) / 5);
int gridZ = (int) ((doorZ + 2 * Math.signum(doorZ)) / 5);
return new Int3(gridX, doorY, gridZ);
}
public List<Int3> getGriddedPositions(ForgeDirection dir)
{
List<Int3> positionList = new ArrayList();
for (BlockSet blockSet : blockList)
{
for (Int3 pos : blockSet.getPositions())
{
int xOff = pos.xCoord;
int zOff = pos.zCoord;
switch (dir)
{
case SOUTH:
xOff *= -1;
zOff *= -1;
break;
case WEST:
int temp = zOff;
zOff = xOff * -1;
xOff = temp;
break;
case EAST:
int temp2 = zOff * -1;
zOff = xOff;
xOff = temp2;
break;
default:
}
Int3 nextPos = new Int3(xOff, 0, zOff);
if (!positionList.contains(nextPos))
{
positionList.add(nextPos);
}
}
}
return positionList;
}
public void destroyAllInField(World world, int xCoord, int yCoord, int zCoord, ForgeDirection dir)
{
GridSpaceHolder grid = this.createGSH(); //GridSpaceHolder is not aware of the buildings - need to use the schematic
List<Int3> positionList = getGriddedPositions(dir);
for (int i = this.getMinY(); i <= this.getMaxY(); i++)
{
for (Int3 pos : positionList)
{
Block block = world.getBlock(xCoord + pos.xCoord, yCoord + i, zCoord + pos.zCoord);
if (block != ModBlocks.blockDemonPortal)
{
world.setBlockToAir(xCoord + pos.xCoord, yCoord + i, zCoord + pos.zCoord);
}
}
}
}
public int getMinY()
{
int min = 0;
for (BlockSet set : blockList)
{
for (Int3 pos : set.getPositions())
{
if (pos.yCoord < min)
{
min = pos.yCoord;
}
}
}
return min;
}
public int getMaxY()
{
int max = 0;
for (BlockSet set : blockList)
{
for (Int3 pos : set.getPositions())
{
if (pos.yCoord > max)
{
max = pos.yCoord;
}
}
}
return max;
}
}

View file

@ -1,120 +1,120 @@
package WayofTime.alchemicalWizardry.common.demonVillage;
import WayofTime.alchemicalWizardry.common.Int3;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import WayofTime.alchemicalWizardry.common.Int3;
public class DemonBuilding
public class DemonBuilding
{
public static final int BUILDING_HOUSE = 0;
public static final int BUILDING_PORTAL = 1;
public BuildingSchematic schematic;
public GridSpaceHolder area;
public int buildingTier;
public int buildingType;
public Int3 doorGridSpace;
public DemonBuilding(BuildingSchematic schematic)
{
this.schematic = schematic;
this.buildingType = schematic.buildingType;
this.buildingTier = schematic.buildingTier;
this.area = this.createGSHForSchematic(schematic);
this.doorGridSpace = schematic.getGridSpotOfDoor();
}
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)
{
switch(this.buildingType)
{
case DemonBuilding.BUILDING_HOUSE:
return scheme.createGSH();
case DemonBuilding.BUILDING_PORTAL:
}
return scheme.createGSH();
}
public Int3 getDoorSpace(ForgeDirection dir)
{
int x = 0;
int z = 0;
switch(dir)
{
case SOUTH:
x = -doorGridSpace.xCoord;
z = -doorGridSpace.zCoord;
break;
case WEST:
x = doorGridSpace.zCoord;
z = -doorGridSpace.xCoord;
break;
case EAST:
x = -doorGridSpace.zCoord;
z = doorGridSpace.xCoord;
break;
default:
x = doorGridSpace.xCoord;
z = doorGridSpace.zCoord;
break;
}
return new Int3(x, doorGridSpace.yCoord, z);
}
public Int3 getGridOffsetFromRoad(ForgeDirection sideOfRoad, int yLevel)
{
Int3 doorSpace = this.getDoorSpace(sideOfRoad);
int x = doorSpace.xCoord;
int z = doorSpace.zCoord;
switch(sideOfRoad)
{
case SOUTH:
z++;
break;
case EAST:
x++;
break;
case WEST:
x--;
break;
default:
z--;
break;
}
return new Int3(x, yLevel, z);
}
public void destroyAllInField(World world, int xCoord, int yCoord, int zCoord, ForgeDirection dir)
{
schematic.destroyAllInField(world, xCoord, yCoord, zCoord, dir);
}
public int getNumberOfGridSpaces()
{
return area.getNumberOfGridSpaces();
}
public static final int BUILDING_HOUSE = 0;
public static final int BUILDING_PORTAL = 1;
public BuildingSchematic schematic;
public GridSpaceHolder area;
public int buildingTier;
public int buildingType;
public Int3 doorGridSpace;
public DemonBuilding(BuildingSchematic schematic)
{
this.schematic = schematic;
this.buildingType = schematic.buildingType;
this.buildingTier = schematic.buildingTier;
this.area = this.createGSHForSchematic(schematic);
this.doorGridSpace = schematic.getGridSpotOfDoor();
}
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)
{
switch (this.buildingType)
{
case DemonBuilding.BUILDING_HOUSE:
return scheme.createGSH();
case DemonBuilding.BUILDING_PORTAL:
}
return scheme.createGSH();
}
public Int3 getDoorSpace(ForgeDirection dir)
{
int x = 0;
int z = 0;
switch (dir)
{
case SOUTH:
x = -doorGridSpace.xCoord;
z = -doorGridSpace.zCoord;
break;
case WEST:
x = doorGridSpace.zCoord;
z = -doorGridSpace.xCoord;
break;
case EAST:
x = -doorGridSpace.zCoord;
z = doorGridSpace.xCoord;
break;
default:
x = doorGridSpace.xCoord;
z = doorGridSpace.zCoord;
break;
}
return new Int3(x, doorGridSpace.yCoord, z);
}
public Int3 getGridOffsetFromRoad(ForgeDirection sideOfRoad, int yLevel)
{
Int3 doorSpace = this.getDoorSpace(sideOfRoad);
int x = doorSpace.xCoord;
int z = doorSpace.zCoord;
switch (sideOfRoad)
{
case SOUTH:
z++;
break;
case EAST:
x++;
break;
case WEST:
x--;
break;
default:
z--;
break;
}
return new Int3(x, yLevel, z);
}
public void destroyAllInField(World world, int xCoord, int yCoord, int zCoord, ForgeDirection dir)
{
schematic.destroyAllInField(world, xCoord, yCoord, zCoord, dir);
}
public int getNumberOfGridSpaces()
{
return area.getNumberOfGridSpaces();
}
}

View file

@ -2,21 +2,21 @@ package WayofTime.alchemicalWizardry.common.demonVillage;
import net.minecraft.world.World;
public class DemonCrosspath
public class DemonCrosspath
{
private int xCoord;
private int yLevel;
private int zCoord;
public DemonCrosspath(int xCoord, int yLevel, int zCoord)
{
this.xCoord = xCoord;
this.yLevel = yLevel;
this.zCoord = zCoord;
}
public void createCrosspath(World world)
{
}
private int xCoord;
private int yLevel;
private int zCoord;
public DemonCrosspath(int xCoord, int yLevel, int zCoord)
{
this.xCoord = xCoord;
this.yLevel = yLevel;
this.zCoord = zCoord;
}
public void createCrosspath(World world)
{
}
}

View file

@ -1,135 +1,135 @@
package WayofTime.alchemicalWizardry.common.demonVillage;
import WayofTime.alchemicalWizardry.ModBlocks;
import WayofTime.alchemicalWizardry.common.Int3;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import WayofTime.alchemicalWizardry.ModBlocks;
import WayofTime.alchemicalWizardry.common.Int3;
public class DemonVillagePath
public class DemonVillagePath
{
public int xi;
public int yi;
public int zi;
public ForgeDirection dir;
public int length;
public DemonVillagePath(int xi, int yi, int zi, ForgeDirection dir, int length)
{
this.xi = xi;
this.yi = yi;
this.zi = zi;
this.dir = dir;
this.length = length;
}
public Int3 constructFullPath(World world, int clearance, Block block, int meta)
{
int xPos = this.xi;
int yPos = this.yi;
int zPos = this.zi;
int rad = this.getRoadRadius();
for(int i=-rad; i<=rad; i++)
{
this.constructPartialPath(world, clearance, block, meta, xPos-rad*dir.offsetX+i*dir.offsetZ, yPos, zPos-rad*dir.offsetZ+i*dir.offsetX, dir, length+2*rad);
}
return this.getFinalLocation(world, clearance);
}
public void constructPartialPath(World world, int clearance, Block roadBlock, int meta, int xi, int yi, int zi, ForgeDirection dir, int length)
{
int xPos = xi;
int yPos = yi;
int zPos = zi;
for(int i=0; i<length; i++)
{
int xOffset = i*dir.offsetX;
int zOffset = i*dir.offsetZ;
for(int yOffset=0; yOffset<=clearance; yOffset++)
{
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(!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, roadBlock, meta, 3);
yPos += sign*yOffset;
break;
}else
{
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(!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, roadBlock, meta, 3);
yPos += sign*yOffset;
break;
}
}
}
}
}
public Int3 getFinalLocation(World world, int clearance)
{
int xPos = xi;
int yPos = yi;
int zPos = zi;
for(int i=0; i<length; i++)
{
int xOffset = i*dir.offsetX;
int zOffset = i*dir.offsetZ;
for(int yOffset=0; yOffset<=clearance; yOffset++)
{
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(!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;
}else
{
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(!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;
}
}
}
}
return new Int3(xPos,yPos,zPos);
}
public int getRoadRadius()
{
return 1;
}
public boolean isBlockReplaceable(Block block)
{
if(block.getMaterial() == Material.leaves || block.getMaterial() == Material.vine)
{
return false;
}
return !block.equals(ModBlocks.blockDemonPortal);
}
public int xi;
public int yi;
public int zi;
public ForgeDirection dir;
public int length;
public DemonVillagePath(int xi, int yi, int zi, ForgeDirection dir, int length)
{
this.xi = xi;
this.yi = yi;
this.zi = zi;
this.dir = dir;
this.length = length;
}
public Int3 constructFullPath(World world, int clearance, Block block, int meta)
{
int xPos = this.xi;
int yPos = this.yi;
int zPos = this.zi;
int rad = this.getRoadRadius();
for (int i = -rad; i <= rad; i++)
{
this.constructPartialPath(world, clearance, block, meta, xPos - rad * dir.offsetX + i * dir.offsetZ, yPos, zPos - rad * dir.offsetZ + i * dir.offsetX, dir, length + 2 * rad);
}
return this.getFinalLocation(world, clearance);
}
public void constructPartialPath(World world, int clearance, Block roadBlock, int meta, int xi, int yi, int zi, ForgeDirection dir, int length)
{
int xPos = xi;
int yPos = yi;
int zPos = zi;
for (int i = 0; i < length; i++)
{
int xOffset = i * dir.offsetX;
int zOffset = i * dir.offsetZ;
for (int yOffset = 0; yOffset <= clearance; yOffset++)
{
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 (!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, roadBlock, meta, 3);
yPos += sign * yOffset;
break;
} else
{
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 (!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, roadBlock, meta, 3);
yPos += sign * yOffset;
break;
}
}
}
}
}
public Int3 getFinalLocation(World world, int clearance)
{
int xPos = xi;
int yPos = yi;
int zPos = zi;
for (int i = 0; i < length; i++)
{
int xOffset = i * dir.offsetX;
int zOffset = i * dir.offsetZ;
for (int yOffset = 0; yOffset <= clearance; yOffset++)
{
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 (!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;
} else
{
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 (!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;
}
}
}
}
return new Int3(xPos, yPos, zPos);
}
public int getRoadRadius()
{
return 1;
}
public boolean isBlockReplaceable(Block block)
{
if (block.getMaterial() == Material.leaves || block.getMaterial() == Material.vine)
{
return false;
}
return !block.equals(ModBlocks.blockDemonPortal);
}
}

View file

@ -2,76 +2,76 @@ package WayofTime.alchemicalWizardry.common.demonVillage;
import net.minecraft.nbt.NBTTagCompound;
public class GridSpace
public class GridSpace
{
public static final int EMPTY = 0;
public static final int MAIN_PORTAL = 1;
public static final int MINI_PORTAL = 2;
public static final int ROAD = 3;
public static final int CROSSROAD = 4;
public static final int HOUSE = 5;
private int yLevel;
private int type;
public GridSpace()
{
this(EMPTY, -1);
}
public GridSpace(int type, int yLevel)
{
this.type = type;
this.yLevel = yLevel;
}
public int getGridType()
{
return this.type;
}
public void setGridType(int type)
{
this.type = type;
}
public int getYLevel()
{
return this.yLevel;
}
public void setYLevel(int yLevel)
{
this.yLevel = yLevel;
}
public boolean isEmpty()
{
return type == this.EMPTY;
}
public static GridSpace getGridFromTag(NBTTagCompound tag)
{
return new GridSpace(tag.getInteger("type"), tag.getInteger("yLevel"));
}
public NBTTagCompound getTag()
{
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger("type", type);
tag.setInteger("yLevel", yLevel);
return tag;
}
public boolean isRoadSegment()
{
return type == this.ROAD || type == this.CROSSROAD;
}
public boolean isBuilding()
{
return type == this.HOUSE;
}
public static final int EMPTY = 0;
public static final int MAIN_PORTAL = 1;
public static final int MINI_PORTAL = 2;
public static final int ROAD = 3;
public static final int CROSSROAD = 4;
public static final int HOUSE = 5;
private int yLevel;
private int type;
public GridSpace()
{
this(EMPTY, -1);
}
public GridSpace(int type, int yLevel)
{
this.type = type;
this.yLevel = yLevel;
}
public int getGridType()
{
return this.type;
}
public void setGridType(int type)
{
this.type = type;
}
public int getYLevel()
{
return this.yLevel;
}
public void setYLevel(int yLevel)
{
this.yLevel = yLevel;
}
public boolean isEmpty()
{
return type == this.EMPTY;
}
public static GridSpace getGridFromTag(NBTTagCompound tag)
{
return new GridSpace(tag.getInteger("type"), tag.getInteger("yLevel"));
}
public NBTTagCompound getTag()
{
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger("type", type);
tag.setInteger("yLevel", yLevel);
return tag;
}
public boolean isRoadSegment()
{
return type == this.ROAD || type == this.CROSSROAD;
}
public boolean isBuilding()
{
return type == this.HOUSE;
}
}

View file

@ -7,303 +7,303 @@ 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)
{
System.out.println("negXRadius: " + negXRadius + " posXRadius: " + posXRadius + " negZRadius: " + negZRadius + " posZRadius: " + posZRadius);
for(int i=-negXRadius; i<=posXRadius; i++)
{
for(int j=-negZRadius; j<=posZRadius; j++)
{
GridSpace thisSpace = this.getGridSpace(i, j);
if(thisSpace.isEmpty())
{
continue;
}
System.out.println("x: " + i + " z: " + j);
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)
{
System.out.println("Grid space selected: (" + xInit + "," + zInit + ")");
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;
}
System.out.println("Grid space (" + (xInit + xOff) + "," + (zInit + zOff) + ")");
master.setGridSpace(xInit + xOff, zInit + zOff, new GridSpace(type, yLevel));
}
}
}
}
public void destroyAllInGridSpaces(World world, int xCoord, int yCoord, int zCoord, ForgeDirection dir)
{
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;
}
for(int l = -2; l<=2; l++)
{
for(int m = -2; m<=2; m++)
{
Block block = world.getBlock(xCoord + xOff*5 + l, yCoord, zCoord + zOff*5 + m);
if(block == ModBlocks.blockDemonPortal)
{
continue;
}
world.setBlockToAir(xCoord + xOff*5 + l, yCoord, zCoord + zOff*5 + m);
}
}
}
}
}
public int getNumberOfGridSpaces()
{
int num = 0;
for(int i=-this.negXRadius; i<=this.posXRadius; i++)
{
for(int j=-this.negZRadius; j<=this.posZRadius; j++)
{
if(!this.getGridSpace(i, j).isEmpty())
{
num++;
}
}
}
return num;
}
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)
{
System.out.println("negXRadius: " + negXRadius + " posXRadius: " + posXRadius + " negZRadius: " + negZRadius + " posZRadius: " + posZRadius);
for (int i = -negXRadius; i <= posXRadius; i++)
{
for (int j = -negZRadius; j <= posZRadius; j++)
{
GridSpace thisSpace = this.getGridSpace(i, j);
if (thisSpace.isEmpty())
{
continue;
}
System.out.println("x: " + i + " z: " + j);
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)
{
System.out.println("Grid space selected: (" + xInit + "," + zInit + ")");
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;
}
System.out.println("Grid space (" + (xInit + xOff) + "," + (zInit + zOff) + ")");
master.setGridSpace(xInit + xOff, zInit + zOff, new GridSpace(type, yLevel));
}
}
}
}
public void destroyAllInGridSpaces(World world, int xCoord, int yCoord, int zCoord, ForgeDirection dir)
{
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;
}
for (int l = -2; l <= 2; l++)
{
for (int m = -2; m <= 2; m++)
{
Block block = world.getBlock(xCoord + xOff * 5 + l, yCoord, zCoord + zOff * 5 + m);
if (block == ModBlocks.blockDemonPortal)
{
continue;
}
world.setBlockToAir(xCoord + xOff * 5 + l, yCoord, zCoord + zOff * 5 + m);
}
}
}
}
}
public int getNumberOfGridSpaces()
{
int num = 0;
for (int i = -this.negXRadius; i <= this.posXRadius; i++)
{
for (int j = -this.negZRadius; j <= this.posZRadius; j++)
{
if (!this.getGridSpace(i, j).isEmpty())
{
num++;
}
}
}
return num;
}
}

View file

@ -4,5 +4,5 @@ import net.minecraft.nbt.NBTTagCompound;
public class TileBlockSet extends BlockSet
{
public NBTTagCompound tag;
public NBTTagCompound tag;
}