-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fbfb96
commit 02b39f0
Showing
22 changed files
with
133 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/com/linngdu664/drglaserpointer/network/SwitchInventoryPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/linngdu664/drglaserpointer/registry/KeyMappingRegister.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters