update license
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package com.straice.smoothdoors;
|
||||
|
||||
import com.straice.smoothdoors.client.anim.SddAnimator;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
public class SmoothDoubleDoorsClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
// No-op: hooks handled by mixins/events
|
||||
SddAnimator.initClientHooks();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.straice.smoothdoors.client.anim;
|
||||
import com.straice.smoothdoors.config.SddConfig;
|
||||
import com.straice.smoothdoors.config.SddConfigManager;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.enums.BlockHalf;
|
||||
import net.minecraft.block.enums.DoorHinge;
|
||||
@@ -13,6 +14,7 @@ import net.minecraft.client.render.WorldRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.util.math.RotationAxis;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
|
||||
public final class SddAnimator {
|
||||
@@ -24,16 +26,31 @@ public final class SddAnimator {
|
||||
|
||||
private static final Long2ObjectOpenHashMap<Anim> ANIMS = new Long2ObjectOpenHashMap<>();
|
||||
|
||||
private static boolean hooksInit = false;
|
||||
private static long lastNs = 0L;
|
||||
|
||||
private SddAnimator() {}
|
||||
|
||||
// === API que te piden los mixins ===
|
||||
// === Hook de render (NO mixin a WorldRenderer) ===
|
||||
public static void initClientHooks() {
|
||||
if (hooksInit) return;
|
||||
hooksInit = true;
|
||||
|
||||
WorldRenderEvents.LAST.register(ctx -> {
|
||||
if (MC.world == null) return;
|
||||
Vec3d camPos = ctx.camera().getPos();
|
||||
renderAll(camPos);
|
||||
});
|
||||
}
|
||||
|
||||
// === API usada por mixins ===
|
||||
|
||||
/** Se usa en BlockRenderManagerMixin para ocultar el bloque vanilla mientras animamos. */
|
||||
public static boolean shouldHideInChunk(BlockPos pos, BlockState state) {
|
||||
return ANIMS.containsKey(pos.asLong());
|
||||
}
|
||||
|
||||
/** Se usa para arrancar/parar animaciones cuando cambia un bloque. */
|
||||
/** Se usa en ClientWorldMixin para arrancar/parar animaciones al cambiar OPEN. */
|
||||
public static void onBlockUpdate(BlockPos pos, BlockState oldState, BlockState newState) {
|
||||
Kind kind = kindOf(oldState, newState);
|
||||
if (kind == null) {
|
||||
@@ -54,18 +71,20 @@ public final class SddAnimator {
|
||||
float speed = speedFor(cfg, kind);
|
||||
if (speed <= 0.001f) speed = 1.0f;
|
||||
|
||||
// Renderizamos SIEMPRE el modelo "cerrado" y nosotros aplicamos la rotación.
|
||||
// Renderizamos SIEMPRE el modelo "cerrado" y aplicamos rotación nosotros.
|
||||
BlockState base = forceClosedModel(newState, kind);
|
||||
|
||||
Anim anim = new Anim(pos.toImmutable(), base, kind, oldOpen, newOpen, speed);
|
||||
ANIMS.put(pos.asLong(), anim);
|
||||
}
|
||||
|
||||
/** Render con tickDelta explícito. */
|
||||
public static void renderAll(Vec3d camPos, float tickDelta) {
|
||||
// === Render ===
|
||||
|
||||
/** Render por frame (se llama desde WorldRenderEvents). */
|
||||
public static void renderAll(Vec3d camPos) {
|
||||
if (ANIMS.isEmpty() || MC.world == null) return;
|
||||
|
||||
tick(tickDelta);
|
||||
tickByTime();
|
||||
|
||||
VertexConsumerProvider.Immediate consumers = MC.getBufferBuilders().getEntityVertexConsumers();
|
||||
MatrixStack matrices = new MatrixStack();
|
||||
@@ -74,24 +93,20 @@ public final class SddAnimator {
|
||||
renderOne(a, camPos, matrices, consumers);
|
||||
}
|
||||
|
||||
consumers.draw();
|
||||
consumers.draw(); // flush
|
||||
cleanupFinished();
|
||||
}
|
||||
|
||||
/** Overload por compat si algún sitio llama sin tickDelta. */
|
||||
public static void renderAll(Vec3d camPos) {
|
||||
float tickDelta = 0.0f;
|
||||
if (MC != null) {
|
||||
// En 1.21.x normalmente es esto:
|
||||
tickDelta = MC.getRenderTickCounter().getTickProgress(true);
|
||||
}
|
||||
renderAll(camPos, tickDelta);
|
||||
}
|
||||
|
||||
// === Interno ===
|
||||
|
||||
private static void tick(float tickDelta) {
|
||||
float dt = (1.0f / 20.0f) * MathHelper.clamp(tickDelta, 0.0f, 1.0f);
|
||||
private static void tickByTime() {
|
||||
long now = System.nanoTime();
|
||||
if (lastNs == 0L) lastNs = now;
|
||||
float dt = (now - lastNs) / 1_000_000_000.0f;
|
||||
lastNs = now;
|
||||
|
||||
// cap por si hay alt-tab / lag
|
||||
dt = MathHelper.clamp(dt, 0.0f, 0.10f);
|
||||
|
||||
for (Anim a : ANIMS.values()) {
|
||||
float duration = BASE_DURATION_S / a.speed;
|
||||
@@ -113,6 +128,8 @@ public final class SddAnimator {
|
||||
BlockState state = anim.baseState;
|
||||
|
||||
matrices.push();
|
||||
|
||||
// Fijo al bloque (no “pegado” a la cámara): worldPos - camPos
|
||||
matrices.translate(
|
||||
pos.getX() - camPos.x,
|
||||
pos.getY() - camPos.y,
|
||||
@@ -182,11 +199,13 @@ public final class SddAnimator {
|
||||
float pivotZ = facing.getOffsetZ() == 1 ? 1.0f : (facing.getOffsetZ() == -1 ? 0.0f : 0.5f);
|
||||
|
||||
matrices.translate(pivotX, 0.5f, pivotZ);
|
||||
|
||||
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
|
||||
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(angleDeg));
|
||||
} else {
|
||||
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-angleDeg));
|
||||
}
|
||||
|
||||
matrices.translate(-pivotX, -0.5f, -pivotZ);
|
||||
}
|
||||
|
||||
@@ -230,7 +249,7 @@ public final class SddAnimator {
|
||||
return switch (kind) {
|
||||
case DOOR -> cfg.animateDoors;
|
||||
case TRAPDOOR -> cfg.animateTrapdoors;
|
||||
case FENCE_GATE -> cfg.animateFenceGates; // debe existir en tu config
|
||||
case FENCE_GATE -> cfg.animateFenceGates;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -238,7 +257,7 @@ public final class SddAnimator {
|
||||
return switch (kind) {
|
||||
case DOOR -> cfg.doorSpeed;
|
||||
case TRAPDOOR -> cfg.trapdoorSpeed;
|
||||
case FENCE_GATE -> cfg.fenceGateSpeed; // debe existir en tu config
|
||||
case FENCE_GATE -> cfg.fenceGateSpeed;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,21 +2,18 @@ package com.straice.smoothdoors.mixin.client;
|
||||
|
||||
import com.straice.smoothdoors.client.anim.SddAnimator;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(World.class)
|
||||
public class WorldMixin {
|
||||
@Mixin(ClientWorld.class)
|
||||
public class ClientWorldMixin {
|
||||
|
||||
@Inject(
|
||||
method = "scheduleBlockRerenderIfNeeded(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;)V",
|
||||
at = @At("HEAD")
|
||||
)
|
||||
private void sdd$onRerender(BlockPos pos, BlockState oldState, BlockState newState, CallbackInfo ci) {
|
||||
@Inject(method = "updateListeners", at = @At("TAIL"))
|
||||
private void sdd$updateListeners(BlockPos pos, BlockState oldState, BlockState newState, int flags, CallbackInfo ci) {
|
||||
SddAnimator.onBlockUpdate(pos, oldState, newState);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user