code cleanups (great way to feel productive without doing much of anything)

This commit is contained in:
quat1024 2023-08-31 21:27:02 -04:00
parent 78e3e82bbe
commit 11e24ef876
14 changed files with 67 additions and 30 deletions

48
CHANGELOG.md Normal file
View File

@ -0,0 +1,48 @@
Versions before 2.1.2 have been backfilled; I gotta be more on top of changelogs.
# 2.1.2 (unreleased)
* Remove some unused stuff from the jar
road map:
* want to fix texture orientation on vertical slabs/doors
* really want to fix the way vertical slabs place lmao (it's so buggy)
* clean up `StairShapeMaker`
# 2.1.1 (Aug 2, 2023)
Enable ambient-occlusion ("smooth lighting") on all Templates except for the slopes, which are still bugged
# 2.1.0 (Jul 31, 2023)
* Add a vertical slab template
* Add a "tiny slope" template
* Change the block entity NBT format to be much smaller
* Reduce memory footprint of the block entity
* Respect `doTileDrops`
* Improve creative ctrl-pick behavior on glowing Templates
* Adding a Barrier block to a Template makes it remove its model (not unbreakable)
# 2.0.4 (Jul 25, 2023)
* Apply more block tags
* Apply item tags
# 2.0.3 (Jul 23, 2023)
* add Door and Iron Door templates
* cool rivulet
# 2.0.2 (Jul 20, 2023)
* Add an Iron Trapdoor template
* Add some more mod metadata (change name to "Templates 2", add authors, fix sources link)
# 2.0.1 (Jul 11, 2023)
Fix a duplication glitch with the Stair Template, which was retaining its block entity after being broken.
# 2.0.0 (Jul 11, 2023)
Initial release

View File

@ -24,14 +24,6 @@ tasks.withType(JavaCompile) {
options.release = 17 options.release = 17
} }
if(rootProject.file("private.gradle").exists()) { //Publishing details
apply from: "private.gradle"
}
archivesBaseName = "templates"
group = "io.github.cottonmc"
version = "2.1.1+1.20.1"
repositories { repositories {
mavenCentral() mavenCentral()

View File

@ -1,2 +1,6 @@
# dedodated wam # dedodated wam
org.gradle.jvmargs=-Xmx6G org.gradle.jvmargs=-Xmx6G
archivesBaseName=templates
group=io.github.cottonmc
version=2.1.2+1.20.1

View File

@ -22,7 +22,8 @@ import org.jetbrains.annotations.NotNull;
import java.util.Objects; import java.util.Objects;
public class TemplatesClient implements ClientModInitializer { public class TemplatesClient implements ClientModInitializer {
public static TemplatesModelProvider provider = new TemplatesModelProvider(); //2.2 note: Yes, this wasn't final before, but it should have been
public static final TemplatesModelProvider provider = new TemplatesModelProvider();
public static @NotNull Renderer getFabricRenderer() { public static @NotNull Renderer getFabricRenderer() {
return Objects.requireNonNull(RendererAccess.INSTANCE.getRenderer(), "A Fabric Rendering API implementation is required to use Templates!"); return Objects.requireNonNull(RendererAccess.INSTANCE.getRenderer(), "A Fabric Rendering API implementation is required to use Templates!");

View File

@ -18,6 +18,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.function.Function; import java.util.function.Function;
@SuppressWarnings("unused") //part of the api
public class TemplatesModelProvider implements ModelResourceProvider, ModelVariantProvider { public class TemplatesModelProvider implements ModelResourceProvider, ModelVariantProvider {
private final Map<Identifier, UnbakedModel> models = new HashMap<>(); private final Map<Identifier, UnbakedModel> models = new HashMap<>();
private final Map<ModelIdentifier, Identifier> itemAssignments = new HashMap<>(); private final Map<ModelIdentifier, Identifier> itemAssignments = new HashMap<>();

View File

@ -5,7 +5,6 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext; import net.minecraft.block.ShapeContext;
import net.minecraft.block.enums.SlabType; import net.minecraft.block.enums.SlabType;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids; import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -108,7 +107,7 @@ public class TemplateVerticalSlabBlock extends TemplateSlabBlock {
} }
} }
enum Affinity implements StringIdentifiable { protected enum Affinity implements StringIdentifiable {
X, Z; X, Z;
@Override @Override

View File

@ -100,7 +100,7 @@ public class TemplateWallBlock extends WallBlock implements BlockEntityProvider
//Shapemap heck (WallBlock has a map keyed on BlockState, but since we add more blockstates most of those map lookups fail) //Shapemap heck (WallBlock has a map keyed on BlockState, but since we add more blockstates most of those map lookups fail)
protected static record ShapeKey(boolean up, WallShape north, WallShape east, WallShape south, WallShape west) { protected record ShapeKey(boolean up, WallShape north, WallShape east, WallShape south, WallShape west) {
static ShapeKey fromBlockstate(BlockState state) { static ShapeKey fromBlockstate(BlockState state) {
return new ShapeKey( return new ShapeKey(
state.get(WallBlock.UP), state.get(WallBlock.UP),
@ -112,8 +112,8 @@ public class TemplateWallBlock extends WallBlock implements BlockEntityProvider
} }
} }
protected Map<ShapeKey, VoxelShape> newShapeMap = new HashMap<>(); protected final Map<ShapeKey, VoxelShape> newShapeMap = new HashMap<>();
protected Map<ShapeKey, VoxelShape> newCollisionShapeMap = new HashMap<>(); protected final Map<ShapeKey, VoxelShape> newCollisionShapeMap = new HashMap<>();
protected void initNewShapemaps() { protected void initNewShapemaps() {
initNewShapemap(((WallBlockAccessor) this).templates$getShapeMap(), newShapeMap); initNewShapemap(((WallBlockAccessor) this).templates$getShapeMap(), newShapeMap);

View File

@ -9,10 +9,7 @@ import org.spongepowered.asm.mixin.gen.Accessor;
public interface AccessorParticle { public interface AccessorParticle {
@Accessor("random") Random templates$getRandom(); @Accessor("random") Random templates$getRandom();
@Accessor("red") float templates$red();
@Accessor("red") void templates$setRed(float red); @Accessor("red") void templates$setRed(float red);
@Accessor("green") float templates$green();
@Accessor("green") void templates$setGreen(float green); @Accessor("green") void templates$setGreen(float green);
@Accessor("blue") float templates$blue();
@Accessor("blue") void templates$setBlue(float blue); @Accessor("blue") void templates$setBlue(float blue);
} }

View File

@ -28,11 +28,11 @@ public class MeshTransformUtil {
} }
//Hard to explain what this is for... //Hard to explain what this is for...
//Basically, the previous incarnation of this mod assembled the north/south/east/west faces all individually. //Basically, Templates 1.x manually emitted the north/south/east/west faces all individually.
//This means it was easy to get the orientation of the block correct - to popular the north face of the slope, look at //This means it was easy to get the orientation of the block correct - to popular the north face of the slope, look at
//the north texture of the theme block. In this version, there is only *one* slope model that is dynamically rotated //the north texture of the theme block. In this version, there is only *one* slope model that is dynamically rotated
//to form the other possible orientations. If I populate the north face of the model using the north face of the theme, //to form the other possible orientations. If I populate the north face of the model using the north face of the theme,
//that model will then be rotated so it's no longer facing the right way. //then rotate the model, it's no longer facing the right way. So I need to "un-rotate" the face assignments first.
// //
//This seems to work, but I'm kinda surprised I don't need to invert the transformation here, which is a clue that //This seems to work, but I'm kinda surprised I don't need to invert the transformation here, which is a clue that
//I don't really understand all the math, loool //I don't really understand all the math, loool

View File

@ -1,10 +1,8 @@
package io.github.cottonmc.templates.model; package io.github.cottonmc.templates.model;
import io.github.cottonmc.templates.TemplatesClient;
import io.github.cottonmc.templates.block.TemplateEntity; import io.github.cottonmc.templates.block.TemplateEntity;
import io.github.cottonmc.templates.mixin.MinecraftAccessor; import io.github.cottonmc.templates.mixin.MinecraftAccessor;
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
@ -48,7 +46,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel {
protected final BlockState itemModelState; protected final BlockState itemModelState;
protected final boolean ao; protected final boolean ao;
private static record CacheKey(BlockState state, TemplateAppearance appearance) {} protected record CacheKey(BlockState state, TemplateAppearance appearance) {}
private final ConcurrentMap<CacheKey, Mesh> retexturedMeshes = new ConcurrentHashMap<>(); //mutable, append-only cache private final ConcurrentMap<CacheKey, Mesh> retexturedMeshes = new ConcurrentHashMap<>(); //mutable, append-only cache
protected static final Direction[] DIRECTIONS = Direction.values(); protected static final Direction[] DIRECTIONS = Direction.values();
@ -129,6 +127,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel {
} }
protected class RetexturingTransformer implements RenderContext.QuadTransform { protected class RetexturingTransformer implements RenderContext.QuadTransform {
//TODO: remove the "tint" parameter, it's been kicked to TintingTransformer
protected RetexturingTransformer(TemplateAppearance ta, int tint) { protected RetexturingTransformer(TemplateAppearance ta, int tint) {
this.ta = ta; this.ta = ta;
this.tint = tint; this.tint = tint;

View File

@ -1,7 +1,6 @@
package io.github.cottonmc.templates.model; package io.github.cottonmc.templates.model;
import io.github.cottonmc.templates.TemplatesClient; import io.github.cottonmc.templates.TemplatesClient;
import io.github.cottonmc.templates.util.TattletaleRandom;
import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; import net.fabricmc.fabric.api.renderer.v1.material.BlendMode;
import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder; import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder;
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
@ -83,7 +82,7 @@ public class TemplateAppearanceManager {
private TemplateAppearance computeAppearance(BlockState state) { private TemplateAppearance computeAppearance(BlockState state) {
if(state.getBlock() == Blocks.BARRIER) return barrierItemAppearance; if(state.getBlock() == Blocks.BARRIER) return barrierItemAppearance;
TattletaleRandom rand = new TattletaleRandom(Random.create()); Random rand = Random.create(42);
BakedModel model = MinecraftClient.getInstance().getBlockRenderManager().getModel(state); BakedModel model = MinecraftClient.getInstance().getBlockRenderManager().getModel(state);
//Only for parsing vanilla quads: //Only for parsing vanilla quads:
@ -102,7 +101,7 @@ public class TemplateAppearanceManager {
BakedQuad arbitraryQuad = sideQuads.get(0); //TODO: maybe pick a largest quad instead? BakedQuad arbitraryQuad = sideQuads.get(0); //TODO: maybe pick a largest quad instead?
if(arbitraryQuad == null) continue; if(arbitraryQuad == null) continue;
if(arbitraryQuad.hasColor()) hasColorMask |= (1 << dir.ordinal()); if(arbitraryQuad.hasColor()) hasColorMask |= (byte) (1 << dir.ordinal());
Sprite sprite = arbitraryQuad.getSprite(); Sprite sprite = arbitraryQuad.getSprite();
if(sprite == null) continue; if(sprite == null) continue;
@ -151,10 +150,6 @@ public class TemplateAppearanceManager {
if(sprites[i] == null) sprites[i] = defaultAppearance.getParticleSprite(); if(sprites[i] == null) sprites[i] = defaultAppearance.getParticleSprite();
} }
if(rand.wasUsed) {
//System.err.println("State " + state + " makes use of a randomized model");
}
return new ComputedApperance( return new ComputedApperance(
sprites, sprites,
bakeFlags, bakeFlags,

View File

@ -5,6 +5,7 @@ import net.minecraft.util.shape.VoxelShapes;
import org.joml.Vector3d; import org.joml.Vector3d;
public class StairShapeMaker { public class StairShapeMaker {
//TODO: clean this the fuck up, maybe keep in mind that VoxelShapes can be rotated multiples of 90 degrees by just rotating their corners
public static VoxelShape makeStair(Edge innerEdge, double stepIn, double initialStepRise, double stepRise, double stepRun, int stepCount) { public static VoxelShape makeStair(Edge innerEdge, double stepIn, double initialStepRise, double stepRise, double stepRun, int stepCount) {
Edge.CoordinateFrame frame = innerEdge.makeCoordinateFrame(); Edge.CoordinateFrame frame = innerEdge.makeCoordinateFrame();
Vector3d origin = frame.origin(); Vector3d origin = frame.origin();