aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/galacticgreg/schematics
diff options
context:
space:
mode:
authorNotAPenguin <michiel.vandeginste@gmail.com>2024-09-02 23:17:17 +0200
committerGitHub <noreply@github.com>2024-09-02 23:17:17 +0200
commit1b820de08a05070909a267e17f033fcf58ac8710 (patch)
tree02831a025986a06b20f87e5bcc69d1e0c639a342 /src/main/java/galacticgreg/schematics
parentafd3fd92b6a6ab9ab0d0dc3214e6bc8ff7a86c9b (diff)
downloadGT5-Unofficial-1b820de08a05070909a267e17f033fcf58ac8710.tar.gz
GT5-Unofficial-1b820de08a05070909a267e17f033fcf58ac8710.tar.bz2
GT5-Unofficial-1b820de08a05070909a267e17f033fcf58ac8710.zip
The Great Renaming (#3014)
* move kekztech to a single root dir * move detrav to a single root dir * move gtnh-lanthanides to a single root dir * move tectech and delete some gross reflection in gt++ * remove more reflection inside gt5u * delete more reflection in gt++ * fix imports * move bartworks and bwcrossmod * fix proxies * move galactigreg and ggfab * move gtneioreplugin * try to fix gt++ bee loader * apply the rename rules to BW * apply rename rules to bwcrossmod * apply rename rules to detrav scanner mod * apply rename rules to galacticgreg * apply rename rules to ggfab * apply rename rules to goodgenerator * apply rename rules to gtnh-lanthanides * apply rename rules to gt++ * apply rename rules to kekztech * apply rename rules to kubatech * apply rename rules to tectech * apply rename rules to gt apply the rename rules to gt * fix tt import * fix mui hopefully * fix coremod except intergalactic * rename assline recipe class * fix a class name i stumbled on * rename StructureUtility to GTStructureUtility to prevent conflict with structurelib * temporary rename of GTTooltipDataCache to old name * fix gt client/server proxy names
Diffstat (limited to 'src/main/java/galacticgreg/schematics')
-rw-r--r--src/main/java/galacticgreg/schematics/SpaceSchematic.java100
-rw-r--r--src/main/java/galacticgreg/schematics/SpaceSchematicFactory.java33
-rw-r--r--src/main/java/galacticgreg/schematics/SpaceSchematicHandler.java182
-rw-r--r--src/main/java/galacticgreg/schematics/SpaceSchematicWrapper.java104
4 files changed, 419 insertions, 0 deletions
diff --git a/src/main/java/galacticgreg/schematics/SpaceSchematic.java b/src/main/java/galacticgreg/schematics/SpaceSchematic.java
new file mode 100644
index 0000000000..976b699e85
--- /dev/null
+++ b/src/main/java/galacticgreg/schematics/SpaceSchematic.java
@@ -0,0 +1,100 @@
+package galacticgreg.schematics;
+
+import java.util.ArrayList;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import net.minecraft.block.Block;
+import net.minecraft.util.Vec3;
+
+import galacticgreg.api.StructureInformation;
+
+/**
+ * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with
+ * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod. However, feel
+ * free to copy this code to your own mod to implement structures. If you have questions, find me on github and ask
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "SpaceSchematic")
+public class SpaceSchematic {
+
+ @XmlAttribute(name = "enabled")
+ protected boolean _mStructureEnabled;
+ @XmlAttribute(name = "centerX")
+ protected int _mCenterX;
+ @XmlAttribute(name = "centerY")
+ protected int _mCenterY;
+ @XmlAttribute(name = "centerZ")
+ protected int _mCenterZ;
+
+ @XmlElement(name = "StructureName")
+ protected String _mStructureName;
+
+ @XmlElement(name = "Rarity")
+ protected int _mRarity;
+
+ @XmlElementWrapper(name = "Coords")
+ @XmlElement(name = "block")
+ protected ArrayList<BaseStructureInfo> mStructureInfoList;
+
+ public boolean isEnabled() {
+ return _mStructureEnabled;
+ }
+
+ public Vec3 getStructureCenter() {
+ return Vec3.createVectorHelper(_mCenterX, _mCenterY, _mCenterZ);
+ }
+
+ public int getRarity() {
+ return _mRarity;
+ }
+
+ public String getName() {
+ return _mStructureName;
+ }
+
+ public ArrayList<BaseStructureInfo> coordInfo() {
+ if (mStructureInfoList == null) mStructureInfoList = new ArrayList<>();
+
+ return mStructureInfoList;
+ }
+
+ public void addStructureInfo(StructureInformation pStrucInfo) {
+ if (mStructureInfoList == null) mStructureInfoList = new ArrayList<>();
+ mStructureInfoList.add(new BaseStructureInfo(pStrucInfo));
+ }
+
+ public static class BaseStructureInfo {
+
+ @XmlAttribute(name = "X")
+ protected int posX;
+ @XmlAttribute(name = "Y")
+ protected int posY;
+ @XmlAttribute(name = "Z")
+ protected int posZ;
+ @XmlAttribute(name = "Block")
+ protected String blockName;
+ @XmlAttribute(name = "Meta")
+ protected int blockMeta;
+
+ public BaseStructureInfo(StructureInformation pSI) {
+ posX = pSI.getX();
+ posY = pSI.getY();
+ posZ = pSI.getZ();
+ blockName = Block.blockRegistry.getNameForObject(
+ pSI.getBlock()
+ .getBlock());
+ blockMeta = pSI.getBlock()
+ .getMeta();
+ }
+
+ public Vec3 getVec3Pos() {
+ return Vec3.createVectorHelper(posX, posY, posZ);
+ }
+ }
+}
diff --git a/src/main/java/galacticgreg/schematics/SpaceSchematicFactory.java b/src/main/java/galacticgreg/schematics/SpaceSchematicFactory.java
new file mode 100644
index 0000000000..584ea80319
--- /dev/null
+++ b/src/main/java/galacticgreg/schematics/SpaceSchematicFactory.java
@@ -0,0 +1,33 @@
+package galacticgreg.schematics;
+
+import net.minecraft.block.Block;
+import net.minecraft.util.Vec3;
+
+import galacticgreg.api.Enums.AllowedBlockPosition;
+import galacticgreg.api.Enums.TargetBlockPosition;
+import galacticgreg.api.SpecialBlockComb;
+import galacticgreg.api.StructureInformation;
+
+/**
+ * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with
+ * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod. However, feel
+ * free to copy this code to your own mod to implement structures. If you have questions, find me on github and ask
+ */
+public class SpaceSchematicFactory {
+
+ public static SpaceSchematic createSchematic(String pName) {
+ SpaceSchematic tSchem = new SpaceSchematic();
+ tSchem._mStructureName = pName;
+ tSchem._mRarity = 100;
+ tSchem._mStructureEnabled = false;
+
+ return tSchem;
+ }
+
+ public static StructureInformation createStructureInfo(int pX, int pY, int pZ, Block pBlock, int pMeta) {
+ return new StructureInformation(
+ Vec3.createVectorHelper(pX, pY, pZ),
+ TargetBlockPosition.Invalid,
+ new SpecialBlockComb(pBlock, pMeta, AllowedBlockPosition.AsteroidCoreAndShell));
+ }
+}
diff --git a/src/main/java/galacticgreg/schematics/SpaceSchematicHandler.java b/src/main/java/galacticgreg/schematics/SpaceSchematicHandler.java
new file mode 100644
index 0000000000..9282ebca06
--- /dev/null
+++ b/src/main/java/galacticgreg/schematics/SpaceSchematicHandler.java
@@ -0,0 +1,182 @@
+package galacticgreg.schematics;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.commons.io.FileUtils;
+
+import galacticgreg.GalacticGreg;
+
+/**
+ * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with
+ * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod. However, feel
+ * free to copy this code to your own mod to implement structures. If you have questions, find me on github and ask
+ */
+public class SpaceSchematicHandler {
+
+ File _mConfigFolderName;
+ File _mSchematicsFolderName;
+ private List<SpaceSchematic> _mSpaceSchematics;
+
+ @SuppressWarnings("ResultOfMethodCallIgnored")
+ public SpaceSchematicHandler(File pConfigFolder) {
+ _mConfigFolderName = new File(String.format("%s/%s", pConfigFolder.toString(), GalacticGreg.NICE_MODID));
+ _mSchematicsFolderName = new File(String.format("%s/schematics", _mConfigFolderName));
+
+ _mSpaceSchematics = new ArrayList<>();
+
+ if (!_mSchematicsFolderName.exists()) _mSchematicsFolderName.mkdirs();
+ }
+
+ /**
+ * Get a random schematic to be placed.
+ *
+ * @return A schematic that can be spawned in space
+ */
+ public SpaceSchematic getRandomSpaceSchematic() {
+ int tRandomChance = GalacticGreg.GalacticRandom.nextInt(100);
+ List<Integer> tRandomIDs = new ArrayList<>();
+ SpaceSchematic tChoosenSchematic = null;
+
+ if (_mSpaceSchematics == null) return null;
+
+ if (_mSpaceSchematics.size() == 0) return null;
+
+ if (_mSpaceSchematics.size() == 1) {
+ tChoosenSchematic = _mSpaceSchematics.get(0);
+ if (tChoosenSchematic.getRarity() < tRandomChance) tChoosenSchematic = null;
+ } else {
+ for (int i = 0; i < _mSpaceSchematics.size(); i++) {
+ if (_mSpaceSchematics.get(i)
+ .getRarity() >= tRandomChance) tRandomIDs.add(i);
+ }
+ }
+
+ if (tRandomIDs.size() > 0) {
+ int tRnd = GalacticGreg.GalacticRandom.nextInt(tRandomIDs.size());
+ tChoosenSchematic = _mSpaceSchematics.get(tRandomIDs.get(tRnd));
+ }
+
+ return tChoosenSchematic;
+ }
+
+ /**
+ * Try to reload the schematics. Will not change the list of currently loaded schematics if any errors are detected,
+ * except if you force it to do so
+ *
+ * @return
+ */
+ public boolean reloadSchematics(boolean pForceReload) {
+ try {
+ Collection<File> structureFiles = FileUtils
+ .listFiles(_mSchematicsFolderName, new String[] { "xml" }, false);
+ List<SpaceSchematic> tNewSpaceSchematics = new ArrayList<>();
+ int tErrorsFound = 0;
+
+ if (structureFiles.isEmpty()) return true;
+
+ for (File tSchematic : structureFiles) {
+ try {
+ SpaceSchematic tSchematicObj = LoadSpaceSchematic(tSchematic);
+ if (tSchematicObj != null) tNewSpaceSchematics.add(tSchematicObj);
+ else {
+ GalacticGreg.Logger.warn("Could not load Schematic %s. Please check the syntax", tSchematic);
+ tErrorsFound++;
+ }
+ } catch (Exception e) {
+ GalacticGreg.Logger.error("Error while loading Schematic %s", tSchematic);
+ e.printStackTrace();
+ }
+
+ }
+
+ GalacticGreg.Logger.info("Successfully loaded %d Schematics", tNewSpaceSchematics.size());
+ boolean tDoReplace = true;
+
+ if (tErrorsFound > 0) {
+ GalacticGreg.Logger.warn("Found %d errors while loading, not all schematics will be available");
+ if (pForceReload)
+ GalacticGreg.Logger.info("Reload was forced, replacing currently active list with new one");
+ else {
+ GalacticGreg.Logger.warn("Nothing was replaced. Fix any errors and reload again");
+ tDoReplace = false;
+ }
+ }
+
+ if (tDoReplace) _mSpaceSchematics = tNewSpaceSchematics;
+
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * Saves the schematic to disk. The schematics name will be used as filename
+ *
+ * @param pSchematic
+ * @return
+ */
+ public boolean SaveSpaceStructure(SpaceSchematic pSchematic) {
+ try {
+ if (pSchematic.getName()
+ .length() < 1) return false;
+
+ JAXBContext tJaxbCtx = JAXBContext.newInstance(SpaceSchematic.class);
+ Marshaller jaxMarsh = tJaxbCtx.createMarshaller();
+ jaxMarsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ jaxMarsh.marshal(
+ pSchematic,
+ new FileOutputStream(String.format("%s/%s.xml", _mSchematicsFolderName, pSchematic.getName()), false));
+
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * Load a schematic from disk by the schematic-name itself, without .xml or path
+ *
+ * @param pSchematicName
+ * @return
+ */
+ public SpaceSchematic LoadSpaceSchematic(String pSchematicName) {
+ return LoadSpaceSchematic(new File(String.format("%s/%s.xml", _mSchematicsFolderName, pSchematicName)));
+ }
+
+ /**
+ * Load a schematic file from disk by providing the actual file-object
+ *
+ * @param pName
+ * @return
+ */
+ public SpaceSchematic LoadSpaceSchematic(File pName) {
+ SpaceSchematic tSchematic = null;
+
+ try {
+ JAXBContext tJaxbCtx = JAXBContext.newInstance(SpaceSchematic.class);
+ if (!pName.exists()) {
+ GalacticGreg.Logger.error("SchematicFile %s could not be found", pName);
+ return null;
+ }
+
+ Unmarshaller jaxUnmarsh = tJaxbCtx.createUnmarshaller();
+ tSchematic = (SpaceSchematic) jaxUnmarsh.unmarshal(pName);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return tSchematic;
+ }
+}
diff --git a/src/main/java/galacticgreg/schematics/SpaceSchematicWrapper.java b/src/main/java/galacticgreg/schematics/SpaceSchematicWrapper.java
new file mode 100644
index 0000000000..4addc5107d
--- /dev/null
+++ b/src/main/java/galacticgreg/schematics/SpaceSchematicWrapper.java
@@ -0,0 +1,104 @@
+package galacticgreg.schematics;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.minecraft.block.Block;
+import net.minecraft.util.Vec3;
+
+import cpw.mods.fml.common.registry.GameRegistry;
+import galacticgreg.GalacticGreg;
+import galacticgreg.api.BlockMetaComb;
+import galacticgreg.api.Enums.SpaceObjectType;
+import galacticgreg.api.Enums.TargetBlockPosition;
+import galacticgreg.api.ISpaceObjectGenerator;
+import galacticgreg.api.StructureInformation;
+import galacticgreg.schematics.SpaceSchematic.BaseStructureInfo;
+
+/**
+ * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with
+ * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod. However, feel
+ * free to copy this code to your own mod to implement structures. If you have questions, find me on github and ask
+ */
+public class SpaceSchematicWrapper implements ISpaceObjectGenerator {
+
+ private SpaceSchematic _mSchematic;
+ private Vec3 _mCenter = Vec3.createVectorHelper(0, 0, 0);
+ private List<StructureInformation> _mFinalizedStructure;
+
+ public SpaceSchematicWrapper(SpaceSchematic pSchematic) {
+ _mSchematic = pSchematic;
+ }
+
+ public boolean isCalculated() {
+ return _mFinalizedStructure != null && _mFinalizedStructure.size() > 0;
+ }
+
+ /**
+ * Recalculate the Structures position, center it around _mCenter
+ */
+ private void RecalculatePosition() {
+ _mFinalizedStructure = new ArrayList<>();
+
+ for (BaseStructureInfo bsi : _mSchematic.coordInfo()) {
+ try {
+ String tModID = bsi.blockName.split(":")[0];
+ String tBlockName = bsi.blockName.split(":")[1];
+
+ Block tBlock = GameRegistry.findBlock(tModID, tBlockName);
+ if (tBlock != null) {
+ BlockMetaComb bmc = new BlockMetaComb(tBlock, bsi.blockMeta);
+ Vec3 tCenteredPos = _mCenter.addVector(bsi.posX, bsi.posY, bsi.posZ);
+ StructureInformation tnewSI = new StructureInformation(
+ tCenteredPos,
+ TargetBlockPosition.StructureBlock,
+ bmc);
+ _mFinalizedStructure.add(tnewSI);
+ } else GalacticGreg.Logger
+ .warn("Block %s:%s could not be found. Schematic will be incomplete!", tModID, tBlockName);
+ } catch (Exception e) {
+ e.printStackTrace();
+ GalacticGreg.Logger.error("Error while recalculating blocks position");
+ }
+ }
+ }
+
+ @Override
+ public Vec3 getCenterPoint() {
+ return _mCenter;
+ }
+
+ @Override
+ public void setCenterPoint(int pX, int pY, int pZ) {
+ _mCenter = Vec3.createVectorHelper(pX, pY, pZ);
+ }
+
+ @Override
+ public void setCenterPoint(Vec3 pCenter) {
+ _mCenter = pCenter;
+ }
+
+ @Override
+ public List<StructureInformation> getStructure() {
+ return _mFinalizedStructure;
+ }
+
+ @Override
+ public void calculate() {
+ RecalculatePosition();
+ }
+
+ @Override
+ public void randomize(int pSizeMin, int pSizeMax) {}
+
+ @Override
+ public SpaceObjectType getType() {
+ return SpaceObjectType.NonOreSchematic;
+ }
+
+ @Override
+ public void reset() {
+
+ }
+
+}