-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b81ca0
commit 94b1cc9
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/mods/bio/gttweaker/oredict/CTMaterialData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
src/main/java/mods/bio/gttweaker/oredict/CTMaterialStack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |