Skip to content

Commit

Permalink
feat: Open waystone settings even if waystone blocks are shift-clicke…
Browse files Browse the repository at this point in the history
…d with an item in hand
  • Loading branch information
BlayTheNinth committed Dec 27, 2023
1 parent bd3c377 commit fa4e80c
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package net.blay09.mods.waystones.client;

import net.blay09.mods.balm.api.Balm;
import net.blay09.mods.balm.api.client.BalmClient;
import net.blay09.mods.balm.api.event.client.UseItemInputEvent;
import net.blay09.mods.waystones.InternalClientMethodsImpl;
import net.blay09.mods.waystones.api.client.WaystonesClientAPI;
import net.blay09.mods.waystones.block.entity.WaystoneBlockEntityBase;
import net.blay09.mods.waystones.client.requirement.RequirementClientRegistry;
import net.blay09.mods.waystones.compat.Compat;
import net.blay09.mods.waystones.network.message.RequestEditWaystoneMessage;
import net.minecraft.client.ClientBrandRetriever;
import net.minecraft.client.Minecraft;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;

import java.util.Locale;

Expand All @@ -22,5 +29,22 @@ public static void initialize() {
InventoryButtonGuiHandler.initialize();

Compat.isVivecraftInstalled = ClientBrandRetriever.getClientModName().toLowerCase(Locale.ENGLISH).contains(Compat.VIVECRAFT);

Balm.getEvents().onEvent(UseItemInputEvent.class, event -> {
final var mc = Minecraft.getInstance();
if (mc.level == null || mc.player == null || mc.hitResult == null || mc.hitResult.getType() != HitResult.Type.BLOCK) {
return;
}

if (mc.player.isShiftKeyDown()) {
final var blockHitResult = (BlockHitResult) mc.hitResult;
final var targetBlockEntity = mc.level.getBlockEntity(blockHitResult.getBlockPos());
if (targetBlockEntity instanceof WaystoneBlockEntityBase waystoneBlockEntity) {
Balm.getNetworking().sendToServer(new RequestEditWaystoneMessage(waystoneBlockEntity.getBlockPos()));
mc.player.swing(event.getHand());
event.setCanceled(true);
}
}
});
}
}

0 comments on commit fa4e80c

Please sign in to comment.