diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/crafting/AltarRecipe.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/crafting/AltarRecipe.java index d8293a4e2..8540920a6 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/crafting/AltarRecipe.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/crafting/AltarRecipe.java @@ -162,11 +162,11 @@ private void copyIngredientTag(@Nullable AltarRecipeInventory inventory, Entity data = matchStack.getTagElement(this.copyTag); } if (data != null && !data.isEmpty()) { - if (resultEntity instanceof LivingEntity) { - ((LivingEntity) resultEntity).readAdditionalSaveData(data); + if (resultEntity instanceof LivingEntity livingEntity) { + livingEntity.readAdditionalSaveData(data); } - if (resultEntity instanceof ItemEntity) { - ((ItemEntity) resultEntity).readAdditionalSaveData(data); + if (resultEntity instanceof ItemEntity itemEntity) { + itemEntity.readAdditionalSaveData(data); } } } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/item/ItemFilm.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/item/ItemFilm.java index 03543d8d8..b6b458366 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/item/ItemFilm.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/item/ItemFilm.java @@ -10,9 +10,8 @@ import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundSource; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -23,11 +22,12 @@ import javax.annotation.Nullable; import java.util.List; import java.util.Objects; -import java.util.Optional; import static com.github.tartaricacid.touhoulittlemaid.item.MaidGroup.MAIN_TAB; public class ItemFilm extends AbstractStoreMaidItem { + private static final String ID_TAG = "id"; + public ItemFilm() { super((new Item.Properties()).tab(MAIN_TAB).stacksTo(1)); } @@ -39,15 +39,20 @@ public static ItemStack maidToFilm(EntityMaid maid) { maid.setHomeModeEnable(false); maid.saveWithoutId(maidTag); removeMaidSomeData(maidTag); - maidTag.putString("id", Objects.requireNonNull(ForgeRegistries.ENTITY_TYPES.getKey(InitEntities.MAID.get())).toString()); + maidTag.putString(ID_TAG, Objects.requireNonNull(ForgeRegistries.ENTITY_TYPES.getKey(InitEntities.MAID.get())).toString()); filmTag.put(MAID_INFO, maidTag); film.setTag(filmTag); return film; } public static void filmToMaid(ItemStack film, Level worldIn, BlockPos pos, Player player) { - Optional entityOptional = EntityType.create(getMaidData(film), worldIn); - if (entityOptional.isPresent() && entityOptional.get() instanceof EntityMaid maid) { + CompoundTag data = getMaidData(film); + ResourceLocation entityId = new ResourceLocation(data.getString(ID_TAG)); + ResourceLocation maidId = ForgeRegistries.ENTITY_TYPES.getKey(InitEntities.MAID.get()); + + if (entityId.equals(maidId)) { + EntityMaid maid = new EntityMaid(worldIn); + maid.readAdditionalSaveData(data); maid.setPos(pos.getX(), pos.getY(), pos.getZ()); // 实体生成必须在服务端应用 if (!worldIn.isClientSide) { @@ -56,7 +61,9 @@ public static void filmToMaid(ItemStack film, Level worldIn, BlockPos pos, Playe worldIn.playSound(null, pos, InitSounds.ALTAR_CRAFT.get(), SoundSource.VOICE, 1.0f, 1.0f); } film.shrink(1); + return; } + if (!worldIn.isClientSide) { player.sendSystemMessage(Component.translatable("tooltips.touhou_little_maid.film.no_data.desc")); } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/util/IconCache.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/util/IconCache.java index 29db8a87c..85d57de26 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/util/IconCache.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/util/IconCache.java @@ -1,17 +1,8 @@ package com.github.tartaricacid.touhoulittlemaid.util; -import com.mojang.blaze3d.platform.Lighting; import com.mojang.blaze3d.platform.NativeImage; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; import net.minecraft.client.Screenshot; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.block.model.ItemTransforms; -import net.minecraft.client.renderer.texture.OverlayTexture; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.world.item.ItemStack; -//import org.joml.Matrix4f; import org.lwjgl.system.MemoryUtil; /** @@ -60,37 +51,4 @@ private static NativeImage getSubImage(NativeImage image, int width, int height) } return imageSub; } - -// private static void renderGuiItem(PoseStack poseStack, ItemStack stack, int x, int y, float scale) { -// BakedModel bakedModel = Minecraft.getInstance().getItemRenderer().getModel(stack, null, null, 0); -// -// poseStack.pushPose(); -// poseStack.scale(scale / 16, scale / 16, 1); -// poseStack.translate((float) x, (float) y, 100.0F); -// poseStack.translate(8.0F, 8.0F, 0.0F); -// poseStack.mulPoseMatrix((new Matrix4f()).scaling(1.0F, -1.0F, 1.0F)); -// poseStack.scale(16.0F, 16.0F, 16.0F); -// MultiBufferSource.BufferSource bufferSource = Minecraft.getInstance().renderBuffers().bufferSource(); -// -// boolean useBlockLight = !bakedModel.usesBlockLight(); -// if (useBlockLight) { -// Lighting.setupForFlatItems(); -// } -// -// PoseStack viewStack = RenderSystem.getModelViewStack(); -// viewStack.pushPose(); -// viewStack.mulPoseMatrix(poseStack.last().pose()); -// RenderSystem.applyModelViewMatrix(); -// Minecraft.getInstance().getItemRenderer().render(stack, ItemTransforms.TransformType.GUI, false, new PoseStack(), bufferSource, 0xf000f0, OverlayTexture.NO_OVERLAY, bakedModel); -// bufferSource.endBatch(); -// RenderSystem.enableDepthTest(); -// -// if (useBlockLight) { -// Lighting.setupFor3DItems(); -// } -// -// poseStack.popPose(); -// viewStack.popPose(); -// RenderSystem.applyModelViewMatrix(); -// } }