fix some villager and rendering jank

This commit is contained in:
yrsegal@gmail.com 2022-06-09 17:01:47 -04:00
parent b743c8e7a2
commit b0bdbb7d76
13 changed files with 43 additions and 31 deletions

View file

@ -1,7 +1,6 @@
package at.petrak.hexcasting.api.misc; package at.petrak.hexcasting.api.misc;
import at.petrak.hexcasting.api.addldata.Colorizer; import at.petrak.hexcasting.api.addldata.Colorizer;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.common.items.colorizer.ItemPrideColorizer; import at.petrak.hexcasting.common.items.colorizer.ItemPrideColorizer;
import at.petrak.hexcasting.common.lib.HexItems; import at.petrak.hexcasting.common.lib.HexItems;
import at.petrak.hexcasting.xplat.IXplatAbstractions; import at.petrak.hexcasting.xplat.IXplatAbstractions;
@ -45,7 +44,7 @@ public record FrozenColorizer(ItemStack item, UUID owner) {
public CompoundTag serializeToNBT() { public CompoundTag serializeToNBT() {
var out = new CompoundTag(); var out = new CompoundTag();
out.put(TAG_STACK, HexUtils.serializeToNBT(this.item)); out.put(TAG_STACK, this.item.save(new CompoundTag()));
out.putUUID(TAG_OWNER, this.owner); out.putUUID(TAG_OWNER, this.owner);
return out; return out;
} }

View file

@ -1,28 +1,23 @@
package at.petrak.hexcasting.client; package at.petrak.hexcasting.client;
import net.minecraft.client.Minecraft;
public class ClientTickCounter { public class ClientTickCounter {
public static long ticksInGame = 0L; public static long ticksInGame = 0L;
public static float partialTicks = 0.0F; public static float partialTicks = 0.0F;
public static float delta = 0.0F;
public static float total = 0.0F; public static float getTotal() {
return (float)ticksInGame + partialTicks;
}
public static void renderTickStart(float renderTickTime) { public static void renderTickStart(float renderTickTime) {
partialTicks = renderTickTime; partialTicks = renderTickTime;
} }
public static void renderTickEnd() {
calcDelta();
}
public static void clientTickEnd() { public static void clientTickEnd() {
if (!Minecraft.getInstance().isPaused()) {
++ticksInGame; ++ticksInGame;
partialTicks = 0.0F; partialTicks = 0.0F;
calcDelta();
} }
private static void calcDelta() {
float oldTotal = total;
total = (float)ticksInGame + partialTicks;
delta = total - oldTotal;
} }
} }

View file

@ -60,7 +60,7 @@ public class HexAdditionalRenderers {
sentinel.position().y - playerPos.y, sentinel.position().y - playerPos.y,
sentinel.position().z - playerPos.z); sentinel.position().z - playerPos.z);
var time = ClientTickCounter.total / 2; var time = ClientTickCounter.getTotal() / 2;
var bobSpeed = 1f / 20; var bobSpeed = 1f / 20;
var magnitude = 0.1f; var magnitude = 0.1f;
ps.translate(0, Mth.sin(bobSpeed * time) * magnitude, 0); ps.translate(0, Mth.sin(bobSpeed * time) * magnitude, 0);

View file

@ -185,7 +185,7 @@ fun makeZappy(points: List<Vec2>, hops: Int, variance: Float, speed: Float, flow
return emptyList() return emptyList()
} }
val scaleVariance = { it: Double -> 1.0.coerceAtMost(8 * (0.5 - abs(0.5 - it))) } val scaleVariance = { it: Double -> 1.0.coerceAtMost(8 * (0.5 - abs(0.5 - it))) }
val zSeed = ClientTickCounter.total.toDouble() * speed val zSeed = ClientTickCounter.getTotal().toDouble() * speed
// Create our output list of zap points // Create our output list of zap points
val zappyPts = mutableListOf(points[0]) val zappyPts = mutableListOf(points[0])
// For each segment in the original... // For each segment in the original...

View file

