added better placemthods for dugeons
This commit is contained in:
parent
fcee5d7ee8
commit
9b44fcf4e0
@ -32,6 +32,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.world.GameRules;
|
import net.minecraft.world.GameRules;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.gen.GenerationStep;
|
import net.minecraft.world.gen.GenerationStep;
|
||||||
|
import net.Chipperfluff.chipi.command.CommandHandler;
|
||||||
|
|
||||||
public class ChipiMod implements ModInitializer {
|
public class ChipiMod implements ModInitializer {
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ public class ChipiMod implements ModInitializer {
|
|||||||
ModEffects.register();
|
ModEffects.register();
|
||||||
ChipiBlessingEvents.register();
|
ChipiBlessingEvents.register();
|
||||||
ChipiHungerHandler.register();
|
ChipiHungerHandler.register();
|
||||||
|
CommandHandler.register();
|
||||||
|
|
||||||
FabricDefaultAttributeRegistry.register(ModEntities.MEP, MepEntity.createMepAttributes());
|
FabricDefaultAttributeRegistry.register(ModEntities.MEP, MepEntity.createMepAttributes());
|
||||||
|
|
||||||
@ -63,10 +65,6 @@ public class ChipiMod implements ModInitializer {
|
|||||||
RegistryKey.of(RegistryKeys.PLACED_FEATURE, new Identifier("chipi", "chipper_ore"))
|
RegistryKey.of(RegistryKeys.PLACED_FEATURE, new Identifier("chipi", "chipper_ore"))
|
||||||
);
|
);
|
||||||
|
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
|
||||||
ChpCommand.register(dispatcher);
|
|
||||||
});
|
|
||||||
|
|
||||||
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
||||||
SERVER = server;
|
SERVER = server;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -0,0 +1,18 @@
|
|||||||
|
package net.Chipperfluff.chipi.command;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
|
||||||
|
public final class CommandHandler {
|
||||||
|
|
||||||
|
private CommandHandler() {}
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
CommandRegistrationCallback.EVENT.register(
|
||||||
|
(dispatcher, registryAccess, environment) -> {
|
||||||
|
ChpCommand.register(dispatcher);
|
||||||
|
CspCommand.register(dispatcher);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
65
src/main/java/net/Chipperfluff/chipi/command/CspCommand.java
Normal file
65
src/main/java/net/Chipperfluff/chipi/command/CspCommand.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package net.Chipperfluff.chipi.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
|
||||||
|
import net.Chipperfluff.chipi.world.gen.struct.ChipiStructures;
|
||||||
|
import net.minecraft.command.CommandSource;
|
||||||
|
import net.minecraft.command.argument.BlockPosArgumentType;
|
||||||
|
import net.minecraft.server.command.CommandManager;
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
public class CspCommand {
|
||||||
|
|
||||||
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||||
|
dispatcher.register(
|
||||||
|
CommandManager.literal("csp")
|
||||||
|
.then(
|
||||||
|
CommandManager.argument("name", StringArgumentType.word())
|
||||||
|
.suggests((ctx, builder) ->
|
||||||
|
CommandSource.suggestMatching(ChipiStructures.getNames(), builder))
|
||||||
|
.then(
|
||||||
|
CommandManager.argument("center", BlockPosArgumentType.blockPos())
|
||||||
|
.then(
|
||||||
|
CommandManager.argument("worldPos", BlockPosArgumentType.blockPos())
|
||||||
|
.executes(ctx -> execute(ctx))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int execute(CommandContext<ServerCommandSource> ctx) {
|
||||||
|
ServerCommandSource source = ctx.getSource();
|
||||||
|
ServerWorld world = source.getWorld();
|
||||||
|
|
||||||
|
String name = StringArgumentType.getString(ctx, "name");
|
||||||
|
BlockPos center = BlockPosArgumentType.getBlockPos(ctx, "center");
|
||||||
|
BlockPos worldPos = BlockPosArgumentType.getBlockPos(ctx, "worldPos");
|
||||||
|
|
||||||
|
var structure = ChipiStructures.get(name);
|
||||||
|
|
||||||
|
if (structure == null) {
|
||||||
|
source.sendError(Text.literal("Unknown structure: " + name));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockPos local = structure.worldToLocal(center, worldPos);
|
||||||
|
|
||||||
|
source.sendFeedback(
|
||||||
|
() -> Text.literal(
|
||||||
|
"localPos = (" +
|
||||||
|
local.getX() + ", " +
|
||||||
|
local.getY() + ", " +
|
||||||
|
local.getZ() + ")"
|
||||||
|
),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -62,6 +62,18 @@ public abstract class ChipiStructure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BlockPos localToWorld(BlockPos structureOrigin, BlockPos localPos) {
|
public BlockPos localToWorld(BlockPos structureOrigin, BlockPos localPos) {
|
||||||
return structureOrigin.add(deltaX + localPos.getX(), deltaY + localPos.getY(), deltaZ + localPos.getZ());
|
return structureOrigin.add(
|
||||||
|
deltaX + localPos.getX(),
|
||||||
|
deltaY + localPos.getY(),
|
||||||
|
deltaZ + localPos.getZ()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos worldToLocal(BlockPos structureOrigin, BlockPos worldPos) {
|
||||||
|
return new BlockPos(
|
||||||
|
worldPos.getX() - structureOrigin.getX() - deltaX,
|
||||||
|
worldPos.getY() - structureOrigin.getY() - deltaY,
|
||||||
|
worldPos.getZ() - structureOrigin.getZ() - deltaZ
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ public final class DungeonContext {
|
|||||||
|
|
||||||
private Integer grid_x;
|
private Integer grid_x;
|
||||||
private Integer grid_y;
|
private Integer grid_y;
|
||||||
private BlockPos structure_origin;
|
private BlockPos structure_origin; // logical center
|
||||||
private ChipiStructure structure;
|
private ChipiStructure structure;
|
||||||
private ServerWorld world;
|
private ServerWorld world;
|
||||||
|
|
||||||
@ -44,6 +44,10 @@ public final class DungeonContext {
|
|||||||
return structure;
|
return structure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockPos getStructureOrigin() {
|
||||||
|
return structure_origin;
|
||||||
|
}
|
||||||
|
|
||||||
public void setBlock(BlockPos localPos, BlockState state) {
|
public void setBlock(BlockPos localPos, BlockState state) {
|
||||||
BlockPos worldPos = structure.localToWorld(structure_origin, localPos);
|
BlockPos worldPos = structure.localToWorld(structure_origin, localPos);
|
||||||
System.out.println("[CHIPI] setBlock grid=(" + grid_x + "," + grid_y + ") worldPos=" + worldPos);
|
System.out.println("[CHIPI] setBlock grid=(" + grid_x + "," + grid_y + ") worldPos=" + worldPos);
|
||||||
|
|||||||
@ -35,11 +35,9 @@ public final class WorldMaster {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static RoomBaseStructure afterPlaceRoom(DungeonContext ctx) {
|
public static RoomBaseStructure afterPlaceRoom(DungeonContext ctx) {
|
||||||
|
|
||||||
if (ctx.getGridX() == 1 && ctx.getGridY() == 1) {
|
if (ctx.getGridX() == 1 && ctx.getGridY() == 1) {
|
||||||
ctx.setBlock(new BlockPos(0, 0, 0), Blocks.REDSTONE_BLOCK.getDefaultState());
|
ctx.setBlock(new BlockPos(9, 1, 8), Blocks.REDSTONE_BLOCK.getDefaultState());
|
||||||
}
|
}
|
||||||
|
|
||||||
return getDefaultRoom();
|
return getDefaultRoom();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user