added spawn structure to spwan at 0 80 0 and player at 5 90 6

This commit is contained in:
Chipperfluff 2025-12-16 01:00:48 +01:00
parent 0c0139275b
commit 90ca08146a
10 changed files with 143 additions and 5 deletions

View File

@ -5,30 +5,78 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameRules;
import net.minecraft.structure.StructurePlacementData;
import net.minecraft.structure.StructureTemplate;
import net.Chipperfluff.chipi.command.ChipperCommand;
import net.Chipperfluff.chipi.block.ModBlocks;
import net.Chipperfluff.chipi.item.ModItems;
public class ChipiMod implements ModInitializer {
public static final String MOD_ID = "chipi";
private static final Identifier CHIPI_DIM =
new Identifier("chipi", "chipi_dimension");
private static final Identifier SPAWN_STRUCTURE =
new Identifier("chipi", "spawn");
@Override
public void onInitialize() {
ServerTickEvents.END_WORLD_TICK.register((ServerWorld world) -> {
if (!world.getRegistryKey().getValue().equals(CHIPI_DIM)) return;
if (!world.getRegistryKey().getValue().equals(CHIPI_DIM)) {
return;
}
// 🌙 Lock time
world.setTimeOfDay(18000);
world.getGameRules()
.get(GameRules.DO_DAYLIGHT_CYCLE)
.set(false, world.getServer());
// 🧠 persistent spawn state
SpawnPlacedState state = world.getPersistentStateManager()
.getOrCreate(
SpawnPlacedState::fromNbt,
SpawnPlacedState::new,
"chipi_spawn"
);
if (state.placed) return;
var optional = world.getStructureTemplateManager()
.getTemplate(SPAWN_STRUCTURE);
if (optional.isEmpty()) {
System.err.println("[CHIPI] spawn.nbt not found!");
return;
}
StructureTemplate template = optional.get();
BlockPos origin = new BlockPos(0, 80, 0);
template.place(
world,
origin,
origin,
new StructurePlacementData(),
world.getRandom(),
2
);
world.setSpawnPos(origin.up(), 0.0f);
state.placed = true;
state.markDirty();
System.out.println("[CHIPI] Spawn structure placed");
});
ModBlocks.register();
ModItems.register();
CommandRegistrationCallback.EVENT.register(
(dispatcher, registryAccess, environment) ->
ChipperCommand.register(dispatcher)

View File

@ -0,0 +1,21 @@
package net.Chipperfluff.chipi;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.world.PersistentState;
public class SpawnPlacedState extends PersistentState {
public boolean placed = false;
public static SpawnPlacedState fromNbt(NbtCompound nbt) {
SpawnPlacedState state = new SpawnPlacedState();
state.placed = nbt.getBoolean("placed");
return state;
}
@Override
public NbtCompound writeNbt(NbtCompound nbt) {
nbt.putBoolean("placed", placed);
return nbt;
}
}

View File

@ -0,0 +1,28 @@
package net.Chipperfluff.chipi.block;
import net.minecraft.block.Block;
import net.minecraft.block.AbstractBlock;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.Chipperfluff.chipi.ChipiMod;
public class ModBlocks {
public static final Block VOID_BLOCK = register(
"void_block",
new Block(AbstractBlock.Settings.create()
.strength(1.5f, 6.0f)
)
);
private static Block register(String name, Block block) {
return Registry.register(
Registries.BLOCK,
new Identifier(ChipiMod.MOD_ID, name),
block
);
}
public static void register() {}
}

View File

@ -0,0 +1,27 @@
package net.Chipperfluff.chipi.item;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.Chipperfluff.chipi.ChipiMod;
import net.Chipperfluff.chipi.block.ModBlocks;
public class ModItems {
public static final Item VOID_BLOCK = register(
"void_block",
new BlockItem(ModBlocks.VOID_BLOCK, new Item.Settings())
);
private static Item register(String name, Item item) {
return Registry.register(
Registries.ITEM,
new Identifier(ChipiMod.MOD_ID, name),
item
);
}
public static void register() {}
}

View File

@ -0,0 +1,5 @@
{
"variants": {
"": { "model": "chipi:block/void_block" }
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "chipi:block/void_block"
}
}

View File

@ -0,0 +1,3 @@
{
"parent": "chipi:block/void_block"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 581 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 581 B

Binary file not shown.