good_hotdog

Develop a plugin that allows players to press "M" to automatically construct a predefined house structure in front of them. Include customizable house templates, configurable build distance, and permission settings to control which players can use the feature. Add a cooldown timer to prevent spamming and ensure it's compatible with various block types.

Kodari AI
KodariApr 17 at 5:55 pm 37,471 (v2)
InstantHouseBuilder
A Fabric 1.21.4 mod that lets players press M to instantly construct a predefined house structure in front of them. Features multiple house templates (small, medium, large), configurable build distance, per-template permission nodes, and a per-player cooldown timer to prevent spam. Templates define block palettes and 3D layouts, and structures are placed relative to the player's facing direction with proper rotation support.

Let me read the necessary docs before writing any code.

Now let me read the mixin and networking docs since I need client key binding and server-side structure placement.

InstantHouseBuilder
A Fabric 1.21.4 mod letting players press M to instantly build a predefined house structure in front of them. Offers three templates (Small, Medium, Large) cycled with a second key binding. Structure placement respects the player's facing direction with full rotation support. Includes per-template permission levels, configurable build distance and cooldown timer, plus an admin command for manual construction and config reload.

Now I have all the information I need. Let me plan before writing:

  • Key binding (client) sends BuildHousePayload (C2S) with template name → server validates permission, cooldown, then calls StructurePlacer

  • HouseTemplate enum holds 3D char-based block layouts parsed into BlockEntry lists; placement uses player facing with computed right-vector for rotation

  • ConfigManager (Gson JSON) stores build distance, cooldown, per-template permission levels; CooldownManager tracks UUID→lastBuildTime

  • Admin command /house <template> for manual builds and /house reload for config reload

  • No mixins needed — key binding uses ClientTickEvents, interaction uses networking

Good — blank slate. Creating all files now.

All 15 files are created. Here’s a summary of what was built:

  • Key bindings: M builds the selected house template; N cycles through Small → Medium → Large with an action bar notification

  • 3 house templates: Small (5×5×5), Medium (7×7×6), Large (9×9×7) — each defined as char-grid layers (F=planks, L=oak log, G=glass, R=slab, space=skip) with a 2-block-tall entrance facing the player

  • Rotation support: StructurePlacer computes forward/right vectors from player.getHorizontalFacing() and transforms all template coordinates so the entrance always faces the player regardless of direction

  • Cooldown: CooldownManager tracks per-UUID last-build timestamps; commands bypass cooldown

  • Config (instanthouse.json): configurable buildDistance, cooldownSeconds, and per-template permission levels (Large defaults to op-only)

  • Commands: /house build <template> (op-only) for admin manual builds, /house reload to hot-reload config, /house cooldown clear <player> to manually reset cooldowns

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
15 585
src/client/java/com/instanthouse/InstantHouseBuilderClient.java
package com.instanthouse;

import com.instanthouse.house.HouseTemplate;
import com.instanthouse.network.BuildHousePayload;
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.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;

public class InstantHouseBuilderClient implements ClientModInitializer {
    private static KeyBinding buildKey;
    private static KeyBinding cycleKey;
    private static HouseTemplate selectedTemplate = HouseTemplate.SMALL;

    @Override
    public void onInitializeClient() {
        buildKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
                "key.instanthouse.build",
                InputUtil.Type.KEYSYM,
                GLFW.GLFW_KEY_M,
                "key.categories.instanthouse"
        ));

        cycleKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
                "key.instanthouse.cycle",
                InputUtil.Type.KEYSYM,
                GLFW.GLFW_KEY_N,
                "key.categories.instanthouse"
        ));

        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            while (cycleKey.wasPressed()) {
                selectedTemplate = selectedTemplate.next();
                if (client.player != null) {
                    client.player.sendMessage(
                            Text.translatable("instanthouse.message.template_selected",
                                    Text.translatable(selectedTemplate.getTranslationKey())),
                            true
                    );
                }
            }

            while (buildKey.wasPressed()) {
                if (client.player != null && client.currentScreen == null) {
                    ClientPlayNetworking.send(new BuildHousePayload(selectedTemplate.name()));
                }
            }
        });
    }

    public static HouseTemplate getSelectedTemplate() {
        return selectedTemplate;
    }
}