New commit
This commit is contained in:
parent
184f4bb85d
commit
a9c857bbcb
11 changed files with 1683 additions and 0 deletions
|
@ -0,0 +1,150 @@
|
|||
package WayofTime.alchemicalWizardry.common.demonVillage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
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
|
||||
{
|
||||
private String blockid;
|
||||
private int[] metadata;
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
yOff *= -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package WayofTime.alchemicalWizardry.common.demonVillage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BuildingSchematic
|
||||
{
|
||||
public String name;
|
||||
public List<BlockSet> blockList;
|
||||
|
||||
public BuildingSchematic()
|
||||
{
|
||||
this("");
|
||||
}
|
||||
|
||||
public BuildingSchematic(String name)
|
||||
{
|
||||
this.name = name;
|
||||
blockList = new ArrayList();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package WayofTime.alchemicalWizardry.common.demonVillage;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
package WayofTime.alchemicalWizardry.common.demonVillage;
|
||||
|
||||
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 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);
|
||||
|
||||
if(!world.isAirBlock(xPos + xOffset, yPos + sign*yOffset, zPos + zOffset) && this.isBlockReplaceable(block1) && world.isAirBlock(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);
|
||||
|
||||
if(!world.isAirBlock(xPos + xOffset, yPos + sign*yOffset, zPos + zOffset) && this.isBlockReplaceable(block2) && world.isAirBlock(xPos + xOffset, yPos + sign*yOffset + 1, zPos + zOffset))
|
||||
{
|
||||
yPos += sign*yOffset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Int3(xi,yi,zi);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package WayofTime.alchemicalWizardry.common.demonVillage;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue