PON Wxd

make me a mob can auto place tnt mincart when i place reil and not just place i want to go the tnt mincart hotbare and place it mod for 1.21.11 fibrce

Kodari AI
KodariToday at 7:02 pm 5
AutoTNTMinecartPlacer
Automatically places TNT minecarts on rails when the player places a rail block. Instead of requiring manual placement, the mod detects rail placement events, retrieves a TNT minecart from the player's hotbar, and places it on the rail automatically. Works with all rail types including powered, detector, and activator rails. Includes configurable toggle and hotbar slot preference settings.
  • Detect successful rail placement on the client.

  • Switch to a TNT minecart in the hotbar and place it on the new rail.

Created the client-side Fabric 1.21.11 mod. Put TNT minecarts in your hotbar, then place a rail: the mod selects a minecart and places it on the rail.

You’ll need to reselect your rails to place another one. The mod uses your existing items; it doesn’t create extra minecarts.

PON Wxd

make me a mod can auto place tnt mincart when i place reil and not just place i want to go the tnt mincart hotbare and place it mod for 1.21.11 fibrce

Kodari AI
KodariToday at 7:03 pm 1

The mod already does this: put TNT minecarts in your hotbar and place a rail. It switches to the minecart slot and attempts to place one on the rail.

You’ll need to select your rails again for the next placement.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
7 167
src/client/java/com/kodari/autotnt/AutoTntMinecartClient.java
package com.kodari.autotnt;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.block.AbstractRailBlock;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.item.Items;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;

public class AutoTntMinecartClient implements ClientModInitializer {
    private static BlockPos pendingRail;
    private static ClientWorld pendingWorld;

    public static void queueRail(ClientWorld world, BlockPos pos) {
        pendingWorld = world;
        pendingRail = pos.toImmutable();
    }

    @Override
    public void onInitializeClient() {
        ClientTickEvents.END_CLIENT_TICK.register(AutoTntMinecartClient::onTick);
    }

    private static void onTick(MinecraftClient client) {
        BlockPos pos = pendingRail;
        ClientWorld world = pendingWorld;
        pendingRail = null;
        pendingWorld = null;
        if (pos == null || world != client.world || client.player == null || client.interactionManager == null
                || !AbstractRailBlock.isRail(world, pos)) {
            return;
        }
        for (int slot = 0; slot < 9; slot++) {
            if (client.player.getInventory().getStack(slot).isOf(Items.TNT_MINECART)) {
                client.player.getInventory().setSelectedSlot(slot);
                client.interactionManager.interactBlock(client.player, Hand.MAIN_HAND,
                        new BlockHitResult(Vec3d.ofCenter(pos), Direction.UP, pos, false));
                return;
            }
        }
    }
}