From 85ed121158cc1a06f4a8dba5dcdf05fdba463ead Mon Sep 17 00:00:00 2001 From: ah-OOG-ah <75745146+ah-OOG-ah@users.noreply.github.com> Date: Tue, 20 Feb 2024 12:33:13 -0500 Subject: [PATCH] Remove unready code, for now --- .../models/unready/common/BlockTest.java | 101 ----- .../models/unready/json/JsonModel.java | 355 ------------------ .../angelica/models/unready/json/Loader.java | 118 ------ .../models/unready/json/ModelDisplay.java | 48 --- .../models/unready/json/ModelElement.java | 96 ----- .../models/unready/json/TestBakedModel.java | 90 ----- .../angelica/models/unready/json/Variant.java | 29 -- .../angelica/proxy/CommonProxy.java | 3 - 8 files changed, 840 deletions(-) delete mode 100644 src/main/java/com/gtnewhorizons/angelica/models/unready/common/BlockTest.java delete mode 100644 src/main/java/com/gtnewhorizons/angelica/models/unready/json/JsonModel.java delete mode 100644 src/main/java/com/gtnewhorizons/angelica/models/unready/json/Loader.java delete mode 100644 src/main/java/com/gtnewhorizons/angelica/models/unready/json/ModelDisplay.java delete mode 100644 src/main/java/com/gtnewhorizons/angelica/models/unready/json/ModelElement.java delete mode 100644 src/main/java/com/gtnewhorizons/angelica/models/unready/json/TestBakedModel.java delete mode 100644 src/main/java/com/gtnewhorizons/angelica/models/unready/json/Variant.java diff --git a/src/main/java/com/gtnewhorizons/angelica/models/unready/common/BlockTest.java b/src/main/java/com/gtnewhorizons/angelica/models/unready/common/BlockTest.java deleted file mode 100644 index 0291c9f9b..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/unready/common/BlockTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.gtnewhorizons.angelica.models.unready.common; - -import com.gtnewhorizons.angelica.api.QuadProvider; -import com.gtnewhorizons.angelica.compat.mojang.BlockPos; -import com.gtnewhorizons.angelica.compat.nd.Quad; -import com.gtnewhorizons.angelica.models.unready.json.JsonModel; -import com.gtnewhorizons.angelica.models.unready.json.Loader; -import com.gtnewhorizons.angelica.models.unready.json.Variant; -import com.gtnewhorizons.angelica.utils.ObjectPooler; -import it.unimi.dsi.fastutil.objects.ObjectImmutableList; -import java.util.List; -import java.util.Random; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import org.jetbrains.annotations.NotNull; - -public class BlockTest extends Block implements QuadProvider { - - public static final Variant[] modelId = { - new Variant( - new ResourceLocation("blocks/lectern"), - 0, - 0, - false - ), - new Variant( - new ResourceLocation("blocks/lectern"), - 180, - 0, - false - ), - new Variant( - new ResourceLocation("blocks/lectern"), - 90, - 0, - false - ), - new Variant( - new ResourceLocation("blocks/lectern"), - 270, - 0, - false - ), - }; - public static final List EMPTY = ObjectImmutableList.of(); - private static final JsonModel[] model = new JsonModel[4]; - - public BlockTest() { - - super(Material.rock); - } - - public static void loadModel() { - for (int i = 0; i < 4; ++i) - model[i] = Loader.getModel(modelId[i]); - } - - @Override - public boolean isOpaqueCube() { - return false; - } - - @Override - public void registerBlockIcons(IIconRegister reg) { - - reg.registerIcon("angelica:test_block"); - reg.registerIcon("lectern_base"); - reg.registerIcon("lectern_front"); - reg.registerIcon("lectern_sides"); - reg.registerIcon("lectern_top"); - reg.registerIcon("oak_planks"); - } - - @Override - public List getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, ObjectPooler quadPool) { - - if (meta < 2 || meta > 5) meta = 2; - - return (model[meta - 2] != null) ? model[meta - 2].getQuads(world, pos, block, meta, dir, random, quadPool) : EMPTY; - } - - /** - * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata - */ - @Override - public int onBlockPlaced(@NotNull World worldIn, int x, int y, int z, int side, float subX, float subY, float subZ, int meta) { - - // Face NORTH if placed up or down - final ForgeDirection s = ForgeDirection.values()[side]; - if (s == ForgeDirection.UP || s == ForgeDirection.DOWN) - return 2; - - // Face the placed side - return side; - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/unready/json/JsonModel.java b/src/main/java/com/gtnewhorizons/angelica/models/unready/json/JsonModel.java deleted file mode 100644 index 063da0999..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/unready/json/JsonModel.java +++ /dev/null @@ -1,355 +0,0 @@ -package com.gtnewhorizons.angelica.models.unready.json; - -import com.google.gson.JsonArray; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.gtnewhorizons.angelica.api.QuadProvider; -import com.gtnewhorizons.angelica.compat.mojang.Axis; -import com.gtnewhorizons.angelica.compat.mojang.BlockPos; -import com.gtnewhorizons.angelica.compat.nd.Quad; -import com.gtnewhorizons.angelica.models.NdQuadBuilder; -import com.gtnewhorizons.angelica.utils.DirUtil; -import com.gtnewhorizons.angelica.utils.ObjectPooler; -import it.unimi.dsi.fastutil.Function; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import it.unimi.dsi.fastutil.objects.ObjectImmutableList; -import java.lang.reflect.Type; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Random; -import net.minecraft.block.Block; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.common.util.ForgeDirection; -import org.jetbrains.annotations.Nullable; -import org.joml.Matrix4f; -import org.joml.Vector3f; -import org.joml.Vector4f; - -import static com.gtnewhorizons.angelica.utils.JsonUtil.loadBool; -import static com.gtnewhorizons.angelica.utils.JsonUtil.loadFloat; -import static com.gtnewhorizons.angelica.utils.JsonUtil.loadInt; -import static com.gtnewhorizons.angelica.utils.JsonUtil.loadStr; - -public class JsonModel implements QuadProvider { - - @Nullable - private final ResourceLocation parentId; - @Nullable - private JsonModel parent; - private final boolean useAO; - private final Map display; - private final Map textures; - private List elements; - private List bakedQuadStore = new ObjectArrayList<>(); - - JsonModel(@Nullable ResourceLocation parentId, boolean useAO, Map display, Map textures, List elements) { - this.parentId = parentId; - this.useAO = useAO; - this.display = display; - this.textures = textures; - this.elements = elements; - } - - /** - * Makes a shallow copy of og. This allows you to bake the same model multiple times with various transformations. - */ - JsonModel(JsonModel og) { - - this.parentId = og.parentId; - this.parent = og.parent; - this.useAO = og.useAO; - this.display = og.display; - this.textures = og.textures; - this.elements = og.elements; - } - - public void bake(Variant v) { - - final Matrix4f vRot = v.getAffineMatrix(); - - final NdQuadBuilder builder = new NdQuadBuilder(); - - // Append faces from each element - for (ModelElement e : this.elements) { - - final Matrix4f rot = (e.getRotation() == null) ? ModelElement.Rotation.NOOP.getAffineMatrix() : e.getRotation().getAffineMatrix(); - //rot.mulLocal(vRot); - - final Vector3f from = e.getFrom(); - final Vector3f to = e.getTo(); - - for (ModelElement.Face f : e.getFaces()) { - - // Assign vertexes - for (int i = 0; i < 4; ++i) { - - final Vector3f vert = rot.transformPosition(NdQuadBuilder.mapSideToVertex(from, to, i, f.getName())); - vRot.transformPosition(vert); - builder.pos(i, vert.x, vert.y, vert.z); - } - - // Set culling and nominal faces - builder.cullFace(f.getCullFace()); - builder.nominalFace(f.getName()); - - // Set bake flags - int flags = switch(f.getRotation()) { - case 90 -> NdQuadBuilder.BAKE_ROTATE_90; - case 180 -> NdQuadBuilder.BAKE_ROTATE_180; - case 270 -> NdQuadBuilder.BAKE_ROTATE_270; - default -> NdQuadBuilder.BAKE_ROTATE_NONE; - }; - - // Set UV - final Vector4f uv = f.getUv(); - if (uv != null) { - - builder.uv(0, uv.x, uv.y); - builder.uv(1, uv.x, uv.w); - builder.uv(2, uv.z, uv.w); - builder.uv(3, uv.z, uv.y); - } else { - - // Not sure if this is correct, but it seems to fix things - flags |= NdQuadBuilder.BAKE_LOCK_UV; - } - - // Set the sprite - builder.spriteBake(this.textures.get(f.getTexture()), flags); - - // Set the tint index - final int tint = f.getTintIndex(); - builder.color(tint, tint, tint, tint); - - // Bake and add it - this.bakedQuadStore.add(builder.build(new Quad())); - } - } - - this.bakedQuadStore = new ObjectImmutableList<>(this.bakedQuadStore); - } - - public List getParents() { - return Arrays.asList(parentId); - } - - @Override - public List getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, ObjectPooler quadPool) { - - final List ret = new ObjectArrayList<>(this.bakedQuadStore.size()); - - //noinspection ForLoopReplaceableByForEach - for (int i = 0; i < bakedQuadStore.size(); ++i) { - final Quad q = quadPool.getInstance(); - q.copyFrom(this.bakedQuadStore.get(i)); - ret.add(q); - } - - return ret; - } - - public void resolveParents(Function modelLoader) { - - if (this.parentId != null && this.parent == null) { - - final JsonModel p = modelLoader.apply(this.parentId); - p.resolveParents(modelLoader); - - // Inherit properties - this.parent = p; - if (this.elements.isEmpty()) this.elements = this.parent.elements; - - // Resolve texture variables - // Add parent texture mappings, but prioritize ours. - for (Map.Entry e : this.parent.textures.entrySet()) { - - this.textures.putIfAbsent(e.getKey(), e.getValue()); - } - - // Flatten them, merging s -> s1, s1 -> s2 to s -> s2, s1 -> s2. - boolean flat = false; - final Map tmp = new Object2ObjectOpenHashMap<>(); - while (!flat) { - flat = true; - - for (Map.Entry e : this.textures.entrySet()) { - - // If there is a value in the key set, replace with the value it points to - // Also avoid adding a loop - if (this.textures.containsKey(e.getValue())) { - - if (!e.getKey().equals(e.getValue())) - tmp.put(e.getKey(), this.textures.get(e.getValue())); - else tmp.put(e.getKey(), ""); - flat = false; - } else { - tmp.put(e.getKey(), e.getValue()); - } - } - this.textures.putAll(tmp); - } - } - } - - static class Deserializer implements JsonDeserializer { - - private Vector3f loadVec3(JsonObject in, String name) { - - final JsonArray arr = in.getAsJsonArray(name); - final Vector3f ret = new Vector3f(); - - for (int i = 0; i < 3; ++i) { - ret.setComponent(i, arr.get(i).getAsFloat()); - } - - return ret; - } - - private Vector4f loadVec4(JsonObject in, String name) { - - final JsonArray arr = in.getAsJsonArray(name); - final Vector4f ret = new Vector4f(); - - for (int i = 0; i < 4; ++i) { - ret.setComponent(i, arr.get(i).getAsFloat()); - } - - return ret; - } - - private ModelDisplay loadADisplay(JsonObject in) { - - final Vector3f rotation = loadVec3(in, "rotation"); - final Vector3f translation = loadVec3(in, "translation"); - final Vector3f scale = loadVec3(in, "scale"); - - return new ModelDisplay(rotation, translation, scale); - } - - private Map loadDisplay(JsonObject in) { - - // wow such long - final Map ret = new Object2ObjectOpenHashMap<>(ModelDisplay.Position.values().length); - - if (in.has("display")) { - - final JsonObject display = in.getAsJsonObject("display"); - - for (Map.Entry j : display.entrySet()) { - - final String name = j.getKey(); - final ModelDisplay.Position pos = ModelDisplay.Position.getByName(name); - ret.put(pos, loadADisplay(j.getValue().getAsJsonObject())); - } - } - - for (ModelDisplay.Position p : ModelDisplay.Position.values()) { - ret.putIfAbsent(p, ModelDisplay.DEFAULT); - } - - return ret; - } - - private Map loadTextures(JsonObject in) { - - final Map textures = new Object2ObjectOpenHashMap<>(); - - if (in.has("textures")) { - for (Map.Entry e : in.getAsJsonObject("textures").entrySet()) { - - // Trim leading octothorpes. They indicate a texture variable, but I don't actually care. - String s = e.getValue().getAsString(); - if (s.startsWith("#")) s = s.substring(1); - textures.put(e.getKey(), s); - } - } - - return textures; - } - - private ModelElement.Rotation loadRotation(JsonObject in) { - - if (in.has("rotation")) { - final JsonObject json = in.getAsJsonObject("rotation"); - - final Vector3f origin = loadVec3(json, "origin").div(16); - final Axis axis = Axis.fromName(loadStr(json, "axis")); - final float angle = loadFloat(json, "angle"); - final boolean rescale = loadBool(json, "rescale", false); - - return new ModelElement.Rotation(origin, axis, angle, rescale); - } else { - - return null; - } - } - - private List loadFaces(JsonObject in) { - - final List ret = new ObjectArrayList<>(); - final JsonObject json = in.getAsJsonObject("faces"); - - for (Map.Entry e : json.entrySet()) { - - final ForgeDirection side = DirUtil.fromName(e.getKey()); - final JsonObject face = e.getValue().getAsJsonObject(); - - final Vector4f uv = (face.has("uv")) ? loadVec4(face, "uv") : null; - String texture = loadStr(face, "texture"); - if (texture.startsWith("#")) texture = texture.substring(1); - final ForgeDirection cullFace = DirUtil.fromName(loadStr(face, "cullface", "unknown")); - final int rotation = loadInt(face, "rotation", 0); - final int tintIndex = loadInt(face, "tintindex", -1); - - ret.add(new ModelElement.Face(side, uv, texture, cullFace, rotation, tintIndex)); - } - - return ret; - } - - private List loadElements(JsonObject in) { - - final List ret = new ObjectArrayList<>(); - - if (in.has("elements")) { - - final JsonArray arr = in.getAsJsonArray("elements"); - for (JsonElement e : arr) { - - final JsonObject json = e.getAsJsonObject(); - final Vector3f from = loadVec3(json, "from").div(16); - final Vector3f to = loadVec3(json, "to").div(16); - final ModelElement.Rotation rotation = loadRotation(json); - final boolean shade = loadBool(json, "shade", true); - final List faces = loadFaces(json); - - ret.add(new ModelElement(from, to, rotation, shade, faces)); - } - } - - return ret; - } - - @Override - public JsonModel deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - - final JsonObject in = json.getAsJsonObject(); - - final String parent = loadStr(in, "parent", ""); - final ResourceLocation parentId = (parent.isEmpty()) ? null : new ResourceLocation(parent); - - final boolean useAO = loadBool(in, "ambientocclusion", true); - final Map display = loadDisplay(in); - final Map textures = loadTextures(in); - final List elements = loadElements(in); - - return new JsonModel(parentId, useAO, display, textures, elements); - } - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/unready/json/Loader.java b/src/main/java/com/gtnewhorizons/angelica/models/unready/json/Loader.java deleted file mode 100644 index 91c79ff85..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/unready/json/Loader.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.gtnewhorizons.angelica.models.unready.json; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.gtnewhorizons.angelica.loading.AngelicaTweaker; -import com.gtnewhorizons.angelica.utils.Callback; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import net.minecraft.block.Block; -import net.minecraft.util.ResourceLocation; - -/** - * Model loading should proceed as follows:
    - *
  • Models to load are registered in PREINIT.
  • - *
  • All registered models are recursively loaded in INIT.
  • - *
  • Models registered for baking are baked on the first tick of the game.
  • - *
- *

Alternatively, you can register blocks with blockstate variants in preinit, and the rest is handled by - * {@link Loader}. - *

As for icons, register them in {@link Block#registerBlockIcons}. Whatever gets them in the block texture atlas. - */ -public class Loader { - - static final Gson GSON = new GsonBuilder() - .registerTypeAdapter(JsonModel.class, new JsonModel.Deserializer()).create(); - private static final List unloadedModels = new ObjectArrayList<>(); - private static final Map loadedModels = new Object2ObjectOpenHashMap<>(); - private static final Map modelsToBake = new Object2ObjectOpenHashMap<>(); - private static final List postBakeCallbacks = new ObjectArrayList<>(); - - /** - * Pass the variant you want to load, and if needed a callback which puts the models in a useful place, e.g. saving - * them to a static field after baking. - */ - public static void registerModel(Variant loc, Callback loader) { - unloadedModels.add(loc.getModel()); - modelsToBake.put(loc, null); - postBakeCallbacks.add(loader); - } - - /** - * Convenience method to register multiple variants. See {@link #registerModel}. - */ - public static void registerModels(Callback loader, Variant... variants) { - - registerModels(Arrays.asList(variants), loader); - } - - /** - * Convenience method to register multiple variants. See {@link #registerModel}. - */ - public static void registerModels(Collection variants, Callback loader) { - - for (Variant v : variants) { - - unloadedModels.add(v.getModel()); - modelsToBake.put(v, null); - } - - postBakeCallbacks.add(loader); - } - - public static void loadModels() { - - for (ResourceLocation l : unloadedModels) { - - if (l == null) continue; - if (loadedModels.containsKey(l)) continue; - - final JsonModel model = loadJson( - "/assets/" + l.getResourceDomain() + "/models/" + l.getResourcePath() + ".json", JsonModel.class); - unloadedModels.addAll(model.getParents()); - loadedModels.put(l, model); - } - } - - private static T loadJson(String path, Class clazz) { - try (final InputStream is = Loader.class.getResourceAsStream(path)) { - - return GSON.fromJson(new InputStreamReader(is), clazz); - - } catch (IOException | NullPointerException e) { - - AngelicaTweaker.LOGGER.fatal("Could not find " + path); - throw new RuntimeException(e); - } - } - - public static void bakeModels() { - - for (Map.Entry l : modelsToBake.entrySet()) { - - final JsonModel dough = new JsonModel(loadedModels.get(l.getKey().getModel())); - - // Resolve the parent chain - dough.resolveParents(loadedModels::get); - - // Bake - dough.bake(l.getKey()); - - l.setValue(dough); - } - - for (Callback c : postBakeCallbacks) - c.run(); - } - - public static JsonModel getModel(Variant loc) { - return modelsToBake.get(loc); - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/unready/json/ModelDisplay.java b/src/main/java/com/gtnewhorizons/angelica/models/unready/json/ModelDisplay.java deleted file mode 100644 index 032a741dc..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/unready/json/ModelDisplay.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.gtnewhorizons.angelica.models.unready.json; - -import org.joml.Vector3f; - -public class ModelDisplay { - - public static final ModelDisplay DEFAULT = new ModelDisplay( - new Vector3f(0, 0, 0), - new Vector3f(0, 0, 0), - new Vector3f(1, 1, 1) - ); - - private final Vector3f rotation; - private final Vector3f translation; - private final Vector3f scale; - - public ModelDisplay(Vector3f rotation, Vector3f translation, Vector3f scale) { - - this.rotation = rotation; - this.translation = translation; - this.scale = scale; - } - - enum Position { - thirdperson_righthand, - thirdperson_lefthand, - firstperson_righthand, - firstperson_lefthand, - gui, - head, - ground, - fixed; - - public static Position getByName(String name) { - return switch (name) { - case "thirdperson_righthand" -> thirdperson_righthand; - case "thirdperson_lefthand" -> thirdperson_lefthand; - case "firstperson_righthand" -> firstperson_righthand; - case "firstperson_lefthand" -> firstperson_lefthand; - case "gui" -> gui; - case "head" -> head; - case "ground" -> ground; - case "fixed" -> fixed; - default -> null; - }; - } - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/unready/json/ModelElement.java b/src/main/java/com/gtnewhorizons/angelica/models/unready/json/ModelElement.java deleted file mode 100644 index 6ed52fecc..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/unready/json/ModelElement.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.gtnewhorizons.angelica.models.unready.json; - -import com.gtnewhorizons.angelica.compat.mojang.Axis; -import java.util.List; -import lombok.Getter; -import net.minecraftforge.common.util.ForgeDirection; -import org.jetbrains.annotations.Nullable; -import org.joml.Matrix4f; -import org.joml.Vector3f; -import org.joml.Vector4f; - -public class ModelElement { - - @Getter - private final Vector3f from; - @Getter - private final Vector3f to; - @Nullable - @Getter - private final Rotation rotation; - private final boolean shade; - @Getter - private final List faces; - - ModelElement(Vector3f from, Vector3f vector3f, @Nullable Rotation rotation, boolean shade, List faces) { - this.from = from; - to = vector3f; - this.rotation = rotation; - this.shade = shade; - this.faces = faces; - } - - - static class Face { - - @Getter - private final ForgeDirection name; - @Getter - private final Vector4f uv; - @Getter - private final String texture; - @Getter - private final ForgeDirection cullFace; - @Getter - private final int rotation; - @Getter - private final int tintIndex; - - Face(ForgeDirection name, Vector4f uv, String texture, ForgeDirection cullFace, int rotation, int tintIndex) { - this.name = name; - this.uv = uv; - this.texture = texture; - this.cullFace = cullFace; - this.rotation = rotation; - this.tintIndex = tintIndex; - } - } - - static class Rotation { - - static final Rotation NOOP = new Rotation( - new Vector3f(0, 0, 0), - Axis.X, - 0, - false - ); - - private final Vector3f origin; - private final Axis axis; - private final float angle; - private final boolean rescale; - - Rotation(Vector3f origin, Axis axis, float angle, boolean rescale) { - this.origin = origin; - this.axis = axis; - this.angle = (float) Math.toRadians(angle); - this.rescale = rescale; - } - - Matrix4f getAffineMatrix() { - - // Subtract origin - final Matrix4f ret = new Matrix4f().translation(-this.origin.x, -this.origin.y, -this.origin.z); - - // Rotate - switch (this.axis) { - case X -> ret.rotateLocalX(angle); - case Y -> ret.rotateLocalY(angle); - case Z -> ret.rotateLocalZ(angle); - } - - // Add the origin back in - return ret.translateLocal(this.origin.x, this.origin.y, this.origin.z); - } - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/unready/json/TestBakedModel.java b/src/main/java/com/gtnewhorizons/angelica/models/unready/json/TestBakedModel.java deleted file mode 100644 index 4b0ec673a..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/unready/json/TestBakedModel.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.gtnewhorizons.angelica.models.unready.json; - -import com.gtnewhorizons.angelica.api.QuadProvider; -import com.gtnewhorizons.angelica.compat.mojang.BlockPos; -import com.gtnewhorizons.angelica.compat.nd.Quad; -import com.gtnewhorizons.angelica.models.NdQuadBuilder; -import com.gtnewhorizons.angelica.models.unready.json.JsonModel; -import com.gtnewhorizons.angelica.utils.ObjectPooler; -import it.unimi.dsi.fastutil.objects.ObjectImmutableList; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Random; -import java.util.function.Function; -import net.minecraft.block.Block; -import net.minecraft.util.IIcon; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.common.util.ForgeDirection; - -/** - * This is a half-baked port of Fabric's sample custom model, for reference. - */ -public class TestBakedModel implements QuadProvider { - - private static final String[] SPRITE_IDS = new String[]{ - "furnace_front_on", - "furnace_top" - }; - private final IIcon[] sprites = new IIcon[SPRITE_IDS.length]; - - // Some constants to avoid magic numbers, these need to match the SPRITE_IDS - private static final int SPRITE_SIDE = 0; - private static final int SPRITE_TOP = 1; - - private final Quad[] quadStore = new Quad[6]; - private static final List EMPTY = ObjectImmutableList.of(); - - //@Override - public Collection getModelDependencies() { - return Arrays.asList(); // This model does not depend on other models. - } - - public void setParents(Function modelLoader) { - // This is related to model parents, it's not required for our use case - } - - public void bake() { - - // Get the sprites - for(int i = 0; i < SPRITE_IDS.length; ++i) { - //sprites[i] = getBlockIcon(SPRITE_IDS[i]); - } - - // Build the mesh using my API - final NdQuadBuilder builder = new NdQuadBuilder(); - - // This is a cube, it only has sides on VALID_DIRECTIONS - // But something like tall grass will need to go over UNKNOWN too - for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { - - // UP and DOWN share the Y axis - int spriteIdx = direction == ForgeDirection.UP || direction == ForgeDirection.DOWN ? SPRITE_TOP : SPRITE_SIDE; - // Add a new face to the mesh - builder.square(direction, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f); - // Set the sprite of the face, must be called after .square() - // We haven't specified any UV coordinates, so we want to use the whole texture. BAKE_LOCK_UV does exactly that. - builder.spriteBake(sprites[spriteIdx], NdQuadBuilder.BAKE_LOCK_UV); - // Enable texture usage - builder.color(-1, -1, -1, -1); - // Add the quad to the mesh - quadStore[direction.ordinal()] = builder.build(new Quad()); - } - - } - - @Override - public List getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, ObjectPooler quadPool) { - - if (dir == ForgeDirection.UNKNOWN) - return EMPTY; - - final Quad q = quadPool.getInstance(); - //q.copyFrom(this.quadStore[dir.ordinal()]); - final List ret = new ArrayList<>(); - ret.add(q); - return ret; - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/unready/json/Variant.java b/src/main/java/com/gtnewhorizons/angelica/models/unready/json/Variant.java deleted file mode 100644 index 20eafb24b..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/unready/json/Variant.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.gtnewhorizons.angelica.models.unready.json; - -import lombok.Getter; -import net.minecraft.util.ResourceLocation; -import org.joml.Matrix4f; - -import static java.lang.Math.toRadians; - -public class Variant { - - @Getter - private final ResourceLocation model; - private final float x; - private final float y; - private final boolean uvLock; - - public Variant(ResourceLocation model, int x, int y, boolean uvLock) { - this.model = model; - this.x = (float) toRadians(x); - this.y = (float) toRadians(y); - this.uvLock = uvLock; - } - - Matrix4f getAffineMatrix() { - - return new Matrix4f() - .translation(-.5f, -.5f, -.5f).rotateLocalY(x).rotateLocalX(y).translateLocal(.5f, .5f, .5f); - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/proxy/CommonProxy.java b/src/main/java/com/gtnewhorizons/angelica/proxy/CommonProxy.java index 919273266..f5171db8e 100644 --- a/src/main/java/com/gtnewhorizons/angelica/proxy/CommonProxy.java +++ b/src/main/java/com/gtnewhorizons/angelica/proxy/CommonProxy.java @@ -1,11 +1,8 @@ package com.gtnewhorizons.angelica.proxy; -import com.gtnewhorizons.angelica.models.unready.common.BlockTest; -import com.gtnewhorizons.angelica.config.AngelicaConfig; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.registry.GameRegistry; public class CommonProxy {