Skip to content

Commit

Permalink
+ MatData and MatStack Bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
bioastroiner committed Dec 12, 2023
1 parent 7b81ca0 commit 94b1cc9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/mods/bio/gttweaker/GTTweaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public void onModInit2(FMLInitializationEvent aEvent) {
MineTweakerAPI.registerClass(CTIOreDictExpansion.class);
MineTweakerAPI.registerClass(CTIItemStackExpansion.class);
MineTweakerAPI.registerClass(CTMaterial.class);
MineTweakerAPI.registerClass(CTMaterialData.class);
MineTweakerAPI.registerClass(CTMaterialStack.class);
MineTweakerAPI.registerClass(CTPrefix.class);
MineTweakerAPI.registerBracketHandler(new CTRecipeMapBracketHandler());
MineTweakerAPI.registerBracketHandler(new CTPrefixBracketHandler());
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/mods/bio/gttweaker/oredict/CTMaterialData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
package mods.bio.gttweaker.oredict;

import gregapi.oredict.OreDictItemData;
import stanhebben.zenscript.annotations.ZenClass;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@ZenClass("mods.gregtech.oredict.MaterialData")
public class CTMaterialData {
private final OreDictItemData backingData;
public CTMaterialStack material(){
return new CTMaterialStack(backingData.mMaterial);
}
public CTPrefix prefix(){
return new CTPrefix(backingData.mPrefix);
}
private List<CTMaterialStack> byProducts(){
return Arrays.stream(backingData.mByProducts).map(CTMaterialStack::new).collect(Collectors.toList());
}

public CTMaterialData(OreDictItemData backingData) {
this.backingData = backingData;
}

/**
* @return a very JSON like CTMaterialData Representation tough it's not ready for json parsing at all
* but is human readable.
* {
* MainMaterial: <material:name> * amount U ,
* ByProducts: [
* 1: <material:name> * amount U,
* 2 :<material:name> * amount U,
* 3: <material:name> * amount U
* ]
* }
*
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
if(material() != null) builder.append("{MainMaterial:").append(material());
else builder.append("{NULL");
List<CTMaterialStack> list = byProducts();
if(!list.isEmpty()) builder.append(",ByProducts:[");
list.forEach(s->builder.append(String.format("%d: %s,",list.indexOf(s),s)));
if (!list.isEmpty()) builder.reverse().deleteCharAt(0).reverse().append("]}");
return builder.toString();
}
}
34 changes: 34 additions & 0 deletions src/main/java/mods/bio/gttweaker/oredict/CTMaterialStack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package mods.bio.gttweaker.oredict;

import gregapi.oredict.OreDictMaterialStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;

import static mods.bio.gttweaker.oredict.CTUnifier.U;

@ZenClass("mods.gregtech.MaterialStack")
public class CTMaterialStack {
private final OreDictMaterialStack _backingStack;

@ZenGetter
public CTMaterial material(){
return new CTMaterial(_backingStack.mMaterial);
}

public long amount(){
return _backingStack.mAmount;
}

public CTMaterialStack(OreDictMaterialStack backingStack) {
_backingStack = backingStack;
}

/**
* @return <material:name> * amount U
*/
@Override
public String toString() {
// NOTE THAT THIS IS NOT VALID IN ZS
return String.format("%s * %f U",material(),((double)amount())/ U());
}
}

0 comments on commit 94b1cc9

Please sign in to comment.