Added Interfaces and SolarCellComponent

This commit is contained in:
2026-02-06 17:42:04 +01:00
parent 2370f624c7
commit 4cb965adb9
6 changed files with 91 additions and 27 deletions

View File

@@ -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<EntityStore> 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);
}

View File

@@ -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;
}
}

View File

@@ -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();
}

View File

@@ -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<ChunkStore> {
public static final BuilderCodec<SolarCellComponent> 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<ChunkStore> 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;
}
}

View File

@@ -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);
}
}

View File

@@ -14,7 +14,8 @@
"Website": "https://github.com/KainTim/hytale-solar-cell-plugin",
"ServerVersion": "*",
"Dependencies": {
"Hytale:EntityModule": "*",
"Hytale:BlockModule": "*"
},
"OptionalDependencies": {