Added Somewhat functional Transmission between storages

This commit is contained in:
2026-02-08 02:00:22 +01:00
parent 59e8fc1734
commit 3950bdab08
15 changed files with 293 additions and 104 deletions

View File

@@ -1,8 +1,6 @@
package org.KaiFlo.SolarCell.Systems;
import com.hypixel.hytale.component.ArchetypeChunk;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.*;
import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
import com.hypixel.hytale.math.util.ChunkUtil;
@@ -13,52 +11,62 @@ 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.ChunkSection;
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
import org.KaiFlo.SolarCell.Components.EnergyConsumer.Implementations.EnergyConsumerComponent;
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.EnergySourceComponent;
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.NullableDecl;
import java.util.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
public class EnergyTickingSystem extends EntityTickingSystem<ChunkStore> {
private final List<IEnergySourceTicking> energySourceTicking = List.of(new SolarCellSourceTicking());
private final Map<List<ComponentType<ChunkStore, ?>>, ITickingSystem> componentsToTickingSystem = new HashMap<>();
@Override
public void tick(float v, int i, @NonNullDecl ArchetypeChunk<ChunkStore> archetypeChunk, @NonNullDecl Store<ChunkStore> store, @NonNullDecl CommandBuffer<ChunkStore> commandBuffer) {
var blockSection = archetypeChunk.getComponent(i, BlockSection.getComponentType());
public void tick(float v, int archetypeIndex, @NonNullDecl ArchetypeChunk<ChunkStore> archetypeChunk, @NonNullDecl Store<ChunkStore> store, @NonNullDecl CommandBuffer<ChunkStore> commandBuffer) {
var blockSection = archetypeChunk.getComponent(archetypeIndex, BlockSection.getComponentType());
if (blockSection == null || blockSection.getTickingBlocksCount() != 0) return;
var chunkSection = archetypeChunk.getComponent(i, ChunkSection.getComponentType());
var chunkSection = archetypeChunk.getComponent(archetypeIndex, ChunkSection.getComponentType());
if (chunkSection == null) return;
var blockComponentChunk = commandBuffer.getComponent(chunkSection.getChunkColumnReference(), BlockComponentChunk.getComponentType());
var worldChunk = commandBuffer.getComponent(chunkSection.getChunkColumnReference(), WorldChunk.getComponentType());
if (blockComponentChunk == null || worldChunk == null) return;
blockSection.forEachTicking(blockComponentChunk, commandBuffer, chunkSection.getY(),
(blockCompChunk, _, localX, localY, localZ, _) -> {
var blockRef = blockCompChunk.getEntityReference(ChunkUtil.indexBlockInColumn(localX, localY, localZ));
if (blockRef == null) return BlockTickStrategy.IGNORED;
var entrySet = componentsToTickingSystem.entrySet();
var foundComponentTypes = new ArrayList<ComponentType<ChunkStore, ?>>();
int globalX = localX + (worldChunk.getX() * 32);
int globalZ = localZ + (worldChunk.getZ() * 32);
var globalPosition = new Vector3i(globalX, localY, globalZ);
blockSection.forEachTicking(blockComponentChunk, commandBuffer, chunkSection.getY(), (blockCompChunk, _, localX, localY, localZ, _) -> {
var blockRef = blockCompChunk.getEntityReference(ChunkUtil.indexBlockInColumn(localX, localY, localZ));
if (blockRef == null) return BlockTickStrategy.IGNORED;
var energySourceComponent = commandBuffer.getComponent(blockRef, EnergySourceComponent.getComponentType());
var energyConsumerComponent = commandBuffer.getComponent(blockRef, EnergyConsumerComponent.getComponentType());
var energyStorageComponent = commandBuffer.getComponent(blockRef, EnergyStorageComponent.getComponentType());
if (energySourceComponent != null && energyStorageComponent != null){
energySourceTicking.forEach(energySourceTicking -> energySourceTicking.accept(energySourceComponent, energyStorageComponent,globalPosition,blockCompChunk,commandBuffer));
return BlockTickStrategy.CONTINUE;
}
int globalX = localX + (worldChunk.getX() * 32);
int globalZ = localZ + (worldChunk.getZ() * 32);
var globalPosition = new Vector3i(globalX, localY, globalZ);
return BlockTickStrategy.IGNORED;
var archetype = commandBuffer.getArchetype(blockRef);
foundComponentTypes.clear();
var foundComponents = new ArrayList<Component<ChunkStore>>();
for (int i = 0; i < archetype.length(); i++) {
var type = archetype.get(i);
if (type == null) continue;
foundComponentTypes.add(type);
foundComponents.add(commandBuffer.getComponent(blockRef, type));
}
AtomicBoolean hasAny = new AtomicBoolean(false);
entrySet.stream()
.filter(entry -> foundComponentTypes.containsAll(entry.getKey())).map(Map.Entry::getValue)
.forEach(tickingSystem -> {
hasAny.set(true);
tickingSystem.accept(foundComponents, archetype, globalPosition, blockCompChunk, commandBuffer, worldChunk.getWorld());
});
return hasAny.get() ? BlockTickStrategy.CONTINUE : BlockTickStrategy.IGNORED;
});
}
@@ -67,4 +75,9 @@ public class EnergyTickingSystem extends EntityTickingSystem<ChunkStore> {
public Query<ChunkStore> getQuery() {
return Query.and(BlockSection.getComponentType(), ChunkSection.getComponentType());
}
public EnergyTickingSystem withTickingSystemForComponentTypes(List<ComponentType<ChunkStore, ?>> componentTypes, ITickingSystem tickingSystem) {
componentsToTickingSystem.put(componentTypes, tickingSystem);
return this;
}
}