Skip to content

Commit

Permalink
* make MaterialData more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
bioastroiner committed Dec 16, 2023
1 parent c66c920 commit 1c79cd4
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 33 deletions.
53 changes: 26 additions & 27 deletions src/main/java/mods/bio/gttweaker/command/GTCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import minetweaker.api.minecraft.MineTweakerMC;
import minetweaker.api.player.IPlayer;
import minetweaker.api.server.ICommandFunction;
import mods.bio.gttweaker.mods.gregtech.oredict.CTMaterial;
import mods.bio.gttweaker.mods.gregtech.oredict.CTPrefix;
import mods.bio.gttweaker.mods.gregtech.oredict.CTMaterialData;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -52,32 +51,32 @@ private static void HAND(String[] arguments, IPlayer player) {
// TODO Implement GT Hand recipe for held item
IItemStack item = player.getCurrentItem();
if (item != null) {
OreDictItemData data = OreDictManager.INSTANCE.getAssociation(MineTweakerMC.getItemStack(item),true);
CTMaterialData data = CTMaterialData.association(item);
if(data!=null){
List<String> list = new ArrayList<>();
list.add("=============================");
list.add("== OP: " + new CTPrefix(data.mPrefix));
list.add("== MT: "+ new CTMaterial(data.mMaterial.mMaterial));
list.add("== UNI: " + MineTweakerMC.getIItemStack(data.getStack(1)));
list.add("** MineTweaker **");
list.add("== IOreDict: <ore:"+data +">");
list.add("== IItemStack: "+item);
list.add("=============================");
list.forEach(player::sendChat);
list.forEach(MineTweakerAPI::logCommand);
// copy the <prefix:material> into inventory
// copies the <ore:prefix-material> into clipboard
if(arguments.length < 2)
player.sendChat("Supply additional flags \"ore\" and \"item\" to copy the IOreDict and IItemStack into your clipboard respectively.");
if(arguments.length > 1 && Objects.equals(arguments[1],"ore")){
player.sendChat("<ore:"+data +">" + " was coppied to your clipboard");
copyToClipboard("<ore:"+data +">");
}
else if(arguments.length > 1 && Objects.equals(arguments[1],"item")) {
player.sendChat(MineTweakerMC.getIItemStack(data.getStack(1)).toString() +" was coppied to your clipboard");
//player.sendChat("use /minetweaker gt6 hand {ore} , In Order to get the <ore:prefix-material> enrty");
copyToClipboard(MineTweakerMC.getIItemStack(data.getStack(1)).toString());
}
List<String> list = new ArrayList<>();
list.add("=============================");
list.add("== OP: " + data.prefix());
list.add("== MT: "+ data.material());
list.add("== UNI: " + MineTweakerMC.getIItemStack(data.backingData.getStack(1)));
list.add("** MineTweaker **");
list.add("== IOreDict: <ore:"+data.backingData +">");
list.add("== IItemStack: "+item);
list.add("=============================");
list.forEach(player::sendChat);
list.forEach(MineTweakerAPI::logCommand);
// copy the <prefix:material> into inventory
// copies the <ore:prefix-material> into clipboard
if(arguments.length < 2)
player.sendChat("Supply additional flags \"ore\" and \"item\" to copy the IOreDict and IItemStack into your clipboard respectively.");
if(arguments.length > 1 && Objects.equals(arguments[1],"ore")){
player.sendChat("<ore:"+data.backingData +">" + " was coppied to your clipboard");
copyToClipboard("<ore:"+data.backingData +">");
}
else if(arguments.length > 1 && Objects.equals(arguments[1],"item")) {
player.sendChat(MineTweakerMC.getIItemStack(data.backingData.getStack(1)).toString() +" was coppied to your clipboard");
//player.sendChat("use /minetweaker gt6 hand {ore} , In Order to get the <ore:prefix-material> enrty");
copyToClipboard(MineTweakerMC.getIItemStack(data.backingData.getStack(1)).toString());
}
}else player.sendChat("Item { "+item+ "} dose not contain GT associated data!");
} else player.sendChat("No item was found");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package mods.bio.gttweaker.mods.gregtech.oredict;

import gregapi.oredict.OreDictItemData;
import gregapi.oredict.OreDictManager;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IItemStack;
import minetweaker.api.minecraft.MineTweakerMC;
import minetweaker.api.oredict.IOreDictEntry;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;

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

import static gregapi.data.CS.F;

@ZenClass("mods.gregtech.oredict.MaterialData")
public class CTMaterialData {
private final OreDictItemData backingData;
public final OreDictItemData backingData;
@ZenGetter
public CTMaterialStack material(){
if(backingData.mMaterial != null) return new CTMaterialStack(backingData.mMaterial);
Expand Down Expand Up @@ -41,8 +48,27 @@ public List<CTMaterialStack> materials(){
return list;
}

public CTMaterialData(OreDictItemData backingData) {
private CTMaterialData(OreDictItemData backingData) {
this.backingData = backingData;
if(backingData==null) {
MineTweakerAPI.logError("Material Data cannot be null",new NullPointerException("Not a valid Material Data."));
}
}

@ZenMethod
public static CTMaterialData association(IItemStack item){
OreDictItemData data = OreDictManager.INSTANCE.getAssociation(MineTweakerMC.getItemStack(item),F);
if(data!=null) return new CTMaterialData(data);
MineTweakerAPI.logError(item + " dose not have a GT Association!");
return null;
}

@ZenMethod
public static CTMaterialData association(IOreDictEntry ore){
OreDictItemData data = OreDictManager.INSTANCE.getAutomaticItemData(ore.getName());
if(data!=null) return new CTMaterialData(data);
MineTweakerAPI.logError(ore + " dose not have a GT Association!");
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public static boolean removeMaterialData(IItemStack aIItemStack) {
return CTUnifier.removeRecyclingCT(aIItemStack);
}

@ZenGetter
public static CTMaterialData association(IItemStack iItemStack){
return CTMaterialData.association(iItemStack);
}

@ZenGetter
public static CTMaterialData data(IItemStack iItemStack){
OreDictItemData data = OreDictManager.INSTANCE.getAssociation_(MineTweakerMC.getItemStack(iItemStack), false);
if(data!=null) return new CTMaterialData(data);
MineTweakerAPI.logError(String.format("%s dose not contain any gt material data", iItemStack));
return null;
return association(iItemStack);
}

@ZenGetter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import minetweaker.api.item.IItemStack;
import minetweaker.api.oredict.IOreDictEntry;
import mods.bio.gttweaker.mods.gregtech.oredict.CTMaterial;
import mods.bio.gttweaker.mods.gregtech.oredict.CTMaterialData;
import mods.bio.gttweaker.mods.gregtech.oredict.CTPrefix;
import mods.bio.gttweaker.mods.gregtech.oredict.CTUnifier;
import stanhebben.zenscript.annotations.ZenExpansion;
Expand All @@ -29,4 +30,14 @@ public static CTPrefix prefix(IOreDictEntry oreDictEntry){
public static long amount(IOreDictEntry oreDictEntry){
return prefix(oreDictEntry).amount();
}

@ZenGetter
public static CTMaterialData association(IOreDictEntry oreDictEntry){
return CTMaterialData.association(oreDictEntry);
}

@ZenGetter
public static CTMaterialData data(IOreDictEntry oreDictEntry){
return association(oreDictEntry);
}
}

0 comments on commit 1c79cd4

Please sign in to comment.