voidsensei07

create a mod that support the minecraft latest version 1.20.11 in this mod when im stuck in a cobweb then if i have waterbucket in my inventory when my crosshair point on cobweb it automatically places cobweb.There should be an keybind which we can change in setting after clicking on the key a menu pop up a there will be an on/off button for this mod.

Kodari AI
KodariFeb 5 at 8:49 am 1,728 (v2)

I’ll create a Fabric mod for Minecraft 1.20.11 that automatically places water from a bucket when stuck in cobwebs and aiming at them, with a configurable keybind to toggle the feature via a simple menu.

CobwebWaterPlacer
A Fabric mod for Minecraft 1.20.11 that automatically places water from a bucket when the player is stuck in a cobweb and aims at it. Includes a configurable keybind to toggle the feature on/off via a simple menu.
  • Set up basic Fabric mod structure with fabric.mod.json, build.gradle, and main classes

  • Implement client-side cobweb detection, inventory checking, and auto water placement logic

  • Add keybind registration and toggle screen with on/off button

  • Create language file for UI and keybind text

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
Code
8 184
src/main/java/com/example/cobwebwaterplacer/client/CobwebWaterPlacerClient.java
package com.example.cobwebwaterplacer.client;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.world.World;
import org.lwjgl.glfw.GLFW;

public class CobwebWaterPlacerClient implements ClientModInitializer {
    public static boolean enabled = true;
    private static KeyBinding toggleKey;

    @Override
    public void onInitializeClient() {
        toggleKey = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.cobwebwaterplacer.toggle", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, "category.cobwebwaterplacer"));
        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            if (toggleKey.wasPressed()) {
                client.setScreen(new ToggleScreen());
            }
            if (!enabled) {
                return;
            }
            ClientPlayerEntity player = client.player;
            if (player == null) {
                return;
            }
            World world = player.getWorld();
            if (!world.getBlockState(player.getBlockPos()).isOf(net.minecraft.block.Blocks.COBWEB)) {
                return;
            }
            int bucketSlot = -1;
            for (int i = 0; i < player.getInventory().size(); i++) {
                if (player.getInventory().getStack(i).isOf(Items.WATER_BUCKET)) {
                    bucketSlot = i;
                    break;
                }
            }
            if (bucketSlot == -1) {
                return;
            }
            if (!(client.crosshairTarget instanceof BlockHitResult hit)) {
                return;
            }
            if (!world.getBlockState(hit.getBlockPos()).isOf(net.minecraft.block.Blocks.COBWEB)) {
                return;
            }
            int currentSlot = player.getInventory().selectedSlot;
            ItemStack currentStack = player.getInventory().getStack(currentSlot);
            player.getInventory().setStack(currentSlot, player.getInventory().getStack(bucketSlot));
            player.getInventory().setStack(bucketSlot, currentStack);
            client.interactionManager.interactBlock(player, Hand.MAIN_HAND, hit);
            player.getInventory().setStack(bucketSlot, player.getInventory().getStack(currentSlot));
            player.getInventory().setStack(currentSlot, currentStack);
        });
    }
}