From 8176e705b164973bcc198b63b5572587ae50f353 Mon Sep 17 00:00:00 2001 From: GeorgeRNG Date: Sat, 19 Aug 2023 13:40:56 +0100 Subject: [PATCH 1/7] scope switcher finish later --- .../codeclient/dev/InteractionManager.java | 27 +++++++- .../MClientPlayerInteractionManager.java | 7 ++ .../codeclient/switcher/GenericSwitcher.java | 4 +- .../codeclient/switcher/ScopeSwitcher.java | 64 +++++++++++++++++++ 4 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 src/main/java/dev/dfonline/codeclient/switcher/ScopeSwitcher.java diff --git a/src/main/java/dev/dfonline/codeclient/dev/InteractionManager.java b/src/main/java/dev/dfonline/codeclient/dev/InteractionManager.java index d2180e39..a539ca23 100644 --- a/src/main/java/dev/dfonline/codeclient/dev/InteractionManager.java +++ b/src/main/java/dev/dfonline/codeclient/dev/InteractionManager.java @@ -7,6 +7,7 @@ import dev.dfonline.codeclient.Utility; import dev.dfonline.codeclient.config.Config; import dev.dfonline.codeclient.location.Dev; +import dev.dfonline.codeclient.switcher.ScopeSwitcher; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import net.minecraft.block.Block; @@ -15,6 +16,7 @@ import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.EntityDimensions; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; @@ -189,7 +191,7 @@ public static BlockPos getPlacePos(BlockHitResult hitResult) { public static BlockHitResult onBlockInteract(BlockHitResult hitResult) { if(CodeClient.location instanceof Dev plot) { BlockPos pos = hitResult.getBlockPos(); - if(plot.isInCodeSpace(pos.getX(), plot.getZ()) && pos.getY() % 5 == 4) { // Is a code space level (glass) + if(plot.isInDev(pos) && pos.getY() % 5 == 4) { // Is a code space level (glass) if(hitResult.getSide() == Direction.UP || hitResult.getSide() == Direction.DOWN) { if(CodeClient.MC.world.getBlockState(pos).isAir() && Config.getConfig().PlaceOnAir) return new BlockHitResult(hitResult.getPos(),Direction.UP,hitResult.getBlockPos().add(0,1,0),hitResult.isInsideBlock()); if(Config.getConfig().CustomBlockInteractions) return new BlockHitResult(hitResult.getPos(), Direction.UP, hitResult.getBlockPos(), hitResult.isInsideBlock()); @@ -202,6 +204,27 @@ public static BlockHitResult onBlockInteract(BlockHitResult hitResult) { } return hitResult; } + + public static boolean onItemInteract(PlayerEntity player, Hand hand) { +// if(!player.isSneaking()) return false; + + ItemStack stack = player.getStackInHand(hand); + + NbtCompound nbt = stack.getNbt(); + if(nbt == null) return false; + NbtCompound pbv = (NbtCompound) nbt.get("PublicBukkitValues"); + if(pbv == null) return false; + NbtString varItem = (NbtString) pbv.get("hypercube:varitem"); + if(varItem == null) return false; + JsonObject var = JsonParser.parseString(varItem.asString()).getAsJsonObject(); + if(!var.get("id").getAsString().equals("var")) return false; + JsonObject data = var.get("data").getAsJsonObject(); + String scopeName = data.get("scope").getAsString(); + + CodeClient.MC.setScreen(new ScopeSwitcher(scopeName)); + return true; + } + // public static boolean onBlockInteract(ClientPlayerEntity player, Hand hand, BlockHitResult hitResult) { // MinecraftClient MC = CodeClient.MC; // if(CodeClient.location instanceof Dev plot && plot.isInCodeSpace(hitResult.getPos().getX(), hitResult.getPos().getZ())) { @@ -265,7 +288,7 @@ public static BlockHitResult onBlockInteract(BlockHitResult hitResult) { public static VoxelShape customVoxelShape(BlockView world, BlockPos pos) { if(CodeClient.MC != null && CodeClient.MC.player != null && CodeClient.location instanceof Dev plot) { Config.LayerInteractionMode mode = Config.getConfig().CodeLayerInteractionMode; - Boolean isInDev = plot.isInDev(pos.toCenterPos()); + Boolean isInDev = plot.isInDev(pos); boolean isLevel = isInDev != null && isInDev && pos.getY() % 5 == 4; boolean noClipAllowsBlock = Config.getConfig().NoClipEnabled || world.getBlockState(pos).isAir(); boolean hideCodeSpace = diff --git a/src/main/java/dev/dfonline/codeclient/mixin/entity/player/MClientPlayerInteractionManager.java b/src/main/java/dev/dfonline/codeclient/mixin/entity/player/MClientPlayerInteractionManager.java index 05bee13f..931772a8 100644 --- a/src/main/java/dev/dfonline/codeclient/mixin/entity/player/MClientPlayerInteractionManager.java +++ b/src/main/java/dev/dfonline/codeclient/mixin/entity/player/MClientPlayerInteractionManager.java @@ -71,6 +71,13 @@ public void interactItemMovement(ClientPlayNetworkHandler instance, Packet pa } } + @Inject(method = "interactItem", at = @At("HEAD"), cancellable = true) + public void interactItem(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { + if(InteractionManager.onItemInteract(player, hand)) { + cir.setReturnValue(ActionResult.PASS); + } + } + @Inject(method = "clickSlot", at = @At("HEAD"), cancellable = true) private void clickSlot(int syncId, int slotId, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) { if(slotId < 0) return; diff --git a/src/main/java/dev/dfonline/codeclient/switcher/GenericSwitcher.java b/src/main/java/dev/dfonline/codeclient/switcher/GenericSwitcher.java index 9671458d..494569aa 100644 --- a/src/main/java/dev/dfonline/codeclient/switcher/GenericSwitcher.java +++ b/src/main/java/dev/dfonline/codeclient/switcher/GenericSwitcher.java @@ -113,7 +113,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { return super.keyPressed(keyCode, scanCode, modifiers); } - private boolean checkFinished() { + protected boolean checkFinished() { if(this.client == null) return false; if(!InputUtil.isKeyPressed(this.client.getWindow().getHandle(), HOLD_KEY)) { Option selected = getSelected(); @@ -124,7 +124,7 @@ private boolean checkFinished() { return false; } - private Option getSelected() { + protected Option getSelected() { List