Removed unnecessary Data structures, parameters and imports
This commit is contained in:
@@ -46,20 +46,8 @@ public class ExampleCommand extends CommandBase {
|
||||
var size = sizeArg.get(ctx);
|
||||
if (size == null) size = 5;
|
||||
BlockHelper.executeForCubeAround(playerPosition.x, playerPosition.y, playerPosition.z, size,true, (x, y, z) -> {
|
||||
// BlockType blockType = defaultWorld.getBlockType(x, y, z);
|
||||
// if (blockType != null) {
|
||||
// LOGGER.atInfo().log(blockType.getId() + " at " + x + "," + y + "," + z);
|
||||
// }
|
||||
defaultWorld.breakBlock(x, y, z, 0);
|
||||
});
|
||||
// chunkIndexes.forEach(chunkIndex -> {
|
||||
// if (blockType == null) {
|
||||
// LOGGER.atInfo().log("No blocktype found for chunk index: " + chunkIndex);
|
||||
// return;
|
||||
// }
|
||||
// String id = blockType.getId();
|
||||
// LOGGER.atInfo().log("Block ID: " + id);
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@ import org.KaiFlo.SolarCell.Components.EnergyStorage.IEnergyStorage;
|
||||
import org.KaiFlo.SolarCell.SolarCellPlugin;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.KaiFlo.SolarCell.Helpers.BlockHelper.HyLogger;
|
||||
|
||||
public class EnergyStorageComponent implements Component<ChunkStore>, IEnergyStorage {
|
||||
@@ -102,12 +100,6 @@ public class EnergyStorageComponent implements Component<ChunkStore>, IEnergySto
|
||||
public long extractEnergy(long requiredEnergy) {
|
||||
var extractedEnergy = Math.min(currentEnergyAmount, Math.min(requiredEnergy, extractEnergyPerTick));
|
||||
currentEnergyAmount -= extractedEnergy;
|
||||
// if (extractedEnergy >=1000){
|
||||
// HyLogger.atInfo().log("Extracted Energy: " + extractedEnergy + " now at " + currentEnergyAmount);
|
||||
// for (StackTraceElement element : Arrays.stream(Thread.currentThread().getStackTrace()).limit(7).toList()) {
|
||||
// HyLogger.atInfo().log(String.valueOf(element));
|
||||
// }
|
||||
// }
|
||||
return extractedEnergy;
|
||||
}
|
||||
|
||||
@@ -115,7 +107,6 @@ public class EnergyStorageComponent implements Component<ChunkStore>, IEnergySto
|
||||
public long receiveEnergy(long inputEnergy) {
|
||||
var receivedEnergy = Math.min(maxCapacity - currentEnergyAmount, Math.min(inputEnergy, receiveEnergyPerTick));
|
||||
currentEnergyAmount += receivedEnergy;
|
||||
// HyLogger.atInfo().log("Received Energy: " + receivedEnergy + " now at " + currentEnergyAmount);
|
||||
return receivedEnergy;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.KaiFlo.SolarCell.Components.EnergyStorage.Implementations.EnergyStora
|
||||
import org.KaiFlo.SolarCell.Systems.ITickingSystem;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.KaiFlo.SolarCell.Helpers.BlockHelper.HyLogger;
|
||||
import static org.KaiFlo.SolarCell.Helpers.ComponentHelper.getComponentOfType;
|
||||
@@ -21,7 +20,7 @@ import static org.KaiFlo.SolarCell.Helpers.ComponentHelper.getComponentOfType;
|
||||
public class SolarCellSourceTicking implements ITickingSystem {
|
||||
|
||||
@Override
|
||||
public void accept(Ref<ChunkStore> blockRef, List<Component<ChunkStore>> foundComponents, Archetype<ChunkStore> archetype, Vector3i globalPosition, BlockComponentChunk blockComponentChunk, CommandBuffer<ChunkStore> commandBuffer, World world, Set<Ref<ChunkStore>> blockRefs) {
|
||||
public void accept(Ref<ChunkStore> blockRef, List<Component<ChunkStore>> foundComponents, Archetype<ChunkStore> archetype, Vector3i globalPosition, BlockComponentChunk blockComponentChunk, CommandBuffer<ChunkStore> commandBuffer, World world) {
|
||||
var energyStorage = getComponentOfType(foundComponents, EnergyStorageComponent.class).orElse(null);
|
||||
if (energyStorage == null) return;
|
||||
var energySource = getComponentOfType(foundComponents, EnergySourceComponent.class).orElse(null);
|
||||
|
||||
@@ -9,13 +9,11 @@ import org.KaiFlo.SolarCell.Components.EnergyStorage.Implementations.EnergyStora
|
||||
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||
|
||||
import static org.KaiFlo.SolarCell.Helpers.BlockHelper.HyLogger;
|
||||
import static org.KaiFlo.SolarCell.Helpers.BlockHelper.setBlockRefTicking;
|
||||
|
||||
public class EnergyStorageInitializerSystem extends RefSystem<ChunkStore> {
|
||||
@Override
|
||||
public void onEntityAdded(@NonNullDecl Ref<ChunkStore> ref, @NonNullDecl AddReason addReason, @NonNullDecl Store<ChunkStore> store, @NonNullDecl CommandBuffer<ChunkStore> commandBuffer) {
|
||||
HyLogger.atInfo().log("onEntityAdded");
|
||||
setBlockRefTicking(ref, commandBuffer);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.KaiFlo.SolarCell.Components.EnergyStorage.Implementations.EnergyStora
|
||||
import org.KaiFlo.SolarCell.Systems.ITickingSystem;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.KaiFlo.SolarCell.Helpers.BlockHelper.HyLogger;
|
||||
import static org.KaiFlo.SolarCell.Helpers.BlockHelper.executeForCubeAroundChunkSafe;
|
||||
@@ -22,16 +21,13 @@ import static org.KaiFlo.SolarCell.Helpers.ComponentHelper.getComponentOfType;
|
||||
public class BatteryStorageTicking implements ITickingSystem {
|
||||
|
||||
@Override
|
||||
public void accept(Ref<ChunkStore> blockRef, List<Component<ChunkStore>> foundComponents, Archetype<ChunkStore> archetype, Vector3i globalPosition, BlockComponentChunk blockComponentChunk, CommandBuffer<ChunkStore> commandBuffer, World world, Set<Ref<ChunkStore>> blockRefs) {
|
||||
public void accept(Ref<ChunkStore> blockRef, List<Component<ChunkStore>> foundComponents, Archetype<ChunkStore> archetype, Vector3i globalPosition, BlockComponentChunk blockComponentChunk, CommandBuffer<ChunkStore> commandBuffer, World world) {
|
||||
var energyStorage = getComponentOfType(foundComponents, EnergyStorageComponent.class).orElse(null);
|
||||
if (energyStorage == null) return;
|
||||
var energySourceComponent = getComponentOfType(foundComponents, EnergySourceComponent.class).orElse(null);
|
||||
if (energySourceComponent != null) return;
|
||||
executeForCubeAroundChunkSafe(globalPosition.x, globalPosition.y, globalPosition.z, 5, false, world, commandBuffer,
|
||||
(x, y, z, targetRef, blockCompChunk, targetChunk) -> {
|
||||
// if (blockRefs.contains(targetRef)) {
|
||||
// return;
|
||||
// }
|
||||
(x, y, z, targetRef, _, _) -> {
|
||||
if (energyStorage.getCurrentEnergyAmount() >= energyStorage.getMaxCapacity()) {
|
||||
return;
|
||||
}
|
||||
@@ -63,8 +59,6 @@ public class BatteryStorageTicking implements ITickingSystem {
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// blockRefs.add(blockRef);
|
||||
}
|
||||
|
||||
private static void transmitEnergy( EnergyStorageComponent energyStorage, EnergyStorageComponent targetEnergyStorage,long extractTarget, Vector3i globalPosition, int x, int y, int z) {
|
||||
|
||||
@@ -6,36 +6,24 @@ import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
|
||||
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.universe.Universe;
|
||||
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.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.Helpers.BlockHelper;
|
||||
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.KaiFlo.SolarCell.Helpers.BlockHelper.HyLogger;
|
||||
|
||||
public class EnergyTickingSystem extends EntityTickingSystem<ChunkStore> {
|
||||
|
||||
private final Map<List<ComponentType<ChunkStore, ?>>, Map.Entry<ITickingSystem,Set<Ref<ChunkStore>>>> componentsToTickingSystem = new HashMap<>();
|
||||
private long lastTime = 0L;
|
||||
private final Map<List<ComponentType<ChunkStore, ?>>, ITickingSystem> componentsToTickingSystem = new HashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public void tick(float v, int archetypeIndex, @NonNullDecl ArchetypeChunk<ChunkStore> archetypeChunk, @NonNullDecl Store<ChunkStore> store, @NonNullDecl CommandBuffer<ChunkStore> commandBuffer) {
|
||||
var currentTime = System.nanoTime();
|
||||
// HyLogger.atInfo().log("V:"+v);
|
||||
if ((currentTime/1_000_000_000.0)-0.1> lastTime/1_000_000_000.0){
|
||||
// HyLogger.atInfo().log("Reset, currentTime: "+currentTime/1_000_000_000.0+", lastTime: "+lastTime/1_000_000_000.0);
|
||||
lastTime = currentTime;
|
||||
componentsToTickingSystem.forEach((_, iTickingSystemSetEntry) -> iTickingSystemSetEntry.getValue().clear());
|
||||
}
|
||||
var blockSection = archetypeChunk.getComponent(archetypeIndex, BlockSection.getComponentType());
|
||||
if (blockSection == null) return;
|
||||
|
||||
@@ -52,16 +40,13 @@ public class EnergyTickingSystem extends EntityTickingSystem<ChunkStore> {
|
||||
blockSection.forEachTicking(null, null, chunkSection.getY(), (_, _, localX, localY, localZ, _) -> {
|
||||
var blockRef = blockComponentChunk.getEntityReference(ChunkUtil.indexBlockInColumn(localX, localY, localZ));
|
||||
if (blockRef == null) {
|
||||
|
||||
// HyLogger.atInfo().log("Ignored block at "+localX+", "+localY+", "+localZ);
|
||||
return BlockTickStrategy.CONTINUE;
|
||||
return BlockTickStrategy.IGNORED;
|
||||
}
|
||||
|
||||
int globalX = localX + (worldChunk.getX() * 32);
|
||||
int globalZ = localZ + (worldChunk.getZ() * 32);
|
||||
var globalPosition = new Vector3i(globalX, localY, globalZ);
|
||||
|
||||
|
||||
var archetype = commandBuffer.getArchetype(blockRef);
|
||||
|
||||
foundComponentTypes.clear();
|
||||
@@ -76,13 +61,11 @@ public class EnergyTickingSystem extends EntityTickingSystem<ChunkStore> {
|
||||
AtomicBoolean hasAny = new AtomicBoolean(false);
|
||||
entrySet.stream()
|
||||
.filter(entry -> foundComponentTypes.containsAll(entry.getKey())).map(Map.Entry::getValue)
|
||||
.forEach(entry -> {
|
||||
.forEach(tickingSystem -> {
|
||||
hasAny.set(true);
|
||||
entry.getKey().accept(blockRef,foundComponents, archetype, globalPosition, blockComponentChunk, commandBuffer, worldChunk.getWorld(),entry.getValue());
|
||||
tickingSystem.accept(blockRef, foundComponents, archetype, globalPosition, blockComponentChunk, commandBuffer, worldChunk.getWorld());
|
||||
});
|
||||
|
||||
// HyLogger.atInfo().log("Continued block at "+localX+", "+localY+", "+localZ);
|
||||
return BlockTickStrategy.CONTINUE;
|
||||
return hasAny.get() ? BlockTickStrategy.CONTINUE : BlockTickStrategy.IGNORED;
|
||||
});
|
||||
|
||||
}
|
||||
@@ -94,7 +77,7 @@ public class EnergyTickingSystem extends EntityTickingSystem<ChunkStore> {
|
||||
}
|
||||
|
||||
public EnergyTickingSystem withTickingSystemForComponentTypes(List<ComponentType<ChunkStore, ?>> componentTypes, ITickingSystem tickingSystem) {
|
||||
componentsToTickingSystem.put(componentTypes, Map.entry(tickingSystem, new HashSet<>()));
|
||||
componentsToTickingSystem.put(componentTypes, tickingSystem);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,8 @@ import com.hypixel.hytale.server.core.universe.world.chunk.BlockComponentChunk;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ITickingSystem {
|
||||
|
||||
void accept(Ref<ChunkStore> blockRef, List<Component<ChunkStore>> foundComponents, Archetype<ChunkStore> archetype, Vector3i globalPosition, BlockComponentChunk blockComponentChunk, CommandBuffer<ChunkStore> commandBuffer, World world, Set<Ref<ChunkStore>> blockRefs);
|
||||
void accept(Ref<ChunkStore> blockRef, List<Component<ChunkStore>> foundComponents, Archetype<ChunkStore> archetype, Vector3i globalPosition, BlockComponentChunk blockComponentChunk, CommandBuffer<ChunkStore> commandBuffer, World world);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user