Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -6,12 +6,13 @@ import com.hypixel.hytale.codec.builder.BuilderCodec;
|
|||||||
import com.hypixel.hytale.codec.validation.Validators;
|
import com.hypixel.hytale.codec.validation.Validators;
|
||||||
import com.hypixel.hytale.component.Component;
|
import com.hypixel.hytale.component.Component;
|
||||||
import com.hypixel.hytale.component.ComponentType;
|
import com.hypixel.hytale.component.ComponentType;
|
||||||
import com.hypixel.hytale.logger.HytaleLogger;
|
|
||||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||||
import org.KaiFlo.SolarCell.Components.EnergyConsumer.IEnergyConsumer;
|
import org.KaiFlo.SolarCell.Components.EnergyConsumer.IEnergyConsumer;
|
||||||
import org.KaiFlo.SolarCell.SolarCellPlugin;
|
import org.KaiFlo.SolarCell.SolarCellPlugin;
|
||||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||||
|
|
||||||
|
import static org.KaiFlo.SolarCell.Helpers.BlockHelper.LOGGER;
|
||||||
|
|
||||||
public class EnergyConsumerComponent implements Component<ChunkStore>, IEnergyConsumer {
|
public class EnergyConsumerComponent implements Component<ChunkStore>, IEnergyConsumer {
|
||||||
public static final BuilderCodec<EnergyConsumerComponent> CODEC = BuilderCodec.builder(EnergyConsumerComponent.class, EnergyConsumerComponent::new)
|
public static final BuilderCodec<EnergyConsumerComponent> CODEC = BuilderCodec.builder(EnergyConsumerComponent.class, EnergyConsumerComponent::new)
|
||||||
.append(new KeyedCodec<>("ConsumptionPerTick", Codec.LONG),
|
.append(new KeyedCodec<>("ConsumptionPerTick", Codec.LONG),
|
||||||
@@ -26,8 +27,6 @@ public class EnergyConsumerComponent implements Component<ChunkStore>, IEnergyCo
|
|||||||
private long consumptionPerTick;
|
private long consumptionPerTick;
|
||||||
private float workingCapabilityRatio;
|
private float workingCapabilityRatio;
|
||||||
|
|
||||||
private final HytaleLogger Logger = HytaleLogger.getLogger();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getWorkingCapabilityRatio() {
|
public float getWorkingCapabilityRatio() {
|
||||||
return workingCapabilityRatio;
|
return workingCapabilityRatio;
|
||||||
@@ -60,7 +59,7 @@ public class EnergyConsumerComponent implements Component<ChunkStore>, IEnergyCo
|
|||||||
try {
|
try {
|
||||||
super.clone();
|
super.clone();
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
Logger.atWarning().log("Cloning of " + this.getClass().getName() + " failed.");
|
LOGGER.atWarning().log("Cloning of " + this.getClass().getName() + " failed.");
|
||||||
}
|
}
|
||||||
return new EnergyConsumerComponent().copyFrom(this);
|
return new EnergyConsumerComponent().copyFrom(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ import com.hypixel.hytale.codec.builder.BuilderCodec;
|
|||||||
import com.hypixel.hytale.codec.validation.Validators;
|
import com.hypixel.hytale.codec.validation.Validators;
|
||||||
import com.hypixel.hytale.component.Component;
|
import com.hypixel.hytale.component.Component;
|
||||||
import com.hypixel.hytale.component.ComponentType;
|
import com.hypixel.hytale.component.ComponentType;
|
||||||
import com.hypixel.hytale.logger.HytaleLogger;
|
|
||||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||||
import org.KaiFlo.SolarCell.Components.EnergySource.IEnergySource;
|
import org.KaiFlo.SolarCell.Components.EnergySource.IEnergySource;
|
||||||
import org.KaiFlo.SolarCell.SolarCellPlugin;
|
import org.KaiFlo.SolarCell.SolarCellPlugin;
|
||||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||||
|
|
||||||
|
import static org.KaiFlo.SolarCell.Helpers.BlockHelper.LOGGER;
|
||||||
|
|
||||||
public class EnergySourceComponent implements Component<ChunkStore>, IEnergySource {
|
public class EnergySourceComponent implements Component<ChunkStore>, IEnergySource {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static final BuilderCodec<EnergySourceComponent> CODEC = BuilderCodec.builder(EnergySourceComponent.class, EnergySourceComponent::new)
|
public static final BuilderCodec<EnergySourceComponent> CODEC = BuilderCodec.builder(EnergySourceComponent.class, EnergySourceComponent::new)
|
||||||
@@ -31,7 +32,6 @@ public class EnergySourceComponent implements Component<ChunkStore>, IEnergySour
|
|||||||
.add()
|
.add()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private final HytaleLogger Logger = HytaleLogger.getLogger();
|
|
||||||
private long generatesPerTick = 5;
|
private long generatesPerTick = 5;
|
||||||
private boolean isEndless = true;
|
private boolean isEndless = true;
|
||||||
private long energyCapacity = -1;
|
private long energyCapacity = -1;
|
||||||
@@ -51,7 +51,7 @@ public class EnergySourceComponent implements Component<ChunkStore>, IEnergySour
|
|||||||
try {
|
try {
|
||||||
super.clone();
|
super.clone();
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
Logger.atWarning().log("Cloning of " + this.getClass().getName() + " failed.");
|
LOGGER.atWarning().log("Cloning of " + this.getClass().getName() + " failed.");
|
||||||
}
|
}
|
||||||
return new EnergySourceComponent().copyFrom(this);
|
return new EnergySourceComponent().copyFrom(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ import com.hypixel.hytale.codec.builder.BuilderCodec;
|
|||||||
import com.hypixel.hytale.codec.validation.Validators;
|
import com.hypixel.hytale.codec.validation.Validators;
|
||||||
import com.hypixel.hytale.component.Component;
|
import com.hypixel.hytale.component.Component;
|
||||||
import com.hypixel.hytale.component.ComponentType;
|
import com.hypixel.hytale.component.ComponentType;
|
||||||
import com.hypixel.hytale.logger.HytaleLogger;
|
|
||||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||||
import org.KaiFlo.SolarCell.Components.EnergyStorage.IEnergyStorage;
|
import org.KaiFlo.SolarCell.Components.EnergyStorage.IEnergyStorage;
|
||||||
import org.KaiFlo.SolarCell.SolarCellPlugin;
|
import org.KaiFlo.SolarCell.SolarCellPlugin;
|
||||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||||
|
|
||||||
|
import static org.KaiFlo.SolarCell.Helpers.BlockHelper.LOGGER;
|
||||||
|
|
||||||
public class EnergyStorageComponent implements Component<ChunkStore>, IEnergyStorage {
|
public class EnergyStorageComponent implements Component<ChunkStore>, IEnergyStorage {
|
||||||
public static final BuilderCodec<EnergyStorageComponent> CODEC = BuilderCodec.builder(EnergyStorageComponent.class, EnergyStorageComponent::new)
|
public static final BuilderCodec<EnergyStorageComponent> CODEC = BuilderCodec.builder(EnergyStorageComponent.class, EnergyStorageComponent::new)
|
||||||
.append(new KeyedCodec<>("MaxCapacity", Codec.LONG),
|
.append(new KeyedCodec<>("MaxCapacity", Codec.LONG),
|
||||||
@@ -44,7 +45,6 @@ public class EnergyStorageComponent implements Component<ChunkStore>, IEnergySto
|
|||||||
.add()
|
.add()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private final HytaleLogger Logger = HytaleLogger.getLogger();
|
|
||||||
|
|
||||||
private long maxCapacity;
|
private long maxCapacity;
|
||||||
private long extractEnergyPerTick;
|
private long extractEnergyPerTick;
|
||||||
@@ -124,7 +124,7 @@ public class EnergyStorageComponent implements Component<ChunkStore>, IEnergySto
|
|||||||
try {
|
try {
|
||||||
super.clone();
|
super.clone();
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
Logger.atWarning().log("Cloning of " + this.getClass().getName() + " failed.");
|
LOGGER.atWarning().log("Cloning of " + this.getClass().getName() + " failed.");
|
||||||
}
|
}
|
||||||
return new EnergyStorageComponent().copyFrom(this);
|
return new EnergyStorageComponent().copyFrom(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
|||||||
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||||
|
|
||||||
public class BlockHelper {
|
public class BlockHelper {
|
||||||
|
public static final HytaleLogger LOGGER = HytaleLogger.getLogger();
|
||||||
|
|
||||||
public static void executeForCubeAround(int x, int y, int z, int size, boolean own, Callback callback) {
|
public static void executeForCubeAround(int x, int y, int z, int size, boolean own, Callback callback) {
|
||||||
for (int xOffset = 0; xOffset < size; xOffset++) {
|
for (int xOffset = 0; xOffset < size; xOffset++) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.KaiFlo.SolarCell.Components.EnergyConsumer.Implementations.EnergyCons
|
|||||||
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.EnergySourceComponent;
|
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.EnergySourceComponent;
|
||||||
import org.KaiFlo.SolarCell.Components.EnergyStorage.Implementations.EnergyStorageComponent;
|
import org.KaiFlo.SolarCell.Components.EnergyStorage.Implementations.EnergyStorageComponent;
|
||||||
import org.KaiFlo.SolarCell.Systems.EnergySource.EnergySourceInitializerSystem;
|
import org.KaiFlo.SolarCell.Systems.EnergySource.EnergySourceInitializerSystem;
|
||||||
import org.KaiFlo.SolarCell.Systems.EnergySource.EnergyProducerTickingSystem;
|
import org.KaiFlo.SolarCell.Systems.EnergyTickingSystem;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ public class SolarCellPlugin extends JavaPlugin {
|
|||||||
this.getCommandRegistry().registerCommand(new ExampleCommand(this.getName(), this.getManifest().getVersion().toString()));
|
this.getCommandRegistry().registerCommand(new ExampleCommand(this.getName(), this.getManifest().getVersion().toString()));
|
||||||
|
|
||||||
this.getChunkStoreRegistry().registerSystem(new EnergySourceInitializerSystem());
|
this.getChunkStoreRegistry().registerSystem(new EnergySourceInitializerSystem());
|
||||||
this.getChunkStoreRegistry().registerSystem(new EnergyProducerTickingSystem());
|
this.getChunkStoreRegistry().registerSystem(new EnergyTickingSystem());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,30 +3,18 @@ package org.KaiFlo.SolarCell.Systems.EnergySource;
|
|||||||
import com.hypixel.hytale.component.*;
|
import com.hypixel.hytale.component.*;
|
||||||
import com.hypixel.hytale.component.query.Query;
|
import com.hypixel.hytale.component.query.Query;
|
||||||
import com.hypixel.hytale.component.system.RefSystem;
|
import com.hypixel.hytale.component.system.RefSystem;
|
||||||
import com.hypixel.hytale.logger.HytaleLogger;
|
|
||||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
|
||||||
import com.hypixel.hytale.server.core.modules.block.BlockModule;
|
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 com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||||
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.EnergySourceComponent;
|
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.EnergySourceComponent;
|
||||||
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||||
|
|
||||||
|
import static org.KaiFlo.SolarCell.Helpers.BlockHelper.setBlockRefTicking;
|
||||||
|
|
||||||
public class EnergySourceInitializerSystem extends RefSystem<ChunkStore> {
|
public class EnergySourceInitializerSystem extends RefSystem<ChunkStore> {
|
||||||
@Override
|
@Override
|
||||||
public void onEntityAdded(@NonNullDecl Ref<ChunkStore> ref, @NonNullDecl AddReason addReason, @NonNullDecl Store<ChunkStore> store, @NonNullDecl CommandBuffer<ChunkStore> commandBuffer) {
|
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());
|
setBlockRefTicking(ref, commandBuffer);
|
||||||
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);
|
|
||||||
HytaleLogger.getLogger().atInfo().log(String.valueOf(worldChunk.isTicking(x, y, z)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.KaiFlo.SolarCell.Systems.EnergySource;
|
||||||
|
|
||||||
|
import com.hypixel.hytale.component.CommandBuffer;
|
||||||
|
import com.hypixel.hytale.protocol.Vector3i;
|
||||||
|
import com.hypixel.hytale.server.core.universe.world.chunk.BlockComponentChunk;
|
||||||
|
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||||
|
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.EnergySourceComponent;
|
||||||
|
import org.KaiFlo.SolarCell.Components.EnergyStorage.Implementations.EnergyStorageComponent;
|
||||||
|
|
||||||
|
public interface IEnergySourceTicking{
|
||||||
|
void accept (EnergySourceComponent thisEnergySource, EnergyStorageComponent thisEnergyStorage, Vector3i globalPosition, BlockComponentChunk blockComponentChunk, CommandBuffer<ChunkStore> commandBuffer);
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.KaiFlo.SolarCell.Systems.EnergySource;
|
||||||
|
|
||||||
|
import com.hypixel.hytale.component.CommandBuffer;
|
||||||
|
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||||
|
import com.hypixel.hytale.protocol.Vector3i;
|
||||||
|
import com.hypixel.hytale.server.core.universe.world.chunk.BlockComponentChunk;
|
||||||
|
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||||
|
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.EnergySourceComponent;
|
||||||
|
import org.KaiFlo.SolarCell.Components.EnergyStorage.Implementations.EnergyStorageComponent;
|
||||||
|
import org.KaiFlo.SolarCell.Helpers.BlockHelper;
|
||||||
|
|
||||||
|
import static org.KaiFlo.SolarCell.Helpers.BlockHelper.LOGGER;
|
||||||
|
|
||||||
|
public class SolarCellSourceTicking implements IEnergySourceTicking{
|
||||||
|
@Override
|
||||||
|
public void accept(EnergySourceComponent thisEnergySource, EnergyStorageComponent thisEnergyStorage, Vector3i globalPosition, BlockComponentChunk blockComponentChunk, CommandBuffer<ChunkStore> commandBuffer){
|
||||||
|
|
||||||
|
BlockHelper.executeForCubeAround(globalPosition.x, globalPosition.y, globalPosition.z, 5, false, (x, y, z) -> {
|
||||||
|
var index = ChunkUtil.indexBlockInColumn(x, y, z);
|
||||||
|
var targetRef = blockComponentChunk.getEntityReference(index);
|
||||||
|
if (targetRef == null) return;
|
||||||
|
var targetEnergySource = commandBuffer.getComponent(targetRef, EnergySourceComponent.getComponentType());
|
||||||
|
var targetEnergyStorage = commandBuffer.getComponent(targetRef, EnergyStorageComponent.getComponentType());
|
||||||
|
if (targetEnergySource == null || targetEnergyStorage == null) return;
|
||||||
|
|
||||||
|
var energy = targetEnergyStorage.extractEnergy(targetEnergySource.getGeneratesPerTick());
|
||||||
|
var inserted = thisEnergyStorage.receiveEnergy(energy);
|
||||||
|
LOGGER.atInfo().log("Inserted " + inserted + "/" + energy + " |" + targetEnergyStorage.getCurrentEnergyAmount() + "| into storage" +
|
||||||
|
" at Block " + globalPosition.x + ", " + globalPosition.y + ", " + globalPosition.z + ", " +
|
||||||
|
thisEnergyStorage.getCurrentEnergyAmount() + "/" + thisEnergyStorage.getMaxCapacity());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,30 @@
|
|||||||
package org.KaiFlo.SolarCell.Systems.EnergySource;
|
package org.KaiFlo.SolarCell.Systems;
|
||||||
|
|
||||||
import com.hypixel.hytale.component.ArchetypeChunk;
|
import com.hypixel.hytale.component.ArchetypeChunk;
|
||||||
import com.hypixel.hytale.component.CommandBuffer;
|
import com.hypixel.hytale.component.CommandBuffer;
|
||||||
import com.hypixel.hytale.component.Store;
|
import com.hypixel.hytale.component.Store;
|
||||||
import com.hypixel.hytale.component.query.Query;
|
import com.hypixel.hytale.component.query.Query;
|
||||||
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
|
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
|
||||||
import com.hypixel.hytale.logger.HytaleLogger;
|
|
||||||
import com.hypixel.hytale.math.util.ChunkUtil;
|
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||||
|
import com.hypixel.hytale.protocol.Vector3i;
|
||||||
import com.hypixel.hytale.server.core.asset.type.blocktick.BlockTickStrategy;
|
import com.hypixel.hytale.server.core.asset.type.blocktick.BlockTickStrategy;
|
||||||
import com.hypixel.hytale.server.core.universe.world.chunk.BlockComponentChunk;
|
import com.hypixel.hytale.server.core.universe.world.chunk.BlockComponentChunk;
|
||||||
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
|
||||||
import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection;
|
import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection;
|
||||||
import com.hypixel.hytale.server.core.universe.world.chunk.section.ChunkSection;
|
import com.hypixel.hytale.server.core.universe.world.chunk.section.ChunkSection;
|
||||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||||
import dev.zkiller.energystorage.components.EnergyStorageBlockComponent;
|
import org.KaiFlo.SolarCell.Components.EnergyConsumer.Implementations.EnergyConsumerComponent;
|
||||||
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.EnergySourceComponent;
|
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.EnergySourceComponent;
|
||||||
import org.KaiFlo.SolarCell.Helpers.BlockHelper;
|
import org.KaiFlo.SolarCell.Components.EnergyStorage.Implementations.EnergyStorageComponent;
|
||||||
|
import org.KaiFlo.SolarCell.Systems.EnergySource.IEnergySourceTicking;
|
||||||
|
import org.KaiFlo.SolarCell.Systems.EnergySource.SolarCellSourceTicking;
|
||||||
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||||
|
|
||||||
public class EnergyProducerTickingSystem extends EntityTickingSystem<ChunkStore> {
|
import java.util.List;
|
||||||
private final HytaleLogger LOGGER = HytaleLogger.getLogger();
|
|
||||||
|
public class EnergyTickingSystem extends EntityTickingSystem<ChunkStore> {
|
||||||
|
private final List<IEnergySourceTicking> energySourceTicking = List.of(new SolarCellSourceTicking());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick(float v, int i, @NonNullDecl ArchetypeChunk<ChunkStore> archetypeChunk, @NonNullDecl Store<ChunkStore> store, @NonNullDecl CommandBuffer<ChunkStore> commandBuffer) {
|
public void tick(float v, int i, @NonNullDecl ArchetypeChunk<ChunkStore> archetypeChunk, @NonNullDecl Store<ChunkStore> store, @NonNullDecl CommandBuffer<ChunkStore> commandBuffer) {
|
||||||
@@ -38,30 +42,22 @@ public class EnergyProducerTickingSystem extends EntityTickingSystem<ChunkStore>
|
|||||||
(blockCompChunk, _, localX, localY, localZ, _) -> {
|
(blockCompChunk, _, localX, localY, localZ, _) -> {
|
||||||
var blockRef = blockCompChunk.getEntityReference(ChunkUtil.indexBlockInColumn(localX, localY, localZ));
|
var blockRef = blockCompChunk.getEntityReference(ChunkUtil.indexBlockInColumn(localX, localY, localZ));
|
||||||
if (blockRef == null) return BlockTickStrategy.IGNORED;
|
if (blockRef == null) return BlockTickStrategy.IGNORED;
|
||||||
var thisEnergySourceComponent = commandBuffer.getComponent(blockRef, EnergySourceComponent.getComponentType());
|
|
||||||
var thisEnergyStorageComponent = commandBuffer.getComponent(blockRef, EnergyStorageBlockComponent.getComponentType());
|
|
||||||
if (thisEnergySourceComponent == null || thisEnergyStorageComponent == null)
|
|
||||||
return BlockTickStrategy.IGNORED;
|
|
||||||
|
|
||||||
int globalX = localX + (worldChunk.getX() * 32);
|
int globalX = localX + (worldChunk.getX() * 32);
|
||||||
int globalZ = localZ + (worldChunk.getZ() * 32);
|
int globalZ = localZ + (worldChunk.getZ() * 32);
|
||||||
|
var globalPosition = new Vector3i(globalX, localY, globalZ);
|
||||||
|
|
||||||
BlockHelper.executeForCubeAround(globalX, localY, globalZ, 5, false, (x, y, z) -> {
|
var energySourceComponent = commandBuffer.getComponent(blockRef, EnergySourceComponent.getComponentType());
|
||||||
var index = ChunkUtil.indexBlockInColumn(x, y, z);
|
var energyConsumerComponent = commandBuffer.getComponent(blockRef, EnergyConsumerComponent.getComponentType());
|
||||||
var targetRef = blockCompChunk.getEntityReference(index);
|
var energyStorageComponent = commandBuffer.getComponent(blockRef, EnergyStorageComponent.getComponentType());
|
||||||
if (targetRef == null) return;
|
|
||||||
var targetEnergySource = commandBuffer.getComponent(targetRef, EnergySourceComponent.getComponentType());
|
|
||||||
var targetEnergyStorage = commandBuffer.getComponent(targetRef, EnergyStorageBlockComponent.getComponentType());
|
|
||||||
if (targetEnergySource == null || targetEnergyStorage == null) return;
|
|
||||||
|
|
||||||
var energy = targetEnergyStorage.extractEnergy(targetEnergySource.getGeneratesPerTick(), false);
|
|
||||||
var inserted = thisEnergyStorageComponent.receiveEnergy(energy, false);
|
|
||||||
LOGGER.atInfo().log("Inserted " + inserted + "/" + energy + " |" + targetEnergyStorage.getEnergyStored() + "| into storage" +
|
|
||||||
" at Block " + globalX + ", " + localY + ", " + globalZ + ", " +
|
|
||||||
thisEnergyStorageComponent.getEnergyStored() + "/" + thisEnergyStorageComponent.getMaxEnergyStored());
|
|
||||||
});
|
|
||||||
|
|
||||||
|
if (energySourceComponent != null && energyStorageComponent != null){
|
||||||
|
energySourceTicking.forEach(energySourceTicking -> energySourceTicking.accept(energySourceComponent, energyStorageComponent,globalPosition,blockCompChunk,commandBuffer));
|
||||||
return BlockTickStrategy.CONTINUE;
|
return BlockTickStrategy.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return BlockTickStrategy.IGNORED;
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user