Skip to content

Commit

Permalink
+ json materials
Browse files Browse the repository at this point in the history
  • Loading branch information
bioastroiner committed Dec 11, 2023
1 parent 3ea7fe7 commit fb3d170
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main/java/mods/bio/gttweaker/GTTweaker.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
package mods.bio.gttweaker;

import com.google.gson.*;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import gregapi.NEI_GT_API_Config;
import gregapi.data.CS;
import gregapi.data.MT;
import gregapi.oredict.OreDictMaterial;
import gregapi.recipes.Recipe;
import gregapi.util.UT;
import io.netty.util.internal.logging.Log4JLoggerFactory;
import minetweaker.MineTweakerAPI;
import minetweaker.MineTweakerImplementationAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.util.IEventHandler;
import mods.bio.gttweaker.command.GTCommand;
import mods.bio.gttweaker.oredict.CTMaterial;
import mods.bio.gttweaker.oredict.CTPrefix;
import mods.bio.gttweaker.oredict.bracket.CTMaterialBracketHandler;
import mods.bio.gttweaker.oredict.bracket.CTPrefixBracketHandler;
import mods.bio.gttweaker.recipe.*;
import mods.bio.gttweaker.recipe.bracket.CTRecipeMapBracketHandler;
import mods.bio.gttweaker.oredict.CTIOreDictExpansion;
import mods.bio.gttweaker.oredict.CTUnifier;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.logging.impl.Log4JLogger;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Objects;
import java.util.logging.Logger;

