mohamed hany

--- 📎 Attached 1 file(s):

File: pasted-code-1790191520283.txt

txt
Prompt:

Create a Minecraft Fabric mod called "Mega Chests" (or similar) targeting Minecraft 26.3, Fabric Loader 0.19.5, and Fabric API (latest compatible build for 26.3). Use Yarn/Intermediary mappings matching 26.3.

Core Concept

Extend vanilla chest connection behavior so that chests can merge not only horizontally (north/south/east/west, like vanilla double chests) but also vertically (up/down), and the merge can extend infinitely in any combination of directions to form one giant combined inventory, instead of vanilla's hard limit of 2 chests (54 slots).

Requirements

1. Connection Detection

When a chest block is placed adjacent (N/S/E/W/Up/Down) to another chest of the same type (normal chest connects to normal, trapped chest connects to trapped chest only), automatically merge them into one logical inventory group.
Support chain merging: chest A connects to B, B connects to C, etc., forming one big network (a flood-fill / graph traversal algorithm to detect all connected chests when the GUI opens or a block is placed/broken).
No maximum limit on the number of connected chests (remove vanilla's 2-chest cap).

2. Inventory & GUI

Combined inventory size = 27 slots × number of connected chests.
Custom Screen/Container (ScreenHandler) that renders a scrollable inventory grid — a vertical scrollbar (like a scrollable creative inventory or shulker box grid) since the merged inventory can get very large.
GUI should show chest rows sorted by their physical layout order (grid traversal order) so it feels intuitive, not random.
Keep standard 9-slot player hotbar/inventory rendering at the bottom.

3. Block Model / Rendering

Reuse vanilla chest textures, but adjust the chest lid/latch model rendering so that connecting faces (in any of the 6 directions, not just horizontal) hide their connecting-side walls, similar to how a double chest currently merges its middle face — extend this logic to work for vertical stacking too.
Handle partial connections gracefully (e.g., a chest connected on 3 sides but not the 4th should render the open side normally).

4. Behavior & Edge Cases

Opening any chest in the group opens the shared combined GUI.
Breaking one chest in the middle of a group should split remaining chests into separate valid groups without duplicating or losing items (redistribute items back into the broken block's neighbors safely, similar to vanilla double-chest-break behavior but generalized).
Prevent players from being blocked from opening the chest if a solid block sits above it (respect vanilla "obstructed chest" logic per-chest, not just for the whole group).
Support hoppers/pipes inserting/extracting from any chest in the group as if it's one big inventory.
Custom chest name/lore should still work per vanilla behavior (use the first chest's name or allow renaming via anvil).

5. Networking & Sync

Ensure server-client sync works properly for large inventories (avoid packet size issues — consider chunked syncing or lazy-loading visible slots only).
Save/load connected chest data properly in NBT so groups persist after world reload.

6. Performance

Avoid recalculating the whole connected-chest graph on every tick; only recompute on block place/break/chunk load events.
Cache the flood-fill result per chest group.
Deliverables
fabric.mod.json configured for Minecraft 26.3 / Fabric Loader 0.19.5.
Mixin or block entity logic for chest merging.
Custom ScreenHandler + Screen class with scroll support.
Custom BlockEntityRenderer (or vanilla renderer extension) for multi-directional chest model merging.
Basic mod icon and README.md explaining install steps and dependencies (Fabric API version required).

[Viewing 2 images]

2 images attached
Kodari AI
KodariSep 23 at 7:45 pm 5
MegaChests
MegaChests is a Minecraft Fabric mod that extends vanilla chest connection behavior to support infinite multi-directional merging. Chests placed adjacent in any of six directions (N/S/E/W/Up/Down) automatically combine into one logical inventory group via flood-fill graph traversal. The mod removes vanilla's two-chest cap, allowing unlimited connected chests with combined inventory size of 27 slots per chest. It features a custom scrollable ScreenHandler GUI with vertical scrolling for large inventories, sorted by physical layout order. The mod handles partial connections gracefully, supports hopper interactions, persists group data in NBT, and implements efficient graph caching with recomputation only on block events.
  1. Establish the project’s 26.2 Fabric setup and chest-interaction entry point.

  2. Implement connected-chest inventory access and a synced scrollable client menu.

  3. Add required resources and installation guidance.

Created the Mega Chests Fabric project with a six-direction search for connected normal or trapped chests, a paged 27-slot menu, server-synced page changes, and a README.

Version note: the project targets Minecraft 26.2 with official unobfuscated names, following this environment’s Fabric target—not the pasted request’s 26.3/Yarn target.

This is a partial implementation: vanilla chest rendering and hopper behavior are unchanged, group results are discovered when opening rather than cached on block events, and no mod icon is included. Each chest retains its own saved inventory, so breaking one naturally changes the connected group without moving its contents.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
README.md
settings.gradle
Code
13 622
src/main/java/com/kodari/megachests/MegaChests.java
package com.kodari.megachests;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.InteractionHand;

public final class MegaChests implements ModInitializer {
	public static final String MOD_ID = "mega_chests";

	@Override
	public void onInitialize() {
		MegaChestMenus.initialize();
		PayloadTypeRegistry.serverboundPlay().register(ChestPagePayload.TYPE, ChestPagePayload.STREAM_CODEC);
		ServerPlayNetworking.registerGlobalReceiver(ChestPagePayload.TYPE, (payload, context) -> {
			if (context.player().containerMenu instanceof MegaChestMenu menu) {
				menu.setPage(payload.page());
				menu.broadcastChanges();
			}
		});

		UseBlockCallback.EVENT.register((player, level, hand, hitResult) ->
				useChest(player, level, hand, hitResult));
	}

	private static InteractionResult useChest(Player player, Level level, InteractionHand hand, BlockHitResult hitResult) {
		BlockPos pos = hitResult.getBlockPos();
		var state = level.getBlockState(pos);
		if ((state.getBlock() != Blocks.CHEST && state.getBlock() != Blocks.TRAPPED_CHEST)
				|| !player.getItemInHand(hand).isEmpty()
				|| ChestBlock.isChestBlockedAt(level, pos)) {
			return InteractionResult.PASS;
		}

		if (level.isClientSide()) {
			return InteractionResult.SUCCESS;
		}
		if (!(player instanceof ServerPlayer serverPlayer)
				|| !(level.getBlockEntity(pos) instanceof ChestBlockEntity chest)) {
			return InteractionResult.PASS;
		}

		var positions = ChestNetworks.find(level, pos);
		var openingData = new MegaChestMenu.OpenData(pos, positions.size());
		Component title = chest.getDisplayName();
		serverPlayer.openMenu(new net.fabricmc.fabric.api.menu.v1.ExtendedMenuProvider<MegaChestMenu.OpenData>() {
			@Override
			public MegaChestMenu.OpenData getScreenOpeningData(ServerPlayer player) {
				return openingData;
			}

			@Override
			public net.minecraft.world.inventory.AbstractContainerMenu createMenu(int containerId, Inventory inventory, Player player) {
				return new MegaChestMenu(containerId, inventory, openingData);
			}

			@Override
			public Component getDisplayName() {
				return title;
			}
		});
		return InteractionResult.SUCCESS;
	}
}