January 26

Каб

1️⃣ Структура проекта

SkyDimensionMod/
├─ src/main/java/com/alidar/skydimension/
│ ├─ SkyDimensionMod.java # Main класс мода
│ ├─ item/DreamActivatorItem.java # Предмет "Активатор грёз"
│ └─ dimension/SkyChunkGenerator.java # Генератор измерения
│ └─ dimension/SkyDimension.java # Телепортация и логика измерения
├─ src/main/resources/
│ ├─ assets/skydimension/
│ │ ├─ item/
│ │ │ └─ dream_activator.png # Твоя текстура
│ │ └─ models/item/dream_activator.json
│ └─ data/skydimension/recipes/dream_activator.json
└─ fabric.mod.json

2️⃣ fabric.mod.json

{
"schemaVersion": 1,
"id": "skydimension",
"version": "1.0.0",
"name": "Sky Dimension Mod",
"description": "Мод с измерением Грез, островами, деревьями, овцами и алмазами.",
"authors": ["Alidar"],
"contact": {},
"license": "MIT",
"environment": "*",
"entrypoints": {
"main": ["com.alidar.skydimension.SkyDimensionMod"]
},
"depends": {
"fabric": "*",
"minecraft": "1.21.5"
}
}

3️⃣ Main класс: SkyDimensionMod.java

package com.alidar.skydimension;

import net.fabricmc.api.ModInitializer;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;

import com.alidar.skydimension.item.DreamActivatorItem;

public class SkyDimensionMod implements ModInitializer {

public static final Item DREAM_ACTIVATOR = new DreamActivatorItem();

@Override
public void onInitialize() {
// Регистрация предмета
Registry.register(Registry.ITEM, new ResourceLocation("skydimension", "dream_activator"), DREAM_ACTIVATOR);
System.out.println("SkyDimensionMod инициализирован!");
}
}

4️⃣ Предмет: DreamActivatorItem.java

package com.alidar.skydimension.item;

import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;

import com.alidar.skydimension.dimension.SkyDimension;

public class DreamActivatorItem extends Item {

public DreamActivatorItem() {
super(new FabricItemSettings().stacksTo(1));
}

@Override
public InteractionResult useOn(UseOnContext context) {
Player player = context.getPlayer();
Level world = context.getLevel();

if (!world.isClientSide() && player != null) {
SkyDimension.teleportToDreamDimension(player, world);
}
return InteractionResult.SUCCESS;
}
}

5️⃣ Генератор островов: SkyChunkGenerator.java

(с деревьями, овцами, алмазами и двумя биомами)

package com.alidar.skydimension.dimension;

import net.minecraft.block.Blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.Sheep;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.IChunk;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.tileentity.ChestTileEntity;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.tileentity.TileEntity;

import java.util.Random;

public class SkyChunkGenerator extends ChunkGenerator {

public SkyChunkGenerator(Level world) {
super(world, world.getSeed());
}

@Override
public void generateChunk(IChunk chunk) {
Random random = new Random(chunk.getPos().x * 341873128712L + chunk.getPos().z * 132897987541L);
int baseY = 100;
boolean isBiome1 = random.nextBoolean();

for (int i = 0; i < 3; i++) {
int x = random.nextInt(16);
int z = random.nextInt(16);
int radius = 3 + random.nextInt(4);

for (int dx=-radius; dx<=radius; dx++) {
for (int dz=-radius; dz<=radius; dz++) {
int dist = dx*dx + dz*dz;
if(dist <= radius*radius) {
int height = random.nextInt(2)+1;
for(int dy=0; dy<height; dy++) {
BlockPos pos = new BlockPos(x+dx, baseY+dy, z+dz);
if(isBiome1) {
chunk.setBlockState(pos, dy==height-1?Blocks.GRASS_BLOCK.defaultBlockState():Blocks.STONE.defaultBlockState(), false);
} else {
chunk.setBlockState(pos, dy==height-1?Blocks.SAND.defaultBlockState():Blocks.SANDSTONE.defaultBlockState(), false);
}
}
}
}
}

int chestY = baseY+2;
chunk.setBlockState(new BlockPos(x, chestY, z), Blocks.CHEST.defaultBlockState(), false);
TileEntity te = chunk.getTileEntity(new BlockPos(x, chestY, z));
if(te instanceof ChestTileEntity) {
IInventory chest = (IInventory) te;
if(isBiome1) {
chest.setInventorySlotContents(0,new ItemStack(Items.DIAMOND,2));
chest.setInventorySlotContents(1,new ItemStack(Items.IRON_INGOT,5));
chest.setInventorySlotContents(2,new ItemStack(Items.GOLD_INGOT,3));
} else {
chest.setInventorySlotContents(0,new ItemStack(Items.IRON_INGOT,2));
chest.setInventorySlotContents(1,new ItemStack(Items.STICK,4));
}
}

if(isBiome1) {
Sheep sheep = new Sheep(EntityType.SHEEP, chunk.getLevel());
sheep.moveTo(x+0.5, baseY+4, z+0.5);
chunk.getLevel().addFreshEntity(sheep);

// Дерево
for(int ty=0; ty<4; ty++)
chunk.setBlockState(new BlockPos(x, baseY+4+ty, z), Blocks.OAK_LOG.defaultBlockState(), false);
for(int dx=-2; dx<=2; dx++)
for(int dz=-2; dz<=2; dz++)
chunk.setBlockState(new BlockPos(x+dx, baseY+8, z+dz), Blocks.OAK_LEAVES.defaultBlockState(), false);
}

// Алмазы часто
for(int n=0; n<radius*2; n++){
int oreY = baseY + random.nextInt(2);
chunk.setBlockState(new BlockPos(x+random.nextInt(3)-1, oreY, z+random.nextInt(3)-1), Blocks.DIAMOND_ORE.defaultBlockState(), false);
}
}

// Вода
int waterY = baseY-50;
for(int xx=0; xx<16; xx++)
for(int zz=0; zz<16; zz++)
chunk.setBlockState(new BlockPos(xx, waterY, zz), Blocks.WATER.defaultBlockState(), false);
}
}


6️⃣ Логика телепортации: SkyDimension.java

package com.alidar.skydimension.dimension;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.core.BlockPos;

public class SkyDimension {

public static void teleportToDreamDimension(ServerPlayer player, Level world) {
if (!(world instanceof ServerLevel)) return;

// Здесь можно заменить на отдельное измерение
ServerLevel targetWorld = world.getServer().getLevel(Level.OVERWORLD);
if(targetWorld == null) return;

double scale = 1.0/12000.0;
BlockPos pos = player.blockPosition();
double x = pos.getX()*scale;
double y = pos.getY();
double z = pos.getZ()*scale;

player.teleportTo(targetWorld, x, y, z, player.getYRot(), player.getXRot());

// Ограничение выхода через сон
player.setSleepingIgnored(true);
}
}


7️⃣ Рецепт крафта: dream_activator.json

{
"type": "minecraft:crafting_shaped",
"pattern": [
" N ",
"S B",
" "
],
"key": {
"S": { "item": "minecraft:sculk_catalyst" },
"N": { "item": "minecraft:netherite_block" },
"B": { "item": "minecraft:beacon" }
},
"result": {
"item": "skydimension:dream_activator",
"count": 1
}
}