@ -77,7 +77,7 @@ public class PatternTooltipGreeble implements ClientTooltipComponent, TooltipCom
outer, outer, null); outer, outer, null);
RenderLib.drawLineSeq(mat, this.zappyPoints, 2f, 0, RenderLib.drawLineSeq(mat, this.zappyPoints, 2f, 0,
innerDark, innerLight, innerDark, innerLight,
ClientTickCounter.total / 40f); ClientTickCounter.getTotal() / 40f);
RenderLib.drawSpot(mat, this.zappyPoints.get(0), 2.5f, 1f, 0.1f, 0.15f, 0.6f); RenderLib.drawSpot(mat, this.zappyPoints.get(0), 2.5f, 1f, 0.1f, 0.15f, 0.6f);
for (var dot : this.pathfinderDots) { for (var dot : this.pathfinderDots) {

View file

@ -31,7 +31,6 @@ object FabricHexClientInitializer : ClientModInitializer {
} }
HudRenderCallback.EVENT.register(HexAdditionalRenderers::overlayGui) HudRenderCallback.EVENT.register(HexAdditionalRenderers::overlayGui)
WorldRenderEvents.START.register { ClientTickCounter.renderTickStart(it.tickDelta()) } WorldRenderEvents.START.register { ClientTickCounter.renderTickStart(it.tickDelta()) }
WorldRenderEvents.END.register { ClientTickCounter.renderTickEnd() }
ClientTickEvents.END_CLIENT_TICK.register { ClientTickCounter.clientTickEnd() } ClientTickEvents.END_CLIENT_TICK.register { ClientTickCounter.clientTickEnd() }
MouseScrollCallback.EVENT.register(ShiftScrollListener::onScroll) MouseScrollCallback.EVENT.register(ShiftScrollListener::onScroll)

View file

@ -3,7 +3,6 @@ package at.petrak.hexcasting.fabric.event;
import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory; import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.npc.Villager;
// https://fabricmc.net/wiki/tutorial:events // https://fabricmc.net/wiki/tutorial:events
@ -20,5 +19,5 @@ public interface VillagerConversionCallback {
} }
}); });
void interact(Villager original, LivingEntity outcome); void interact(LivingEntity original, LivingEntity outcome);
} }

View file

@ -164,7 +164,7 @@ public class VillagerEmiStack extends EmiStack {
RenderSystem.enableBlend(); RenderSystem.enableBlend();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
renderEntity(poseStack, villager, level, x + 8, y + 16, ClientTickCounter.total, 8, 0, renderEntity(poseStack, villager, level, x + 8, y + 16, ClientTickCounter.getTotal(), 8, 0,
mindless ? (it) -> new FakeBufferSource(it, HexRenderTypes::getGrayscaleLayer) : it -> it); mindless ? (it) -> new FakeBufferSource(it, HexRenderTypes::getGrayscaleLayer) : it -> it);
} }
} }

View file

@ -38,7 +38,7 @@ public class VillagerWidget extends Widget {
RenderSystem.enableBlend(); RenderSystem.enableBlend();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
renderEntity(poseStack, displayVillager, level, 50 + x, 62.5f + y, ClientTickCounter.total, 20, 0); renderEntity(poseStack, displayVillager, level, 50 + x, 62.5f + y, ClientTickCounter.getTotal(), 20, 0);
} }
if (isMouseOver(mouseX, mouseY)) if (isMouseOver(mouseX, mouseY))

View file

@ -0,0 +1,21 @@
package at.petrak.hexcasting.fabric.mixin;
import at.petrak.hexcasting.fabric.event.VillagerConversionCallback;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
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.CallbackInfoReturnable;
@Mixin(Mob.class)
public class FabricMobMixin {
@Inject(method = "convertTo", at = @At("RETURN"))
public <T extends Mob> void onThunderHit(EntityType<T> entityType, boolean bl, CallbackInfoReturnable<T> cir) {
var self = (Mob) (Object) this;
var mob = cir.getReturnValue();
if (mob != null) {
VillagerConversionCallback.EVENT.invoker().interact(self, mob);
}
}
}

View file

@ -10,12 +10,13 @@
"FabricEnchantmentTableBlockMixin", "FabricEnchantmentTableBlockMixin",
"FabricItemEntityMixin", "FabricItemEntityMixin",
"FabricLivingEntityMixin", "FabricLivingEntityMixin",
"FabricVillagerTurnIntoWitchMixin" "FabricVillagerTurnIntoWitchMixin",
"FabricMobMixin"
], ],
"client": [ "client": [
"client.FabricAbstractTextureMixin", "client.FabricAbstractTextureMixin",
"client.FabricMixinGameRenderer",
"client.FabricMouseHandlerMixin", "client.FabricMouseHandlerMixin",
"client.FabricParticleEngineMixin", "client.FabricParticleEngineMixin"
"client.FabricMixinGameRenderer"
] ]
} }

View file

@ -34,8 +34,6 @@ public class ForgeHexClientInitializer {
evBus.addListener((TickEvent.RenderTickEvent e) -> { evBus.addListener((TickEvent.RenderTickEvent e) -> {
if (e.phase == TickEvent.Phase.START) { if (e.phase == TickEvent.Phase.START) {
ClientTickCounter.renderTickStart(e.renderTickTime); ClientTickCounter.renderTickStart(e.renderTickTime);
} else {
ClientTickCounter.renderTickEnd();
} }
}); });

View file

@ -82,7 +82,7 @@ public class BrainsweepRecipeCategory implements IRecipeCategory<BrainsweepRecip
RenderSystem.enableBlend(); RenderSystem.enableBlend();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
renderEntity(stack, villager, level, 50, 62.5f, ClientTickCounter.total, 20, 0); renderEntity(stack, villager, level, 50, 62.5f, ClientTickCounter.getTotal(), 20, 0);
} }
} }