mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 23:47:38 +01:00
util and core cleanup
- Consolidate/audit utility classes - Move more towards sane vertex types
This commit is contained in:
parent
aa96a28f0b
commit
b8034b4b2e
14 changed files with 126 additions and 175 deletions
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<SuperGlueEntity> 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<SuperGlueEntity> implements ITi
|
|||
}
|
||||
|
||||
private Instancer<OrientedData> 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<SuperGlueEntity> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<RenderedCont
|
|||
|
||||
layer.setupRenderState();
|
||||
|
||||
TextureBinder.bindActiveTextures();
|
||||
Textures.bindActiveTextures();
|
||||
|
||||
ContraptionProgram structureShader = CreateContexts.STRUCTURE.getProgram(AllProgramSpecs.STRUCTURE);
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ import java.util.Optional;
|
|||
import java.util.function.Function;
|
||||
|
||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||
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;
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.simibubi.create.foundation.render;
|
|||
|
||||
import com.jozufozu.flywheel.backend.gl.attrib.CommonAttributes;
|
||||
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
||||
import com.jozufozu.flywheel.core.Formats;
|
||||
|
||||
public class AllInstanceFormats {
|
||||
|
||||
|
@ -27,7 +26,8 @@ public class AllInstanceFormats {
|
|||
.build();
|
||||
|
||||
private static VertexFormat.Builder kineticInstance() {
|
||||
return Formats.litInstance()
|
||||
return VertexFormat.builder()
|
||||
.addAttributes(CommonAttributes.LIGHT, CommonAttributes.RGBA)
|
||||
.addAttributes(CommonAttributes.VEC3, CommonAttributes.FLOAT, CommonAttributes.FLOAT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.simibubi.create.foundation.render;
|
||||
|
||||
import com.jozufozu.flywheel.util.BlockFormatReader;
|
||||
import com.jozufozu.flywheel.util.ModelReader;
|
||||
import com.jozufozu.flywheel.core.vertex.BlockVertexList;
|
||||
import com.jozufozu.flywheel.core.vertex.VertexList;
|
||||
import com.jozufozu.flywheel.util.transform.Rotate;
|
||||
import com.jozufozu.flywheel.util.transform.Scale;
|
||||
import com.jozufozu.flywheel.util.transform.TStack;
|
||||
|
@ -32,7 +32,7 @@ import net.minecraftforge.client.model.pipeline.LightUtil;
|
|||
|
||||
public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperByteBuffer>, Rotate<SuperByteBuffer>, TStack<SuperByteBuffer> {
|
||||
|
||||
private final ModelReader template;
|
||||
private final VertexList template;
|
||||
|
||||
// Vertex Position
|
||||
private final PoseStack transforms;
|
||||
|
@ -64,7 +64,7 @@ public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperB
|
|||
private static final Long2IntMap WORLD_LIGHT_CACHE = new Long2IntOpenHashMap();
|
||||
|
||||
public SuperByteBuffer(BufferBuilder buf) {
|
||||
template = new BlockFormatReader(buf);
|
||||
template = new BlockVertexList(buf);
|
||||
transforms = new PoseStack();
|
||||
transforms.pushPose();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue