Skip to content

Commit

Permalink
most work on first ZenExpansion
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Sep 5, 2021
1 parent be1cab6 commit 3247af2
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package gregtech.api.unification.crafttweaker;

import com.google.common.collect.ImmutableList;
import crafttweaker.annotations.ZenRegister;
import gregtech.api.unification.Element;
import gregtech.api.unification.Elements;
import gregtech.api.unification.material.Material;
import gregtech.api.unification.material.Material.FluidType;
import gregtech.api.unification.material.info.MaterialFlag;
import gregtech.api.unification.material.info.MaterialIconSet;
import gregtech.api.unification.stack.MaterialStack;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;

import static gregtech.api.unification.crafttweaker.CTMaterialHelpers.validateComponentList;
import static gregtech.api.unification.crafttweaker.CTMaterialHelpers.validateFluidType;

@ZenClass("mods.gregtech.material.MaterialBuilder")
@ZenRegister
@SuppressWarnings("unused")
Expand Down Expand Up @@ -163,14 +164,4 @@ public CTMaterialBuilder itemPipeProperties(int priority, float stacksPerSec) {
public Material build() {
return backingBuilder.build();
}

private static ImmutableList<MaterialStack> validateComponentList(MaterialStack[] components) {
return components == null || components.length == 0 ? ImmutableList.of() : ImmutableList.copyOf(components);
}

private static FluidType validateFluidType(String fluidTypeName) {
if (fluidTypeName == null || fluidTypeName.equals("fluid")) return FluidType.FLUID;
else if (fluidTypeName.equals("gas")) return FluidType.GAS;
else throw new IllegalArgumentException("Fluid Type must be either \"fluid\" or \"gas\"!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gregtech.api.unification.crafttweaker;

import com.google.common.collect.ImmutableList;
import crafttweaker.CraftTweakerAPI;
import gregtech.api.unification.material.Material;
import gregtech.api.unification.material.MaterialRegistry;
import gregtech.api.unification.stack.MaterialStack;

public class CTMaterialHelpers {

protected static ImmutableList<MaterialStack> validateComponentList(MaterialStack[] components) {
return components == null || components.length == 0 ? ImmutableList.of() : ImmutableList.copyOf(components);
}

protected static Material.FluidType validateFluidType(String fluidTypeName) {
if (fluidTypeName == null || fluidTypeName.equals("fluid")) return Material.FluidType.FLUID;
else if (fluidTypeName.equals("gas")) return Material.FluidType.GAS;
else throw new IllegalArgumentException("Fluid Type must be either \"fluid\" or \"gas\"!");
}

protected static boolean checkFrozen(String description) {
if (MaterialRegistry.isFrozen()) {
CraftTweakerAPI.logError("Cannot " + description + " now, must be done in a file labeled with \"#loader gregtech\"");
return true;
} return false;
}

protected static void logError(Material m, String cause, String type) {
CraftTweakerAPI.logError("Cannot " + cause + " of a Material with no " + type + "! Try calling \"add" + type + "\" in your \"#loader gregtech\" file first if this is intentional. Material: " + m.getUnlocalizedName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package gregtech.api.unification.crafttweaker;

import crafttweaker.CraftTweakerAPI;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.enchantments.IEnchantment;
import crafttweaker.api.liquid.ILiquidDefinition;
import crafttweaker.api.minecraft.CraftTweakerMC;
import gregtech.api.GTValues;
import gregtech.api.enchants.EnchantmentData;
import gregtech.api.unification.material.Material;
import gregtech.api.unification.material.info.MaterialFlag;
import gregtech.api.unification.material.info.MaterialIconSet;
import gregtech.api.unification.material.properties.*;
import net.minecraft.enchantment.Enchantment;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenExpansion;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;

import static gregtech.api.unification.crafttweaker.CTMaterialHelpers.checkFrozen;
import static gregtech.api.unification.crafttweaker.CTMaterialHelpers.logError;

@ZenExpansion("mods.gregtech.material.Material")
@ZenRegister
@SuppressWarnings("unused")
public class MaterialExpansion {

// Basic Material methods
@ZenMethod
public static void setFormula(Material m, String formula, @Optional boolean withFormatting) {
if (checkFrozen("set material chemical formula")) return;
m.setFormula(formula, withFormatting);
}

@ZenMethod
public static boolean hasFlag(Material m, String flagName) {
return m.hasFlag(MaterialFlag.getByName(flagName));
}

@ZenMethod
public static void setIconSet(Material m, String iconSetName) {
if (checkFrozen("set material icon set")) return;
m.setMaterialIconSet(MaterialIconSet.getByName(iconSetName));
}

// Fluid Property
@ZenMethod
public static boolean hasFluid(Material m) { // todo move?
return m.hasProperty(PropertyKey.FLUID);
}

@ZenMethod
public static boolean isGaseous(Material m) {
FluidProperty prop = m.getProperty(PropertyKey.FLUID);
return prop != null && prop.isGas();
}

@ZenMethod
public static void setFluidTemperature(Material m, int fluidTemperature) {
if (checkFrozen("set fluid temperature")) return;
FluidProperty prop = m.getProperty(PropertyKey.FLUID);
if (prop != null) {
prop.setFluidTemperature(fluidTemperature);
} else logError(m, "set temperature", "Fluid");
}

@ZenGetter("fluidTemperature") // todo is this allowed here?
public static int fluidTemperature(Material m) {
FluidProperty prop = m.getProperty(PropertyKey.FLUID);
if (prop != null) {
return prop.getFluidTemperature();
} else logError(m, "get temperature", "Fluid");
return 0;
}

// TODO May need to move this to Material
@ZenGetter("fluid")
@net.minecraftforge.fml.common.Optional.Method(modid = GTValues.MODID_CT)
public static ILiquidDefinition getFluid(Material m) {
FluidProperty prop = m.getProperty(PropertyKey.FLUID);
if (prop != null) {
return CraftTweakerMC.getILiquidDefinition(prop.getFluid());
} else logError(m, "get a Fluid", "Fluid");
return null;
}

// Dust Property
@ZenGetter("harvestLevel")
public static int harvestLevel(Material m) {
DustProperty prop = m.getProperty(PropertyKey.DUST);
if (prop != null) {
return prop.getHarvestLevel();
} else logError(m, "get the harvest level", "Dust");
return 0;
}

@ZenGetter("burnTime")
public static int burnTime(Material m) {
DustProperty prop = m.getProperty(PropertyKey.DUST);
if (prop != null) {
return prop.getBurnTime();
} else logError(m, "get the burn time", "Dust");
return 0;
}

@ZenMethod
public static void setHarvestLevel(Material m, int harvestLevel) {
if (checkFrozen("set harvest level")) return;
DustProperty prop = m.getProperty(PropertyKey.DUST);
if (prop != null) {
prop.setHarvestLevel(harvestLevel);
} else logError(m, "set the harvest level", "Dust");
}

@ZenMethod
public static void setBurnTime(Material m, int burnTime) {
if (checkFrozen("set burn time")) return;
DustProperty prop = m.getProperty(PropertyKey.DUST);
if (prop != null) {
prop.setBurnTime(burnTime);
} else logError(m, "set the burn time", "Dust");
}

// Ingot Property todo

// Plasma Property
@ZenGetter("plasma")
@net.minecraftforge.fml.common.Optional.Method(modid = GTValues.MODID_CT)
public static ILiquidDefinition getPlasma(Material m) {
PlasmaProperty prop = m.getProperty(PropertyKey.PLASMA);
if (prop != null) {
return CraftTweakerMC.getILiquidDefinition(prop.getPlasma());
} else logError(m, "get a Plasma", "Plasma");
return null;
}

// Tool Property
@ZenGetter("toolSpeed")
public static float toolSpeed(Material m) {
ToolProperty prop = m.getProperty(PropertyKey.TOOL);
if (prop != null) {
return prop.toolSpeed;
} else logError(m, "get the tool speed", "Tool");
return 0;
}

@ZenGetter("toolAttackDamage")
public static float attackDamage(Material m) {
ToolProperty prop = m.getProperty(PropertyKey.TOOL);
if (prop != null) {
return prop.toolAttackDamage;
} else logError(m, "get the tool attack damage", "Tool");
return 0;
}

@ZenGetter("toolDurability")
public static int toolDurability(Material m) {
ToolProperty prop = m.getProperty(PropertyKey.TOOL);
if (prop != null) {
return prop.toolDurability;
} else logError(m, "get the tool durability", "Tool");
return 0;
}

@ZenGetter("toolEnchantability")
public static int toolEnchant(Material m) {
ToolProperty prop = m.getProperty(PropertyKey.TOOL);
if (prop != null) {
return prop.toolEnchantability;
} else logError(m, "get the tool enchantability", "Tool");
return 0;
}

@ZenMethod
@net.minecraftforge.fml.common.Optional.Method(modid = GTValues.MODID_CT)
public static void addToolEnchantment(Material m, IEnchantment enchantment) {
if (checkFrozen("add tool enchantment")) return;
ToolProperty prop = m.getProperty(PropertyKey.TOOL);
if (prop != null) {
Enchantment enchantmentType = (Enchantment) enchantment.getDefinition().getInternal();
prop.toolEnchantments.add(new EnchantmentData(enchantmentType, enchantment.getLevel()));
} else logError(m, "change tool enchantments", "Tool");
}

// Wire/Item Pipe/Fluid Pipe stuff?

// Blast Property
@ZenMethod
public static void setBlastTemp(Material m, int blastTemp) {
if (checkFrozen("set blast temperature")) return;
if (blastTemp <= 0) {
CraftTweakerAPI.logError("Blast Temperature must be greater than zero! Material: " + m.getUnlocalizedName());
return;
}
BlastProperty prop = m.getProperty(PropertyKey.BLAST);
if (prop != null) prop.setBlastTemperature(blastTemp);
else m.setProperty(PropertyKey.BLAST, new BlastProperty(blastTemp));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package gregtech.api.unification.crafttweaker;

import crafttweaker.annotations.ZenRegister;
import gregtech.api.unification.material.Material;
import gregtech.api.unification.material.properties.PropertyKey;
import stanhebben.zenscript.annotations.ZenExpansion;
import stanhebben.zenscript.annotations.ZenMethod;

@ZenExpansion("mods.gregtech.material.Material")
@ZenRegister
@SuppressWarnings("unused")
public class MaterialPropertyExpansion {

// Property Checkers and Setters
@ZenMethod
public static boolean hasBlastTemp(Material m) {
return m.hasProperty(PropertyKey.BLAST);
}

// TODO
}
Loading

0 comments on commit 3247af2

Please sign in to comment.