diff --git a/gradle.properties b/gradle.properties index 0b4b15b..c96687c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ parchment_mappings=1.20.1:2023.07.02 loader_version=0.14.21 # Mod Properties -mod_version=3.2.2.1 +mod_version=3.2.3 maven_group=com.cstav.genshinstrument archives_base_name=genshinstrument diff --git a/src/main/java/com/cstav/genshinstrument/GInstrumentMod.java b/src/main/java/com/cstav/genshinstrument/GInstrumentMod.java index 6e8b321..5522b3a 100644 --- a/src/main/java/com/cstav/genshinstrument/GInstrumentMod.java +++ b/src/main/java/com/cstav/genshinstrument/GInstrumentMod.java @@ -6,6 +6,7 @@ import com.cstav.genshinstrument.block.ModBlockEntities; import com.cstav.genshinstrument.block.ModBlocks; import com.cstav.genshinstrument.criteria.ModCriteria; +import com.cstav.genshinstrument.event.ServerEvents; import com.cstav.genshinstrument.item.ModItems; import com.cstav.genshinstrument.networking.ModPacketHandler; import com.cstav.genshinstrument.sound.ModSounds; @@ -19,6 +20,8 @@ public class GInstrumentMod implements ModInitializer { @Override public void onInitialize() { ModPacketHandler.registerServerPackets(); + ServerEvents.register(); + ModCriteria.register(); ModSounds.load(); diff --git a/src/main/java/com/cstav/genshinstrument/block/partial/AbstractInstrumentBlock.java b/src/main/java/com/cstav/genshinstrument/block/partial/AbstractInstrumentBlock.java index 56dd558..f7e0d01 100644 --- a/src/main/java/com/cstav/genshinstrument/block/partial/AbstractInstrumentBlock.java +++ b/src/main/java/com/cstav/genshinstrument/block/partial/AbstractInstrumentBlock.java @@ -5,7 +5,7 @@ import com.cstav.genshinstrument.networking.ModPacketHandler; import com.cstav.genshinstrument.networking.OpenInstrumentPacketSender; import com.cstav.genshinstrument.networking.packets.instrument.NotifyInstrumentOpenPacket; -import com.cstav.genshinstrument.util.ModEntityData; +import com.cstav.genshinstrument.util.InstrumentEntityData; import com.cstav.genshinstrument.util.ServerUtil; import net.fabricmc.api.EnvType; @@ -70,7 +70,7 @@ public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState for (final Player player : pLevel.players()) { ibe.users.forEach((user) -> { - ModEntityData.setInstrumentClosed(pLevel.getPlayerByUUID(user)); + InstrumentEntityData.setClosed(pLevel.getPlayerByUUID(user)); ModPacketHandler.sendToClient(new NotifyInstrumentOpenPacket(user, false), (ServerPlayer)player); }); } diff --git a/src/main/java/com/cstav/genshinstrument/client/ClientInitiator.java b/src/main/java/com/cstav/genshinstrument/client/ClientInitiator.java index af32a82..533fd50 100644 --- a/src/main/java/com/cstav/genshinstrument/client/ClientInitiator.java +++ b/src/main/java/com/cstav/genshinstrument/client/ClientInitiator.java @@ -11,6 +11,7 @@ import com.cstav.genshinstrument.client.gui.screens.instrument.windsonglyre.WindsongLyreScreen; import com.cstav.genshinstrument.event.ClientEvents; import com.cstav.genshinstrument.event.ResourcesLoadedEvent; +import com.cstav.genshinstrument.item.ItemPoseModifier; import com.cstav.genshinstrument.networking.ModPacketHandler; import fuzs.forgeconfigapiport.api.config.v2.ForgeConfigRegistry; @@ -31,9 +32,11 @@ public class ClientInitiator implements ClientModInitializer { @Override public void onInitializeClient() { ModPacketHandler.registerClientPackets(); + ForgeConfigRegistry.INSTANCE.register(GInstrumentMod.MODID, ModConfig.Type.CLIENT, ModClientConfigs.CONFIGS); ClientEvents.register(); + ItemPoseModifier.register(); // Load necessary classes, as listed above diff --git a/src/main/java/com/cstav/genshinstrument/client/ModArmPose.java b/src/main/java/com/cstav/genshinstrument/client/ModArmPose.java index 2b6dd25..4babd90 100644 --- a/src/main/java/com/cstav/genshinstrument/client/ModArmPose.java +++ b/src/main/java/com/cstav/genshinstrument/client/ModArmPose.java @@ -2,7 +2,7 @@ import com.cstav.genshinstrument.event.PosePlayerArmEvent.HandType; import com.cstav.genshinstrument.event.PosePlayerArmEvent.PosePlayerArmEventArgs; -import com.cstav.genshinstrument.util.ModEntityData; +import com.cstav.genshinstrument.util.InstrumentEntityData; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -13,7 +13,7 @@ public abstract class ModArmPose { public static final float HAND_HEIGHT_ROT = .9f; public static void poseForItemInstrument(final PosePlayerArmEventArgs args) { - if (!ModEntityData.isInstrumentOpen(args.player) || !ModEntityData.isInstrumentItem(args.player)) + if (!InstrumentEntityData.isOpen(args.player) || !InstrumentEntityData.isItem(args.player)) return; final ModelPart arm = args.arm; diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractInstrumentScreen.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractInstrumentScreen.java index 4c48cf0..e646696 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractInstrumentScreen.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractInstrumentScreen.java @@ -10,12 +10,11 @@ import com.cstav.genshinstrument.client.gui.screens.instrument.GenshinConsentScreen; import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.NoteButton; import com.cstav.genshinstrument.client.gui.screens.options.instrument.AbstractInstrumentOptionsScreen; -import com.cstav.genshinstrument.item.InstrumentItem; import com.cstav.genshinstrument.networking.ModPacketHandler; import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier; import com.cstav.genshinstrument.networking.packets.instrument.CloseInstrumentPacket; import com.cstav.genshinstrument.sound.NoteSound; -import com.cstav.genshinstrument.util.ModEntityData; +import com.cstav.genshinstrument.util.InstrumentEntityData; import com.mojang.blaze3d.platform.InputConstants.Key; import com.mojang.blaze3d.platform.InputConstants.Type; @@ -29,7 +28,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.player.Player; @Environment(EnvType.CLIENT) public abstract class AbstractInstrumentScreen extends Screen { @@ -37,15 +35,13 @@ public abstract class AbstractInstrumentScreen extends Screen { @SuppressWarnings("resource") public int getNoteSize() { - final int guiScale = Minecraft.getInstance().options.guiScale().get(); - - return switch (guiScale) { + return switch (Minecraft.getInstance().options.guiScale().get()) { case 0 -> 40; case 1 -> 35; case 2 -> 46; case 3 -> 48; - case 4 -> 41; - default -> guiScale * 18; + case 4 -> 40; + default -> 20; }; } @@ -106,25 +102,9 @@ public String[] noteLayout() { * or, if it is an item, if the item has been ripped out of the player's hands. * @return Whether the instrument has closed as a result of this method */ - public boolean handleAbruptClosing() { - final Player player = minecraft.player; - - if (!ModEntityData.isInstrumentOpen(player)) { + public void handleAbruptClosing() { + if (!InstrumentEntityData.isOpen(minecraft.player)) onClose(false); - return true; - } - - // Handle item not in hand seperately - // This is done like so because there is no event (that I know of) for when an item is moved/removed - if ( - (ModEntityData.isInstrumentItem(player) && interactionHand.isPresent()) - && !(player.getItemInHand(interactionHand.get()).getItem() instanceof InstrumentItem) - ) { - onClose(true); - return true; - } - - return false; } @@ -306,7 +286,7 @@ public void onClose() { } public void onClose(final boolean notify) { if (notify) { - ModEntityData.setInstrumentClosed(minecraft.player); + InstrumentEntityData.setClosed(minecraft.player); ModPacketHandler.sendToServer(new CloseInstrumentPacket()); } diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteButton.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteButton.java index 4a843d3..6363cc1 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteButton.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteButton.java @@ -10,7 +10,7 @@ import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier; import com.cstav.genshinstrument.networking.packets.instrument.InstrumentPacket; import com.cstav.genshinstrument.sound.NoteSound; -import com.cstav.genshinstrument.util.ModEntityData; +import com.cstav.genshinstrument.util.InstrumentEntityData; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -153,9 +153,9 @@ public void play() { final Player player = minecraft.player; - final BlockPos pos = ModEntityData.isInstrumentItem(player) + final BlockPos pos = InstrumentEntityData.isItem(player) ? player.blockPosition() - : ModEntityData.getInstrumentBlockPos(player); + : InstrumentEntityData.getBlockPos(player); // Send sound packet to server ModPacketHandler.sendToServer( diff --git a/src/main/java/com/cstav/genshinstrument/event/ClientEvents.java b/src/main/java/com/cstav/genshinstrument/event/ClientEvents.java index 3354bf5..8e6af8b 100644 --- a/src/main/java/com/cstav/genshinstrument/event/ClientEvents.java +++ b/src/main/java/com/cstav/genshinstrument/event/ClientEvents.java @@ -7,7 +7,7 @@ import com.cstav.genshinstrument.event.InstrumentPlayedEvent.InstrumentPlayedEventArgs; import com.cstav.genshinstrument.event.PosePlayerArmEvent.PosePlayerArmEventArgs; import com.cstav.genshinstrument.sound.NoteSound; -import com.cstav.genshinstrument.util.ModEntityData; +import com.cstav.genshinstrument.util.InstrumentEntityData; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -32,11 +32,11 @@ public static void register() { public static void posePlayerArmEvent(final PosePlayerArmEventArgs args) { final Player player = args.player; - if (!ModEntityData.isInstrumentOpen(player) || ModEntityData.isInstrumentItem(player)) + if (!InstrumentEntityData.isOpen(player) || InstrumentEntityData.isItem(player)) return; - final Block block = player.level().getBlockState(ModEntityData.getInstrumentBlockPos(player)).getBlock(); + final Block block = player.level().getBlockState(InstrumentEntityData.getBlockPos(player)).getBlock(); if (block instanceof AbstractInstrumentBlock blockInstrument) blockInstrument.onPosePlayerArm(args); } diff --git a/src/main/java/com/cstav/genshinstrument/event/InstrumentPlayedEvent.java b/src/main/java/com/cstav/genshinstrument/event/InstrumentPlayedEvent.java index ea77f2b..95e31ec 100644 --- a/src/main/java/com/cstav/genshinstrument/event/InstrumentPlayedEvent.java +++ b/src/main/java/com/cstav/genshinstrument/event/InstrumentPlayedEvent.java @@ -9,7 +9,7 @@ import com.cstav.genshinstrument.event.impl.ModEvent; import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier; import com.cstav.genshinstrument.sound.NoteSound; -import com.cstav.genshinstrument.util.ModEntityData; +import com.cstav.genshinstrument.util.InstrumentEntityData; import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; @@ -95,7 +95,7 @@ public ByPlayerArgs(NoteSound sound, int pitch, Player player, BlockPos pos, Opt } else { itemInstrument = Optional.empty(); this.hand = Optional.empty(); - blockInstrumentPos = Optional.ofNullable(ModEntityData.getInstrumentBlockPos(player)); + blockInstrumentPos = Optional.ofNullable(InstrumentEntityData.getBlockPos(player)); } } } diff --git a/src/main/java/com/cstav/genshinstrument/event/ServerEvents.java b/src/main/java/com/cstav/genshinstrument/event/ServerEvents.java new file mode 100644 index 0000000..78e3a22 --- /dev/null +++ b/src/main/java/com/cstav/genshinstrument/event/ServerEvents.java @@ -0,0 +1,37 @@ +package com.cstav.genshinstrument.event; + +import com.cstav.genshinstrument.item.InstrumentItem; +import com.cstav.genshinstrument.util.CommonUtil; +import com.cstav.genshinstrument.util.InstrumentEntityData; +import com.cstav.genshinstrument.util.ServerUtil; + +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; + +public abstract class ServerEvents { + + public static void register() { + ServerTickEvents.START_WORLD_TICK.register(ServerEvents::onServerTick); + } + + public static void onServerTick(final Level level) { + level.players().forEach(ServerEvents::handleAbruptInstrumentClose); + } + + private static void handleAbruptInstrumentClose(final Player player) { + if (!InstrumentEntityData.isOpen(player)) + return; + + if (InstrumentEntityData.isItem(player)) { + // This is done like so because there is no event (that I know of) for when an item is moved/removed + if (CommonUtil.getItemInHands(InstrumentItem.class, player).isEmpty()) + ServerUtil.setInstrumentClosed(player); + } else { + // Close an instrument block if the player is too far away + if (InstrumentEntityData.getBlockPos(player).closerToCenterThan(player.position(), 5)) + ServerUtil.setInstrumentClosed(player); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/cstav/genshinstrument/item/InstrumentItem.java b/src/main/java/com/cstav/genshinstrument/item/InstrumentItem.java index 0730e4e..1d44566 100644 --- a/src/main/java/com/cstav/genshinstrument/item/InstrumentItem.java +++ b/src/main/java/com/cstav/genshinstrument/item/InstrumentItem.java @@ -2,15 +2,12 @@ import com.cstav.genshinstrument.client.ModArmPose; import com.cstav.genshinstrument.client.gui.screens.instrument.partial.AbstractInstrumentScreen; -import com.cstav.genshinstrument.event.PosePlayerArmEvent; import com.cstav.genshinstrument.event.PosePlayerArmEvent.PosePlayerArmEventArgs; import com.cstav.genshinstrument.networking.OpenInstrumentPacketSender; -import com.cstav.genshinstrument.util.CommonUtil; import com.cstav.genshinstrument.util.ServerUtil; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; @@ -22,7 +19,7 @@ /** * An item responsible for opening an {@link AbstractInstrumentScreen}. */ -public class InstrumentItem extends Item { +public class InstrumentItem extends Item implements ItemPoseModifier { protected final OpenInstrumentPacketSender onOpenRequest; /** @@ -55,19 +52,9 @@ public InteractionResultHolder use(Level pLevel, Player pPlayer, Inte } - static { - if (FabricLoader.getInstance().getEnvironmentType() != EnvType.SERVER) - PosePlayerArmEvent.EVENT.register(InstrumentItem::itemArmPose); - } - @Environment(EnvType.CLIENT) - private static void itemArmPose(final PosePlayerArmEventArgs args) { - CommonUtil.getItemInHands(InstrumentItem.class, args.player).ifPresent((item) -> - item.onPosePlayerArm(args) - ); - } - + @Override @Environment(EnvType.CLIENT) - public void onPosePlayerArm(PosePlayerArmEventArgs args) { + public void onPosePlayerArm(final PosePlayerArmEventArgs args) { ModArmPose.poseForItemInstrument(args); } } diff --git a/src/main/java/com/cstav/genshinstrument/item/ItemPoseModifier.java b/src/main/java/com/cstav/genshinstrument/item/ItemPoseModifier.java new file mode 100644 index 0000000..a175d22 --- /dev/null +++ b/src/main/java/com/cstav/genshinstrument/item/ItemPoseModifier.java @@ -0,0 +1,26 @@ +package com.cstav.genshinstrument.item; + +import com.cstav.genshinstrument.event.PosePlayerArmEvent; +import com.cstav.genshinstrument.event.PosePlayerArmEvent.PosePlayerArmEventArgs; +import com.cstav.genshinstrument.util.CommonUtil; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +public interface ItemPoseModifier { + + @Environment(EnvType.CLIENT) + public static void register() { + PosePlayerArmEvent.EVENT.register((args) -> { + + CommonUtil.getItemInHands(ItemPoseModifier.class, args.player).ifPresent((item) -> + item.onPosePlayerArm(args) + ); + + }); + } + + @Environment(EnvType.CLIENT) + void onPosePlayerArm(final PosePlayerArmEventArgs args); + +} diff --git a/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/CloseInstrumentPacket.java b/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/CloseInstrumentPacket.java index 2e7df33..76fa57f 100644 --- a/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/CloseInstrumentPacket.java +++ b/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/CloseInstrumentPacket.java @@ -2,7 +2,7 @@ import com.cstav.genshinstrument.networking.IModPacket; import com.cstav.genshinstrument.networking.ModPacketHandler; -import com.cstav.genshinstrument.util.ModEntityData; +import com.cstav.genshinstrument.util.InstrumentEntityData; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.minecraft.network.FriendlyByteBuf; @@ -17,7 +17,7 @@ public CloseInstrumentPacket(FriendlyByteBuf buf) {} @Override public void handle(Player player, PacketSender responseSender) { - ModEntityData.setInstrumentClosed(player); + InstrumentEntityData.setClosed(player); for (final Player oPlayer : player.level().players()) ModPacketHandler.sendToClient(new NotifyInstrumentOpenPacket(player.getUUID(), false), (ServerPlayer)oPlayer); diff --git a/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/InstrumentPacket.java b/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/InstrumentPacket.java index 2679185..bfd022a 100644 --- a/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/InstrumentPacket.java +++ b/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/InstrumentPacket.java @@ -5,7 +5,7 @@ import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier; import com.cstav.genshinstrument.networking.packets.INoteIdentifierSender; import com.cstav.genshinstrument.sound.NoteSound; -import com.cstav.genshinstrument.util.ModEntityData; +import com.cstav.genshinstrument.util.InstrumentEntityData; import com.cstav.genshinstrument.util.ServerUtil; import net.fabricmc.fabric.api.networking.v1.PacketSender; @@ -60,7 +60,7 @@ public void write(final FriendlyByteBuf buf) { @Override public void handle(Player player, PacketSender responseSender) { - if (!ModEntityData.isInstrumentOpen(player)) + if (!InstrumentEntityData.isOpen(player)) return; ServerUtil.sendPlayNotePackets((ServerPlayer)player, pos, hand, sound, instrumentId, noteIdentifier, pitch); diff --git a/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/NotifyInstrumentOpenPacket.java b/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/NotifyInstrumentOpenPacket.java index ad556f6..f8e0531 100644 --- a/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/NotifyInstrumentOpenPacket.java +++ b/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/NotifyInstrumentOpenPacket.java @@ -4,7 +4,7 @@ import java.util.UUID; import com.cstav.genshinstrument.networking.IModPacket; -import com.cstav.genshinstrument.util.ModEntityData; +import com.cstav.genshinstrument.util.InstrumentEntityData; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.minecraft.client.Minecraft; @@ -57,12 +57,12 @@ public void handle(Player player, PacketSender responseSender) { if (isOpen) { if (pos.isPresent()) - ModEntityData.setInstrumentOpen(_player, pos.get()); + InstrumentEntityData.setOpen(_player, pos.get()); else - ModEntityData.setInstrumentOpen(_player); + InstrumentEntityData.setOpen(_player); } else - ModEntityData.setInstrumentClosed(_player); + InstrumentEntityData.setClosed(_player); } } diff --git a/src/main/java/com/cstav/genshinstrument/util/CommonUtil.java b/src/main/java/com/cstav/genshinstrument/util/CommonUtil.java index 4ab5aa7..912421b 100644 --- a/src/main/java/com/cstav/genshinstrument/util/CommonUtil.java +++ b/src/main/java/com/cstav/genshinstrument/util/CommonUtil.java @@ -15,7 +15,7 @@ public abstract class CommonUtil { @SuppressWarnings("unchecked") - public static Optional getItemInHands(final Class item, final Player player) { + public static Optional getItemInHands(final Class item, final Player player) { final Item mainItem = player.getItemInHand(InteractionHand.MAIN_HAND).getItem(), offItem = player.getItemInHand(InteractionHand.OFF_HAND).getItem(); diff --git a/src/main/java/com/cstav/genshinstrument/util/ModEntityData.java b/src/main/java/com/cstav/genshinstrument/util/InstrumentEntityData.java similarity index 70% rename from src/main/java/com/cstav/genshinstrument/util/ModEntityData.java rename to src/main/java/com/cstav/genshinstrument/util/InstrumentEntityData.java index 5f497a2..91c0abf 100644 --- a/src/main/java/com/cstav/genshinstrument/util/ModEntityData.java +++ b/src/main/java/com/cstav/genshinstrument/util/InstrumentEntityData.java @@ -8,8 +8,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; -//TODO: Change to "InstrumentEntityData" and remove all "instruments" from method names -public abstract class ModEntityData { +public abstract class InstrumentEntityData { public static final String OPEN_TAG = "instrumentOpen", IS_ITEM_TAG = "isItem", BLOCK_POS_TAG = "blockPos"; @@ -19,34 +18,34 @@ public static CompoundTag getModTag(final Entity entity) { } - public static boolean isInstrumentOpen(final Player player) { + public static boolean isOpen(final Player player) { return getModTag(player).getBoolean(OPEN_TAG); } - public static boolean isInstrumentItem(final Player player) { + public static boolean isItem(final Player player) { return getModTag(player).getBoolean(IS_ITEM_TAG); } - public static BlockPos getInstrumentBlockPos(final Player player) { + public static BlockPos getBlockPos(final Player player) { final CompoundTag posTag = getModTag(player).getCompound(BLOCK_POS_TAG); return posTag.isEmpty() ? null : NbtUtils.readBlockPos(posTag); } - public static void setInstrumentOpen(final Player player, final BlockPos pos) { + public static void setOpen(final Player player, final BlockPos pos) { final CompoundTag modTag = getModTag(player); modTag.putBoolean(OPEN_TAG, true); modTag.put(BLOCK_POS_TAG, NbtUtils.writeBlockPos(pos)); modTag.putBoolean(IS_ITEM_TAG, false); } - public static void setInstrumentOpen(final Player player) { + public static void setOpen(final Player player) { final CompoundTag modTag = getModTag(player); modTag.putBoolean(OPEN_TAG, true); modTag.putBoolean(IS_ITEM_TAG, true); } - public static void setInstrumentClosed(final Player player) { + public static void setClosed(final Player player) { getModTag(player).putBoolean(OPEN_TAG, false); } diff --git a/src/main/java/com/cstav/genshinstrument/util/ServerUtil.java b/src/main/java/com/cstav/genshinstrument/util/ServerUtil.java index 397d2ab..ac2e45d 100644 --- a/src/main/java/com/cstav/genshinstrument/util/ServerUtil.java +++ b/src/main/java/com/cstav/genshinstrument/util/ServerUtil.java @@ -143,6 +143,20 @@ private static List noteListeners(Level level, BlockPos pos) { } + public static void setInstrumentClosed(final Player player) { + // Update the the capabilty on server + InstrumentEntityData.setClosed(player); + + // And clients + player.level().players().forEach((nearbyPlayer) -> + ModPacketHandler.sendToClient( + new NotifyInstrumentOpenPacket(player.getUUID(), false), + (ServerPlayer)nearbyPlayer + ) + ); + } + + /** * Gets a {@link NoteButtonIdentifier} as described by the {@code classType} destination. * Will only return a class type if it is valid and included in the {@code acceptableIdentifiers} list. @@ -184,9 +198,9 @@ private static boolean sendOpenPacket(ServerPlayer player, InteractionHand usedH // Update the the capabilty on server if (pos == null) - ModEntityData.setInstrumentOpen(player); + InstrumentEntityData.setOpen(player); else - ModEntityData.setInstrumentOpen(player, pos); + InstrumentEntityData.setOpen(player, pos); // And clients final Optional playPos = Optional.ofNullable(pos); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8c799d0..e67c001 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "genshinstrument", - "version": "3.2.2.1", + "version": "3.2.3", "name": "Genshin Instruments", "description": "A mod that brings Genshin Impact's instruments to Minecraft!\nThis is my first ever published mod, and I am quite proud of it :')\nHope you enjoy it as much as I do!!", "authors": [