From ef405062a649d89c429f92dbfeebb199770f1e33 Mon Sep 17 00:00:00 2001 From: quat1024 Date: Mon, 31 Jul 2023 03:31:09 -0400 Subject: [PATCH] Tiny slopes !!!!!! --- .../github/cottonmc/templates/Templates.java | 7 +- .../cottonmc/templates/TemplatesClient.java | 8 ++- .../templates/block/TemplateSlopeBlock.java | 26 +++++-- .../templates/model/SlopeBaseMesh.java | 53 ++++++++++++++- .../cottonmc/templates/util/BbModelepic.java | 67 +++++++++++++++++++ .../templates/blockstates/tiny_slope.json | 64 ++++++++++++++++++ .../assets/templates/lang/en_us.json | 1 + .../models/block/tiny_slope_base.json | 11 +++ .../minecraft/tags/blocks/mineable/axe.json | 3 +- .../recipes/decorations/templates.json | 3 +- .../loot_tables/blocks/tiny_slope.json | 19 ++++++ .../data/templates/recipes/tiny_slope.json | 20 ++++++ 12 files changed, 269 insertions(+), 13 deletions(-) create mode 100644 src/main/java/io/github/cottonmc/templates/util/BbModelepic.java create mode 100644 src/main/resources/assets/templates/blockstates/tiny_slope.json create mode 100644 src/main/resources/assets/templates/models/block/tiny_slope_base.json create mode 100644 src/main/resources/data/templates/loot_tables/blocks/tiny_slope.json create mode 100644 src/main/resources/data/templates/recipes/tiny_slope.json diff --git a/src/main/java/io/github/cottonmc/templates/Templates.java b/src/main/java/io/github/cottonmc/templates/Templates.java index f2f5265..031b8bd 100644 --- a/src/main/java/io/github/cottonmc/templates/Templates.java +++ b/src/main/java/io/github/cottonmc/templates/Templates.java @@ -76,6 +76,7 @@ public class Templates implements ModInitializer { //oddball templates: public static final Block SLOPE = Registry.register(Registries.BLOCK, id("slope") , new TemplateSlopeBlock(TemplateInteractionUtil.makeSettings())); + public static final Block TINY_SLOPE = Registry.register(Registries.BLOCK, id("tiny_slope") , new TemplateSlopeBlock.Tiny(TemplateInteractionUtil.makeSettings())); //30 degree slope (shallow/deep) //corner slopes //quarter slabs???? @@ -111,7 +112,8 @@ public class Templates implements ModInitializer { TRAPDOOR, VERTICAL_SLAB, WALL, - SLOPE + SLOPE, + TINY_SLOPE ).build(null) ); @@ -147,7 +149,9 @@ public class Templates implements ModInitializer { Registry.register(Registries.ITEM, id("trapdoor") , new BlockItem(TRAPDOOR, new Item.Settings())); Registry.register(Registries.ITEM, id("vertical_slab") , new BlockItem(VERTICAL_SLAB, new Item.Settings())); Registry.register(Registries.ITEM, id("wall") , new BlockItem(WALL, new Item.Settings())); + Registry.register(Registries.ITEM, id("slope") , new BlockItem(SLOPE, new Item.Settings())); + Registry.register(Registries.ITEM, id("tiny_slope") , new BlockItem(TINY_SLOPE, new Item.Settings())); Registry.register(Registries.ITEM, id("cool_rivulet") , new BlockItem(COOL_RIVULET, new Item.Settings())); //Very good } @@ -187,6 +191,7 @@ public class Templates implements ModInitializer { //Oddball that doesn't look anything like vanilla blocks e.add(SLOPE); + e.add(TINY_SLOPE); //Very good e.add(COOL_RIVULET); diff --git a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java index b163fb5..3d52ef6 100644 --- a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java +++ b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java @@ -74,7 +74,9 @@ public class TemplatesClient implements ClientModInitializer { Templates.TRAPDOOR, Templates.VERTICAL_SLAB, Templates.WALL, - Templates.SLOPE + + Templates.SLOPE, + Templates.TINY_SLOPE ); //vanilla style models (using "auto" method) @@ -128,6 +130,8 @@ public class TemplatesClient implements ClientModInitializer { //mesh models provider.addTemplateModel(Templates.id("slope_special") , new UnbakedMeshRetexturedModel(Templates.id("block/slope_base"), SlopeBaseMesh::makeUpright)); provider.addTemplateModel(Templates.id("slope_side_special") , new UnbakedMeshRetexturedModel(Templates.id("block/slope_base"), SlopeBaseMesh::makeSide)); + provider.addTemplateModel(Templates.id("tiny_slope_special") , new UnbakedMeshRetexturedModel(Templates.id("block/tiny_slope_base"), SlopeBaseMesh::makeTinyUpright)); + provider.addTemplateModel(Templates.id("tiny_slope_side_special") , new UnbakedMeshRetexturedModel(Templates.id("block/tiny_slope_base"), SlopeBaseMesh::makeTinySide)); //item only models provider.addTemplateModel(Templates.id("button_inventory_special") , new UnbakedAutoRetexturedModel(new Identifier("block/button_inventory"))); @@ -149,6 +153,8 @@ public class TemplatesClient implements ClientModInitializer { provider.assignItemModel(Templates.id("trapdoor_bottom_special") , Templates.TRAPDOOR); provider.assignItemModel(Templates.id("vertical_slab_special") , Templates.VERTICAL_SLAB); provider.assignItemModel(Templates.id("wall_inventory_special") , Templates.WALL); + provider.assignItemModel(Templates.id("slope_special") , Templates.SLOPE); + provider.assignItemModel(Templates.id("tiny_slope_special") , Templates.TINY_SLOPE); } } diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateSlopeBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateSlopeBlock.java index ceb3faa..0fee8b1 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateSlopeBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateSlopeBlock.java @@ -19,16 +19,19 @@ import javax.annotation.Nullable; public class TemplateSlopeBlock extends WaterloggableTemplateBlock { public static final EnumProperty EDGE = EnumProperty.of("edge", Edge.class); - private static final VoxelShape[] shapes = new VoxelShape[Edge.values().length]; - static { - for(Edge edge : Edge.values()) { - shapes[edge.ordinal()] = StairShapeMaker.makeStair(edge, 1, 0.125d, 0.125d, 0.125d, 8); - } - } + protected final VoxelShape[] shapes = new VoxelShape[Edge.values().length]; public TemplateSlopeBlock(Settings settings) { super(settings); setDefaultState(getDefaultState().with(EDGE, Edge.DOWN_NORTH)); + + for(Edge edge : Edge.values()) { + shapes[edge.ordinal()] = getShape(edge); + } + } + + protected VoxelShape getShape(Edge edge) { + return StairShapeMaker.makeStair(edge, 1, 0.125d, 0.125d, 0.125d, 8); } @Override @@ -58,4 +61,15 @@ public class TemplateSlopeBlock extends WaterloggableTemplateBlock { public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) { return shapes[state.get(EDGE).ordinal()]; } + + public static class Tiny extends TemplateSlopeBlock { + public Tiny(Settings settings) { + super(settings); + } + + @Override + protected VoxelShape getShape(Edge edge) { + return StairShapeMaker.makeStair(edge, 0.5, 0.125d, 0.125d, 0.125d, 4); + } + } } diff --git a/src/main/java/io/github/cottonmc/templates/model/SlopeBaseMesh.java b/src/main/java/io/github/cottonmc/templates/model/SlopeBaseMesh.java index 9212802..3439f49 100644 --- a/src/main/java/io/github/cottonmc/templates/model/SlopeBaseMesh.java +++ b/src/main/java/io/github/cottonmc/templates/model/SlopeBaseMesh.java @@ -21,10 +21,8 @@ public class SlopeBaseMesh { public static Mesh makeUpright() { Renderer renderer = TemplatesClient.getFabricRenderer(); - MeshBuilder builder = renderer.meshBuilder(); QuadEmitter qu = builder.getEmitter(); - qu.tag(TAG_SLOPE) .pos(0, 0f, 0f, 0f).pos(1, 0f, 1f, 1f).pos(2, 1f, 1f, 1f).pos(3, 1f, 0f, 0f) .color(-1, -1, -1, -1) @@ -60,7 +58,56 @@ public class SlopeBaseMesh { public static Mesh makeSide() { Matrix4f mat = new Matrix4f(); RotationAxis.POSITIVE_Z.rotationDegrees(90).get(mat); - return MeshTransformUtil.pretransformMesh(makeUpright(), MeshTransformUtil.applyMatrix(mat)); } + + //looks weird since i wrote a janky script to massage a .bbmodel, some manual fixups applied + public static Mesh makeTinyUpright() { + Renderer renderer = TemplatesClient.getFabricRenderer(); + MeshBuilder builder = renderer.meshBuilder(); + QuadEmitter qu = builder.getEmitter(); + qu.tag(TAG_LEFT) + .pos(0, 1f, 0.25f, 0.75f).uv(0, 0.25f, 0.75f) + .pos(1, 1f, 0.5f, 1f).uv(1, 0f, 0.5f) + .pos(2, 1f, 0f, 1f).uv(2, 0f, 1f) + .pos(3, 1f, 0f, 0.5f).uv(3, 0.5f, 1f) + .color(-1, -1, -1, -1) + .emit() + .tag(TAG_RIGHT) + .pos(0, 0f, 0f, 1f).uv(0, 1f, 1f) + .pos(1, 0f, 0.5f, 1f).uv(1, 1f, 0.5f) + .pos(2, 0f, 0.25f, 0.75f).uv(2, 0.75f, 0.75f) + .pos(3, 0f, 0f, 0.5f).uv(3, 0.5f, 1f) + .color(-1, -1, -1, -1) + .emit() + .tag(TAG_BOTTOM) + .pos(0, 1f, 0f, 0.5f).uv(0, 1f, 0.5f) + .pos(1, 1f, 0f, 1f).uv(1, 1f, 0f) + .pos(2, 0f, 0f, 1f).uv(2, 0f, 0f) + .pos(3, 0f, 0f, 0.5f).uv(3, 0f, 0.5f) + .color(-1, -1, -1, -1) + .emit() + .tag(TAG_BACK) + .pos(0, 1f, 0f, 1f).uv(0, 1f, 1f) + .pos(1, 1f, 0.5f, 1f).uv(1, 1f, 0.5f) + .pos(2, 0f, 0.5f, 1f).uv(2, 0f, 0.5f) + .pos(3, 0f, 0f, 1f).uv(3, 0f, 1f) + .color(-1, -1, -1, -1) + .emit() + .tag(TAG_SLOPE) + .pos(0, 1f, 0.5f, 1f).uv(2, 0f, 0.5f) //manually permuted uvs + .pos(1, 1f, 0f, 0.5f).uv(3, 0f, 1f) + .pos(2, 0f, 0f, 0.5f).uv(0, 1f, 1f) + .pos(3, 0f, 0.5f, 1f).uv(1, 1f, 0.5f) + .color(-1, -1, -1, -1) + .emit() + ; + return builder.build(); + } + + public static Mesh makeTinySide() { + Matrix4f mat = new Matrix4f(); + RotationAxis.POSITIVE_Z.rotationDegrees(90).get(mat); + return MeshTransformUtil.pretransformMesh(makeTinyUpright(), MeshTransformUtil.applyMatrix(mat)); + } } diff --git a/src/main/java/io/github/cottonmc/templates/util/BbModelepic.java b/src/main/java/io/github/cottonmc/templates/util/BbModelepic.java new file mode 100644 index 0000000..a8498a9 --- /dev/null +++ b/src/main/java/io/github/cottonmc/templates/util/BbModelepic.java @@ -0,0 +1,67 @@ +package io.github.cottonmc.templates.util; + +import com.google.gson.Gson; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +//i probalby shouldnt ship this in the mod lol +public class BbModelepic { + static class Model { + List elements; + } + + static class Elem { + Map> vertices; + Map faces; + } + + static class Face { + Map> uv; + List vertices; + } + + public static void main(String[] args) { + Model m = new Gson().fromJson(model, Model.class); + + Map> verts = m.elements.get(0).vertices; + List faces = m.elements.get(0).faces.values().stream().toList(); + + List classifications = List.of("TAG_LEFT", "TAG_RIGHT", "TAG_BOTTOM", "TAG_BACK", "TAG_SLOPE"); + Iterator asd = classifications.iterator(); + + for(Face face : faces) { + System.out.printf(".tag(%s)%n", asd.next()); + + for(int i = 0; i < 4; i++) { + String vertId = face.vertices.get(permute(i)); + List coords = verts.get(vertId); + System.out.printf(".pos(%s, %sf, %sf, %sf)", i, p(coords.get(0)/16f), p(coords.get(1)/16f), p(coords.get(2)/16f)); + + List uv = face.uv.get(vertId); + System.out.printf(".uv(%s, %sf, %sf)%n", i, p(uv.get(0)/16f), p(uv.get(1)/16f)); + } + + System.out.println(".color(-1, -1, -1, -1)\n.emit()"); + } + System.out.println(';'); + } + + //i don't like "16.0f" i'd rather "16f" + private static String p(float f) { + if(f == (long) f) return Long.toString((long) f); + else return Float.toString(f); + } + + private static int permute(int i) { + if(i == 0) return 2; + if(i == 1) return 0; + if(i == 2) return 1; + if(i == 3) return 3; + throw new IllegalArgumentException(); + } + + private static final String model = """ +{"meta":{"format_version":"4.5","model_format":"free","box_uv":false},"name":"","model_identifier":"","visible_box":[1,1,0],"variable_placeholders":"","variable_placeholder_buttons":[],"timeline_setups":[],"unhandled_root_fields":{},"resolution":{"width":16,"height":16},"elements":[{"name":"cuboid","color":4,"origin":[-8,0,-8],"rotation":[0,0,0],"visibility":true,"locked":false,"vertices":{"Iy48":[16,8,16],"dg4s":[16,4,12],"ezd5":[16,0,16],"txzT":[16,0,8],"ZcIz":[0,8,16],"tgTW":[0,0,16],"Q2eV":[0,0,8],"8xsY":[0,4,12]},"faces":{"JSoJzuHO":{"uv":{"Iy48":[0,8],"ezd5":[0,16],"dg4s":[4,12],"txzT":[8,16]},"vertices":["Iy48","ezd5","dg4s","txzT"]},"0I6IF0zk":{"uv":{"ZcIz":[16,8],"tgTW":[16,16],"Q2eV":[8,16],"8xsY":[12,12]},"vertices":["ZcIz","8xsY","tgTW","Q2eV"]},"d7iH7DqS":{"uv":{"ezd5":[16,0],"tgTW":[0,0],"txzT":[16,8],"Q2eV":[0,8]},"vertices":["ezd5","tgTW","txzT","Q2eV"]},"OQ809wKZ":{"uv":{"Iy48":[16,8],"ZcIz":[0,8],"ezd5":[16,16],"tgTW":[0,16]},"vertices":["Iy48","ZcIz","ezd5","tgTW"]},"TSyHMrco":{"uv":{"txzT":[0,16],"Q2eV":[16,16],"Iy48":[0,8],"ZcIz":[16,8]},"vertices":["txzT","Q2eV","Iy48","ZcIz"]}},"type":"mesh","uuid":"3152a30a-ea8e-4ceb-57eb-58319c89815a"}],"outliner":["3152a30a-ea8e-4ceb-57eb-58319c89815a"],"textures":[]}"""; +} diff --git a/src/main/resources/assets/templates/blockstates/tiny_slope.json b/src/main/resources/assets/templates/blockstates/tiny_slope.json new file mode 100644 index 0000000..71f4b26 --- /dev/null +++ b/src/main/resources/assets/templates/blockstates/tiny_slope.json @@ -0,0 +1,64 @@ +{ + "variants": { + "edge=down_east": { + "model": "templates:tiny_slope_special", + "uvlock": true, + "y": 270 + }, + "edge=down_north": { + "model": "templates:tiny_slope_special", + "uvlock": true, + "y": 180 + }, + "edge=down_south": { + "model": "templates:tiny_slope_special" + }, + "edge=down_west": { + "model": "templates:tiny_slope_special", + "uvlock": true, + "y": 90 + }, + "edge=up_east": { + "model": "templates:tiny_slope_special", + "uvlock": true, + "x": 180, + "y": 90 + }, + "edge=up_north": { + "model": "templates:tiny_slope_special", + "uvlock": true, + "x": 180 + }, + "edge=up_south": { + "model": "templates:tiny_slope_special", + "uvlock": true, + "x": 180, + "y": 180 + }, + "edge=up_west": { + "model": "templates:tiny_slope_special", + "uvlock": true, + "x": 180, + "y": 270 + }, + "edge=north_east": { + "model": "templates:tiny_slope_side_special", + "uvlock": true, + "y": 270 + }, + "edge=north_west": { + "model": "templates:tiny_slope_side_special", + "uvlock": true, + "y": 180 + }, + "edge=south_east": { + "model": "templates:tiny_slope_side_special", + "uvlock": true + }, + "edge=south_west": { + "model": "templates:tiny_slope_side_special", + "uvlock": true, + "y": 90 + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/templates/lang/en_us.json b/src/main/resources/assets/templates/lang/en_us.json index e8e8ab0..b5282b1 100644 --- a/src/main/resources/assets/templates/lang/en_us.json +++ b/src/main/resources/assets/templates/lang/en_us.json @@ -15,6 +15,7 @@ "block.templates.post": "Post Template", "block.templates.pressure_plate": "Pressure Plate Template", "block.templates.slope": "Slope Template", + "block.templates.tiny_slope": "Tiny Slope Template", "block.templates.slab": "Slab Template", "block.templates.stairs": "Stairs Template", "block.templates.trapdoor": "Trapdoor Template", diff --git a/src/main/resources/assets/templates/models/block/tiny_slope_base.json b/src/main/resources/assets/templates/models/block/tiny_slope_base.json new file mode 100644 index 0000000..2913dd9 --- /dev/null +++ b/src/main/resources/assets/templates/models/block/tiny_slope_base.json @@ -0,0 +1,11 @@ +{ + "parent": "templates:block/slope_base", + "gui_light": "front", + "display": { + "gui": { + "rotation": [ 30, 225, 0 ], + "translation": [ 2, 0.5, 0], + "scale":[ 0.625, 0.625, 0.625 ] + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/blocks/mineable/axe.json b/src/main/resources/data/minecraft/tags/blocks/mineable/axe.json index 1838bbe..c6cab7f 100644 --- a/src/main/resources/data/minecraft/tags/blocks/mineable/axe.json +++ b/src/main/resources/data/minecraft/tags/blocks/mineable/axe.json @@ -17,6 +17,7 @@ "templates:trapdoor", "templates:vertical_slab", "templates:wall", - "templates:slope" + "templates:slope", + "templates:tiny_slope" ] } \ No newline at end of file diff --git a/src/main/resources/data/templates/advancements/recipes/decorations/templates.json b/src/main/resources/data/templates/advancements/recipes/decorations/templates.json index 3c64f5b..5d9015f 100644 --- a/src/main/resources/data/templates/advancements/recipes/decorations/templates.json +++ b/src/main/resources/data/templates/advancements/recipes/decorations/templates.json @@ -20,7 +20,8 @@ "templates:trapdoor", "templates:vertical_slab", "templates:wall", - "templates:slope" + "templates:slope", + "templates:tiny_slope" ] }, "criteria": { diff --git a/src/main/resources/data/templates/loot_tables/blocks/tiny_slope.json b/src/main/resources/data/templates/loot_tables/blocks/tiny_slope.json new file mode 100644 index 0000000..a76a673 --- /dev/null +++ b/src/main/resources/data/templates/loot_tables/blocks/tiny_slope.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "templates:tiny_slope" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/templates/recipes/tiny_slope.json b/src/main/resources/data/templates/recipes/tiny_slope.json new file mode 100644 index 0000000..dde8b1c --- /dev/null +++ b/src/main/resources/data/templates/recipes/tiny_slope.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "I~", + "II" + ], + "key": { + "I": { + "item": "minecraft:bamboo" + }, + "~": { + "item": "minecraft:string" + } + }, + "result": { + "item": "templates:tiny_slope", + "count": 8 + }, + "group": "templates" +} \ No newline at end of file