From b8034b4b2e1be0049cf0e46250d356168d0d180d Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 22 Dec 2021 00:22:43 -0800 Subject: [PATCH] util and core cleanup - Consolidate/audit utility classes - Move more towards sane vertex types --- .../structureMovement/Contraption.java | 10 +- .../structureMovement/ContraptionLighter.java | 4 +- .../NonStationaryLighter.java | 4 +- .../bearing/AnchoredLighter.java | 2 +- .../structureMovement/glue/GlueInstance.java | 152 +----------------- .../structureMovement/glue/GlueModel.java | 99 ++++++++++++ .../piston/PistonLighter.java | 2 +- .../pulley/AbstractPulleyInstance.java | 4 +- .../pulley/PulleyLighter.java | 2 +- .../render/EmptyLighter.java | 2 +- .../render/FlwContraptionManager.java | 4 +- .../relays/belt/BeltTileEntity.java | 4 +- .../foundation/render/AllInstanceFormats.java | 4 +- .../foundation/render/SuperByteBuffer.java | 8 +- 14 files changed, 126 insertions(+), 175 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueModel.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index 66ad205e5..312afd33c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -25,8 +25,8 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; -import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.light.ImmutableBox; +import com.jozufozu.flywheel.util.box.GridAlignedBB; +import com.jozufozu.flywheel.util.box.ImmutableBox; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllInteractionBehaviours; import com.simibubi.create.AllMovementBehaviours; @@ -874,9 +874,9 @@ public abstract class Contraption { } ListTag paletteNBT = new ListTag(); - for(int i = 0; i < palette.getSize(); ++i) + for(int i = 0; i < palette.getSize(); ++i) paletteNBT.add(NbtUtils.writeBlockState(palette.values.byId(i))); - + compound.put("Palette", paletteNBT); compound.put("BlockList", blockList); @@ -891,7 +891,7 @@ public abstract class Contraption { palette = new HashMapPalette<>(GameData.getBlockStateIDMap(), 16, (i, s) -> { throw new IllegalStateException("Palette Map index exceeded maximum"); }); - + ListTag list = c.getList("Palette", 10); palette.values.clear(); for (int i = 0; i < list.size(); ++i) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java index 95ea67501..76ac67287 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java @@ -1,8 +1,8 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.jozufozu.flywheel.light.GPULightVolume; -import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.light.ImmutableBox; +import com.jozufozu.flywheel.util.box.GridAlignedBB; +import com.jozufozu.flywheel.util.box.ImmutableBox; import com.jozufozu.flywheel.light.LightListener; import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.LightUpdater; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java index 363cd4afa..1e0cd0d8a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; -import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.light.ImmutableBox; +import com.jozufozu.flywheel.util.box.GridAlignedBB; +import com.jozufozu.flywheel.util.box.ImmutableBox; import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.MovingListener; import com.simibubi.create.foundation.config.AllConfigs; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/AnchoredLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/AnchoredLighter.java index 16bd4e82a..1f2a06669 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/AnchoredLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/AnchoredLighter.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; -import com.jozufozu.flywheel.light.GridAlignedBB; +import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java index cb4cf3e2f..dd7c8c3d1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java @@ -8,29 +8,21 @@ import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance; import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.instancing.ConditionalInstance; import com.jozufozu.flywheel.core.materials.oriented.OrientedData; -import com.jozufozu.flywheel.core.model.Model; -import com.jozufozu.flywheel.util.ModelReader; -import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Quaternion; import com.simibubi.create.AllItems; -import com.simibubi.create.AllStitchedTextures; import com.simibubi.create.Create; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.LightLayer; -import net.minecraft.world.phys.Vec3; public class GlueInstance extends EntityInstance implements ITickableInstance { - private static final boolean USE_ATLAS = false; private static final ResourceLocation TEXTURE = Create.asResource("textures/entity/super_glue/slime.png"); private final Quaternion rotation; @@ -51,9 +43,9 @@ public class GlueInstance extends EntityInstance implements ITi } private Instancer getInstancer(MaterialManager materialManager, SuperGlueEntity entity) { - MaterialGroup group = USE_ATLAS ? materialManager.defaultCutout() : materialManager.cutout(RenderType.entityCutout(TEXTURE)); + MaterialGroup group = GlueModel.USE_ATLAS ? materialManager.defaultCutout() : materialManager.cutout(RenderType.entityCutout(TEXTURE)); - return group.material(Materials.ORIENTED).model(entity.getType(), GlueModel::new); + return group.material(Materials.ORIENTED).model(entity.getType(), GlueModel::get); } @Override @@ -94,144 +86,4 @@ public class GlueInstance extends EntityInstance implements ITi || AllItems.SUPER_GLUE.isIn(player.getOffhandItem()); } - public static class GlueModel implements Model, ModelReader { - - @Override - public String name() { - return "glue"; - } - - public void buffer(VertexConsumer buffer) { - Vec3 diff = Vec3.atLowerCornerOf(Direction.SOUTH.getNormal()); - Vec3 extension = diff.normalize() - .scale(1 / 32f - 1 / 128f); - - Vec3 plane = VecHelper.axisAlingedPlaneOf(diff); - Direction.Axis axis = Direction.getNearest(diff.x, diff.y, diff.z) - .getAxis(); - - Vec3 start = Vec3.ZERO.subtract(extension); - Vec3 end = Vec3.ZERO.add(extension); - - plane = plane.scale(1 / 2f); - Vec3 a1 = plane.add(start); - Vec3 b1 = plane.add(end); - plane = VecHelper.rotate(plane, -90, axis); - Vec3 a2 = plane.add(start); - Vec3 b2 = plane.add(end); - plane = VecHelper.rotate(plane, -90, axis); - Vec3 a3 = plane.add(start); - Vec3 b3 = plane.add(end); - plane = VecHelper.rotate(plane, -90, axis); - Vec3 a4 = plane.add(start); - Vec3 b4 = plane.add(end); - - float minU; - float maxU; - float minV; - float maxV; - - if (USE_ATLAS) { - TextureAtlasSprite sprite = AllStitchedTextures.SUPER_GLUE.get(); - minU = sprite.getU0(); - maxU = sprite.getU1(); - minV = sprite.getV0(); - maxV = sprite.getV1(); - } else { - minU = minV = 0; - maxU = maxV = 1; - } - - // inside quad - buffer.vertex(a1.x, a1.y, a1.z).normal(0, 0, -1f).uv(maxU, minV).endVertex(); - buffer.vertex(a2.x, a2.y, a2.z).normal(0, 0, -1f).uv(maxU, maxV).endVertex(); - buffer.vertex(a3.x, a3.y, a3.z).normal(0, 0, -1f).uv(minU, maxV).endVertex(); - buffer.vertex(a4.x, a4.y, a4.z).normal(0, 0, -1f).uv(minU, minV).endVertex(); - // outside quad - buffer.vertex(b4.x, b4.y, b4.z).normal(0, 0, 1f).uv(minU, minV).endVertex(); - buffer.vertex(b3.x, b3.y, b3.z).normal(0, 0, 1f).uv(minU, maxV).endVertex(); - buffer.vertex(b2.x, b2.y, b2.z).normal(0, 0, 1f).uv(maxU, maxV).endVertex(); - buffer.vertex(b1.x, b1.y, b1.z).normal(0, 0, 1f).uv(maxU, minV).endVertex(); - } - - @Override - public int vertexCount() { - return 8; - } - - @Override - public ModelReader getReader() { - return this; - } - - @Override - public int getVertexCount() { - return 8; - } - - @Override - public float getX(int index) { - return 0; - } - - @Override - public float getY(int index) { - return 0; - } - - @Override - public float getZ(int index) { - return 0; - } - - @Override - public byte getR(int index) { - return (byte) 0xFF; - } - - @Override - public byte getG(int index) { - return (byte) 0xFF; - } - - @Override - public byte getB(int index) { - return (byte) 0xFF; - } - - @Override - public byte getA(int index) { - return (byte) 0xFF; - } - - @Override - public float getU(int index) { - return 0; - } - - @Override - public float getV(int index) { - return 0; - } - - @Override - public int getLight(int index) { - return 0; - } - - @Override - public float getNX(int index) { - return 0; - } - - @Override - public float getNY(int index) { - return 0; - } - - @Override - public float getNZ(int index) { - return index > 4 ? -1 : 1; - } - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueModel.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueModel.java new file mode 100644 index 000000000..c5530c8b1 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueModel.java @@ -0,0 +1,99 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.glue; + +import com.jozufozu.flywheel.core.model.Model; +import com.jozufozu.flywheel.core.vertex.PosTexNormalVertexListUnsafe; +import com.jozufozu.flywheel.core.vertex.PosTexNormalWriter; +import com.jozufozu.flywheel.core.vertex.VertexList; +import com.mojang.blaze3d.platform.MemoryTracker; +import com.simibubi.create.AllStitchedTextures; +import com.simibubi.create.foundation.utility.VecHelper; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.core.Direction; +import net.minecraft.world.phys.Vec3; + +public class GlueModel implements Model { + + public static final GlueModel INSTANCE = new GlueModel(); + static final boolean USE_ATLAS = false; + + public static GlueModel get() { + return INSTANCE; + } + + private final PosTexNormalVertexListUnsafe reader; + + private GlueModel() { + PosTexNormalWriter writer = new PosTexNormalWriter(MemoryTracker.create(size())); + createGlueModel(writer); + reader = writer.intoReader(); + } + + @Override + public String name() { + return "glue"; + } + + @Override + public int vertexCount() { + return 8; + } + + @Override + public VertexList getReader() { + return reader; + } + + public static void createGlueModel(PosTexNormalWriter buffer) { + Vec3 diff = Vec3.atLowerCornerOf(Direction.SOUTH.getNormal()); + Vec3 extension = diff.normalize() + .scale(1 / 32f - 1 / 128f); + + Vec3 plane = VecHelper.axisAlingedPlaneOf(diff); + Direction.Axis axis = Direction.getNearest(diff.x, diff.y, diff.z) + .getAxis(); + + Vec3 start = Vec3.ZERO.subtract(extension); + Vec3 end = Vec3.ZERO.add(extension); + + plane = plane.scale(1 / 2f); + Vec3 a1 = plane.add(start); + Vec3 b1 = plane.add(end); + plane = VecHelper.rotate(plane, -90, axis); + Vec3 a2 = plane.add(start); + Vec3 b2 = plane.add(end); + plane = VecHelper.rotate(plane, -90, axis); + Vec3 a3 = plane.add(start); + Vec3 b3 = plane.add(end); + plane = VecHelper.rotate(plane, -90, axis); + Vec3 a4 = plane.add(start); + Vec3 b4 = plane.add(end); + + float minU; + float maxU; + float minV; + float maxV; + + if (USE_ATLAS) { + TextureAtlasSprite sprite = AllStitchedTextures.SUPER_GLUE.get(); + minU = sprite.getU0(); + maxU = sprite.getU1(); + minV = sprite.getV0(); + maxV = sprite.getV1(); + } else { + minU = minV = 0; + maxU = maxV = 1; + } + + // inside quad + buffer.putVertex((float) a1.x, (float) a1.y, (float) a1.z, 0, 0, -1, maxU, minV); + buffer.putVertex((float) a2.x, (float) a2.y, (float) a2.z, 0, 0, -1, maxU, maxV); + buffer.putVertex((float) a3.x, (float) a3.y, (float) a3.z, 0, 0, -1, minU, maxV); + buffer.putVertex((float) a4.x, (float) a4.y, (float) a4.z, 0, 0, -1, minU, minV); + // outside quad + buffer.putVertex((float) b4.x, (float) b4.y, (float) b4.z, 0, 0, 1f, minU, minV); + buffer.putVertex((float) b3.x, (float) b3.y, (float) b3.z, 0, 0, 1f, minU, maxV); + buffer.putVertex((float) b2.x, (float) b2.y, (float) b2.z, 0, 0, 1f, maxU, maxV); + buffer.putVertex((float) b1.x, (float) b1.y, (float) b1.z, 0, 0, 1f, maxU, minV); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java index 2072a657f..5d834de18 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.piston; -import com.jozufozu.flywheel.light.GridAlignedBB; +import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; import net.minecraft.core.Vec3i; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java index 8906a5ab0..f4c600ebf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java @@ -7,8 +7,8 @@ import com.jozufozu.flywheel.core.instancing.ConditionalInstance; import com.jozufozu.flywheel.core.instancing.GroupInstance; import com.jozufozu.flywheel.core.instancing.SelectInstance; import com.jozufozu.flywheel.core.materials.oriented.OrientedData; -import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.light.ImmutableBox; +import com.jozufozu.flywheel.util.box.GridAlignedBB; +import com.jozufozu.flywheel.util.box.ImmutableBox; import com.jozufozu.flywheel.light.LightPacking; import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.LightUpdater; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java index b959b2ca4..2a1faf43c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.pulley; -import com.jozufozu.flywheel.light.GridAlignedBB; +import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/EmptyLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/EmptyLighter.java index da4a5384b..c922a2ccd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/EmptyLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/EmptyLighter.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; -import com.jozufozu.flywheel.light.GridAlignedBB; +import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java index a3b438224..e6376222b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java @@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.RenderLayer; import com.jozufozu.flywheel.backend.gl.GlTextureUnit; import com.jozufozu.flywheel.backend.gl.GlVertexArray; import com.jozufozu.flywheel.event.RenderLayerEvent; -import com.jozufozu.flywheel.util.TextureBinder; +import com.jozufozu.flywheel.util.Textures; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.foundation.render.AllProgramSpecs; import com.simibubi.create.foundation.render.CreateContexts; @@ -44,7 +44,7 @@ public class FlwContraptionManager extends ContraptionRenderManager, Translate, Rotate, TStack { - private final ModelReader template; + private final VertexList template; // Vertex Position private final PoseStack transforms; @@ -64,7 +64,7 @@ public class SuperByteBuffer implements Scale, Translate