New Building on da Block!
This commit is contained in:
parent
126a38c30c
commit
896810ad59
14 changed files with 897 additions and 21 deletions
|
@ -43,6 +43,11 @@ public class BlockSet
|
|||
}
|
||||
}
|
||||
|
||||
public List<Int3> getPositions()
|
||||
{
|
||||
return positions;
|
||||
}
|
||||
|
||||
public void addPositionToBlock(int xOffset, int yOffset, int zOffset)
|
||||
{
|
||||
positions.add(new Int3(xOffset, yOffset, zOffset));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
|
|
|
@ -69,4 +69,9 @@ public class GridSpace
|
|||
{
|
||||
return type == this.ROAD || type == this.CROSSROAD;
|
||||
}
|
||||
|
||||
public boolean isBuilding()
|
||||
{
|
||||
return type == this.HOUSE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue