Tiny slopes !!!!!!

This commit is contained in:
quat1024 2023-07-31 03:31:09 -04:00
parent 3ad97d652d
commit ef405062a6
12 changed files with 269 additions and 13 deletions

View File

@ -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);

View File

@ -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);
}
}

View File

@ -19,16 +19,19 @@ import javax.annotation.Nullable;
public class TemplateSlopeBlock extends WaterloggableTemplateBlock {
public static final EnumProperty<Edge> 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);
}
}
}

View File

@ -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));
}
}

View File

@ -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<Elem> elements;
}
static class Elem {
Map<String, List<Integer>> vertices;
Map<String, Face> faces;
}
static class Face {
Map<String, List<Integer>> uv;
List<String> vertices;
}
public static void main(String[] args) {
Model m = new Gson().fromJson(model, Model.class);
Map<String, List<Integer>> verts = m.elements.get(0).vertices;
List<Face> faces = m.elements.get(0).faces.values().stream().toList();
List<String> classifications = List.of("TAG_LEFT", "TAG_RIGHT", "TAG_BOTTOM", "TAG_BACK", "TAG_SLOPE");
Iterator<String> 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<Integer> 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<Integer> 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":[]}""";
}

View File

@ -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
}
}
}

View File

@ -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",

View File

@ -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 ]
}
}
}

View File

@ -17,6 +17,7 @@
"templates:trapdoor",
"templates:vertical_slab",
"templates:wall",
"templates:slope"
"templates:slope",
"templates:tiny_slope"
]
}

View File

@ -20,7 +20,8 @@
"templates:trapdoor",
"templates:vertical_slab",
"templates:wall",
"templates:slope"
"templates:slope",
"templates:tiny_slope"
]
},
"criteria": {

View File

@ -0,0 +1,19 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "templates:tiny_slope"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}

View File

@ -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"
}