Added SolarCell Ticking System
This commit is contained in:
@@ -13,7 +13,7 @@ import com.hypixel.hytale.server.core.modules.entity.component.TransformComponen
|
|||||||
import com.hypixel.hytale.server.core.universe.Universe;
|
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.World;
|
||||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
import org.KaiFlo.SolarCell.Helpers.BlockHelper;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -45,7 +45,7 @@ public class ExampleCommand extends CommandBase {
|
|||||||
Vector3i playerPosition = Objects.requireNonNull(playerTransform).getPosition().toVector3i();
|
Vector3i playerPosition = Objects.requireNonNull(playerTransform).getPosition().toVector3i();
|
||||||
var size = sizeArg.get(ctx);
|
var size = sizeArg.get(ctx);
|
||||||
if (size == null) size = 5;
|
if (size == null) size = 5;
|
||||||
executeForCubeAround(playerPosition.x, playerPosition.y, playerPosition.z, size, (x, y, z) -> {
|
BlockHelper.executeForCubeAround(playerPosition.x, playerPosition.y, playerPosition.z, size, (x, y, z) -> {
|
||||||
// BlockType blockType = defaultWorld.getBlockType(x, y, z);
|
// BlockType blockType = defaultWorld.getBlockType(x, y, z);
|
||||||
// if (blockType != null) {
|
// if (blockType != null) {
|
||||||
// LOGGER.atInfo().log(blockType.getId() + " at " + x + "," + y + "," + z);
|
// LOGGER.atInfo().log(blockType.getId() + " at " + x + "," + y + "," + z);
|
||||||
@@ -63,17 +63,4 @@ public class ExampleCommand extends CommandBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void executeForCubeAround(int x, int y, int z, int size, Callback callback) {
|
|
||||||
for (int x1 = x - size / 2; x1 < x + size / 2; x1++) {
|
|
||||||
for (int y1 = y - size / 2; y1 < y + size / 2; y1++) {
|
|
||||||
for (int z1 = z - size / 2; z1 < z + size / 2; z1++) {
|
|
||||||
callback.onBlockPosition(x1, y1, z1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Callback {
|
|
||||||
void onBlockPosition(int x, int y, int z);
|
|
||||||
}
|
}
|
||||||
19
src/main/java/org/KaiFlo/SolarCell/Helpers/BlockHelper.java
Normal file
19
src/main/java/org/KaiFlo/SolarCell/Helpers/BlockHelper.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package org.KaiFlo.SolarCell.Helpers;
|
||||||
|
|
||||||
|
public class BlockHelper {
|
||||||
|
|
||||||
|
public static void executeForCubeAround(int x, int y, int z, int size, Callback callback) {
|
||||||
|
for (int x1 = x - size / 2; x1 < x + size / 2; x1++) {
|
||||||
|
for (int y1 = y - size / 2; y1 < y + size / 2; y1++) {
|
||||||
|
for (int z1 = z - size / 2; z1 < z + size / 2; z1++) {
|
||||||
|
callback.accept(x1, y1, z1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public interface Callback {
|
||||||
|
void accept(int x, int y, int z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -8,6 +8,7 @@ import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
|
|||||||
import org.KaiFlo.SolarCell.Commands.ExampleCommand;
|
import org.KaiFlo.SolarCell.Commands.ExampleCommand;
|
||||||
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.SolarCellComponent;
|
import org.KaiFlo.SolarCell.Components.EnergySource.Implementations.SolarCellComponent;
|
||||||
import org.KaiFlo.SolarCell.Systems.EnergySource.SolarCellInitializer;
|
import org.KaiFlo.SolarCell.Systems.EnergySource.SolarCellInitializer;
|
||||||
|
import org.KaiFlo.SolarCell.Systems.EnergySource.SolarCellTickingSystem;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@@ -38,6 +39,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 SolarCellInitializer());
|
this.getChunkStoreRegistry().registerSystem(new SolarCellInitializer());
|
||||||
|
this.getChunkStoreRegistry().registerSystem(new SolarCellTickingSystem());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package org.KaiFlo.SolarCell.Systems.EnergySource;
|
||||||
|
|
||||||
|
import com.hypixel.hytale.component.ArchetypeChunk;
|
||||||
|
import com.hypixel.hytale.component.CommandBuffer;
|
||||||
|
import com.hypixel.hytale.component.Store;
|
||||||
|
import com.hypixel.hytale.component.query.Query;
|
||||||
|
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
|
||||||
|
import com.hypixel.hytale.math.util.ChunkUtil;
|
||||||
|
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.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.EnergySource.Implementations.SolarCellComponent;
|
||||||
|
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
|
||||||
|
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||||
|
|
||||||
|
public class SolarCellTickingSystem extends EntityTickingSystem<ChunkStore> {
|
||||||
|
|
||||||
|
@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());
|
||||||
|
if (blockSection == null || blockSection.getTickingBlocksCount() != 0) return;
|
||||||
|
|
||||||
|
var chunkSection = archetypeChunk.getComponent(i, 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;
|
||||||
|
|
||||||
|
var world = worldChunk.getWorld();
|
||||||
|
|
||||||
|
blockSection.forEachTicking(blockComponentChunk, commandBuffer, chunkSection.getY(),
|
||||||
|
(_, _, localX, localY, localZ, _) -> {
|
||||||
|
var blockRef = blockComponentChunk.getEntityReference(ChunkUtil.indexBlockInColumn(localX, localY, localZ));
|
||||||
|
if (blockRef == null) return BlockTickStrategy.IGNORED;
|
||||||
|
var solarCellComponent = commandBuffer.getComponent(blockRef, SolarCellComponent.getComponentType());
|
||||||
|
if (solarCellComponent == null) return BlockTickStrategy.IGNORED;
|
||||||
|
|
||||||
|
int globalX = localX + (worldChunk.getX() * 32);
|
||||||
|
int globalZ = localZ + (worldChunk.getZ() * 32);
|
||||||
|
|
||||||
|
world.execute(() -> {
|
||||||
|
world.setBlock(globalX + 1, localY, globalZ, "Rock_Ice");
|
||||||
|
});
|
||||||
|
|
||||||
|
return BlockTickStrategy.CONTINUE;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@NullableDecl
|
||||||
|
@Override
|
||||||
|
public Query<ChunkStore> getQuery() {
|
||||||
|
return Query.and(BlockSection.getComponentType(), ChunkSection.getComponentType());
|
||||||
|
}
|
||||||
|
}
|
||||||
66
src/main/resources/Server/Item/Items/SolarCell.json
Normal file
66
src/main/resources/Server/Item/Items/SolarCell.json
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
{
|
||||||
|
"TranslationProperties": {
|
||||||
|
"Name": "server.items.Rock_Stone.name"
|
||||||
|
},
|
||||||
|
"ItemLevel": 10,
|
||||||
|
"MaxStack": 100,
|
||||||
|
"Icon": "Icons/ItemsGenerated/Rock_Stone_Stalactite_Small.png",
|
||||||
|
"Categories": [
|
||||||
|
"Blocks.Rocks"
|
||||||
|
],
|
||||||
|
"PlayerAnimationsId": "Block",
|
||||||
|
"Set": "Rock_Stone",
|
||||||
|
"BlockType": {
|
||||||
|
"Material": "Solid",
|
||||||
|
"DrawType": "Cube",
|
||||||
|
"Group": "Stone",
|
||||||
|
"Flags": {},
|
||||||
|
"Gathering": {
|
||||||
|
"Breaking": {
|
||||||
|
"GatherType": "Rocks",
|
||||||
|
"ItemId": "Rock_Stone_Cobble"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"BlockParticleSetId": "Stone",
|
||||||
|
"Textures": [
|
||||||
|
{
|
||||||
|
"All": "BlockTextures/Rock_Stone.png",
|
||||||
|
"Weight": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"All": "BlockTextures/Rock_Stone_2.png",
|
||||||
|
"Weight": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"All": "BlockTextures/Rock_Stone_3.png",
|
||||||
|
"Weight": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"ParticleColor": "#737055",
|
||||||
|
"BlockSoundSetId": "Stone",
|
||||||
|
"Aliases": [
|
||||||
|
"stone",
|
||||||
|
"stone00"
|
||||||
|
],
|
||||||
|
"BlockBreakingDecalId": "Breaking_Decals_Rock",
|
||||||
|
"BlockEntity": {
|
||||||
|
"Components": {
|
||||||
|
"SolarCell": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ResourceTypes": [
|
||||||
|
{
|
||||||
|
"Id": "Rock"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Id": "Rock_Stone"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Tags": {
|
||||||
|
"Type": [
|
||||||
|
"Rock"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ItemSoundSetId": "ISS_Blocks_Stone"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user