Skip to content

Commit

Permalink
修改神龛的复活方式,避免 mek 之类模组辐射导致女仆频繁死亡的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Sep 5, 2024
1 parent 7ab193e commit 9b27e8e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
Expand All @@ -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<Entity> 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) {
Expand All @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -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();
// }
}

0 comments on commit 9b27e8e

Please sign in to comment.