mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 07:26:48 +01:00
Lids everywhere
- Ender chests and trapped chests, too - Chests orient themselves correctly - Lids do not position themselves correctly - Some math, will probably replace with JOML
This commit is contained in:
parent
9501d01494
commit
80e851a1f1
7 changed files with 256 additions and 8 deletions
|
@ -99,6 +99,8 @@ repositories {
|
|||
dependencies {
|
||||
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
||||
|
||||
//implementation "org.joml:joml:1.10.1"
|
||||
|
||||
annotationProcessor 'org.spongepowered:mixin:0.8.2:processor'
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ public class InstancedRenderRegistry {
|
|||
return this;
|
||||
}
|
||||
|
||||
public InstancedRenderRegistry build() {
|
||||
public InstancedRenderRegistry register() {
|
||||
tiles.put(type, factory);
|
||||
InstancedRenderRegistry.this.skipRender.put(type, skipRender);
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.jozufozu.flywheel.core.materials;
|
|||
import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer;
|
||||
import com.jozufozu.flywheel.backend.instancing.Instancer;
|
||||
|
||||
import com.jozufozu.flywheel.util.vec.Vec3;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Quaternion;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
|
@ -41,6 +43,11 @@ public class OrientedData extends BasicData {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
public OrientedData nudge(Vec3 pos) {
|
||||
return nudge(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public OrientedData nudge(float x, float y, float z) {
|
||||
this.posX += x;
|
||||
this.posY += y;
|
||||
|
@ -57,6 +64,10 @@ public class OrientedData extends BasicData {
|
|||
return setPosition((float) pos.getX(), (float) pos.getY(), (float) pos.getZ());
|
||||
}
|
||||
|
||||
public OrientedData setPivot(Vec3 pos) {
|
||||
return setPivot(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public OrientedData setPivot(float x, float y, float z) {
|
||||
this.pivotX = x;
|
||||
this.pivotY = y;
|
||||
|
|
77
src/main/java/com/jozufozu/flywheel/util/vec/Vec3.java
Normal file
77
src/main/java/com/jozufozu/flywheel/util/vec/Vec3.java
Normal file
|
@ -0,0 +1,77 @@
|
|||
package com.jozufozu.flywheel.util.vec;
|
||||
|
||||
import net.minecraft.util.math.vector.Quaternion;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
|
||||
public class Vec3 {
|
||||
public static final Vec3 NEGATIVE_X = new Vec3(-1.0F, 0.0F, 0.0F);
|
||||
public static final Vec3 POSITIVE_X = new Vec3(1.0F, 0.0F, 0.0F);
|
||||
public static final Vec3 NEGATIVE_Y = new Vec3(0.0F, -1.0F, 0.0F);
|
||||
public static final Vec3 POSITIVE_Y = new Vec3(0.0F, 1.0F, 0.0F);
|
||||
public static final Vec3 NEGATIVE_Z = new Vec3(0.0F, 0.0F, -1.0F);
|
||||
public static final Vec3 POSITIVE_Z = new Vec3(0.0F, 0.0F, 1.0F);
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
private float z;
|
||||
|
||||
public Vec3(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public Vec3 multiply(Quaternion quat) {
|
||||
Vec4 vec4 = new Vec4(this, 1f);
|
||||
|
||||
vec4.multiply(quat);
|
||||
|
||||
set(vec4.getX(), vec4.getY(), vec4.getZ());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vec3 copy() {
|
||||
return new Vec3(x, y, z);
|
||||
}
|
||||
|
||||
public Vector3f convert() {
|
||||
return new Vector3f(x, y, z);
|
||||
}
|
||||
|
||||
public void set(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vec3 add(Vec3 v) {
|
||||
add(v.x, v.y, v.z);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vec3 add(float x, float y, float z) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vec3 sub(float x, float y, float z) {
|
||||
this.x -= x;
|
||||
this.y -= y;
|
||||
this.z -= z;
|
||||
return this;
|
||||
}
|
||||
}
|
66
src/main/java/com/jozufozu/flywheel/util/vec/Vec4.java
Normal file
66
src/main/java/com/jozufozu/flywheel/util/vec/Vec4.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
package com.jozufozu.flywheel.util.vec;
|
||||
|
||||
import net.minecraft.util.math.vector.Quaternion;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
|
||||
public class Vec4 {
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
private float z;
|
||||
private float w;
|
||||
|
||||
public Vec4(float x, float y, float z, float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
public Vec4(Vec3 vec3) {
|
||||
this(vec3, 0);
|
||||
}
|
||||
|
||||
public Vec4(Vec3 vec3, float w) {
|
||||
this.x = vec3.getX();
|
||||
this.y = vec3.getY();
|
||||
this.z = vec3.getZ();
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
public void multiply(Quaternion quat) {
|
||||
Quaternion quaternion = new Quaternion(quat);
|
||||
quaternion.multiply(new Quaternion(this.getX(), this.getY(), this.getZ(), 0.0F));
|
||||
Quaternion quaternion1 = new Quaternion(quat);
|
||||
quaternion1.conjugate();
|
||||
quaternion.multiply(quaternion1);
|
||||
this.set(quaternion.getX(), quaternion.getY(), quaternion.getZ(), this.getW());
|
||||
}
|
||||
|
||||
public Vec3 xyz() {
|
||||
return new Vec3(x, y, z);
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public float getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
public void set(float x, float y, float z, float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
}
|
|
@ -11,6 +11,10 @@ import com.jozufozu.flywheel.core.materials.OrientedData;
|
|||
import com.jozufozu.flywheel.core.model.ModelPart;
|
||||
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
||||
|
||||
import com.jozufozu.flywheel.util.vec.Vec3;
|
||||
import com.jozufozu.flywheel.util.vec.Vec4;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
|
||||
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ChestBlock;
|
||||
|
@ -18,26 +22,34 @@ import net.minecraft.client.renderer.Atlases;
|
|||
import net.minecraft.client.renderer.model.RenderMaterial;
|
||||
import net.minecraft.state.properties.ChestType;
|
||||
import net.minecraft.tileentity.ChestTileEntity;
|
||||
import net.minecraft.tileentity.IChestLid;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityMerger;
|
||||
import net.minecraft.util.math.vector.Quaternion;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraft.util.math.vector.Vector4f;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public class ChestInstance extends TileEntityInstance<ChestTileEntity> implements IDynamicInstance {
|
||||
public class ChestInstance<T extends TileEntity & IChestLid> extends TileEntityInstance<T> implements IDynamicInstance {
|
||||
|
||||
private final OrientedData body;
|
||||
private final OrientedData lid;
|
||||
|
||||
private final Float2FloatFunction lidProgress;
|
||||
private final RenderMaterial renderMaterial;
|
||||
@Nonnull
|
||||
private final ChestType chestType;
|
||||
private final Quaternion baseRotation;
|
||||
|
||||
public ChestInstance(MaterialManager<?> materialManager, ChestTileEntity tile) {
|
||||
public ChestInstance(MaterialManager<?> materialManager, T tile) {
|
||||
super(materialManager, tile);
|
||||
|
||||
Block block = blockState.getBlock();
|
||||
|
||||
ChestType chestType = blockState.contains(ChestBlock.TYPE) ? blockState.get(ChestBlock.TYPE) : ChestType.SINGLE;
|
||||
chestType = blockState.contains(ChestBlock.TYPE) ? blockState.get(ChestBlock.TYPE) : ChestType.SINGLE;
|
||||
renderMaterial = Atlases.getChestTexture(tile, chestType, isChristmas());
|
||||
|
||||
body = baseInstance()
|
||||
|
@ -48,6 +60,15 @@ public class ChestInstance extends TileEntityInstance<ChestTileEntity> implement
|
|||
|
||||
if (block instanceof ChestBlock) {
|
||||
|
||||
// MatrixStack stack = new MatrixStack();
|
||||
//
|
||||
// stack.push();
|
||||
float horizontalAngle = blockState.get(ChestBlock.FACING).getHorizontalAngle();
|
||||
|
||||
baseRotation = Vector3f.POSITIVE_Y.getDegreesQuaternion(-horizontalAngle);
|
||||
|
||||
body.setRotation(baseRotation);
|
||||
|
||||
ChestBlock chestBlock = (ChestBlock) block;
|
||||
|
||||
TileEntityMerger.ICallbackWrapper<? extends ChestTileEntity> wrapper = chestBlock.getBlockEntitySource(blockState, world, getWorldPosition(), true);
|
||||
|
@ -56,6 +77,7 @@ public class ChestInstance extends TileEntityInstance<ChestTileEntity> implement
|
|||
|
||||
|
||||
} else {
|
||||
baseRotation = Quaternion.IDENTITY;
|
||||
lidProgress = $ -> 0f;
|
||||
}
|
||||
}
|
||||
|
@ -69,10 +91,22 @@ public class ChestInstance extends TileEntityInstance<ChestTileEntity> implement
|
|||
|
||||
float angleX = -(progress * ((float) Math.PI / 2F));
|
||||
|
||||
Quaternion quaternion = new Quaternion(Vector3f.POSITIVE_X, angleX, false);
|
||||
|
||||
Vec3 axis = Vec3.POSITIVE_X.copy();
|
||||
Vec3 pivot = new Vec3(0, 0, 1f / 16f);
|
||||
pivot.add(0.5f, 0.5f, 0.5f)
|
||||
.multiply(baseRotation)
|
||||
.sub(0.5f, 0.5f, 0.5f);
|
||||
axis.multiply(baseRotation);
|
||||
|
||||
Quaternion quaternion = new Quaternion(axis.convert(), angleX, false);
|
||||
|
||||
quaternion.multiply(baseRotation);
|
||||
|
||||
lid.setRotation(quaternion)
|
||||
.setPivot(0, 0, 1f / 16f);
|
||||
.setPosition(getInstancePosition())
|
||||
.nudge(0, 9f/16f, 0)
|
||||
.setPivot(pivot);
|
||||
|
||||
}
|
||||
|
||||
|
@ -103,6 +137,27 @@ public class ChestInstance extends TileEntityInstance<ChestTileEntity> implement
|
|||
|
||||
private BufferedModel getBaseModel() {
|
||||
|
||||
switch (chestType) {
|
||||
case LEFT:
|
||||
return ModelPart.builder(64, 64)
|
||||
.sprite(renderMaterial.getSprite())
|
||||
.cuboid()
|
||||
.textureOffset(0, 19)
|
||||
.start(0, 0, 1)
|
||||
.size(15, 10, 14)
|
||||
.endCuboid()
|
||||
.build();
|
||||
case RIGHT:
|
||||
return ModelPart.builder(64, 64)
|
||||
.sprite(renderMaterial.getSprite())
|
||||
.cuboid()
|
||||
.textureOffset(0, 19)
|
||||
.start(1, 0, 1)
|
||||
.size(15, 10, 14)
|
||||
.endCuboid()
|
||||
.build();
|
||||
}
|
||||
|
||||
return ModelPart.builder(64, 64)
|
||||
.sprite(renderMaterial.getSprite())
|
||||
.cuboid()
|
||||
|
@ -115,12 +170,41 @@ public class ChestInstance extends TileEntityInstance<ChestTileEntity> implement
|
|||
|
||||
private BufferedModel getLidModel() {
|
||||
|
||||
switch (chestType) {
|
||||
case LEFT:
|
||||
return ModelPart.builder(64, 64)
|
||||
.sprite(renderMaterial.getSprite())
|
||||
.cuboid()
|
||||
.textureOffset(0, 0)
|
||||
.start(0, 0, 1)
|
||||
.size(15, 5, 14)
|
||||
.endCuboid()
|
||||
.cuboid()
|
||||
.start(0, -2, 15)
|
||||
.size(1, 4, 1)
|
||||
.endCuboid()
|
||||
.build();
|
||||
case RIGHT:
|
||||
return ModelPart.builder(64, 64)
|
||||
.sprite(renderMaterial.getSprite())
|
||||
.cuboid()
|
||||
.textureOffset(0, 0)
|
||||
.start(1, 0, 1)
|
||||
.end(15, 5, 15)
|
||||
.size(15, 5, 14)
|
||||
.endCuboid()
|
||||
.cuboid()
|
||||
.start(15, -2, 15)
|
||||
.size(1, 4, 1)
|
||||
.endCuboid()
|
||||
.build();
|
||||
}
|
||||
|
||||
return ModelPart.builder(64, 64)
|
||||
.sprite(renderMaterial.getSprite())
|
||||
.cuboid()
|
||||
.textureOffset(0, 0)
|
||||
.start(1, 0, 1)
|
||||
.size(14, 5, 14)
|
||||
.endCuboid()
|
||||
.cuboid()
|
||||
.start(7, -2, 15)
|
||||
|
|
|
@ -12,6 +12,14 @@ public class VanillaInstances {
|
|||
r.tile(TileEntityType.CHEST)
|
||||
.setSkipRender(true)
|
||||
.factory(ChestInstance::new)
|
||||
.build();
|
||||
.register();
|
||||
r.tile(TileEntityType.ENDER_CHEST)
|
||||
.setSkipRender(true)
|
||||
.factory(ChestInstance::new)
|
||||
.register();
|
||||
r.tile(TileEntityType.TRAPPED_CHEST)
|
||||
.setSkipRender(true)
|
||||
.factory(ChestInstance::new)
|
||||
.register();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue