Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
public class BuildingSchematic {

public final String name;
public final int buildingType = DemonBuilding.BUILDING_HOUSE;
public final List<BlockSet> blockList = new ArrayList<>();
// Set by GSON when reading structure schematics, do not remove
public int doorX = 0;
public int doorZ = 0;
public int doorY = 0;
public int buildingTier = 0;
public int buildingType = DemonBuilding.BUILDING_HOUSE;

public BuildingSchematic() {
this("");
Expand Down Expand Up @@ -60,6 +65,13 @@ public GridSpaceHolder createGSH() {
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<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class DemonBuilding {
public DemonBuilding(BuildingSchematic schematic) {
this.schematic = schematic;
this.buildingType = schematic.buildingType;
this.buildingTier = 0;
this.buildingTier = schematic.buildingTier;
this.area = this.createGSHForSchematic(schematic);
this.doorGridSpace = new Int3(0, 0, 0);
this.doorGridSpace = schematic.getGridSpotOfDoor();
}

public String getName() {
Expand Down Expand Up @@ -67,18 +67,10 @@ public Int3 getGridOffsetFromRoad(ForgeDirection sideOfRoad, int yLevel) {
int z = doorSpace.z();

switch (sideOfRoad) {
case SOUTH:
z++;
break;
case EAST:
x++;
break;
case WEST:
x--;
break;
default:
z--;
break;
case SOUTH -> z++;
case EAST -> x++;
case WEST -> x--;
default -> z--;
}

return new Int3(x, yLevel, z);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package WayofTime.alchemicalWizardry.common.demonVillage.tileEntity;

import java.io.IOException;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import WayofTime.alchemicalWizardry.api.Int3;

public class Int3Adapter extends TypeAdapter<Int3> {

@Override
public Int3 read(JsonReader reader) throws IOException {
int x = 0, y = 0, z = 0;

reader.beginObject();
while (reader.hasNext()) {
switch (reader.nextName()) {
case "xCoord" -> x = reader.nextInt();
case "yCoord" -> y = reader.nextInt();
case "zCoord" -> z = reader.nextInt();
default -> reader.skipValue();
}
}
reader.endObject();

return new Int3(x, y, z);
}

@Override
public void write(JsonWriter writer, Int3 int3) throws IOException {
writer.beginObject();
writer.name("xCoord").value(int3.x());
writer.name("yCoord").value(int3.y());
writer.name("zCoord").value(int3.z());
writer.endObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -945,23 +945,19 @@ public void setGridSpace(int x, int z, GridSpace space) {
}

public void rightClickBlock(EntityPlayer player, int side) {
// if (worldObj.isRemote)
// {
// return;
// }
//
// this.initialize();
//
// if (ForgeDirection.getOrientation(side) == ForgeDirection.UP)
// {
// this.createRandomBuilding(DemonBuilding.BUILDING_HOUSE, 0);
// } else if (ForgeDirection.getOrientation(side) == ForgeDirection.DOWN)
// {
// this.createRandomBuilding(DemonBuilding.BUILDING_PORTAL, 0);
// } else
// {
// this.createRandomRoad();
// }
if (worldObj.isRemote || !player.capabilities.isCreativeMode) {
return;
}

this.initialize();

if (ForgeDirection.getOrientation(side) == ForgeDirection.UP) {
this.createRandomBuilding(DemonBuilding.BUILDING_HOUSE, 0);
} else if (ForgeDirection.getOrientation(side) == ForgeDirection.DOWN) {
this.createRandomBuilding(DemonBuilding.BUILDING_PORTAL, 0);
} else {
this.createRandomRoad();
}
}

public int createRandomBuilding(int type, int tier) {
Expand Down Expand Up @@ -1281,7 +1277,7 @@ public void loadGSH(GridSpaceHolder grid) {

public static void loadBuildingList() {
String folder = "config/BloodMagic/schematics";
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(Int3.class, new Int3Adapter()).create();

File file = new File(folder);
File[] files = file.listFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.ModBlocks;
import WayofTime.alchemicalWizardry.api.Int3;
import WayofTime.alchemicalWizardry.common.demonVillage.BuildingSchematic;
import WayofTime.alchemicalWizardry.common.demonVillage.tileEntity.Int3Adapter;

public class TESchematicSaver extends TileEntity {

Expand Down Expand Up @@ -42,7 +44,7 @@ public void rightClickBlock(EntityPlayer player, int side) {
}
}
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(Int3.class, new Int3Adapter()).create();
String json = gson.toJson(schematic);
try (Writer writer = new FileWriter("config/BloodMagic/schematics/" + new Random().nextInt() + ".json")) {
writer.write(json);
Expand Down