From 4cb965adb9bdd03d2b34f82df346cc9bcf5233ca Mon Sep 17 00:00:00 2001 From: Tim Kainz Date: Fri, 6 Feb 2026 17:42:04 +0100 Subject: [PATCH] Added Interfaces and SolarCellComponent --- .../{ => Commands}/ExampleCommand.java | 35 +++++----------- .../EnergySource/AbstractEnergySource.java | 18 +++++++++ .../EnergySource/IEnergySource.java | 19 +++++++++ .../Implementations/SolarCellComponent.java | 40 +++++++++++++++++++ .../org/KaiFlo/SolarCell/SolarCellPlugin.java | 3 ++ src/main/resources/manifest.json | 3 +- 6 files changed, 91 insertions(+), 27 deletions(-) rename src/main/java/org/KaiFlo/SolarCell/{ => Commands}/ExampleCommand.java (67%) create mode 100644 src/main/java/org/KaiFlo/SolarCell/Components/EnergySource/AbstractEnergySource.java create mode 100644 src/main/java/org/KaiFlo/SolarCell/Components/EnergySource/IEnergySource.java create mode 100644 src/main/java/org/KaiFlo/SolarCell/Components/EnergySource/Implementations/SolarCellComponent.java diff --git a/src/main/java/org/KaiFlo/SolarCell/ExampleCommand.java b/src/main/java/org/KaiFlo/SolarCell/Commands/ExampleCommand.java similarity index 67% rename from src/main/java/org/KaiFlo/SolarCell/ExampleCommand.java rename to src/main/java/org/KaiFlo/SolarCell/Commands/ExampleCommand.java index a303e6a..52ec703 100644 --- a/src/main/java/org/KaiFlo/SolarCell/ExampleCommand.java +++ b/src/main/java/org/KaiFlo/SolarCell/Commands/ExampleCommand.java @@ -1,38 +1,23 @@ -package org.KaiFlo.SolarCell; +package org.KaiFlo.SolarCell.Commands; -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; import java.util.Objects; -import java.util.stream.Collectors; -/** - * This is an example command that will simply print the name of the plugin in chat when used. - */ public class ExampleCommand extends CommandBase { private static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass(); @@ -51,18 +36,16 @@ public class ExampleCommand extends CommandBase { @Override protected void executeSync(@Nonnull CommandContext ctx) { ctx.sendMessage(Message.raw("Hello from the " + pluginName + " v" + pluginVersion + " plugin!")); - World defaultWorld = Universe.get().getDefaultWorld(); - var chunkStore = Objects.requireNonNull(defaultWorld).getChunkStore(); - LongSet chunkIndexes = chunkStore.getChunkIndexes(); + World defaultWorld = Objects.requireNonNull(Universe.get().getDefaultWorld()); defaultWorld.execute(() -> { Store store = defaultWorld.getEntityStore().getStore(); - Vector3i position = Objects.requireNonNull(store.getComponent(Objects.requireNonNull(ctx.senderAsPlayerRef()), TransformComponent.getComponentType())) - .getPosition() - .toVector3i(); + var playerRef = ctx.senderAsPlayerRef(); + var playerTransform = store.getComponent(Objects.requireNonNull(playerRef), TransformComponent.getComponentType()); + Vector3i playerPosition = Objects.requireNonNull(playerTransform).getPosition().toVector3i(); var size = sizeArg.get(ctx); if (size == null) size = 5; - executeForCubeAround(position.x, position.y, position.z, size, (x, y, z) -> { + executeForCubeAround(playerPosition.x, playerPosition.y, playerPosition.z, size, (x, y, z) -> { // BlockType blockType = defaultWorld.getBlockType(x, y, z); // if (blockType != null) { // LOGGER.atInfo().log(blockType.getId() + " at " + x + "," + y + "," + z); @@ -89,8 +72,8 @@ public class ExampleCommand extends CommandBase { } } } +} - interface Callback { - void onBlockPosition(int x, int y, int z); - } +interface Callback { + void onBlockPosition(int x, int y, int z); } \ No newline at end of file diff --git a/src/main/java/org/KaiFlo/SolarCell/Components/EnergySource/AbstractEnergySource.java b/src/main/java/org/KaiFlo/SolarCell/Components/EnergySource/AbstractEnergySource.java new file mode 100644 index 0000000..7cf3d26 --- /dev/null +++ b/src/main/java/org/KaiFlo/SolarCell/Components/EnergySource/AbstractEnergySource.java @@ -0,0 +1,18 @@ +package org.KaiFlo.SolarCell.Components.EnergySource; + +public class AbstractEnergySource implements IEnergySource{ + @Override + public boolean isEndless() { + return true; + } + + @Override + public long getEnergyCapacity() { + return -1; + } + + @Override + public long getEnergyRatePerTick() { + return 1; + } +} diff --git a/src/main/java/org/KaiFlo/SolarCell/Components/EnergySource/IEnergySource.java b/src/main/java/org/KaiFlo/SolarCell/Components/EnergySource/IEnergySource.java new file mode 100644 index 0000000..628f2fc --- /dev/null +++ b/src/main/java/org/KaiFlo/SolarCell/Components/EnergySource/IEnergySource.java @@ -0,0 +1,19 @@ +package org.KaiFlo.SolarCell.Components.EnergySource; + +public interface IEnergySource { + + /** + * @return True if energy source is endless, False otherwise + */ + boolean isEndless(); + + /** + * @return If the energy source is not endless, returns the Capacity of the energy source, otherwise -1 + */ + long getEnergyCapacity(); + + /** + * @return The amount of energy the source produces per Tick + */ + long getEnergyRatePerTick(); +} diff --git a/src/main/java/org/KaiFlo/SolarCell/Components/EnergySource/Implementations/SolarCellComponent.java b/src/main/java/org/KaiFlo/SolarCell/Components/EnergySource/Implementations/SolarCellComponent.java new file mode 100644 index 0000000..44207f4 --- /dev/null +++ b/src/main/java/org/KaiFlo/SolarCell/Components/EnergySource/Implementations/SolarCellComponent.java @@ -0,0 +1,40 @@ +package org.KaiFlo.SolarCell.Components.EnergySource.Implementations; + +import com.hypixel.hytale.codec.builder.BuilderCodec; +import com.hypixel.hytale.component.Component; +import com.hypixel.hytale.logger.HytaleLogger; +import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; +import org.KaiFlo.SolarCell.Components.EnergySource.AbstractEnergySource; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; + +public class SolarCellComponent extends AbstractEnergySource implements Component { + public static final BuilderCodec CODEC = BuilderCodec.builder(SolarCellComponent.class, SolarCellComponent::new).build(); + + private final HytaleLogger Logger = HytaleLogger.getLogger(); + private long energyRatePerTick = 5; + + private SolarCellComponent copyFrom(SolarCellComponent other) { + this.energyRatePerTick = other.energyRatePerTick; + return this; + } + + @NullableDecl + @Override + public Component clone() { + try { + super.clone(); + } catch (CloneNotSupportedException e) { + Logger.atWarning().log("Cloning of " + this.getClass().getName() + " failed."); + } + return new SolarCellComponent().copyFrom(this); + } + + @Override + public long getEnergyRatePerTick() { + return energyRatePerTick; + } + + public void setEnergyRatePerTick(long energyRatePerTick) { + this.energyRatePerTick = energyRatePerTick; + } +} diff --git a/src/main/java/org/KaiFlo/SolarCell/SolarCellPlugin.java b/src/main/java/org/KaiFlo/SolarCell/SolarCellPlugin.java index 17a9734..9cf65aa 100644 --- a/src/main/java/org/KaiFlo/SolarCell/SolarCellPlugin.java +++ b/src/main/java/org/KaiFlo/SolarCell/SolarCellPlugin.java @@ -3,6 +3,8 @@ package org.KaiFlo.SolarCell; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.server.core.plugin.JavaPlugin; import com.hypixel.hytale.server.core.plugin.JavaPluginInit; +import org.KaiFlo.SolarCell.Commands.ExampleCommand; +import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.SolarCellComponent; import javax.annotation.Nonnull; @@ -25,5 +27,6 @@ public class SolarCellPlugin extends JavaPlugin { protected void setup() { LOGGER.atInfo().log("Setting up plugin " + this.getName()); this.getCommandRegistry().registerCommand(new ExampleCommand(this.getName(), this.getManifest().getVersion().toString())); + this.getChunkStoreRegistry().registerComponent(SolarCellComponent.class,"SolarCell",SolarCellComponent.CODEC); } } \ No newline at end of file diff --git a/src/main/resources/manifest.json b/src/main/resources/manifest.json index 0773ced..675ff8e 100644 --- a/src/main/resources/manifest.json +++ b/src/main/resources/manifest.json @@ -14,7 +14,8 @@ "Website": "https://github.com/KainTim/hytale-solar-cell-plugin", "ServerVersion": "*", "Dependencies": { - + "Hytale:EntityModule": "*", + "Hytale:BlockModule": "*" }, "OptionalDependencies": {