From 2370f624c70bed32f4da4867282a759469510d4b Mon Sep 17 00:00:00 2001 From: tikaiz Date: Fri, 6 Feb 2026 13:31:34 +0100 Subject: [PATCH] Add World destruction --- .../org/KaiFlo/SolarCell/ExampleCommand.java | 69 +++++++++++++++---- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/KaiFlo/SolarCell/ExampleCommand.java b/src/main/java/org/KaiFlo/SolarCell/ExampleCommand.java index 084334b..a303e6a 100644 --- a/src/main/java/org/KaiFlo/SolarCell/ExampleCommand.java +++ b/src/main/java/org/KaiFlo/SolarCell/ExampleCommand.java @@ -1,13 +1,29 @@ package org.KaiFlo.SolarCell; import com.hypixel.hytale.component.Archetype; +import com.hypixel.hytale.component.Ref; +import com.hypixel.hytale.component.Store; import com.hypixel.hytale.logger.HytaleLogger; +import com.hypixel.hytale.math.vector.Vector3d; +import com.hypixel.hytale.math.vector.Vector3i; +import com.hypixel.hytale.protocol.BlockPlacementSettings; import com.hypixel.hytale.protocol.GameMode; import com.hypixel.hytale.server.core.Message; +import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; import com.hypixel.hytale.server.core.command.system.CommandContext; +import com.hypixel.hytale.server.core.command.system.arguments.system.ArgWrapper; +import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg; +import com.hypixel.hytale.server.core.command.system.arguments.system.WrappedArg; +import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes; import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase; +import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent; import com.hypixel.hytale.server.core.universe.Universe; +import com.hypixel.hytale.server.core.universe.world.World; +import com.hypixel.hytale.server.core.universe.world.accessor.ChunkAccessor; +import com.hypixel.hytale.server.core.universe.world.chunk.BlockChunk; +import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk; import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; +import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; import it.unimi.dsi.fastutil.longs.LongSet; import javax.annotation.Nonnull; @@ -22,34 +38,59 @@ public class ExampleCommand extends CommandBase { private static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass(); private final String pluginName; private final String pluginVersion; + private final OptionalArg sizeArg; public ExampleCommand(String pluginName, String pluginVersion) { super("test", "Prints a test message from the " + pluginName + " plugin."); this.setPermissionGroup(GameMode.Adventure); // Allows the command to be used by anyone, not just OP this.pluginName = pluginName; this.pluginVersion = pluginVersion; + this.sizeArg = this.withOptionalArg("", "", ArgTypes.INTEGER); } @Override protected void executeSync(@Nonnull CommandContext ctx) { ctx.sendMessage(Message.raw("Hello from the " + pluginName + " v" + pluginVersion + " plugin!")); - var chunkStore = Objects.requireNonNull(Universe.get().getDefaultWorld()).getChunkStore(); + World defaultWorld = Universe.get().getDefaultWorld(); + var chunkStore = Objects.requireNonNull(defaultWorld).getChunkStore(); LongSet chunkIndexes = chunkStore.getChunkIndexes(); - chunkIndexes.forEach(chunkIndex -> { - var ref = chunkStore.getChunkReference(chunkIndex); - if (ref == null) return; - Universe.get().getDefaultWorld().execute(() -> { - LOGGER.atInfo().log("Chunk Ref: "+ref); - Archetype archetype = Universe.get().getDefaultWorld().getChunkStore().getStore().getArchetype(ref); - for (int i = 0; i < archetype.length(); i++) { - var a = archetype.get(i); - if (a == null) continue; + defaultWorld.execute(() -> { - LOGGER.atInfo().log(a.getTypeClass().getName()); - } + Store store = defaultWorld.getEntityStore().getStore(); + Vector3i position = Objects.requireNonNull(store.getComponent(Objects.requireNonNull(ctx.senderAsPlayerRef()), TransformComponent.getComponentType())) + .getPosition() + .toVector3i(); + var size = sizeArg.get(ctx); + if (size == null) size = 5; + executeForCubeAround(position.x, position.y, position.z, size, (x, y, z) -> { +// BlockType blockType = defaultWorld.getBlockType(x, y, z); +// if (blockType != null) { +// LOGGER.atInfo().log(blockType.getId() + " at " + x + "," + y + "," + z); +// } + defaultWorld.breakBlock(x, y, z, 0); }); - +// chunkIndexes.forEach(chunkIndex -> { +// if (blockType == null) { +// LOGGER.atInfo().log("No blocktype found for chunk index: " + chunkIndex); +// return; +// } +// String id = blockType.getId(); +// LOGGER.atInfo().log("Block ID: " + id); +// }); }); - LOGGER.atInfo().log(chunkIndexes.longStream().mapToObj(Long::toString).collect(Collectors.joining(", "))); + } + + void executeForCubeAround(int x, int y, int z, int size, Callback callback) { + for (int x1 = x - size / 2; x1 < x + size / 2; x1++) { + for (int y1 = y - size / 2; y1 < y + size / 2; y1++) { + for (int z1 = z - size / 2; z1 < z + size / 2; z1++) { + callback.onBlockPosition(x1, y1, z1); + } + } + } + } + + interface Callback { + void onBlockPosition(int x, int y, int z); } } \ No newline at end of file