Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

仅安装JEI时发送提醒 #953

Merged
merged 4 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package dev.dubhe.anvilcraft.api.event;

import dev.architectury.platform.Platform;
import dev.architectury.utils.Env;
import dev.dubhe.anvilcraft.AnvilCraft;
import net.fabricmc.api.Environment;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -47,6 +50,8 @@ public void register(@NotNull Object object) {
for (Method method : object.getClass().getMethods()) {
if (method.getParameterCount() != 1) continue;
SubscribeEvent annotation = method.getAnnotation(SubscribeEvent.class);
Environment env = method.getAnnotation(Environment.class);
if (env != null && Env.fromPlatform(env.value()) != Platform.getEnvironment()) continue;
if (null == annotation) continue;
Class<?> event = method.getParameterTypes()[0];
Consumer<?> trigger = (obj) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@

import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;

public class PlayerEvent extends EntityEvent<Player> {
public class PlayerEvent<T extends Player> extends EntityEvent<T> {
/**
* 玩家事件
*
* @param entity 实体
* @param pos 位置
* @param level 世界
*/
public PlayerEvent(Player entity, BlockPos pos, Level level) {
public PlayerEvent(T entity, BlockPos pos, Level level) {
super(entity, pos, level);
}

@Getter
public static class UseEntity extends PlayerEvent {
public static class UseEntity extends PlayerEvent<Player> {
private final Entity target;
private final InteractionHand hand;
@Setter
Expand All @@ -37,4 +38,17 @@ public UseEntity(Player entity, Entity target, InteractionHand hand, Level level
this.hand = hand;
}
}

public static class ClientPlayerJoin extends PlayerEvent<LocalPlayer> {
/**
* 玩家加入事件
*
* @param entity 实体
* @param pos 位置
* @param level 世界
*/
public ClientPlayerJoin(LocalPlayer entity, BlockPos pos, Level level) {
super(entity, pos, level);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public class OtherLang {
* @param provider 提供器
*/
public static void init(@NotNull RegistrateLangProvider provider) {
provider.add(
"modmenu.nameTranslation.anvilcraft",
"AnvilCraft"
);

provider.add(
"item.anvilcraft.default_enchantment.tooltip",
"Has default enchantments:"
Expand All @@ -34,8 +39,14 @@ public static void init(@NotNull RegistrateLangProvider provider) {
);

provider.add(
"item.anvilcraft.disk.stored_from",
"Stored from: %s"
"item.anvilcraft.disk.stored_from",
"Stored from: %s"
);

provider.add(
"tooltip.anvilcraft.only_jei",
"We have detected that you have only installed JEI and will not be able to obtain a complete recipe query. "
+ "We recommend installing %s for a complete gaming experience!"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import dev.dubhe.anvilcraft.api.event.entity.PlayerEvent;
import dev.dubhe.anvilcraft.init.ModBlocks;
import dev.dubhe.anvilcraft.item.ResinBlockItem;
import dev.dubhe.anvilcraft.util.Utils;
import net.minecraft.ChatFormatting;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
Expand All @@ -24,4 +29,33 @@ public void useEntity(@NotNull PlayerEvent.UseEntity event) {
event.setResult(ResinBlockItem.useEntity(player, target, item));
}
}

/**
* @param event 玩家加入事件
*/
@SubscribeEvent
public void onPlayerJoin(@NotNull PlayerEvent.ClientPlayerJoin event) {
if (Utils.onlyJei()) {
LocalPlayer entity = event.getEntity();
entity.sendSystemMessage(
Component.literal("[").withStyle(ChatFormatting.GREEN).append(
Component.translatable("modmenu.nameTranslation.anvilcraft").withStyle(ChatFormatting.GOLD).append(
Component.literal("] ").withStyle(ChatFormatting.GREEN).append(
Component.translatable(
"tooltip.anvilcraft.only_jei",
Component.literal("EMI").withStyle(ChatFormatting.BLUE).withStyle(
style -> style.withClickEvent(
new ClickEvent(
ClickEvent.Action.OPEN_URL,
"https://modrinth.com/mod/emi"
)
)
)
).withStyle(ChatFormatting.WHITE)
)
)
)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package dev.dubhe.anvilcraft.mixin;

import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.api.event.entity.PlayerEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ClientPacketListener.class)
public abstract class ClientPacketListenerMixin {
@Shadow
@Final
private Minecraft minecraft;

@Shadow
public abstract ClientLevel getLevel();

@Inject(
method = "handleLogin",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Options;broadcastOptions()V")
)
private void handleLogin(ClientboundLoginPacket packet, CallbackInfo ci) {
LocalPlayer player = this.minecraft.player;
if (player != null) {
AnvilCraft.EVENT_BUS.post(new PlayerEvent.ClientPlayerJoin(player, player.getOnPos(), this.getLevel()));
}
}
}
16 changes: 16 additions & 0 deletions common/src/main/java/dev/dubhe/anvilcraft/util/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.dubhe.anvilcraft.util;

import dev.architectury.injectables.annotations.ExpectPlatform;

public abstract class Utils {
private Utils() {
}

/**
* @return 是否只加载了 JEI
*/
@ExpectPlatform
public static boolean onlyJei() {
throw new AssertionError();
}
}
1 change: 1 addition & 0 deletions common/src/main/resources/anvilcraft-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
],
"client": [
"ClientLevelMixin",
"ClientPacketListenerMixin",
"ItemInHandRendererMixin",
"LevelRendererMixin",
"TooltipRenderMixin",
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/resources/assets/anvilcraft/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,5 +423,6 @@
"tooltip.anvilcraft.item.topaz": "蕴含闪电的力量",
"tooltip.anvilcraft.item.transmission_pole": "组建电网,传输距离为8个方块",
"tooltip.anvilcraft.jade.power_information": "电网:%d/%d kW",
"tooltip.anvilcraft.ruby_prism.power": "激光等级:%d"
"tooltip.anvilcraft.ruby_prism.power": "激光等级:%d",
"modmenu.nameTranslation.anvilcraft": "铁砧工艺"
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
"itemGroup.anvilcraft.ingredients": "sʇuǝıpǝɹbuI :ʇɟɐɹƆןıʌuⱯ",
"itemGroup.anvilcraft.tools": "sǝıʇıןıʇ∩ :ʇɟɐɹƆןıʌuⱯ",
"message.anvilcraft.need_patchouli_installed": "pǝןןɐʇsuı ǝq oʇ spǝǝu ıןnoɥɔʇɐԀ",
"modmenu.nameTranslation.anvilcraft": "ʇɟɐɹƆןıʌuⱯ",
"patchouli.anvilcraft.landing_text": "ʇɟɐɹƆןıʌuⱯ oʇ ǝɯoɔןǝM",
"screen.anvilcraft.active_silencer.title": "ɹǝɔuǝןıS ǝʌıʇɔⱯ",
"screen.anvilcraft.button.direction": "%s :uoıʇɔǝɹıᗡ ʇndʇnO",
Expand Down Expand Up @@ -433,5 +434,6 @@
"tooltip.anvilcraft.item.topaz": "buıuʇɥbıן ɟo ɹǝʍod ǝɥʇ buıuıɐʇuoƆ",
"tooltip.anvilcraft.item.transmission_pole": "8 ɟo ǝɔuɐʇsıp uoıssıɯsuɐɹʇ ɐ ɥʇıʍ pıɹb ɹǝʍod ɐ pןınᗺ",
"tooltip.anvilcraft.jade.power_information": "Mʞ %d/%d :pıɹ⅁ ɹǝʍoԀ",
"tooltip.anvilcraft.only_jei": "¡ǝɔuǝıɹǝdxǝ buıɯɐb ǝʇǝןdɯoɔ ɐ ɹoɟ %s buıןןɐʇsuı puǝɯɯoɔǝɹ ǝM ˙ʎɹǝnb ǝdıɔǝɹ ǝʇǝןdɯoɔ ɐ uıɐʇqo oʇ ǝןqɐ ǝq ʇou ןןıʍ puɐ IƎſ pǝןןɐʇsuı ʎןuo ǝʌɐɥ noʎ ʇɐɥʇ pǝʇɔǝʇǝp ǝʌɐɥ ǝM",
"tooltip.anvilcraft.ruby_prism.power": "%d :ןǝʌǝן ɹǝsɐꞀ"
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
"itemGroup.anvilcraft.ingredients": "AnvilCraft: Ingredients",
"itemGroup.anvilcraft.tools": "AnvilCraft: Utilities",
"message.anvilcraft.need_patchouli_installed": "Patchouli needs to be installed",
"modmenu.nameTranslation.anvilcraft": "AnvilCraft",
"patchouli.anvilcraft.landing_text": "Welcome to AnvilCraft",
"screen.anvilcraft.active_silencer.title": "Active Silencer",
"screen.anvilcraft.button.direction": "Output Direction: %s",
Expand Down Expand Up @@ -433,5 +434,6 @@
"tooltip.anvilcraft.item.topaz": "Containing the power of lightning",
"tooltip.anvilcraft.item.transmission_pole": "Build a power grid with a transmission distance of 8",
"tooltip.anvilcraft.jade.power_information": "Power Grid: %d/%d kW",
"tooltip.anvilcraft.only_jei": "We have detected that you have only installed JEI and will not be able to obtain a complete recipe query. We recommend installing %s for a complete gaming experience!",
"tooltip.anvilcraft.ruby_prism.power": "Laser level: %d"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.dubhe.anvilcraft.util.fabric;

import net.fabricmc.loader.api.FabricLoader;

public class UtilsImpl {
public static boolean onlyJei() {
return FabricLoader.getInstance().isModLoaded("jei") && !FabricLoader.getInstance().isModLoaded("emi");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
"itemGroup.anvilcraft.ingredients": "sʇuǝıpǝɹbuI :ʇɟɐɹƆןıʌuⱯ",
"itemGroup.anvilcraft.tools": "sǝıʇıןıʇ∩ :ʇɟɐɹƆןıʌuⱯ",
"message.anvilcraft.need_patchouli_installed": "pǝןןɐʇsuı ǝq oʇ spǝǝu ıןnoɥɔʇɐԀ",
"modmenu.nameTranslation.anvilcraft": "ʇɟɐɹƆןıʌuⱯ",
"patchouli.anvilcraft.landing_text": "ʇɟɐɹƆןıʌuⱯ oʇ ǝɯoɔןǝM",
"screen.anvilcraft.active_silencer.title": "ɹǝɔuǝןıS ǝʌıʇɔⱯ",
"screen.anvilcraft.button.direction": "%s :uoıʇɔǝɹıᗡ ʇndʇnO",
Expand Down Expand Up @@ -433,5 +434,6 @@
"tooltip.anvilcraft.item.topaz": "buıuʇɥbıן ɟo ɹǝʍod ǝɥʇ buıuıɐʇuoƆ",
"tooltip.anvilcraft.item.transmission_pole": "8 ɟo ǝɔuɐʇsıp uoıssıɯsuɐɹʇ ɐ ɥʇıʍ pıɹb ɹǝʍod ɐ pןınᗺ",
"tooltip.anvilcraft.jade.power_information": "Mʞ %d/%d :pıɹ⅁ ɹǝʍoԀ",
"tooltip.anvilcraft.only_jei": "¡ǝɔuǝıɹǝdxǝ buıɯɐb ǝʇǝןdɯoɔ ɐ ɹoɟ %s buıןןɐʇsuı puǝɯɯoɔǝɹ ǝM ˙ʎɹǝnb ǝdıɔǝɹ ǝʇǝןdɯoɔ ɐ uıɐʇqo oʇ ǝןqɐ ǝq ʇou ןןıʍ puɐ IƎſ pǝןןɐʇsuı ʎןuo ǝʌɐɥ noʎ ʇɐɥʇ pǝʇɔǝʇǝp ǝʌɐɥ ǝM",
"tooltip.anvilcraft.ruby_prism.power": "%d :ןǝʌǝן ɹǝsɐꞀ"
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
"itemGroup.anvilcraft.ingredients": "AnvilCraft: Ingredients",
"itemGroup.anvilcraft.tools": "AnvilCraft: Utilities",
"message.anvilcraft.need_patchouli_installed": "Patchouli needs to be installed",
"modmenu.nameTranslation.anvilcraft": "AnvilCraft",
"patchouli.anvilcraft.landing_text": "Welcome to AnvilCraft",
"screen.anvilcraft.active_silencer.title": "Active Silencer",
"screen.anvilcraft.button.direction": "Output Direction: %s",
Expand Down Expand Up @@ -433,5 +434,6 @@
"tooltip.anvilcraft.item.topaz": "Containing the power of lightning",
"tooltip.anvilcraft.item.transmission_pole": "Build a power grid with a transmission distance of 8",
"tooltip.anvilcraft.jade.power_information": "Power Grid: %d/%d kW",
"tooltip.anvilcraft.only_jei": "We have detected that you have only installed JEI and will not be able to obtain a complete recipe query. We recommend installing %s for a complete gaming experience!",
"tooltip.anvilcraft.ruby_prism.power": "Laser level: %d"
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void useEntity(@NotNull PlayerInteractEvent.EntityInteract event)
}

@SubscribeEvent
public static void itemTooltip(ItemTooltipEvent event) {
public static void itemTooltip(@NotNull ItemTooltipEvent event) {
TooltipEventListener.addTooltip(event.getItemStack(), event.getToolTip());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ForgeGuiMixin(Minecraft minecraft, ItemRenderer itemRenderer) {
target = "Lcom/mojang/blaze3d/systems/RenderSystem;setShaderColor(FFFF)V",
shift = At.Shift.AFTER
),
remap = false
remap = true
)
void onHudRender(GuiGraphics guiGraphics, float partialTick, CallbackInfo ci) {
if (minecraft.player == null || minecraft.isPaused()) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.dubhe.anvilcraft.util.forge;

import net.minecraftforge.fml.ModList;

public class UtilsImpl {
public static boolean onlyJei() {
return ModList.get().isLoaded("jei") && !ModList.get().isLoaded("emi");
}
}
Loading