@cpw.mods.fml.common.Mod(modid = mods.bio.gttweaker.GTTweaker.MOD_ID, name = mods.bio.gttweaker.GTTweaker.MOD_NAME, version = mods.bio.gttweaker.GTTweaker.VERSION)
public final class GTTweaker extends gregapi.api.Abstract_Mod {
Expand Down Expand Up @@ -120,6 +138,7 @@ public void onModPreInit2(cpw.mods.fml.common.event.FMLPreInitializationEvent aE

@Override
public void onModInit2(FMLInitializationEvent aEvent) {
OreDictMaterial_Serializable._INITLIZE();
MineTweakerAPI.registerClass(CTRecipe.class);
MineTweakerAPI.registerClass(CTRecipeFactory.class);
MineTweakerAPI.registerClass(CTRecipeMap.class);
Expand All @@ -135,7 +154,7 @@ public void onModInit2(FMLInitializationEvent aEvent) {
MineTweakerImplementationAPI.onPostReload(new IEventHandler<MineTweakerImplementationAPI.ReloadEvent>() {
@Override
public void handle(MineTweakerImplementationAPI.ReloadEvent reloadEvent) {

//OreDictMaterial_Serializable._INITLIZE();
}
});

Expand Down
156 changes: 156 additions & 0 deletions src/main/java/mods/bio/gttweaker/OreDictMaterial_Serializable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package mods.bio.gttweaker;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import gregapi.oredict.OreDictMaterial;

import java.io.File;
import java.io.FileWriter;

public class OreDictMaterial_Serializable {
public final transient OreDictMaterial _mat;

public static void _INITLIZE(){
// skip 0 = Empty
long milis = System.currentTimeMillis();
File materials_folder = new File("gt_materials");
materials_folder.mkdir();
for (int i = 1; i < OreDictMaterial.MATERIAL_ARRAY.length; i++) {
try {
if (OreDictMaterial.MATERIAL_ARRAY[i]==null) continue;
File toWrite = new File(materials_folder,String.format("%d.json",i));
if(toWrite.exists()) toWrite.delete();
toWrite.createNewFile();
FileWriter writer = new FileWriter(toWrite);
writer.write(OreDictMaterial_Serializable.serializeMaterial(OreDictMaterial.MATERIAL_ARRAY[i]));
writer.close();
System.out.println((String.format("Material with ID %d was Serialized Successfuly.",i)));
} catch (Exception ig){
ig.printStackTrace();
}
}
System.out.println(String.format("It took %d Seconds to generate the JSON Materials for Gregtech 6!",System.currentTimeMillis() - milis));

}
private transient short mID;
//private final int mHashID;
public String mNameInternal;
public short[] mRGBaSolid, mRGBaLiquid, mRGBaGas, mRGBaPlasma;
public short[][] mRGBa;
public short[] fRGBaSolid, fRGBaLiquid, fRGBaGas, fRGBaPlasma;
public short[][] fRGBa;
//public String mNameLocal;
public String mOriginalMod;
//public ItemStack mDictionaryBook = null;
public String mDescription[], mTooltipChemical;
public byte mOreMultiplier, mOreProcessingMultiplier;
public long mFurnaceBurnTime;
public byte mToolTypes;
public byte mToolQuality;
public long mToolDurability;
public float mToolSpeed;
public float mHeatDamage;
public boolean mHidden;
//public boolean mHasMetallum = F;
public double mGramPerCubicCentimeter;
public long mMeltingPoint, mBoilingPoint, mPlasmaPoint;
//public List<IIconContainer> mTextureSetsBlock = TextureSet.SET_NONE[0].mList, mTextureSetsItems = TextureSet.SET_NONE[1].mList;
//public ITexture mTextureSolid = null, mTextureSmooth = null, mTextureMolten = null, mTextureDust = null, mTextureGem = null;
//public final List<TC.TC_AspectStack> mAspects = new ArrayListNoNulls<>(1);
//public IOreDictConfigurationComponent mComponents = null;
//public final Set<OreDictMaterial> mReRegistrations = new HashSetNoNulls<>(), mToThis = new HashSetNoNulls<>();
//public final List<OreDictMaterial> mByProducts = new ArrayListNoNulls<>();
//public final Set<OreDictMaterial> mAlloyComponentReferences = new HashSetNoNulls<>();
//public final Set<OreDictMaterial> mSourceOf = new HashSetNoNulls<>();
//public final List<IOreDictConfigurationComponent> mAlloyCreationRecipes = new ArrayListNoNulls<>();
//public final List<Achievement> mAchievementsForCreation = new ArrayListNoNulls<>();
public int mPriorityPrefixIndex;
public long mLiquidUnit, mGasUnit, mPlasmaUnit;
public long mNeutrons, mProtons, mElectrons;
public OreDictMaterial_Serializable(OreDictMaterial matIn) {
_mat = matIn;
updateFields();
}

public static String serializeMaterial(OreDictMaterial material) {
return new GsonBuilder().setPrettyPrinting().create().toJson(new OreDictMaterial_Serializable(material));
}

public OreDictMaterial deserializeMaterial(String json){
return new OreDictMaterial_Serializable(new Gson().fromJson(json, OreDictMaterial_Serializable.class)._mat)._mat;
}

private void updateFields() {
mID = _mat.mID;
mNameInternal = _mat.mNameInternal;
mRGBaSolid = _mat.mRGBaSolid;
mRGBaLiquid = _mat.mRGBaLiquid;
mRGBaGas = _mat.mRGBaGas;
mRGBaPlasma = _mat.mRGBaPlasma;
mRGBa = _mat.mRGBa;
fRGBaSolid = _mat.fRGBaSolid;
fRGBaLiquid = _mat.fRGBaLiquid;
fRGBaGas = _mat.fRGBaGas;
fRGBaPlasma = _mat.fRGBaPlasma;
fRGBa = _mat.fRGBa;
mOriginalMod = _mat.mOriginalMod.mID;
mDescription = _mat.mDescription;
mTooltipChemical = _mat.mTooltipChemical;
mOreMultiplier = _mat.mOreMultiplier;
mToolTypes = _mat.mToolTypes;
mFurnaceBurnTime = _mat.mFurnaceBurnTime;
mOreProcessingMultiplier = _mat.mOreProcessingMultiplier;
mToolDurability = _mat.mToolDurability;
mToolQuality = _mat.mToolQuality;
mToolSpeed = _mat.mToolSpeed;
mHeatDamage = _mat.mHeatDamage;
mHidden = _mat.mHidden;
mGramPerCubicCentimeter = _mat.mGramPerCubicCentimeter;
mMeltingPoint = _mat.mMeltingPoint;
mBoilingPoint = _mat.mBoilingPoint;
mPlasmaPoint = _mat.mPlasmaPoint;
mPriorityPrefixIndex = _mat.mPriorityPrefixIndex;
mLiquidUnit = _mat.mLiquidUnit;
mGasUnit = _mat.mGasUnit;
mPlasmaUnit = _mat.mPlasmaUnit;
mNeutrons = _mat.mNeutrons;
mProtons = _mat.mProtons;
mElectrons = _mat.mElectrons;
}
//public OreDictPrefix mPriorityPrefix = null;
//public OreDictMaterial mTargetRegistration = this;
//public OreDictMaterial mHandleMaterial = this;

// public OreDictMaterialStack
// mTargetCrushing = OM.stack(this, U),
// mTargetPulver = OM.stack(this, U),
// mTargetSmelting = OM.stack(this, U),
// mTargetSolidifying = OM.stack(this, U),
// mTargetSmashing = OM.stack(this, U),
// mTargetCutting = OM.stack(this, U),
// mTargetWorking = OM.stack(this, U),
// mTargetForging = OM.stack(this, U),
// mTargetBurning = OM.stack(this, 0), // The remaining Material when being burned. Used for getting the Ashes.
// mTargetBending = OM.stack(this, U),
// mTargetCompressing = OM.stack(this, U);
//
// public final Set<OreDictMaterial>
// mTargetedCrushing = new HashSetNoNulls<>(F, this),
// mTargetedPulver = new HashSetNoNulls<>(F, this),
// mTargetedSmelting = new HashSetNoNulls<>(F, this),
// mTargetedSolidifying = new HashSetNoNulls<>(F, this),
// mTargetedSmashing = new HashSetNoNulls<>(F, this),
// mTargetedCutting = new HashSetNoNulls<>(F, this),
// mTargetedWorking = new HashSetNoNulls<>(F, this),
// mTargetedForging = new HashSetNoNulls<>(F, this),
// mTargetedBurning = new HashSetNoNulls<>(F, this),
// mTargetedBending = new HashSetNoNulls<>(F, this),
// mTargetedCompressing = new HashSetNoNulls<>(F, this);


//public FluidStack mLiquid, mGas, mPlasma;
//private final Set<TagData> mTags = new HashSetNoNulls<>();
//public final List<ObjectStack<Enchantment>> mEnchantmentTools = new ArrayListNoNulls<>(1), mEnchantmentWeapons = new ArrayListNoNulls<>(1), mEnchantmentAmmo = new ArrayListNoNulls<>(1), mEnchantmentRanged = new ArrayListNoNulls<>(1), mEnchantmentArmors = new ArrayListNoNulls<>(1);


}

0 comments on commit fb3d170

Please sign in to comment.