Skip to content

Commit

Permalink
start work on CT material appenders
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Sep 5, 2021
1 parent 3247af2 commit 74c1c43
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ protected static boolean checkFrozen(String description) {
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());
}

protected static void logPropertyExists(Material m, String propName) {
CraftTweakerAPI.logWarning("Material " + m.getUnlocalizedName() + " has " + propName + " already. Skipping...");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,121 @@

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

import static gregtech.api.unification.crafttweaker.CTMaterialHelpers.*;

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

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

// TODO
@ZenMethod
public static boolean hasDust(Material m) {
return m.hasProperty(PropertyKey.DUST);
}

@ZenMethod
public static boolean hasFluidPipes(Material m) {
return m.hasProperty(PropertyKey.FLUID_PIPE);
}

@ZenMethod
public static boolean hasFluid(Material m) {
return m.hasProperty(PropertyKey.FLUID);
}

@ZenMethod
public static boolean hasGem(Material m) {
return m.hasProperty(PropertyKey.GEM);
}

@ZenMethod
public static boolean hasIngot(Material m) {
return m.hasProperty(PropertyKey.INGOT);
}

@ZenMethod
public static boolean hasItemPipes(Material m) {
return m.hasProperty(PropertyKey.ITEM_PIPE);
}

@ZenMethod
public static boolean hasOre(Material m) {
return m.hasProperty(PropertyKey.ORE);
}

@ZenMethod
public static boolean hasPlasma(Material m) {
return m.hasProperty(PropertyKey.PLASMA);
}

@ZenMethod
public static boolean hasTools(Material m) {
return m.hasProperty(PropertyKey.TOOL);
}

@ZenMethod
public static boolean hasWires(Material m) {
return m.hasProperty(PropertyKey.WIRE);
}

// Property Setters
@ZenMethod
public static void addBlastTemp(Material m, int blastTemp) {
if (checkFrozen("add blast temperature")) return;
if (m.hasProperty(PropertyKey.BLAST)) m.getProperty(PropertyKey.BLAST).setBlastTemperature(blastTemp);
else m.setProperty(PropertyKey.BLAST, new BlastProperty(blastTemp));
}

@ZenMethod
public static void addDust(Material m, @Optional int harvestLevel, @Optional int burnTime) {
if (checkFrozen("add a dust to a material")) return;
if (harvestLevel == 0) harvestLevel = 2;
if (m.hasProperty(PropertyKey.DUST)) {
m.getProperty(PropertyKey.DUST).setHarvestLevel(harvestLevel);
m.getProperty(PropertyKey.DUST).setBurnTime(burnTime);
} else m.setProperty(PropertyKey.DUST, new DustProperty(harvestLevel, burnTime));
}

@ZenMethod
public static void addFluidPipes(Material m, int maxFluidTemperature, int throughput, boolean gasProof) {
if (checkFrozen("add fluid pipes to a material")) return;
if (m.hasProperty(PropertyKey.FLUID_PIPE)) {
m.getProperty(PropertyKey.FLUID_PIPE).maxFluidTemperature = maxFluidTemperature;
m.getProperty(PropertyKey.FLUID_PIPE).throughput = throughput;
m.getProperty(PropertyKey.FLUID_PIPE).gasProof = gasProof;
} else m.setProperty(PropertyKey.FLUID_PIPE, new FluidPipeProperties(maxFluidTemperature, throughput, gasProof));
}

@ZenMethod
public static void addFluid(Material m, @Optional String fluidTypeName, @Optional boolean hasBlock) {
if (checkFrozen("add a Fluid to a material")) return;
Material.FluidType type = validateFluidType(fluidTypeName);
if (m.hasProperty(PropertyKey.FLUID)) {
m.getProperty(PropertyKey.FLUID).setIsGas(type == Material.FluidType.GAS);
m.getProperty(PropertyKey.FLUID).setHasBlock(hasBlock);
} else m.setProperty(PropertyKey.FLUID, new FluidProperty(type == Material.FluidType.GAS, hasBlock));
}

@ZenMethod
public static void addGem(Material m) {
if (checkFrozen("add a Gem to a material")) return;
if (!m.hasProperty(PropertyKey.GEM)) m.setProperty(PropertyKey.GEM, new GemProperty());
}

@ZenMethod
public static void addIngot(Material m) {
if (checkFrozen("add an Ingot to a material")) return;
if (!m.hasProperty(PropertyKey.INGOT)) m.setProperty(PropertyKey.INGOT, new IngotProperty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

public class FluidPipeProperties implements IMaterialProperty<FluidPipeProperties> {

public final int maxFluidTemperature;
public final int throughput;
public final boolean gasProof;
public int maxFluidTemperature;
public int throughput;
public boolean gasProof;
public final int tanks;

public FluidPipeProperties(int maxFluidTemperature, int throughput, boolean gasProof) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class FluidProperty implements IMaterialProperty<FluidProperty> {
private Fluid fluid;

private boolean hasBlock;
private final boolean isGas;
private boolean isGas;
private int fluidTemperature = BASE_TEMP;

public FluidProperty(boolean isGas, boolean hasBlock) {
Expand Down Expand Up @@ -51,6 +51,14 @@ public boolean hasBlock() {
return hasBlock;
}

public void setHasBlock(boolean hasBlock) {
this.hasBlock = hasBlock;
}

public void setIsGas(boolean isGas) {
this.isGas = isGas;
}

@Nonnull
public FluidStack getFluid(int amount) {
return new FluidStack(fluid, amount);
Expand Down

0 comments on commit 74c1c43

Please sign in to comment.