Skip to content

Commit

Permalink
新增实体 ID 复制器
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Nov 12, 2024
1 parent ff1d79c commit 1c44323
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public final class InitItems {
public static RegistryObject<Item> PICNIC_BASKET = ITEMS.register("picnic_basket", () -> new ItemPicnicBasket(InitBlocks.PICNIC_MAT.get()));
public static RegistryObject<Item> SCARECROW = ITEMS.register("scarecrow", () -> new BlockItem(InitBlocks.SCARECROW.get(), new Item.Properties().tab(MAIN_TAB)));
public static RegistryObject<Item> SERVANT_BELL = ITEMS.register("servant_bell", ItemServantBell::new);
public static RegistryObject<Item> ENTITY_ID_COPY = ITEMS.register("entity_id_copy", ItemEntityIdCopy::new);
@SuppressWarnings("deprecation")
public static RegistryObject<Item> MONSTER_LIST = ITEMS.register("monster_list", ItemMonsterList::new);

public static RegistryObject<Item> MAID_SPAWN_EGG = ITEMS.register("maid_spawn_egg", () -> new ForgeSpawnEggItem(() -> EntityMaid.TYPE, 0x4a6195, 0xffffff, new Item.Properties()));
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Component> components, TooltipFlag pIsAdvanced) {
components.add(new TranslatableComponent("tooltips.touhou_little_maid.entity_id_copy.desc").withStyle(ChatFormatting.GRAY));
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/touhou_little_maid/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/touhou_little_maid/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "极速",
Expand Down Expand Up @@ -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 右击喂给女仆",
Expand Down Expand Up @@ -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 位玩家的女仆数量",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "touhou_little_maid:item/entity_id_copy"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1c44323

Please sign in to comment.