mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 12:34:11 +01:00
DIY
- Visuals must manually call setChanged on Instances. - Decreases the extent of resource contention and makes what's going on more explicit. - Remove self type parameter from FlatLit, I don't think it was ever needed.
This commit is contained in:
parent
a8b51aacbe
commit
370a891aae
@ -5,7 +5,7 @@ import com.jozufozu.flywheel.api.instance.InstanceType;
|
||||
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
|
||||
public abstract class ColoredLitInstance extends AbstractInstance implements FlatLit<ColoredLitInstance> {
|
||||
public abstract class ColoredLitInstance extends AbstractInstance implements FlatLit {
|
||||
public byte blockLight;
|
||||
public byte skyLight;
|
||||
|
||||
@ -21,14 +21,12 @@ public abstract class ColoredLitInstance extends AbstractInstance implements Fla
|
||||
@Override
|
||||
public ColoredLitInstance setBlockLight(int blockLight) {
|
||||
this.blockLight = (byte) blockLight;
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColoredLitInstance setSkyLight(int skyLight) {
|
||||
this.skyLight = (byte) skyLight;
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -62,7 +60,6 @@ public abstract class ColoredLitInstance extends AbstractInstance implements Fla
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -71,7 +68,6 @@ public abstract class ColoredLitInstance extends AbstractInstance implements Fla
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -11,29 +11,27 @@ import net.minecraft.world.level.LightLayer;
|
||||
* if they wish to make use of Flywheel's provided light update methods.
|
||||
* <p>
|
||||
* This only covers flat lighting, smooth lighting is still TODO.
|
||||
*
|
||||
* @param <I> The name of the class that implements this interface.
|
||||
*/
|
||||
public interface FlatLit<I extends Instance & FlatLit<I>> {
|
||||
public interface FlatLit extends Instance {
|
||||
/**
|
||||
* @param blockLight An integer in the range [0, 15] representing the
|
||||
* amount of block light this instance should receive.
|
||||
* @return {@code this}
|
||||
*/
|
||||
I setBlockLight(int blockLight);
|
||||
FlatLit setBlockLight(int blockLight);
|
||||
|
||||
/**
|
||||
* @param skyLight An integer in the range [0, 15] representing the
|
||||
* amount of sky light this instance should receive.
|
||||
* @return {@code this}
|
||||
*/
|
||||
I setSkyLight(int skyLight);
|
||||
FlatLit setSkyLight(int skyLight);
|
||||
|
||||
default I setLight(int blockLight, int skyLight) {
|
||||
default FlatLit setLight(int blockLight, int skyLight) {
|
||||
return setBlockLight(blockLight).setSkyLight(skyLight);
|
||||
}
|
||||
|
||||
default I updateLight(BlockAndTintGetter level, BlockPos pos) {
|
||||
default FlatLit updateLight(BlockAndTintGetter level, BlockPos pos) {
|
||||
return setLight(level.getBrightness(LightLayer.BLOCK, pos), level.getBrightness(LightLayer.SKY, pos));
|
||||
}
|
||||
|
||||
|
@ -26,25 +26,21 @@ public class OrientedInstance extends ColoredLitInstance implements Rotate<Orien
|
||||
@Override
|
||||
public OrientedInstance rotate(Quaternionf quaternion) {
|
||||
rotation.mul(quaternion);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrientedInstance setRotation(Quaternionf q) {
|
||||
rotation.set(q);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrientedInstance setRotation(float x, float y, float z, float w) {
|
||||
rotation.set(x, y, z, w);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrientedInstance resetRotation() {
|
||||
rotation.identity();
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -52,7 +48,6 @@ public class OrientedInstance extends ColoredLitInstance implements Rotate<Orien
|
||||
pivotX = x;
|
||||
pivotY = y;
|
||||
pivotZ = z;
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -68,7 +63,6 @@ public class OrientedInstance extends ColoredLitInstance implements Rotate<Orien
|
||||
posX += x;
|
||||
posY += y;
|
||||
posZ += z;
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -76,7 +70,6 @@ public class OrientedInstance extends ColoredLitInstance implements Rotate<Orien
|
||||
posX = x;
|
||||
posY = y;
|
||||
posZ = z;
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -25,14 +25,12 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
|
||||
@Override
|
||||
public TransformedInstance mulPose(Matrix4f pose) {
|
||||
this.model.mul(pose);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformedInstance mulNormal(Matrix3f normal) {
|
||||
this.normal.mul(normal);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -53,7 +51,6 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
|
||||
float invZ = 1.0f / z;
|
||||
float f = Mth.fastInvCubeRoot(Math.abs(invX * invY * invZ));
|
||||
normal.scale(f * invX, f * invY, f * invZ);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -61,14 +58,12 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
|
||||
public TransformedInstance rotate(Quaternionf quaternion) {
|
||||
model.rotate(quaternion);
|
||||
normal.rotate(quaternion);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformedInstance translate(double x, double y, double z) {
|
||||
model.translate((float) x, (float) y, (float) z);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -77,7 +72,6 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
|
||||
.pose());
|
||||
this.normal.set(stack.last()
|
||||
.normal());
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -91,14 +85,12 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
|
||||
public TransformedInstance setEmptyTransform() {
|
||||
model.set(ZERO_MATRIX_4f);
|
||||
normal.set(ZERO_MATRIX_3f);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
public TransformedInstance loadIdentity() {
|
||||
model.identity();
|
||||
normal.identity();
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ public abstract class AbstractVisual implements Visual, LightListener {
|
||||
|
||||
/**
|
||||
* Called after initialization and when a light update occurs in the world.
|
||||
*
|
||||
* <br> If your instances need it, update light here.
|
||||
* <br>
|
||||
* If your instances need it, update light here.
|
||||
*/
|
||||
public void updateLight() {
|
||||
}
|
||||
@ -73,21 +73,25 @@ public abstract class AbstractVisual implements Visual, LightListener {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
protected void relight(BlockPos pos, FlatLit<?>... instances) {
|
||||
protected void relight(BlockPos pos, FlatLit... instances) {
|
||||
relight(level.getBrightness(LightLayer.BLOCK, pos), level.getBrightness(LightLayer.SKY, pos), instances);
|
||||
}
|
||||
|
||||
protected void relight(int block, int sky, FlatLit<?>... instances) {
|
||||
for (FlatLit<?> instance : instances) {
|
||||
protected void relight(int block, int sky, FlatLit... instances) {
|
||||
for (FlatLit instance : instances) {
|
||||
instance.setLight(block, sky);
|
||||
instance.handle()
|
||||
.setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected <L extends FlatLit<?>> void relight(BlockPos pos, Stream<L> instances) {
|
||||
protected void relight(BlockPos pos, Stream<? extends FlatLit> instances) {
|
||||
relight(level.getBrightness(LightLayer.BLOCK, pos), level.getBrightness(LightLayer.SKY, pos), instances);
|
||||
}
|
||||
|
||||
protected <L extends FlatLit<?>> void relight(int block, int sky, Stream<L> instances) {
|
||||
instances.forEach(model -> model.setLight(block, sky));
|
||||
protected void relight(int block, int sky, Stream<? extends FlatLit> instances) {
|
||||
instances.forEach(model -> model.setLight(block, sky)
|
||||
.handle()
|
||||
.setChanged());
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,8 @@ public class BellVisual extends AbstractBlockEntityVisual<BellBlockEntity> imple
|
||||
} else {
|
||||
bell.setRotation(new Quaternionf());
|
||||
}
|
||||
|
||||
bell.setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,7 +59,6 @@ public class ChestVisual<T extends BlockEntity & LidBlockEntity> extends Abstrac
|
||||
private TransformedInstance lock;
|
||||
|
||||
private ChestType chestType;
|
||||
private Material texture;
|
||||
private final Quaternionf baseRotation = new Quaternionf();
|
||||
private Float2FloatFunction lidProgress;
|
||||
|
||||
@ -72,11 +71,11 @@ public class ChestVisual<T extends BlockEntity & LidBlockEntity> extends Abstrac
|
||||
@Override
|
||||
public void init(float partialTick) {
|
||||
chestType = blockState.hasProperty(ChestBlock.TYPE) ? blockState.getValue(ChestBlock.TYPE) : ChestType.SINGLE;
|
||||
texture = Sheets.chooseMaterial(blockEntity, chestType, isChristmas());
|
||||
Material texture = Sheets.chooseMaterial(blockEntity, chestType, isChristmas());
|
||||
|
||||
bottom = createBottomInstance().setPosition(getVisualPosition());
|
||||
lid = createLidInstance();
|
||||
lock = createLockInstance();
|
||||
bottom = createBottomInstance(texture).setPosition(getVisualPosition());
|
||||
lid = createLidInstance(texture);
|
||||
lock = createLockInstance(texture);
|
||||
|
||||
Block block = blockState.getBlock();
|
||||
if (block instanceof AbstractChestBlock<?> chestBlock) {
|
||||
@ -97,17 +96,17 @@ public class ChestVisual<T extends BlockEntity & LidBlockEntity> extends Abstrac
|
||||
super.init(partialTick);
|
||||
}
|
||||
|
||||
private OrientedInstance createBottomInstance() {
|
||||
private OrientedInstance createBottomInstance(Material texture) {
|
||||
return instancerProvider.instancer(InstanceTypes.ORIENTED, BOTTOM_MODELS.get(Pair.of(chestType, texture)), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
private TransformedInstance createLidInstance() {
|
||||
private TransformedInstance createLidInstance(Material texture) {
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LID_MODELS.get(Pair.of(chestType, texture)), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
private TransformedInstance createLockInstance() {
|
||||
private TransformedInstance createLockInstance(Material texture) {
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LOCK_MODELS.get(Pair.of(chestType, texture)), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
.createInstance();
|
||||
}
|
||||
@ -143,14 +142,16 @@ public class ChestVisual<T extends BlockEntity & LidBlockEntity> extends Abstrac
|
||||
.rotateCentered(baseRotation)
|
||||
.translate(0, 9f / 16f, 1f / 16f)
|
||||
.rotateX(angleX)
|
||||
.translate(0, -9f / 16f, -1f / 16f);
|
||||
.translate(0, -9f / 16f, -1f / 16f)
|
||||
.setChanged();
|
||||
|
||||
lock.loadIdentity()
|
||||
.translate(getVisualPosition())
|
||||
.rotateCentered(baseRotation)
|
||||
.translate(0, 8f / 16f, 0)
|
||||
.rotateX(angleX)
|
||||
.translate(0, -8f / 16f, 0);
|
||||
.translate(0, -8f / 16f, 0)
|
||||
.setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,12 +163,14 @@ public class MinecartVisual<T extends AbstractMinecart> extends AbstractEntityVi
|
||||
stack.scale(0.75F, 0.75F, 0.75F);
|
||||
stack.translate(-0.5D, (float) (displayOffset - 8) / 16, 0.5D);
|
||||
stack.mulPose(Axis.YP.rotationDegrees(90));
|
||||
contents.setTransform(stack);
|
||||
contents.setTransform(stack)
|
||||
.setChanged();
|
||||
stack.popPose();
|
||||
}
|
||||
|
||||
stack.scale(-1.0F, -1.0F, 1.0F);
|
||||
body.setTransform(stack);
|
||||
body.setTransform(stack)
|
||||
.setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +39,6 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
|
||||
private TransformedInstance base;
|
||||
private TransformedInstance lid;
|
||||
|
||||
private Material texture;
|
||||
private final PoseStack stack = new PoseStack();
|
||||
|
||||
private float lastProgress = Float.NaN;
|
||||
@ -51,6 +50,7 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
|
||||
@Override
|
||||
public void init(float partialTick) {
|
||||
DyeColor color = blockEntity.getColor();
|
||||
Material texture;
|
||||
if (color == null) {
|
||||
texture = Sheets.DEFAULT_SHULKER_TEXTURE_LOCATION;
|
||||
} else {
|
||||
@ -59,26 +59,27 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
|
||||
|
||||
var rotation = getDirection().getRotation();
|
||||
|
||||
TransformStack tstack = TransformStack.of(stack);
|
||||
tstack.translate(getVisualPosition())
|
||||
stack.setIdentity();
|
||||
TransformStack.of(stack)
|
||||
.translate(getVisualPosition())
|
||||
.translate(0.5)
|
||||
.scale(0.9995f)
|
||||
.rotate(rotation)
|
||||
.scale(1, -1, -1)
|
||||
.translateY(-1);
|
||||
|
||||
base = createBaseInstance().setTransform(stack);
|
||||
lid = createLidInstance().setTransform(stack);
|
||||
base = createBaseInstance(texture).setTransform(stack);
|
||||
lid = createLidInstance(texture).setTransform(stack);
|
||||
|
||||
super.init(partialTick);
|
||||
}
|
||||
|
||||
private TransformedInstance createBaseInstance() {
|
||||
private TransformedInstance createBaseInstance(Material texture) {
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, BASE_MODELS.get(texture), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
private TransformedInstance createLidInstance() {
|
||||
private TransformedInstance createLidInstance(Material texture) {
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LID_MODELS.get(texture), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
.createInstance();
|
||||
}
|
||||
@ -110,7 +111,8 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
|
||||
.translateY(-progress * 0.5f)
|
||||
.rotate(spin);
|
||||
|
||||
lid.setTransform(stack);
|
||||
lid.setTransform(stack)
|
||||
.setChanged();
|
||||
|
||||
stack.popPose();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user