added spawn structure to spwan at 0 80 0 and player at 5 90 6
This commit is contained in:
parent
0c0139275b
commit
90ca08146a
@ -5,30 +5,78 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
|||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.GameRules;
|
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.command.ChipperCommand;
|
||||||
|
import net.Chipperfluff.chipi.block.ModBlocks;
|
||||||
|
import net.Chipperfluff.chipi.item.ModItems;
|
||||||
|
|
||||||
public class ChipiMod implements ModInitializer {
|
public class ChipiMod implements ModInitializer {
|
||||||
|
|
||||||
|
public static final String MOD_ID = "chipi";
|
||||||
|
|
||||||
private static final Identifier CHIPI_DIM =
|
private static final Identifier CHIPI_DIM =
|
||||||
new Identifier("chipi", "chipi_dimension");
|
new Identifier("chipi", "chipi_dimension");
|
||||||
|
|
||||||
|
private static final Identifier SPAWN_STRUCTURE =
|
||||||
|
new Identifier("chipi", "spawn");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
|
||||||
ServerTickEvents.END_WORLD_TICK.register((ServerWorld world) -> {
|
ServerTickEvents.END_WORLD_TICK.register((ServerWorld world) -> {
|
||||||
|
if (!world.getRegistryKey().getValue().equals(CHIPI_DIM)) return;
|
||||||
|
|
||||||
if (!world.getRegistryKey().getValue().equals(CHIPI_DIM)) {
|
// 🌙 Lock time
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
world.setTimeOfDay(18000);
|
world.setTimeOfDay(18000);
|
||||||
|
|
||||||
world.getGameRules()
|
world.getGameRules()
|
||||||
.get(GameRules.DO_DAYLIGHT_CYCLE)
|
.get(GameRules.DO_DAYLIGHT_CYCLE)
|
||||||
.set(false, world.getServer());
|
.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(
|
CommandRegistrationCallback.EVENT.register(
|
||||||
(dispatcher, registryAccess, environment) ->
|
(dispatcher, registryAccess, environment) ->
|
||||||
ChipperCommand.register(dispatcher)
|
ChipperCommand.register(dispatcher)
|
||||||
|
|||||||
21
src/main/java/net/Chipperfluff/chipi/SpawnPlacedState.java
Normal file
21
src/main/java/net/Chipperfluff/chipi/SpawnPlacedState.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/main/java/net/Chipperfluff/chipi/block/ModBlocks.java
Normal file
28
src/main/java/net/Chipperfluff/chipi/block/ModBlocks.java
Normal 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() {}
|
||||||
|
}
|
||||||
27
src/main/java/net/Chipperfluff/chipi/item/ModItems.java
Normal file
27
src/main/java/net/Chipperfluff/chipi/item/ModItems.java
Normal 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() {}
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"": { "model": "chipi:block/void_block" }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:block/cube_all",
|
||||||
|
"textures": {
|
||||||
|
"all": "chipi:block/void_block"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"parent": "chipi:block/void_block"
|
||||||
|
}
|
||||||
BIN
src/main/resources/assets/chipi/textures/block/void_block.png
Normal file
BIN
src/main/resources/assets/chipi/textures/block/void_block.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 581 B |
BIN
src/main/resources/assets/chipi/textures/item/void_block.png
Normal file
BIN
src/main/resources/assets/chipi/textures/item/void_block.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 581 B |
BIN
src/main/resources/data/chipi/structures/spawn.nbt
Normal file
BIN
src/main/resources/data/chipi/structures/spawn.nbt
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user