Skip to content

Commit

Permalink
ic 移植1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
linngdu664 committed Sep 28, 2024
1 parent 3fbfb96 commit 02b39f0
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod_name=DRG Laser Pointer
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GNU GPLv3
# The mod version. See https://semver.org/
mod_version=1.0.4
mod_version=1.1.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import com.linngdu664.drglaserpointer.Main;
import com.linngdu664.drglaserpointer.network.LaserColorSwitchPayload;
import com.linngdu664.drglaserpointer.network.SwitchInventoryPayload;
import com.linngdu664.drglaserpointer.registry.ItemRegister;
import com.linngdu664.drglaserpointer.registry.KeyMappingRegister;
import com.linngdu664.drglaserpointer.registry.NetworkRegister;
import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.lwjgl.glfw.GLFW;

@Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class InputEventHandler {
Expand All @@ -31,4 +35,26 @@ public static void onInteractionKeyMappingTriggered(InputEvent.InteractionKeyMap
event.setCanceled(true);
}
}
private static int oldSlot = -1;

@SubscribeEvent
public static void onKeyInput(InputEvent.Key event) {
Minecraft mc = Minecraft.getInstance();
if (mc.screen == null && event.getKey() == KeyMappingRegister.SWITCH_TO_LASER_POINTER.getKey().getValue()) {
Player player = mc.player;
if (event.getAction() == GLFW.GLFW_PRESS && !player.getMainHandItem().is(ItemRegister.LASER_POINTER.get()) && !player.getOffhandItem().is(ItemRegister.LASER_POINTER.get())) {
Inventory inventory = player.getInventory();
for (int i = 0, k = inventory.getContainerSize(); i < k; i++) {
ItemStack stack = inventory.getItem(i);
if (stack.is(ItemRegister.LASER_POINTER.get())) {
oldSlot = i;
NetworkRegister.PACKET_HANDLER.sendToServer(new SwitchInventoryPayload(oldSlot));
return;
}
}
} else if (event.getAction() == GLFW.GLFW_RELEASE && (player.getMainHandItem().is(ItemRegister.LASER_POINTER.get()) || player.getOffhandItem().is(ItemRegister.LASER_POINTER.get()))) {
NetworkRegister.PACKET_HANDLER.sendToServer(new SwitchInventoryPayload(oldSlot));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.linngdu664.drglaserpointer.network;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.network.NetworkEvent;

import java.util.function.Supplier;

public record SwitchInventoryPayload(int slot) {
public static void encoder(SwitchInventoryPayload message, FriendlyByteBuf buffer) {
buffer.writeInt(message.slot);
}
public static SwitchInventoryPayload decoder(FriendlyByteBuf buffer) {
return new SwitchInventoryPayload(buffer.readInt());
}


public static void messageConsumer(SwitchInventoryPayload payload, Supplier<NetworkEvent.Context> ctxSupplier) {
NetworkEvent.Context context = ctxSupplier.get();
context.enqueueWork(() -> {
ServerPlayer player = context.getSender();
Inventory inventory = player.getInventory();
if (payload.slot < 0 || payload.slot >= inventory.getContainerSize()) {
return;
}
ItemStack itemStack1 = inventory.getSelected();
ItemStack itemStack2 = inventory.getItem(payload.slot);
inventory.setItem(inventory.selected, itemStack2);
inventory.setItem(payload.slot, itemStack1);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.linngdu664.drglaserpointer.registry;

import com.linngdu664.drglaserpointer.Main;
import net.minecraft.client.KeyMapping;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.lwjgl.glfw.GLFW;

@Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class KeyMappingRegister {
public static final KeyMapping SWITCH_TO_LASER_POINTER = new KeyMapping("key.laserpointer.switch_to_laser_pointer", GLFW.GLFW_KEY_LEFT_CONTROL, "key.categories.misc");

@SubscribeEvent
public static void registerKeyBindings(RegisterKeyMappingsEvent event) {
event.register(SWITCH_TO_LASER_POINTER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ public static void registerMessage(FMLCommonSetupEvent event) {
NetworkRegister.addNetworkMessage(LaserPickBlockPayload.class, LaserPickBlockPayload::encoder, LaserPickBlockPayload::decoder, LaserPickBlockPayload::messageConsumer);
NetworkRegister.addNetworkMessage(LaserPickEntityPayload.class, LaserPickEntityPayload::encoder, LaserPickEntityPayload::decoder, LaserPickEntityPayload::messageConsumer);
NetworkRegister.addNetworkMessage(LaserPlaySoundPayload.class, LaserPlaySoundPayload::encoder, LaserPlaySoundPayload::decoder, LaserPlaySoundPayload::messageConsumer);
NetworkRegister.addNetworkMessage(SwitchInventoryPayload.class, SwitchInventoryPayload::encoder, SwitchInventoryPayload::decoder,SwitchInventoryPayload::messageConsumer);
}
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/ar_sa.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "نحن أغنياء!",
"advancements.drglaserpointer.were_rich.description": "نعم، نعم، أنت غني. لطفًا تحرك، الإدارة تراقبني هنا!",
"advancements.drglaserpointer.mushroom.title": "فطر!",
"advancements.drglaserpointer.mushroom.description": "\"فطر، فطر\"، اصمت! عد إلى العمل!"
"advancements.drglaserpointer.mushroom.description": "\"فطر، فطر\"، اصمت! عد إلى العمل!",

"key.laserpointer.switch_to_laser_pointer": "التبديل إلى مؤشر الليزر"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "Wir sind reich!",
"advancements.drglaserpointer.were_rich.description": "Ja, ja, ihr seid reich. Bitte macht weiter, das Management sitzt mir im Nacken!",
"advancements.drglaserpointer.mushroom.title": "Pilz!",
"advancements.drglaserpointer.mushroom.description": "\"Pilz, Pilz\", HALT DIE KLAPPE! Zurück an die Arbeit!"
"advancements.drglaserpointer.mushroom.description": "\"Pilz, Pilz\", HALT DIE KLAPPE! Zurück an die Arbeit!",

"key.laserpointer.switch_to_laser_pointer": "Wechsel zum Laserpointer"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "We're rich!",
"advancements.drglaserpointer.were_rich.description": "Yes, yes, you're rich. Kindly get a move on, I got Management breathing down my neck here!",
"advancements.drglaserpointer.mushroom.title": "Mushroom!",
"advancements.drglaserpointer.mushroom.description": "\"Mushroom, mushroom\", SHUT IT! Get back to work!"
"advancements.drglaserpointer.mushroom.description": "\"Mushroom, mushroom\", SHUT IT! Get back to work!",

"key.laserpointer.switch_to_laser_pointer": "Switch to Laser Pointer"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/es_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "¡Somos ricos!",
"advancements.drglaserpointer.were_rich.description": "Sí, sí, eres rico. Por favor, muévete, ¡tengo a la gerencia respirando en mi cuello aquí!",
"advancements.drglaserpointer.mushroom.title": "¡Hongo!",
"advancements.drglaserpointer.mushroom.description": "\"Hongo, hongo\", ¡CÁLLATE! ¡Vuelve al trabajo!"
"advancements.drglaserpointer.mushroom.description": "\"Hongo, hongo\", ¡CÁLLATE! ¡Vuelve al trabajo!",

"key.laserpointer.switch_to_laser_pointer": "Cambiar a Puntero Láser"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/fr_ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "Nous sommes riches!",
"advancements.drglaserpointer.were_rich.description": "Oui, oui, vous êtes riches. Veuillez avancer, la direction me surveille de près ici!",
"advancements.drglaserpointer.mushroom.title": "Champignon!",
"advancements.drglaserpointer.mushroom.description": "\"Champignon, champignon\", TAIS-TOI! Retourne au travail!"
"advancements.drglaserpointer.mushroom.description": "\"Champignon, champignon\", TAIS-TOI! Retourne au travail!",

"key.laserpointer.switch_to_laser_pointer": "Changer pour Pointeur Laser"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/fr_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "Nous sommes riches !",
"advancements.drglaserpointer.were_rich.description": "Oui, oui, vous êtes riches. Veuillez avancer, la direction me met la pression ici !",
"advancements.drglaserpointer.mushroom.title": "Champignon !",
"advancements.drglaserpointer.mushroom.description": "\"Champignon, champignon\", TAIS-TOI ! Retourne au travail !"
"advancements.drglaserpointer.mushroom.description": "\"Champignon, champignon\", TAIS-TOI ! Retourne au travail !",

"key.laserpointer.switch_to_laser_pointer": "Changer pour le Pointeur Laser"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/it_it.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "Siamo ricchi!",
"advancements.drglaserpointer.were_rich.description": "Sì, sì, sei ricco. Per favore, muoviti, ho la gestione che mi sta addosso!",
"advancements.drglaserpointer.mushroom.title": "Fungo!",
"advancements.drglaserpointer.mushroom.description": "\"Fungo, fungo\", BASTA! Torna al lavoro!"
"advancements.drglaserpointer.mushroom.description": "\"Fungo, fungo\", BASTA! Torna al lavoro!",

"key.laserpointer.switch_to_laser_pointer": "Passa al Puntatore Laser"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/ja_jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "私たちは金持ちだ!",
"advancements.drglaserpointer.were_rich.description": "そうそう、君は金持ちだ。早く進んでくれ、管理が私の首を絞めているんだ!",
"advancements.drglaserpointer.mushroom.title": "キノコ!",
"advancements.drglaserpointer.mushroom.description": "「キノコ、キノコ」、黙れ!仕事に戻れ!"
"advancements.drglaserpointer.mushroom.description": "「キノコ、キノコ」、黙れ!仕事に戻れ!",

"key.laserpointer.switch_to_laser_pointer": "レーザーポインターに切り替える"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/ko_kr.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "우리는 부자야!",
"advancements.drglaserpointer.were_rich.description": "네, 네, 당신은 부자입니다. 제발 빨리 움직이세요, 관리부가 제 목을 조르고 있어요!",
"advancements.drglaserpointer.mushroom.title": "버섯!",
"advancements.drglaserpointer.mushroom.description": "\"버섯, 버섯\", 그만해! 일로 돌아가!"
"advancements.drglaserpointer.mushroom.description": "\"버섯, 버섯\", 그만해! 일로 돌아가!",

"key.laserpointer.switch_to_laser_pointer": "레이저 포인터로 전환"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/lzh.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "吾等富矣!",
"advancements.drglaserpointer.were_rich.description": "是,是,汝富矣。行行好速行,吾受上司督促也!",
"advancements.drglaserpointer.mushroom.title": "菌!",
"advancements.drglaserpointer.mushroom.description": "专注,队伍!勿言菌也!"
"advancements.drglaserpointer.mushroom.description": "专注,队伍!勿言菌也!",

"key.laserpointer.switch_to_laser_pointer": "切至光指器"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/nl_nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "We zijn rijk!",
"advancements.drglaserpointer.were_rich.description": "Ja, ja, je bent rijk. Ga alsjeblieft verder, het management zit me op de nek!",
"advancements.drglaserpointer.mushroom.title": "Paddenstoel!",
"advancements.drglaserpointer.mushroom.description": "\"Paddenstoel, paddenstoel\", HOU JE MOND! Ga aan het werk!"
"advancements.drglaserpointer.mushroom.description": "\"Paddenstoel, paddenstoel\", HOU JE MOND! Ga aan het werk!",

"key.laserpointer.switch_to_laser_pointer": "Overschakelen naar Laserpointer"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/pl_pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "Jesteśmy bogaci!",
"advancements.drglaserpointer.were_rich.description": "Tak, tak, jesteś bogaty. Rusz się, zarząd stoi mi nad głową!",
"advancements.drglaserpointer.mushroom.title": "Grzyb!",
"advancements.drglaserpointer.mushroom.description": "\"Grzyb, grzyb\", CISZA! Wracaj do pracy!"
"advancements.drglaserpointer.mushroom.description": "\"Grzyb, grzyb\", CISZA! Wracaj do pracy!",

"key.laserpointer.switch_to_laser_pointer": "Przełącz na wskaźnik laserowy"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "Мы богаты!",
"advancements.drglaserpointer.were_rich.description": "Да, да, вы богаты. Пожалуйста, двигайтесь, у меня тут начальство на хвосте!",
"advancements.drglaserpointer.mushroom.title": "Гриб!",
"advancements.drglaserpointer.mushroom.description": "\"Гриб, гриб\", ЗАТКНИСЬ! Возвращайся к работе!"
"advancements.drglaserpointer.mushroom.description": "\"Гриб, гриб\", ЗАТКНИСЬ! Возвращайся к работе!",

"key.laserpointer.switch_to_laser_pointer": "Переключиться на лазерную указку"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/sv_se.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "Vi är rika!",
"advancements.drglaserpointer.were_rich.description": "Ja, ja, du är rik. Var snäll och skynda på, jag har ledningen flåsande i nacken!",
"advancements.drglaserpointer.mushroom.title": "Svamp!",
"advancements.drglaserpointer.mushroom.description": "\"Svamp, svamp\", TYST! Återgå till arbetet!"
"advancements.drglaserpointer.mushroom.description": "\"Svamp, svamp\", TYST! Återgå till arbetet!",

"key.laserpointer.switch_to_laser_pointer": "Byt till laserpekare"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "我们发财了!",
"advancements.drglaserpointer.were_rich.description": "是,是,是,你发财了。行行好赶紧走吧,管理层就在我身后站着呢!",
"advancements.drglaserpointer.mushroom.title": "蘑菇!",
"advancements.drglaserpointer.mushroom.description": "专注点,小队!别他娘的蘑菇了!"
"advancements.drglaserpointer.mushroom.description": "专注点,小队!别他娘的蘑菇了!",

"key.laserpointer.switch_to_laser_pointer": "切换至激光指示器"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/drglaserpointer/lang/zh_hk.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "我們發財了!",
"advancements.drglaserpointer.were_rich.description": "是,是,是,你發財了。行行好趕緊走吧,管理層就在我身後站著呢!",
"advancements.drglaserpointer.mushroom.title": "蘑菇!",
"advancements.drglaserpointer.mushroom.description": "專注點,小隊!別他娘的蘑菇了!"
"advancements.drglaserpointer.mushroom.description": "專注點,小隊!別他娘的蘑菇了!",

"key.laserpointer.switch_to_laser_pointer": "切換至雷射指示器"
}
6 changes: 4 additions & 2 deletions src/main/resources/assets/drglaserpointer/lang/zh_tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"advancements.drglaserpointer.were_rich.title": "我們發財了!",
"advancements.drglaserpointer.were_rich.description": "是,是,是,你發財了。行行好趕緊走吧,管理層就在我身後站著呢!",
"advancements.drglaserpointer.mushroom.title": "蘑菇!",
"advancements.drglaserpointer.mushroom.description": "專注點,小隊!別他娘的蘑菇了!"
}
"advancements.drglaserpointer.mushroom.description": "專注點,小隊!別他娘的蘑菇了!",

"key.laserpointer.switch_to_laser_pointer": "切換至雷射指示器"
}

0 comments on commit 02b39f0

Please sign in to comment.