2014-06-27 19:43:09 -04:00
|
|
|
package WayofTime.alchemicalWizardry.common.tileEntity;
|
|
|
|
|
2015-07-29 08:23:01 -04:00
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.Writer;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.BlockPos;
|
2014-11-03 16:11:10 -08:00
|
|
|
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
2014-06-27 19:43:09 -04:00
|
|
|
import WayofTime.alchemicalWizardry.ModBlocks;
|
|
|
|
import WayofTime.alchemicalWizardry.common.demonVillage.BuildingSchematic;
|
2015-07-29 08:23:01 -04:00
|
|
|
|
2014-06-27 19:43:09 -04:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.GsonBuilder;
|
|
|
|
|
|
|
|
public class TESchematicSaver extends TileEntity
|
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
public Block targetBlock = ModBlocks.largeBloodStoneBrick;
|
|
|
|
|
2015-07-30 10:21:53 -04:00
|
|
|
public void rightClickBlock()
|
2014-10-13 22:33:20 +02:00
|
|
|
{
|
|
|
|
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++)
|
|
|
|
{
|
2015-07-29 08:23:01 -04:00
|
|
|
BlockPos newPos = pos.add(i, j, k);
|
|
|
|
IBlockState state = worldObj.getBlockState(newPos);
|
|
|
|
Block block = state.getBlock();
|
|
|
|
int meta = block.getMetaFromState(state);
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2015-07-29 08:23:01 -04:00
|
|
|
if (!block.isAir(worldObj, newPos))
|
2014-10-13 22:33:20 +02:00
|
|
|
{
|
|
|
|
schematic.addBlockWithMeta(block, meta, i, j, k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-03 16:11:10 -08:00
|
|
|
AlchemicalWizardry.logger.info("" + i);
|
2014-10-13 22:33:20 +02:00
|
|
|
}
|
|
|
|
|
2014-11-03 16:11:10 -08:00
|
|
|
AlchemicalWizardry.logger.info("I got here!");
|
2014-10-13 22:33:20 +02:00
|
|
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
|
|
String json = gson.toJson(schematic);
|
2014-11-03 16:11:10 -08:00
|
|
|
AlchemicalWizardry.logger.info("Here, too!");
|
2014-10-13 22:33:20 +02:00
|
|
|
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)
|
|
|
|
{
|
2015-07-29 08:23:01 -04:00
|
|
|
if (targetBlock == (worldObj.getBlockState(pos.add(0, i, 0)).getBlock()))
|
2014-10-13 22:33:20 +02:00
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getNegYLimit()
|
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
2015-07-29 08:23:01 -04:00
|
|
|
if (targetBlock == (worldObj.getBlockState(pos.add(0, -i, 0)).getBlock()))
|
2014-10-13 22:33:20 +02:00
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getPosXLimit()
|
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
2015-07-29 08:23:01 -04:00
|
|
|
if (targetBlock == (worldObj.getBlockState(pos.add(i, 0, 0)).getBlock()))
|
2014-10-13 22:33:20 +02:00
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getNegXLimit()
|
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
2015-07-29 08:23:01 -04:00
|
|
|
if (targetBlock == (worldObj.getBlockState(pos.add(-i, 0, 0)).getBlock()))
|
2014-10-13 22:33:20 +02:00
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getPosZLimit()
|
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
2015-07-29 08:23:01 -04:00
|
|
|
if (targetBlock == (worldObj.getBlockState(pos.add(0, 0, i)).getBlock()))
|
2014-10-13 22:33:20 +02:00
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getNegZLimit()
|
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
2015-07-29 08:23:01 -04:00
|
|
|
if (targetBlock == (worldObj.getBlockState(pos.add(0, 0, -i)).getBlock()))
|
2014-10-13 22:33:20 +02:00
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|