I.G Vvv

Make a candyland dimension

Kodari AI
KodariNov 8 at 11:07 pm 2
CandylandDimension
Adds a whimsical Candyland dimension accessible through a portal. The dimension features terrain made of candy blocks including chocolate, gumdrops, and lollipops. Players can craft a special portal frame using sugar blocks and activate it with a golden apple. The dimension includes unique mobs like gingerbread men and candy slimes, plus custom ore generation for candy crystals used in crafting powerful sweets-themed items. Includes dimension registry, biome generation, custom block registration, and portal mechanics for seamless travel between overworld and Candyland.
  • Create a pastel Candyland dimension with cherry-grove scenery and candy-colored layers.

  • Open it in survival by using sugar on a placed cake; use the same action to return.

Created Candyland: a cherry-grove dimension with pastel-colored underground layers.

In survival, place a cake and use sugar on it to travel there. Place another cake and use sugar on it to return to the Overworld.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 136
src/main/java/com/kodari/candyland/Candyland.java
package com.kodari.candyland;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.portal.TeleportTransition;
import net.minecraft.world.phys.Vec3;

public class Candyland implements ModInitializer {
    private static final ResourceKey<Level> CANDYLAND = ResourceKey.create(
            Registries.DIMENSION, Identifier.fromNamespaceAndPath("candyland", "candyland"));

    @Override
    public void onInitialize() {
        UseBlockCallback.EVENT.register((player, level, hand, hit) -> {
            if (!player.getItemInHand(hand).is(Items.SUGAR)
                    || !level.getBlockState(hit.getBlockPos()).is(Blocks.CAKE)) {
                return InteractionResult.PASS;
            }
            if (!(player instanceof ServerPlayer serverPlayer)) {
                return InteractionResult.SUCCESS;
            }
            ResourceKey<Level> target = level.dimension().equals(CANDYLAND) ? Level.OVERWORLD : CANDYLAND;
            ServerLevel destination = serverPlayer.level().getServer().getLevel(target);
            if (destination == null) {
                return InteractionResult.PASS;
            }
            BlockPos surface = destination.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES,
                    new BlockPos(hit.getBlockPos().getX(), 0, hit.getBlockPos().getZ()));
            serverPlayer.teleport(new TeleportTransition(destination,
                    new Vec3(surface.getX() + 0.5, surface.getY(), surface.getZ() + 0.5),
                    Vec3.ZERO, serverPlayer.getYRot(), serverPlayer.getXRot(), TeleportTransition.DO_NOTHING));
            return InteractionResult.SUCCESS_SERVER;
        });
    }
}