From fbbb74ec2f66b80ad8442bd8fb85bbec256b6d40 Mon Sep 17 00:00:00 2001 From: tartaric_acid Date: Fri, 6 Sep 2024 12:39:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=93=E5=AD=98=E6=9C=BA?= =?UTF-8?q?=E5=88=B6=EF=BC=8C=E5=8A=A0=E5=BF=AB=E7=BC=93=E5=AD=98=E9=80=9F?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/entity/cache/CacheIconManager.java | 12 +++--- .../client/gui/entity/cache/CacheScreen.java | 41 +++++++++++++++---- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/gui/entity/cache/CacheIconManager.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/gui/entity/cache/CacheIconManager.java index 603aea568..0c0e886c8 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/gui/entity/cache/CacheIconManager.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/gui/entity/cache/CacheIconManager.java @@ -12,8 +12,8 @@ import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid; import com.github.tartaricacid.touhoulittlemaid.init.InitEntities; import com.github.tartaricacid.touhoulittlemaid.tileentity.TileEntityModelSwitcher; +import com.github.tartaricacid.touhoulittlemaid.util.RenderHelper; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.inventory.InventoryScreen; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -71,7 +71,7 @@ public static void openModelSwitcherModelGui(EntityMaid maid, TileEntityModelSwi } private static CacheScreen getMaidCacheScreen(AbstractModelGui maidModelGui) { - return new CacheScreen<>(maidModelGui, InitEntities.MAID.get(), MAID_CACHE_QUEUE, (graphics, posX, posY, modelInfo, scaleModified, maid) -> { + return new CacheScreen<>(maidModelGui, InitEntities.MAID.get(), MAID_CACHE_QUEUE, (graphics, posX, posY, posZ, modelInfo, scaleModified, maid) -> { clearMaidDataResidue(maid, false); if (modelInfo.getEasterEgg() != null) { maid.setModelId(EASTER_EGG_MODEL); @@ -79,21 +79,23 @@ private static CacheScreen getMaidCacheScreen(Abstrac maid.setModelId(modelInfo.getModelId().toString()); } int scale = scaleModified / 2; - InventoryScreen.renderEntityInInventory( + RenderHelper.renderEntityInInventory( posX + scale, posY + scaleModified - 5, + posZ, (int) (scale * modelInfo.getRenderItemScale() * 0.9), -25, -20, maid); }); } private static CacheScreen getChairCacheScreen(ChairModelGui chairModelGui) { - return new CacheScreen<>(chairModelGui, InitEntities.CHAIR.get(), CHAIR_CACHE_QUEUE, (graphics, posX, posY, modelInfo, scaleModified, chair) -> { + return new CacheScreen<>(chairModelGui, InitEntities.CHAIR.get(), CHAIR_CACHE_QUEUE, (graphics, posX, posY, posZ, modelInfo, scaleModified, chair) -> { chair.setModelId(modelInfo.getModelId().toString()); int scale = scaleModified / 2; - InventoryScreen.renderEntityInInventory( + RenderHelper.renderEntityInInventory( posX + scale, posY + scaleModified - 5, + posZ, (int) (scale * modelInfo.getRenderItemScale() * 0.9), -25, -20, chair); }); diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/gui/entity/cache/CacheScreen.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/gui/entity/cache/CacheScreen.java index 0896e0cc6..d08aa0e89 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/gui/entity/cache/CacheScreen.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/gui/entity/cache/CacheScreen.java @@ -1,5 +1,6 @@ package com.github.tartaricacid.touhoulittlemaid.client.gui.entity.cache; +import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid; import com.github.tartaricacid.touhoulittlemaid.client.renderer.texture.CacheIconTexture; import com.github.tartaricacid.touhoulittlemaid.client.resource.pojo.IModelInfo; import com.github.tartaricacid.touhoulittlemaid.util.EntityCacheUtil; @@ -16,9 +17,11 @@ import net.minecraft.world.level.Level; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import org.apache.commons.lang3.time.StopWatch; import java.util.Queue; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; @OnlyIn(Dist.CLIENT) @@ -28,18 +31,20 @@ public class CacheScreen extends S private final Queue modelInfos; private final EntityRender entityRender; private final int totalCount; + private final StopWatch stopWatch; public CacheScreen(Screen parent, EntityType entityType, Queue modelInfos, EntityRender entityRender) { - super(new TextComponent(" Cache Screen")); + super(new TextComponent("Cache Screen")); this.parent = parent; this.entityType = entityType; this.modelInfos = modelInfos; this.entityRender = entityRender; this.totalCount = modelInfos.size(); + this.stopWatch = StopWatch.createStarted(); } @SuppressWarnings("unchecked") - private void drawEntity(PoseStack poseStack, int posX, int posY, E modelInfo, int scaleModified) { + private void drawEntity(PoseStack pPoseStack, int posX, int posY, int posZ, E modelInfo, int scaleModified) { Level world = getMinecraft().level; if (world == null) { return; @@ -51,7 +56,7 @@ private void drawEntity(PoseStack poseStack, int posX, int posY, E modelInfo, in e.fillInStackTrace(); return; } - entityRender.render(poseStack, posX, posY, modelInfo, scaleModified, entity); + entityRender.render(pPoseStack, posX, posY, posZ, modelInfo, scaleModified, entity); } @Override @@ -60,30 +65,48 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTic super.render(poseStack, mouseX, mouseY, partialTick); if (modelInfos.isEmpty()) { + stopWatch.stop(); + double timeCost = stopWatch.getTime(TimeUnit.MILLISECONDS) / 1000.0; + TouhouLittleMaid.LOGGER.info("Cache icon time: {} seconds", timeCost); Minecraft.getInstance().setScreen(parent); return; } + // 每帧尝试缓存 5 个 + poseStack.pushPose(); + int posZ = 0; + for (int i = 0; i < 5; i++) { + if (modelInfos.isEmpty()) { + return; + } + posZ += 100; + poseStack.translate(0, 0, 100); + doCacheIcon(poseStack, posZ); + } + poseStack.popPose(); + + int finishSize = totalCount - modelInfos.size(); + drawCenteredString(poseStack, font, new TranslatableComponent("gui.touhou_little_maid.cache_screen.progress", finishSize, totalCount), this.width / 2, this.height - 42, 0xFFFFFF); + drawCenteredString(poseStack, font, new TranslatableComponent("gui.touhou_little_maid.cache_screen.desc"), this.width / 2, this.height - 30, 0xFFFFFF); + } + + private void doCacheIcon(PoseStack poseStack, int posZ) { E modelInfo = modelInfos.poll(); if (modelInfo != null) { double guiScale = Minecraft.getInstance().getWindow().getGuiScale(); int scaleModified = (int) Math.ceil((256 / guiScale)); fill(poseStack, 0, 0, scaleModified, scaleModified + 2, IconCache.BACKGROUND_COLOR); - this.drawEntity(poseStack, 0, 0, modelInfo, scaleModified); + this.drawEntity(poseStack, 0, 0, posZ, modelInfo, scaleModified); NativeImage nativeImage = IconCache.exportImageFromScreenshot(256, IconCache.BACKGROUND_COLOR_SHIFTED); ResourceLocation modelId = modelInfo.getModelId(); CacheIconTexture cacheIconTexture = new CacheIconTexture(modelId, nativeImage); Minecraft.getInstance().textureManager.register(modelInfo.getCacheIconId(), cacheIconTexture); } - - int finishSize = totalCount - modelInfos.size(); - drawCenteredString(poseStack, font, new TranslatableComponent("gui.touhou_little_maid.cache_screen.progress", finishSize, totalCount), this.width / 2, this.height - 42, 0xFFFFFF); - drawCenteredString(poseStack, font, new TranslatableComponent("gui.touhou_little_maid.cache_screen.desc"), this.width / 2, this.height - 30, 0xFFFFFF); } public interface EntityRender { - void render(PoseStack poseStack, int posX, int posY, E modelInfo, int scaleModified, T entity); + void render(PoseStack pPoseStack, int posX, int posY, int posZ, E modelInfo, int scaleModified, T entity); } }