Added SolarCellInitializer
This commit is contained in:
@@ -2,9 +2,11 @@ package org.KaiFlo.SolarCell.Components.EnergySource.Implementations;
|
||||
|
||||
import com.hypixel.hytale.codec.builder.BuilderCodec;
|
||||
import com.hypixel.hytale.component.Component;
|
||||
import com.hypixel.hytale.component.ComponentType;
|
||||
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.KaiFlo.SolarCell.SolarCellPlugin;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||
|
||||
public class SolarCellComponent extends AbstractEnergySource implements Component<ChunkStore> {
|
||||
@@ -13,6 +15,10 @@ public class SolarCellComponent extends AbstractEnergySource implements Componen
|
||||
private final HytaleLogger Logger = HytaleLogger.getLogger();
|
||||
private long energyRatePerTick = 5;
|
||||
|
||||
public static ComponentType<ChunkStore, SolarCellComponent> getComponentType() {
|
||||
return SolarCellPlugin.get().getSolarCellComponentType();
|
||||
}
|
||||
|
||||
private SolarCellComponent copyFrom(SolarCellComponent other) {
|
||||
this.energyRatePerTick = other.energyRatePerTick;
|
||||
return this;
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
package org.KaiFlo.SolarCell;
|
||||
|
||||
import com.hypixel.hytale.component.ComponentType;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import org.KaiFlo.SolarCell.Commands.ExampleCommand;
|
||||
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.SolarCellComponent;
|
||||
import org.KaiFlo.SolarCell.Systems.EnergySource.SolarCellInitializer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* This class serves as the entrypoint for your plugin. Use the setup method to register into game registries or add
|
||||
* event listeners.
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class SolarCellPlugin extends JavaPlugin {
|
||||
|
||||
protected static SolarCellPlugin instance;
|
||||
|
||||
public static SolarCellPlugin get() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
|
||||
|
||||
private ComponentType<ChunkStore, SolarCellComponent> solarCellComponentType;
|
||||
|
||||
public SolarCellPlugin(@Nonnull JavaPluginInit init) {
|
||||
super(init);
|
||||
LOGGER.atInfo().log("Hello from " + this.getName() + " version " + this.getManifest().getVersion().toString());
|
||||
@@ -25,8 +30,18 @@ public class SolarCellPlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
protected void setup() {
|
||||
instance = this;
|
||||
LOGGER.atInfo().log("Setting up plugin " + this.getName());
|
||||
|
||||
solarCellComponentType = this.getChunkStoreRegistry().registerComponent(SolarCellComponent.class, "SolarCell", SolarCellComponent.CODEC);
|
||||
|
||||
this.getCommandRegistry().registerCommand(new ExampleCommand(this.getName(), this.getManifest().getVersion().toString()));
|
||||
this.getChunkStoreRegistry().registerComponent(SolarCellComponent.class,"SolarCell",SolarCellComponent.CODEC);
|
||||
|
||||
this.getChunkStoreRegistry().registerSystem(new SolarCellInitializer());
|
||||
|
||||
}
|
||||
|
||||
public ComponentType<ChunkStore, SolarCellComponent> getSolarCellComponentType() {
|
||||
return solarCellComponentType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.KaiFlo.SolarCell.Systems.EnergySource;
|
||||
|
||||
import com.hypixel.hytale.component.*;
|
||||
import com.hypixel.hytale.component.query.Query;
|
||||
import com.hypixel.hytale.component.system.RefSystem;
|
||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||
import com.hypixel.hytale.server.core.modules.block.BlockModule;
|
||||
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.SolarCellComponent;
|
||||
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||
|
||||
public class SolarCellInitializer extends RefSystem<ChunkStore> {
|
||||
@Override
|
||||
public void onEntityAdded(@NonNullDecl Ref<ChunkStore> ref, @NonNullDecl AddReason addReason, @NonNullDecl Store<ChunkStore> store, @NonNullDecl CommandBuffer<ChunkStore> commandBuffer) {
|
||||
BlockModule.BlockStateInfo blockInfo = commandBuffer.getComponent(ref, BlockModule.BlockStateInfo.getComponentType());
|
||||
if(blockInfo == null) return;
|
||||
|
||||
WorldChunk worldChunk = commandBuffer.getComponent(blockInfo.getChunkRef(), WorldChunk.getComponentType());
|
||||
if(worldChunk == null) return;
|
||||
|
||||
int x = ChunkUtil.xFromBlockInColumn(blockInfo.getIndex());
|
||||
int y = ChunkUtil.yFromBlockInColumn(blockInfo.getIndex());
|
||||
int z = ChunkUtil.zFromBlockInColumn(blockInfo.getIndex());
|
||||
|
||||
worldChunk.setTicking(x, y, z, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEntityRemove(@NonNullDecl Ref ref, @NonNullDecl RemoveReason removeReason, @NonNullDecl Store store, @NonNullDecl CommandBuffer commandBuffer) {
|
||||
//Nothing to do yet
|
||||
}
|
||||
|
||||
@NullableDecl
|
||||
@Override
|
||||
public Query<ChunkStore> getQuery() {
|
||||
return Query.and(SolarCellComponent.getComponentType(), BlockModule.BlockStateInfo.getComponentType());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user