started on structures and implementation

This commit is contained in:
ticticboooom
2022-02-20 20:47:44 +00:00
parent 8858322417
commit f74e7db4df
65 changed files with 337 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ import net.minecraft.util.ResourceLocation;
import org.lwjgl.system.CallbackI;
public class Ref {
public static final String MOD_ID = "masterfulmachinery";
public static final String MOD_ID = "mm";
public static ResourceLocation res(String path){
return new ResourceLocation(MOD_ID, path);
}
@@ -15,5 +15,14 @@ public class Ref {
public static final ResourceLocation ITEM_TYPE = res("items");
}
public static final class Reg {
public static final ResourceLocation STRUCTURE_KEY_TYPE = res("structures/key_type");
public static final class SKT {
public static final ResourceLocation BLOCK = res("block");
public static final ResourceLocation PORT = res("port");
public static final ResourceLocation PORT_TIER = res("port_tier");
}
}
public static final ResourceLocation JEI_PLUGIN = res("jei");
}

View File

@@ -20,7 +20,7 @@ public class MMItemGroup extends ItemGroup {
public static final MMItemGroup INSTANCE = new MMItemGroup();
public MMItemGroup() {
super("masterfulmachinery");
super("mm");
}
@Override

View File

@@ -1,7 +1,9 @@
package com.ticticboooom.mods.mm.data;
import com.electronwill.nightconfig.core.conversion.ConversionTable;
import com.ticticboooom.mods.mm.data.model.ControllerModel;
import com.ticticboooom.mods.mm.data.model.PortModel;
import com.ticticboooom.mods.mm.data.model.StructureModel;
import net.minecraft.util.ResourceLocation;
import java.util.HashMap;
@@ -10,4 +12,5 @@ import java.util.Map;
public class DataRegistry {
public static final Map<ResourceLocation, ControllerModel> CONTROLLERS = new HashMap<>();
public static final Map<ResourceLocation, PortModel> PORTS = new HashMap<>();
public static final Map<ResourceLocation, StructureModel> STRUCTURES = new HashMap<>();
}

View File

@@ -0,0 +1,18 @@
package com.ticticboooom.mods.mm.data.model;
import net.minecraft.util.ResourceLocation;
import java.util.List;
import java.util.Map;
public class StructureModel {
public ResourceLocation id;
public ResourceLocation controllerId;
public List<List<String>> pattern;
public Map<Character, Key> keys;
public static final class Key {
public ResourceLocation type;
public Object data;
}
}

View File

@@ -22,7 +22,7 @@ public class ControllerReloadListener extends JsonReloadListener {
public static final Gson GSON = new Gson();
public ControllerReloadListener() {
super(GSON, "masterfulmachinery/controllers");
super(GSON, "mm/controllers");
}
@SubscribeEvent

View File

@@ -22,7 +22,7 @@ public class PortReloadListener extends JsonReloadListener {
public static final Gson GSON = new Gson();
public PortReloadListener() {
super(GSON, "masterfulmachinery/ports");
super(GSON, "mm/port_tiers");
}
@SubscribeEvent

View File

@@ -2,6 +2,9 @@ package com.ticticboooom.mods.mm.data.reload;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ticticboooom.mods.mm.data.DataRegistry;
import com.ticticboooom.mods.mm.data.model.StructureModel;
import net.minecraft.client.resources.JsonReloadListener;
import net.minecraft.profiler.IProfiler;
import net.minecraft.resources.IResourceManager;
@@ -17,7 +20,7 @@ public class StructureReloadListener extends JsonReloadListener {
public static final Gson GSON = new Gson();
public StructureReloadListener() {
super(GSON, "masterfulmachinery/machines");
super(GSON, "mm/machines");
}
@SubscribeEvent
@@ -27,6 +30,12 @@ public class StructureReloadListener extends JsonReloadListener {
@Override
protected void apply(Map<ResourceLocation, JsonElement> objectIn, IResourceManager resourceManagerIn, IProfiler profilerIn) {
for (Map.Entry<ResourceLocation, JsonElement> entry : objectIn.entrySet()) {
DataRegistry.STRUCTURES.put(entry.getKey(), parse(entry.getKey(), entry.getValue().getAsJsonObject()));
}
}
private StructureModel parse(ResourceLocation key, JsonObject asJsonObject) {
}
}

View File

@@ -0,0 +1,28 @@
package com.ticticboooom.mods.mm.setup;
import com.ticticboooom.mods.mm.Ref;
import com.ticticboooom.mods.mm.structures.StructureKeyType;
import com.ticticboooom.mods.mm.structures.keys.BlockStructureKeyType;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.RegistryBuilder;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class MMRegistries {
public static IForgeRegistry<StructureKeyType> STRUCTURE_KEY_TYPES;
@SubscribeEvent
public static void on(RegistryEvent.NewRegistry event) {
STRUCTURE_KEY_TYPES = new RegistryBuilder<StructureKeyType>().setName(Ref.Reg.STRUCTURE_KEY_TYPE).setType(StructureKeyType.class).create();
}
@SubscribeEvent
public static void register(RegistryEvent.Register<StructureKeyType> event) {
event.getRegistry().registerAll(
new BlockStructureKeyType().setRegistryName(Ref.Reg.SKT.BLOCK)
);
}
}

View File

@@ -0,0 +1,13 @@
package com.ticticboooom.mods.mm.structures;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.ForgeRegistryEntry;
import java.util.List;
public abstract class StructureKeyType extends ForgeRegistryEntry<StructureKeyType> {
public abstract boolean matches(JsonElement json);
public abstract Object parse(JsonElement json, List<ResourceLocation> controllerIds, ResourceLocation structureId);
}

View File

@@ -0,0 +1,63 @@
package com.ticticboooom.mods.mm.structures.keys;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ticticboooom.mods.mm.data.util.ParserUtils;
import com.ticticboooom.mods.mm.structures.StructureKeyType;
import net.minecraft.util.ResourceLocation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BlockStructureKeyType extends StructureKeyType {
@Override
public boolean matches(JsonElement json) {
if (json.isJsonPrimitive()){
return true;
}
if (json.isJsonObject()){
if (json.getAsJsonObject().has("include")) {
return true;
}
}
return false;
}
@Override
public Object parse(JsonElement json, List<ResourceLocation> controllerIds, ResourceLocation structureId) {
Value result = new Value();
result.blockSelector = new ArrayList<>();
if (json.isJsonPrimitive()) {
result.blockSelector.add(json.getAsString());
return result;
}
if (json.isJsonObject()) {
JsonObject jsonObj = json.getAsJsonObject();
JsonElement includesJson = jsonObj.get("include");
if (includesJson.isJsonPrimitive()) {
result.blockSelector.add(includesJson.getAsString());
return result;
}
JsonArray includes = includesJson.getAsJsonArray();
includes.forEach(x -> result.blockSelector.add(x.getAsString()));
result.properties = ParserUtils.parseOrDefault(jsonObj, "properties", x -> {
HashMap<String, String> res = new HashMap<>();
JsonObject obj = x.getAsJsonObject();
obj.keySet().forEach(z -> {
res.put(z, obj.get(z).getAsString());
});
return res;
}, new HashMap<>());
}
return result;
}
public static final class Value {
public List<String> blockSelector;
public Map<String, String> properties;
}
}

View File

@@ -0,0 +1,34 @@
package com.ticticboooom.mods.mm.structures.keys;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ticticboooom.mods.mm.Ref;
import com.ticticboooom.mods.mm.data.util.ParserUtils;
import com.ticticboooom.mods.mm.structures.StructureKeyType;
import net.minecraft.util.ResourceLocation;
import java.util.List;
import java.util.Optional;
public class PortStructureKeyType extends StructureKeyType {
@Override
public boolean matches(JsonElement json) {
JsonObject obj = json.getAsJsonObject();
String type = obj.get("type").getAsString();
return type.equals(Ref.Reg.SKT.PORT.toString());
}
@Override
public Object parse(JsonElement json, List<ResourceLocation> controllerIds, ResourceLocation structureId) {
Value result = new Value();
JsonObject obj = json.getAsJsonObject();
result.port = ResourceLocation.tryCreate(obj.get("port").getAsString());
result.input = ParserUtils.parseOrDefault(obj, "input", x -> Optional.of(x.getAsBoolean()), Optional.empty());
return result;
}
public static final class Value {
public ResourceLocation port;
public Optional<Boolean> input;
}
}

View File

@@ -0,0 +1,29 @@
package com.ticticboooom.mods.mm.structures.keys;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ticticboooom.mods.mm.Ref;
import com.ticticboooom.mods.mm.data.util.ParserUtils;
import com.ticticboooom.mods.mm.structures.StructureKeyType;
import net.minecraft.util.ResourceLocation;
import java.util.List;
import java.util.Optional;
public class PortTierStructureKeyType extends StructureKeyType {
@Override
public boolean matches(JsonElement json) {
JsonObject obj = json.getAsJsonObject();
String type = obj.get("type").getAsString();
return type.equals(Ref.Reg.SKT.PORT_TIER.toString());
}
@Override
public Object parse(JsonElement json, List<ResourceLocation> controllerIds, ResourceLocation structureId) {
}
public static final class Value {
public ResourceLocation portTier;
public Optional<Boolean> input;
}
}

View File

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

View File

Before

Width:  |  Height:  |  Size: 693 B

After

Width:  |  Height:  |  Size: 693 B

View File

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

View File

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

View File

@@ -1,7 +1,7 @@
{
"controllerId": "main",
"controllerId": "test:main",
"name": "Main Items",
"type": "masterfulmachinery:items",
"type": "mm:items",
"defaultModel": {
"block": "minecraft:sponge",
"properties": {}

View File

@@ -0,0 +1,21 @@
{
"structure": "test:mystructure",
"inputs": {
"firstboi": {
"type": "mm:modifiable",
"modifier_results": {
"starter": {
"type": "mm:nothing"
},
"basic": {
"type": "mm:speed",
"ticks": "-10%"
},
"intermediate": {
"type": "mm:chance",
"chance": "+10%"
}
}
}
}
}

View File

@@ -0,0 +1,100 @@
{
"controllerId": [
"test:main",
"test:second"
],
"controllerSettings": {
"facing": "west"
},
"pattern": [
[
"ABC",
"DEF",
"GHI"
],
[
" ",
" C ",
" "
],
[
"KLM",
"NOP",
" "
]
],
"keys": {
"A": {
"include": [
"minecraft:dirt",
"#minecraft:logs"
]
},
"B": "minecraft:glass",
"D": "#minecraft:wools",
"E": {
"include": "#minecraft:logs",
"exclude": [
"minecraft:oak_log"
]
},
"F": {
"type": "mm:port_group",
"group": "mygroup"
},
"G": {
"type": "mm:port_tier",
"portTier": "item_main",
"input": false
},
"H": {
"type": "mm:port",
"port": "mm:items",
"input": true
},
"I": {
"type": "mm:modifiable",
"modifiers": {
"starter": "minecraft:air",
"basic": {
"include": [
"minecraft:stone",
"minecraft:cobblestone"
]
},
"intermediate": {
"include": "minecraft:iron_block"
}
}
},
"J": {
"include": "#minecraft:logs",
"properties": {
"axis": "x"
}
}
},
"requiredPorts": {
"first": {
"port": "mm:items",
"input": true,
"tiers": [
"item_main"
]
},
"second": {
"port": "mm:fluids",
"input": false
},
"third": {
"port": "mm:fluids",
"input": true
}
},
"portGroupings": {
"mygroup": [
"first",
"third"
]
}
}

View File

@@ -1,2 +1,2 @@
#Mon Feb 07 23:27:43 GMT 2022
VERSION_CODE=1356
#Thu Feb 17 07:48:47 GMT 2022
VERSION_CODE=1358