diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/event/CopyEntityIdEvent.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/event/CopyEntityIdEvent.java new file mode 100644 index 000000000..536b1b9a3 --- /dev/null +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/event/CopyEntityIdEvent.java @@ -0,0 +1,44 @@ +package com.github.tartaricacid.touhoulittlemaid.event; + +import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid; +import com.github.tartaricacid.touhoulittlemaid.init.InitItems; +import net.minecraft.Util; +import net.minecraft.client.Minecraft; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.loading.FMLEnvironment; +import net.minecraftforge.registries.ForgeRegistries; + +@Mod.EventBusSubscriber(modid = TouhouLittleMaid.MOD_ID) +public final class CopyEntityIdEvent { + @SubscribeEvent + public static void copyEntityId(PlayerInteractEvent.EntityInteract event) { + Player player = event.getPlayer(); + InteractionHand hand = event.getHand(); + Entity target = event.getTarget(); + if (player.getItemInHand(hand).is(InitItems.ENTITY_ID_COPY.get())) { + if (player.level.isClientSide && FMLEnvironment.dist == Dist.CLIENT) { + copyEntityId(player, target); + } + event.setCanceled(true); + } + } + + @OnlyIn(Dist.CLIENT) + private static void copyEntityId(Player player, Entity target) { + ResourceLocation key = ForgeRegistries.ENTITIES.getKey(target.getType()); + if (key == null) { + return; + } + Minecraft.getInstance().keyboardHandler.setClipboard(key.toString()); + player.sendMessage(new TranslatableComponent("message.touhou_little_maid.entity_id_copy.copy", key.toString()), Util.NIL_UUID); + } +} diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/init/InitCreativeTabs.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/init/InitCreativeTabs.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/init/InitItems.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/init/InitItems.java index aaea44af0..58f277229 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/init/InitItems.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/init/InitItems.java @@ -71,6 +71,8 @@ public final class InitItems { public static RegistryObject PICNIC_BASKET = ITEMS.register("picnic_basket", () -> new ItemPicnicBasket(InitBlocks.PICNIC_MAT.get())); public static RegistryObject SCARECROW = ITEMS.register("scarecrow", () -> new BlockItem(InitBlocks.SCARECROW.get(), new Item.Properties().tab(MAIN_TAB))); public static RegistryObject SERVANT_BELL = ITEMS.register("servant_bell", ItemServantBell::new); + public static RegistryObject ENTITY_ID_COPY = ITEMS.register("entity_id_copy", ItemEntityIdCopy::new); + @SuppressWarnings("deprecation") public static RegistryObject MONSTER_LIST = ITEMS.register("monster_list", ItemMonsterList::new); public static RegistryObject MAID_SPAWN_EGG = ITEMS.register("maid_spawn_egg", () -> new ForgeSpawnEggItem(() -> EntityMaid.TYPE, 0x4a6195, 0xffffff, new Item.Properties())); diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/item/ItemEntityIdCopy.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/item/ItemEntityIdCopy.java new file mode 100644 index 000000000..41ff7941d --- /dev/null +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/item/ItemEntityIdCopy.java @@ -0,0 +1,25 @@ +package com.github.tartaricacid.touhoulittlemaid.item; + +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +import static com.github.tartaricacid.touhoulittlemaid.item.MaidGroup.MAIN_TAB; + +public class ItemEntityIdCopy extends Item { + public ItemEntityIdCopy() { + super(new Item.Properties().stacksTo(1).tab(MAIN_TAB)); + } + + @Override + public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List components, TooltipFlag pIsAdvanced) { + components.add(new TranslatableComponent("tooltips.touhou_little_maid.entity_id_copy.desc").withStyle(ChatFormatting.GRAY)); + } +} diff --git a/src/main/resources/assets/touhou_little_maid/lang/en_us.json b/src/main/resources/assets/touhou_little_maid/lang/en_us.json index b061c608e..55d6201fb 100644 --- a/src/main/resources/assets/touhou_little_maid/lang/en_us.json +++ b/src/main/resources/assets/touhou_little_maid/lang/en_us.json @@ -167,6 +167,7 @@ "item.touhou_little_maid.servant_bell": "Servant Bell", "item.touhou_little_maid.monster_list": "Monster List (Removed)", "item.touhou_little_maid.advancement_icon": "Advancement Icon", + "item.touhou_little_maid.entity_id_copy": "Entity ID Copier", "enchantment.touhou_little_maid.impeding": "Impeding Danmaku", "enchantment.touhou_little_maid.impeding.desc": "Danmaku can inflict slowness I - IV on the enemy", "enchantment.touhou_little_maid.speedy": "Speedy Danmaku", @@ -244,6 +245,7 @@ "tooltips.touhou_little_maid.servant_bell.desc.2": "- After mark, you can teleport the bound maid after using it.", "tooltips.touhou_little_maid.monster_list.desc": "Version 1.1.13 and later removed this item and can no longer be used", "tooltips.touhou_little_maid.advancement_icon.desc": "For advancement icon display only", + "tooltips.touhou_little_maid.entity_id_copy.desc": "It is used to copy the entity ID to facilitate filling in the attack list", "overlay.touhou_little_maid.compass.tips": "Right click to display the maid's task area", "overlay.touhou_little_maid.golden_apple.tips": "Golden apple shift click can be fed to maid", "overlay.touhou_little_maid.potion.tips": "Potion shift click can be fed to maid", @@ -462,6 +464,7 @@ "message.touhou_little_maid.cchess.reset": "Right click on the right black area to reset", "message.touhou_little_maid.wchess.move_limit": "Draw by 50-Move Rule!", "message.touhou_little_maid.wchess.reset": "Right click on the light yellow area on either side to reset", + "message.touhou_little_maid.entity_id_copy.copy": "The id of the entity has been copied: %s", "commands.touhou_little_maid.pack.reload.info": "All model pack have been reloaded!", "commands.touhou_little_maid.power.handle.info": "%d players's power point is changed", "commands.touhou_little_maid.maid_num.handle.info": "%d players's maid num is changed", diff --git a/src/main/resources/assets/touhou_little_maid/lang/zh_cn.json b/src/main/resources/assets/touhou_little_maid/lang/zh_cn.json index 9d5abb033..ffd1348be 100644 --- a/src/main/resources/assets/touhou_little_maid/lang/zh_cn.json +++ b/src/main/resources/assets/touhou_little_maid/lang/zh_cn.json @@ -167,6 +167,7 @@ "item.touhou_little_maid.servant_bell": "仆人铃", "item.touhou_little_maid.monster_list": "妖怪名单(移除)", "item.touhou_little_maid.advancement_icon": "进度图标", + "item.touhou_little_maid.entity_id_copy": "实体 ID 复制器", "enchantment.touhou_little_maid.impeding": "阻碍", "enchantment.touhou_little_maid.impeding.desc": "弹幕会对敌方造成缓慢 I - IV 的效果", "enchantment.touhou_little_maid.speedy": "极速", @@ -244,6 +245,7 @@ "tooltips.touhou_little_maid.servant_bell.desc.2": "- 绑定后,右击使用即可召回女仆。", "tooltips.touhou_little_maid.monster_list.desc": "自 1.1.13 版本后移除此物品", "tooltips.touhou_little_maid.advancement_icon.desc": "仅用于进度图标显示的物品", + "tooltips.touhou_little_maid.entity_id_copy.desc": "用于复制实体 ID,方便填写女仆攻击列表", "overlay.touhou_little_maid.compass.tips": "右击可以显示女仆的任务区域", "overlay.touhou_little_maid.golden_apple.tips": "手持金苹果可以使用 Shift 右击喂给女仆", "overlay.touhou_little_maid.potion.tips": "手持药水可以使用 Shift 右击喂给女仆", @@ -462,6 +464,7 @@ "message.touhou_little_maid.cchess.reset": "右击棋盘右侧黑色区域重置", "message.touhou_little_maid.wchess.move_limit": "五十回合限制!", "message.touhou_little_maid.wchess.reset": "右击任意一侧的淡黄色区域进行重置", + "message.touhou_little_maid.entity_id_copy.copy": "该实体 ID 已经被复制:%s", "commands.touhou_little_maid.pack.reload.info": "所有的模型包已经重载!", "commands.touhou_little_maid.power.handle.info": "修改了 %d 位玩家的 P 点", "commands.touhou_little_maid.maid_num.handle.info": "修改了 %d 位玩家的女仆数量", diff --git a/src/main/resources/assets/touhou_little_maid/models/item/entity_id_copy.json b/src/main/resources/assets/touhou_little_maid/models/item/entity_id_copy.json new file mode 100644 index 000000000..ee19ade8a --- /dev/null +++ b/src/main/resources/assets/touhou_little_maid/models/item/entity_id_copy.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "touhou_little_maid:item/entity_id_copy" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/touhou_little_maid/textures/item/entity_id_copy.png b/src/main/resources/assets/touhou_little_maid/textures/item/entity_id_copy.png new file mode 100644 index 000000000..b55d472f5 Binary files /dev/null and b/src/main/resources/assets/touhou_little_maid/textures/item/entity_id_copy.png differ