From 51f7e506f65f792e36d1aaf0818f25ada8a54279 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 4 Jan 2022 19:20:48 +0700 Subject: [PATCH] Matter bottler blockstate addition, streamline capability names --- .../mc/otm/capability/MatteryCapability.java | 4 +- .../mc/otm/block/BlockMatterBottler.kt | 36 ++++++++++++++---- .../otm/block/entity/BlockEntityDriveRack.kt | 3 +- .../block/entity/BlockEntityItemMonitor.kt | 2 +- .../block/entity/BlockEntityMatterBottler.kt | 38 +++++++++++++++---- .../block/entity/BlockEntityMatterCable.kt | 2 +- .../entity/BlockEntityMatterCapacitorBank.kt | 2 +- .../entity/BlockEntityMatterDecomposer.kt | 2 +- .../block/entity/BlockEntityMatterPanel.kt | 3 +- .../entity/BlockEntityMatterReplicator.kt | 2 +- .../block/entity/BlockEntityMatterScanner.kt | 2 +- .../block/entity/BlockEntityPatternStorage.kt | 2 +- .../mc/otm/graph/matter/MatterNetworkGraph.kt | 4 +- .../otm/graph/storage/StorageNetworkGraph.kt | 4 +- 14 files changed, 73 insertions(+), 33 deletions(-) diff --git a/src/main/java/ru/dbotthepony/mc/otm/capability/MatteryCapability.java b/src/main/java/ru/dbotthepony/mc/otm/capability/MatteryCapability.java index 18f32eefe..ee58d1b4f 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/capability/MatteryCapability.java +++ b/src/main/java/ru/dbotthepony/mc/otm/capability/MatteryCapability.java @@ -18,11 +18,11 @@ public class MatteryCapability { public static final Capability ENERGY = CapabilityManager.get(new CapabilityToken<>() {}); public static final Capability ANDROID = CapabilityManager.get(new CapabilityToken<>() {}); public static final Capability MATTER = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability MATTER_CELL = CapabilityManager.get(new CapabilityToken<>() {}); + public static final Capability MATTER_NODE = CapabilityManager.get(new CapabilityToken<>() {}); public static final Capability PATTERN = CapabilityManager.get(new CapabilityToken<>() {}); public static final Capability TASK = CapabilityManager.get(new CapabilityToken<>() {}); public static final Capability DRIVE = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability STORAGE_CELL = CapabilityManager.get(new CapabilityToken<>() {}); + public static final Capability STORAGE_NODE = CapabilityManager.get(new CapabilityToken<>() {}); @SuppressWarnings("unused") public static void register(final RegisterCapabilitiesEvent event) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockMatterBottler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockMatterBottler.kt index 40c3cf69e..08d74ca6d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockMatterBottler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockMatterBottler.kt @@ -6,6 +6,7 @@ import ru.dbotthepony.mc.otm.block.BlockMatteryRotatable import net.minecraft.world.level.block.EntityBlock import net.minecraft.core.BlockPos import net.minecraft.core.Direction +import net.minecraft.world.item.context.BlockPlaceContext import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block @@ -15,6 +16,7 @@ import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterBottler import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.entity.BlockEntityTicker import net.minecraft.world.level.block.state.StateDefinition +import net.minecraft.world.level.block.state.properties.BooleanProperty import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.Registry @@ -42,6 +44,14 @@ class BlockMatterBottler : BlockMatteryRotatable(), EntityBlock { override fun createBlockStateDefinition(builder: StateDefinition.Builder) { super.createBlockStateDefinition(builder) builder.add(WorkerState.SEMI_WORKER_STATE) + builder.add(*SLOT_PROPERTIES) + } + + override fun getStateForPlacement(context: BlockPlaceContext): BlockState { + return super.getStateForPlacement(context)!! + .setValue(SLOT_PROPERTIES[0], false) + .setValue(SLOT_PROPERTIES[1], false) + .setValue(SLOT_PROPERTIES[2], false) } override fun getShape( @@ -54,15 +64,25 @@ class BlockMatterBottler : BlockMatteryRotatable(), EntityBlock { } companion object { - private val def = BlockShapes.MATTER_BOTTLER.computeShape() + private val SHAPES: List - private val SHAPES: List = listOf( - def, - def, - def, - BlockShapes.MATTER_BOTTLER.rotate(Direction.NORTH).computeShape(), - BlockShapes.MATTER_BOTTLER.rotate(Direction.WEST).computeShape(), - BlockShapes.MATTER_BOTTLER.rotate(Direction.EAST).computeShape() + val SLOT_PROPERTIES = arrayOf( + BooleanProperty.create("bottle_0"), + BooleanProperty.create("bottle_1"), + BooleanProperty.create("bottle_2") ) + + init { + val def = BlockShapes.MATTER_BOTTLER.computeShape() + + SHAPES = listOf( + def, + def, + def, + BlockShapes.MATTER_BOTTLER.rotate(Direction.NORTH).computeShape(), + BlockShapes.MATTER_BOTTLER.rotate(Direction.WEST).computeShape(), + BlockShapes.MATTER_BOTTLER.rotate(Direction.EAST).computeShape() + ) + } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityDriveRack.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityDriveRack.kt index e801c08cc..eb2ca83b6 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityDriveRack.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityDriveRack.kt @@ -25,7 +25,6 @@ import ru.dbotthepony.mc.otm.menu.DriveRackMenu import ru.dbotthepony.mc.otm.set import ru.dbotthepony.mc.otm.graph.storage.StorageNetworkGraph import ru.dbotthepony.mc.otm.storage.PoweredVirtualComponent -import ru.dbotthepony.mc.otm.storage.VirtualComponent class BlockEntityDriveRack(p_155229_: BlockPos, p_155230_: BlockState) : BlockEntityMatteryPowered(Registry.BlockEntities.DRIVE_RACK, p_155229_, p_155230_) { @@ -84,7 +83,7 @@ class BlockEntityDriveRack(p_155229_: BlockPos, p_155230_: BlockState) : } override fun getCapability(cap: Capability, side: Direction?): LazyOptional { - return if (cap === MatteryCapability.STORAGE_CELL) { + return if (cap === MatteryCapability.STORAGE_NODE) { cell.get().cast() } else super.getCapability(cap, side) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityItemMonitor.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityItemMonitor.kt index c5ba6c7db..6deadd749 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityItemMonitor.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityItemMonitor.kt @@ -50,7 +50,7 @@ class BlockEntityItemMonitor(p_155229_: BlockPos, p_155230_: BlockState) : } override fun getCapability(cap: Capability, side: Direction?): LazyOptional { - return if (cap === MatteryCapability.STORAGE_CELL) { + return if (cap === MatteryCapability.STORAGE_NODE) { cell.get().cast() } else super.getCapability(cap, side) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterBottler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterBottler.kt index 68a2dece9..d7ff28c8c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterBottler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterBottler.kt @@ -1,7 +1,5 @@ package ru.dbotthepony.mc.otm.block.entity -import net.minecraft.MethodsReturnNonnullByDefault -import javax.annotation.ParametersAreNonnullByDefault import net.minecraft.core.BlockPos import net.minecraft.core.Direction import net.minecraft.world.level.block.state.BlockState @@ -26,6 +24,7 @@ import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block import net.minecraftforge.common.capabilities.Capability import ru.dbotthepony.mc.otm.Registry +import ru.dbotthepony.mc.otm.block.BlockMatterBottler import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState import ru.dbotthepony.mc.otm.core.Fraction import ru.dbotthepony.mc.otm.graph.Graph6Node @@ -34,8 +33,6 @@ import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph import ru.dbotthepony.mc.otm.ifHas import ru.dbotthepony.mc.otm.set -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault class BlockEntityMatterBottler(p_155229_: BlockPos, p_155230_: BlockState) : BlockEntityMatteryPowered(Registry.BlockEntities.MATTER_BOTTLER, p_155229_, p_155230_), IMatterGraphNode { @@ -56,6 +53,26 @@ class BlockEntityMatterBottler(p_155229_: BlockPos, p_155230_: BlockState) : fun switchWorkFlow() { workFlow = !workFlow + updateBlockState() + } + + private fun updateBlockState() { + val level = level as? ServerLevel ?: return + + var state = blockState + val initial = if (workFlow) 0 else 3 + + for (i in initial .. initial + 2) { + val desired = !container.getItem(i).isEmpty && container.getItem(i).getCapability(MatteryCapability.MATTER).isPresent + + if (state.getValue(BlockMatterBottler.SLOT_PROPERTIES[i - initial]) != desired) { + state = state.setValue(BlockMatterBottler.SLOT_PROPERTIES[i - initial], desired) + } + } + + if (state !== blockState) { + level.setBlock(blockPos, state, Block.UPDATE_CLIENTS) + } } // TODO: оно должно что то делать @@ -68,6 +85,11 @@ class BlockEntityMatterBottler(p_155229_: BlockPos, p_155230_: BlockState) : override fun getMaxStackSize(slot: Int): Int { return 1 } + + override fun setChanged(slot: Int, new_state: ItemStack, old_state: ItemStack) { + super.setChanged(slot, new_state, old_state) + updateBlockState() + } } val itemHandler = container.handler({ slot: Int, stack: ItemStack -> @@ -130,7 +152,7 @@ class BlockEntityMatterBottler(p_155229_: BlockPos, p_155230_: BlockState) : return itemHandler.get().cast() } - if (cap === MatteryCapability.MATTER_CELL) { + if (cap === MatteryCapability.MATTER_NODE) { return resolverNode.cast() } } @@ -199,7 +221,7 @@ class BlockEntityMatterBottler(p_155229_: BlockPos, p_155230_: BlockState) : batteryChargeLoop() if (isBlockedByRedstone) { - if (blockState.getValue(WorkerState.SEMI_WORKER_STATE) != WorkerState.IDLE) { + if (blockState.getValue(WorkerState.SEMI_WORKER_STATE) !== WorkerState.IDLE) { level!!.setBlock( blockPos, blockState.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE), @@ -222,7 +244,7 @@ class BlockEntityMatterBottler(p_155229_: BlockPos, p_155230_: BlockState) : if (!itemStack.isEmpty) { val cap = itemStack.getCapability(MatteryCapability.MATTER).resolve() - if (cap.isPresent && cap.get().direction != unexpectedDirection) { + if (cap.isPresent && cap.get().direction !== unexpectedDirection) { if (this.workFlow && cap.get().missingMatter > Fraction.ZERO || !this.workFlow && cap.get().storedMatter > Fraction.ZERO) { work_stack = itemStack capability = cap.get() @@ -244,7 +266,7 @@ class BlockEntityMatterBottler(p_155229_: BlockPos, p_155230_: BlockState) : val graph = node.graph as MatterNetworkGraph? if (capability != null) { - if (blockState.getValue(WorkerState.SEMI_WORKER_STATE) != WorkerState.WORKING) { + if (blockState.getValue(WorkerState.SEMI_WORKER_STATE) !== WorkerState.WORKING) { level!!.setBlock(blockPos, blockState.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.WORKING), Block.UPDATE_CLIENTS) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterCable.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterCable.kt index 75797fb3b..6da055b09 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterCable.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterCable.kt @@ -40,7 +40,7 @@ class BlockEntityMatterCable(p_155229_: BlockPos, p_155230_: BlockState) : override fun getCapability(cap: Capability, side: Direction?): LazyOptional { if (valid) { - if (cap === MatteryCapability.MATTER_CELL) + if (cap === MatteryCapability.MATTER_NODE) return resolverNode.cast() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterCapacitorBank.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterCapacitorBank.kt index 1343fa9f1..59daca1c7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterCapacitorBank.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterCapacitorBank.kt @@ -183,7 +183,7 @@ class BlockEntityMatterCapacitorBank(p_155229_: BlockPos, p_155230_: BlockState) override fun getCapability(cap: Capability, side: Direction?): LazyOptional { if (valid) { if (cap === MatteryCapability.MATTER) return resolver.cast() - if (cap === MatteryCapability.MATTER_CELL) return resolverNode.cast() + if (cap === MatteryCapability.MATTER_NODE) return resolverNode.cast() } return super.getCapability(cap, side) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterDecomposer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterDecomposer.kt index 0eb663b77..f91606687 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterDecomposer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterDecomposer.kt @@ -117,7 +117,7 @@ class BlockEntityMatterDecomposer(pos: BlockPos, state: BlockState) override fun getCapability(cap: Capability, side: Direction?): LazyOptional { if (valid) { if (cap === MatteryCapability.MATTER) return resolverMatter.cast() - if (cap === MatteryCapability.MATTER_CELL) return resolverNode.cast() + if (cap === MatteryCapability.MATTER_NODE) return resolverNode.cast() if (cap === CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return itemHandler.cast() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterPanel.kt index 84db42e23..76cfc3334 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterPanel.kt @@ -32,7 +32,6 @@ import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph import java.util.ArrayList import java.util.List -import java.util.function.Consumer @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault @@ -79,7 +78,7 @@ class BlockEntityMatterPanel(p_155229_: BlockPos, p_155230_: BlockState) : private var resolver = LazyOptional.of { this } override fun getCapability(cap: Capability, side: Direction?): LazyOptional { - if (valid && (cap === MatteryCapability.MATTER_CELL || cap === MatteryCapability.TASK)) + if (valid && (cap === MatteryCapability.MATTER_NODE || cap === MatteryCapability.TASK)) return resolver.cast() return super.getCapability(cap, side) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterReplicator.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterReplicator.kt index 7752c0ca7..67bebdc99 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterReplicator.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterReplicator.kt @@ -207,7 +207,7 @@ class BlockEntityMatterReplicator(p_155229_: BlockPos, p_155230_: BlockState) : override fun getCapability(cap: Capability, side: Direction?): LazyOptional { if (valid) { - if (cap === MatteryCapability.MATTER_CELL) return resolverNode.cast() + if (cap === MatteryCapability.MATTER_NODE) return resolverNode.cast() if (cap === CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return itemHandler.get().cast() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterScanner.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterScanner.kt index 300c6702f..e18def1a4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterScanner.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterScanner.kt @@ -67,7 +67,7 @@ class BlockEntityMatterScanner(p_155229_: BlockPos, p_155230_: BlockState) : if (valid) { if (cap === CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return inputHandler.get().cast() //if (cap === MatteryCapability.MATTER_CELL) return resolver_grid.cast() - if (cap == MatteryCapability.MATTER_CELL) return resolverNode.cast() + if (cap == MatteryCapability.MATTER_NODE) return resolverNode.cast() } return super.getCapability(cap, side) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityPatternStorage.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityPatternStorage.kt index 79c1c31f4..6b018925c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityPatternStorage.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityPatternStorage.kt @@ -138,7 +138,7 @@ class BlockEntityPatternStorage(p_155229_: BlockPos, p_155230_: BlockState) : override fun getCapability(cap: Capability, side: Direction?): LazyOptional { if (valid) { if (cap === MatteryCapability.PATTERN) return resolverPatterns.cast() - if (cap === MatteryCapability.MATTER_CELL) return resolverNode.cast() + if (cap === MatteryCapability.MATTER_NODE) return resolverNode.cast() if (cap === CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return resolverItem.get().cast() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/matter/MatterNetworkGraph.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/matter/MatterNetworkGraph.kt index e2aa51a59..d756d8511 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/matter/MatterNetworkGraph.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/matter/MatterNetworkGraph.kt @@ -379,7 +379,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe tile.blockPos, node, fun(_tile): Graph6Node? { - val resolve = _tile.getCapability(MatteryCapability.MATTER_CELL) + val resolve = _tile.getCapability(MatteryCapability.MATTER_NODE) return if (resolve.isPresent) { resolve.resolve().get().getAsMatterNode() @@ -401,7 +401,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe tile.blockPos, node, fun(_tile): Graph6Node? { - val resolve = _tile.getCapability(MatteryCapability.MATTER_CELL) + val resolve = _tile.getCapability(MatteryCapability.MATTER_NODE) return if (resolve.isPresent) { resolve.resolve().get().getAsMatterNode() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/storage/StorageNetworkGraph.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/storage/StorageNetworkGraph.kt index 04a9c0fe6..021db3c9e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/storage/StorageNetworkGraph.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/storage/StorageNetworkGraph.kt @@ -54,7 +54,7 @@ class StorageNetworkGraph : Abstract6Graph() { tile.blockPos, node, fun(_tile): Graph6Node? { - val resolve = _tile.getCapability(MatteryCapability.STORAGE_CELL) + val resolve = _tile.getCapability(MatteryCapability.STORAGE_NODE) return if (resolve.isPresent) { resolve.resolve().get().getAsStorageNode() @@ -76,7 +76,7 @@ class StorageNetworkGraph : Abstract6Graph() { tile.blockPos, node, fun(_tile): Graph6Node? { - val resolve = _tile.getCapability(MatteryCapability.STORAGE_CELL) + val resolve = _tile.getCapability(MatteryCapability.STORAGE_NODE) return if (resolve.isPresent) { resolve.resolve().get().getAsStorageNode()