Fix broken demon city buildings (#136)

This commit is contained in:
koolkrafter5 authored and GitHub committed 2026-07-06 18:19:33 +02:00
1 parent 2026024920
commit b6284e20dc
5 files changed
+75 -34

No files matched your search

@@ -14,8 +14,13 @@ import WayofTime.alchemicalWizardry.common.demonVillage.tileEntity.TEDemonPortal
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("");
@@ -60,6 +65,13 @@ public class BuildingSchematic {
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<>();
@@ -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() {
@@ -67,18 +67,10 @@ public class DemonBuilding {
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);
@@ -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();
}
}
@@ -945,23 +945,19 @@ public class TEDemonPortal extends TileEntity {
}
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) {
@@ -1281,7 +1277,7 @@ public class TEDemonPortal extends TileEntity {
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();
@@ -14,7 +14,9 @@ import com.google.gson.GsonBuilder;
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 {
@@ -42,7 +44,7 @@ public class TESchematicSaver extends TileEntity {
}
}
}
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);