Skip to content

Commit

Permalink
Fixed resource gen code, implemented new systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragonoidzero committed Jun 9, 2021
1 parent 6d8ce8c commit 81b8f33
Show file tree
Hide file tree
Showing 18 changed files with 370 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package azzy.fabric.incubus_core;

import azzy.fabric.incubus_core.datagen.Metadata;
import azzy.fabric.incubus_core.misc.HandPistonItem;
import azzy.fabric.incubus_core.misc.IncubusToolMaterials;
import azzy.fabric.incubus_core.misc.IncubusItemGroups;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/azzy/fabric/incubus_core/datagen/BSJsonGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

import java.io.IOException;

@SuppressWarnings("unused")
public class BSJsonGen {

public static void genBlockBS(Metadata metadata, Identifier identifier, String path) {

if(!metadata.allowRegen)
return;

String id = identifier.getNamespace() + ":" + path + identifier.getPath();

String json = "{\n" +
Expand All @@ -28,6 +32,9 @@ public static void genBlockBS(Metadata metadata, Identifier identifier, String p

public static void genSlabBS(Metadata metadata, Identifier identifier, Identifier parentIdentifier, String path) {

if(!metadata.allowRegen)
return;

String id = identifier.getNamespace() + ":" + path + identifier.getPath();
String parentId = parentIdentifier.getNamespace() + ":" + path + parentIdentifier.getPath();

Expand All @@ -53,6 +60,9 @@ public static void genSlabBS(Metadata metadata, Identifier identifier, Identifie

public static void genWallBS(Metadata metadata, Identifier identifier, String path) {

if(!metadata.allowRegen)
return;

String id = identifier.getNamespace() + ":" + path + identifier.getPath();

String json = "{\n" +
Expand Down Expand Up @@ -154,6 +164,9 @@ public static void genWallBS(Metadata metadata, Identifier identifier, String pa

public static void genStairsBS(Metadata metadata, Identifier identifier, String path) {

if(!metadata.allowRegen)
return;

String id = identifier.getNamespace() + ":" + path + identifier.getPath();

String json = "{\n" +
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/azzy/fabric/incubus_core/datagen/LootGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

import java.io.IOException;

@SuppressWarnings("unused")
public class LootGen {

public static void genSimpleBlockDropTable(Metadata metadata, Block block) {

if(!metadata.allowRegen)
return;

Identifier id = Registry.ITEM.getId(block.asItem());

String json = "{\n" +
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/azzy/fabric/incubus_core/datagen/Metadata.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
package azzy.fabric.incubus_core.datagen;

import azzy.fabric.incubus_core.IncubusCoreCommon;
import azzy.fabric.incubus_core.datagen.Metadata.DataType;
import azzy.fabric.incubus_core.datagen.Metadata.ResourceType;
import net.fabricmc.loader.api.FabricLoader;
import org.apache.logging.log4j.Marker;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

public class Metadata {

public final String resourcePath;
public final String dataPath;

public Metadata(String id) {
public final boolean allowRegen;

public Metadata(String id, String regenVar) {
genCheck: {
String[] args = FabricLoader.getInstance().getLaunchArguments(false);
for (String arg : args) {
if(arg.equals(regenVar)) {
allowRegen = true;
break genCheck;
}
}
allowRegen = false;
}

IncubusCoreCommon.LOG.error("Datagen integration detected for " + id + " - arg - " + regenVar + " - state - " + (allowRegen ? "ENABLED" : "DISABLED"));

this.resourcePath = Paths.get(System.getProperty("user.dir")).getParent().toString() + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "assets" + File.separator + id;
this.dataPath = Paths.get(System.getProperty("user.dir")).getParent().toString() + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "data" + File.separator + id;
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/azzy/fabric/incubus_core/datagen/ModelJsonGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import java.io.File;
import java.io.IOException;

@SuppressWarnings("unused")
public class ModelJsonGen {

public static void genItemJson(Metadata metadata, Identifier name) {

if(!metadata.allowRegen)
return;

String item = "{\n" +
" \"parent\": \"item/generated\",\n" +
" \"textures\": {\n" +
Expand All @@ -25,6 +30,10 @@ public static void genItemJson(Metadata metadata, Identifier name) {
}

public static void genBlockJson(Metadata metadata, Identifier texId, Identifier name, String path) {

if(!metadata.allowRegen)
return;

String block = "{\n" +
" \"parent\": \"minecraft:block/cube_all\",\n" +
" \"textures\": {\n" +
Expand All @@ -45,6 +54,10 @@ public static void genBlockJson(Metadata metadata, Identifier texId, Identifier
}

public static void genSlabJsons(Metadata metadata, Identifier texId, Identifier name, String path) {

if(!metadata.allowRegen)
return;

String bottom = "{\n" +
" \"parent\": \"minecraft:block/slab\",\n" +
" \"textures\": {\n" +
Expand Down Expand Up @@ -77,6 +90,10 @@ public static void genSlabJsons(Metadata metadata, Identifier texId, Identifier
}

public static void genStairJsons(Metadata metadata, Identifier texId, Identifier name, String path) {

if(!metadata.allowRegen)
return;

String normal = "{\n" +
" \"parent\": \"minecraft:block/stairs\",\n" +
" \"textures\": {\n" +
Expand Down Expand Up @@ -121,6 +138,10 @@ public static void genStairJsons(Metadata metadata, Identifier texId, Identifier
}

public static void genWallJsons(Metadata metadata, Identifier texId, Identifier name, String path) {

if(!metadata.allowRegen)
return;

String post = "{\n" +
" \"parent\": \"minecraft:block/template_wall_post\",\n" +
" \"textures\": {\n" +
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/azzy/fabric/incubus_core/datagen/RecipeJsonGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class RecipeJsonGen {
"}";

public static void genFurnaceRecipe(Metadata metadata, String name, Item input, Item output, float xp, int time) {

if(!metadata.allowRegen)
return;

genDynamicRecipe(
metadata,
name,
Expand All @@ -34,6 +38,10 @@ public static void genFurnaceRecipe(Metadata metadata, String name, Item input,
}

public static void genDynamicRecipe(Metadata metadata, String name, String category, String template, String[] components) {

if(!metadata.allowRegen)
return;

String output = "" + template;
for (int i = 0; i < components.length; i++) {
output = output.replace("component_" + i, components[i]);
Expand All @@ -47,6 +55,9 @@ public static void genDynamicRecipe(Metadata metadata, String name, String categ

public static void gen2x2Recipe(Metadata metadata, String name, Item in, Item out, int count) {

if(!metadata.allowRegen)
return;

String output = Registry.ITEM.getId(out).toString();
String input = Registry.ITEM.getId(in).toString();

Expand Down Expand Up @@ -76,6 +87,9 @@ public static void gen2x2Recipe(Metadata metadata, String name, Item in, Item ou

public static void gen3x3Recipe(Metadata metadata, String name, Item in, Item out, int count) {

if(!metadata.allowRegen)
return;

String output = Registry.ITEM.getId(out).toString();
String input = Registry.ITEM.getId(in).toString();

Expand Down Expand Up @@ -106,6 +120,9 @@ public static void gen3x3Recipe(Metadata metadata, String name, Item in, Item ou

public static void genSlabRecipe(Metadata metadata, String name, Item in, Item out, int count) {

if(!metadata.allowRegen)
return;

String output = Registry.ITEM.getId(out).toString();
String input = Registry.ITEM.getId(in).toString();

Expand Down Expand Up @@ -134,6 +151,9 @@ public static void genSlabRecipe(Metadata metadata, String name, Item in, Item o

public static void genStairsRecipe(Metadata metadata, String name, Item in, Item out, int count) {

if(!metadata.allowRegen)
return;

String output = Registry.ITEM.getId(out).toString();
String input = Registry.ITEM.getId(in).toString();

Expand Down Expand Up @@ -164,6 +184,9 @@ public static void genStairsRecipe(Metadata metadata, String name, Item in, Item

public static void genWallRecipe(Metadata metadata, String name, Item in, Item out, int count) {

if(!metadata.allowRegen)
return;

String output = Registry.ITEM.getId(out).toString();
String input = Registry.ITEM.getId(in).toString();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package azzy.fabric.incubus_core.systems;

import azzy.fabric.incubus_core.IncubusCoreCommon;
import net.minecraft.recipe.Ingredient;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

@SuppressWarnings("unused")
public class DefaultMaterials {

public static void init() {}

//public static final Material MYRCIL = register("myrcil", new Material(475, 0.03, 0, 0, 27500));
public static final Material IRON = register("iron", new Material(1250, 9.5, 5.75, 8.5, 2048, 512, 85000, new Identifier("c", "iron_ingots")));
public static final Material COPPER = register("copper", new Material(700, 21.5, 17.5, 5.5, 256, 128, 15000, new Identifier("c", "copper_ingots")));
public static final Material GOLD = register("gold", new Material(600, 15, 13, 1.5, 256, 64, 22500, new Identifier("c", "gold_ingots")));
public static final Material DIAMOND = register("diamond", new Material(250, 52.75, 35, 2.5, 16384, 128, 137000, new Identifier("c", "diamonds")));
public static final Material AMETHYST = register("amethyst", new Material(850, 13.5, 36.75, 9.5, 4096, 256, 47000, new Identifier("c", "amethyst")));
//public static final Material HSLA_STEEL = register("hsla_steel", new Material(1600, 0.25, 1024, 2048, 150000));
//public static final Material UNOBTANIUM = register("unobtanium", new Material(Double.POSITIVE_INFINITY, 1, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY));

private static Material register(String id, Material material) {
return Registry.register(RegistryRegistry.MATERIAL, new Identifier(IncubusCoreCommon.MODID), material);
}
}
68 changes: 68 additions & 0 deletions src/main/java/azzy/fabric/incubus_core/systems/HeatHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package azzy.fabric.incubus_core.systems;

import net.minecraft.world.biome.Biome;

public class HeatHelper {

public static double exchangeHeat(HeatMaterial medium, double tempA, double tempB, double exchangeArea) {
return medium.transfer * exchangeArea * (tempA - tempB);
}

public static double playerAmbientHeat(HeatMaterial medium, double playerTemp, Biome biome, boolean night, boolean rain, int height) {
return -exchangeHeat(medium, playerTemp, translateBiomeHeat(biome, night, rain, height), 4.5);
}

public static double translateBiomeHeat(Biome biome, boolean night, boolean rain, int height) {
double temp;
if (biome.getCategory() == Biome.Category.NETHER) {
temp = (biome.getTemperature() + 2) * 31.25;
} else if (biome.getCategory() == Biome.Category.THEEND) {
temp = (biome.getTemperature() - 1.5) * 31.25;
} else {
temp = biome.getTemperature() * 31.25;
}
if(night) {
if(biome.getCategory() == Biome.Category.DESERT || biome.getCategory() == Biome.Category.MESA) {
temp -= temp * 0.75;
} else if(biome.getPrecipitation() == Biome.Precipitation.SNOW) {
if(biome.getCategory() == Biome.Category.ICY && temp < 0)
temp += temp * 1.25;
else
temp -= 20;

} else {
temp -= (biome.getPrecipitation() == Biome.Precipitation.NONE) ? 12 : 4;
}
}
if(rain) {
temp -= biome.getPrecipitation() == Biome.Precipitation.SNOW || biome.getPrecipitation() == Biome.Precipitation.RAIN && height >= 100 ? 10 : 3;
}
return temp;
}

public enum HeatMaterial {
NULL(0.0),
AIR(0.026),
BRICK(0.6),
STEEL(50.2),
WATER(0.6),
GENERIC_FLUID(0.35),
DIAMOND(335.2),
GRANITE(1.73),
BEDROCK(400);

private final double transfer;

HeatMaterial(double transfer) {
this.transfer = transfer / 419.0;
}

public static HeatMaterial nullableValueOf(String name){
try {
return HeatMaterial.valueOf(name);
} catch (Exception ignored){
return NULL;
}
}
}
}
33 changes: 33 additions & 0 deletions src/main/java/azzy/fabric/incubus_core/systems/HeatIo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package azzy.fabric.incubus_core.systems;

/**
* An object that can hold and optionally take and provide heat energy.
*/
public interface HeatIo {

/**
* Get the amount of heat stored.
*/
double getTemperature();

/**
* Return false if this object does not support insertion at all, meaning that insertion will always return the passed amount,
* and insert-only cables should not connect.
*/
default boolean supportsTransfer() {
return false;
}

/**
* Insert heat into this inventory, and return the amount of leftover heat.
*
* <p>If simulation is {@link Simulation#SIMULATE}, the result of the operation must be returned, but the underlying state of the object must not change.
*
* @param amount The amount of heat to insert
* @param simulation If {@link Simulation#SIMULATE}, do not mutate this object
* @return the amount of heat that could not be inserted
*/
default double heat(double amount, Simulation simulation) {
return amount;
}
}
31 changes: 31 additions & 0 deletions src/main/java/azzy/fabric/incubus_core/systems/Material.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package azzy.fabric.incubus_core.systems;

import azzy.fabric.incubus_core.util.TagSuperset;
import net.minecraft.item.Item;
import net.minecraft.recipe.Ingredient;
import net.minecraft.tag.ServerTagManagerHolder;
import net.minecraft.tag.Tag;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.DefaultedRegistry;

import java.util.function.Supplier;

public class Material {

public final TagSuperset<Item> tags;
public final double maxTemperature, heatConductivity;
public final double electricalConductivity, resistance;
public final long maxRads, maxNm;
public final double maxPressure;

public Material(double maxTemperature, double heatConductivity, double electricalConductivity, double resistance, long maxRads, long maxNm, double maxPressure, Identifier ... components) {
this.tags = new TagSuperset<>(DefaultedRegistry.ITEM_KEY, components);
this.maxTemperature = maxTemperature;
this.heatConductivity = heatConductivity / 100;
this.electricalConductivity = electricalConductivity / 100;
this.resistance = resistance / 100;
this.maxRads = maxRads;
this.maxNm = maxNm;
this.maxPressure = maxPressure;
}
}
Loading

0 comments on commit 81b8f33

Please sign in to comment.