Matter bottler blockstate addition, streamline capability names
This commit is contained in:
parent
6c029b98b7
commit
51f7e506f6
@ -18,11 +18,11 @@ public class MatteryCapability {
|
||||
public static final Capability<IMatteryEnergyStorage> ENERGY = CapabilityManager.get(new CapabilityToken<>() {});
|
||||
public static final Capability<IAndroidCapability> ANDROID = CapabilityManager.get(new CapabilityToken<>() {});
|
||||
public static final Capability<IMatterHandler> MATTER = CapabilityManager.get(new CapabilityToken<>() {});
|
||||
public static final Capability<IMatterGraphNode> MATTER_CELL = CapabilityManager.get(new CapabilityToken<>() {});
|
||||
public static final Capability<IMatterGraphNode> MATTER_NODE = CapabilityManager.get(new CapabilityToken<>() {});
|
||||
public static final Capability<IPatternStorage> PATTERN = CapabilityManager.get(new CapabilityToken<>() {});
|
||||
public static final Capability<IMatterTaskProvider> TASK = CapabilityManager.get(new CapabilityToken<>() {});
|
||||
public static final Capability<IMatteryDrive> DRIVE = CapabilityManager.get(new CapabilityToken<>() {});
|
||||
public static final Capability<IStorageGraphNode> STORAGE_CELL = CapabilityManager.get(new CapabilityToken<>() {});
|
||||
public static final Capability<IStorageGraphNode> STORAGE_NODE = CapabilityManager.get(new CapabilityToken<>() {});
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void register(final RegisterCapabilitiesEvent event) {
|
||||
|
@ -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<Block, BlockState>) {
|
||||
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,9 +64,18 @@ class BlockMatterBottler : BlockMatteryRotatable(), EntityBlock {
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val def = BlockShapes.MATTER_BOTTLER.computeShape()
|
||||
private val SHAPES: List<VoxelShape>
|
||||
|
||||
private val SHAPES: List<VoxelShape> = listOf(
|
||||
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,
|
||||
@ -66,3 +85,4 @@ class BlockMatterBottler : BlockMatteryRotatable(), EntityBlock {
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
return if (cap === MatteryCapability.STORAGE_CELL) {
|
||||
return if (cap === MatteryCapability.STORAGE_NODE) {
|
||||
cell.get().cast()
|
||||
} else super.getCapability(cap, side)
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class BlockEntityItemMonitor(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
}
|
||||
|
||||
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
return if (cap === MatteryCapability.STORAGE_CELL) {
|
||||
return if (cap === MatteryCapability.STORAGE_NODE) {
|
||||
cell.get().cast()
|
||||
} else super.getCapability(cap, side)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class BlockEntityMatterCable(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
|
||||
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
if (valid) {
|
||||
if (cap === MatteryCapability.MATTER_CELL)
|
||||
if (cap === MatteryCapability.MATTER_NODE)
|
||||
return resolverNode.cast()
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ class BlockEntityMatterCapacitorBank(p_155229_: BlockPos, p_155230_: BlockState)
|
||||
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
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)
|
||||
|
@ -117,7 +117,7 @@ class BlockEntityMatterDecomposer(pos: BlockPos, state: BlockState)
|
||||
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -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 <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
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)
|
||||
|
@ -207,7 +207,7 @@ class BlockEntityMatterReplicator(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
|
||||
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -138,7 +138,7 @@ class BlockEntityPatternStorage(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -379,7 +379,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
||||
tile.blockPos,
|
||||
node,
|
||||
fun(_tile): Graph6Node<IMatterGraphNode>? {
|
||||
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<IMatterGraphNode>(), IMatterGraphListe
|
||||
tile.blockPos,
|
||||
node,
|
||||
fun(_tile): Graph6Node<IMatterGraphNode>? {
|
||||
val resolve = _tile.getCapability(MatteryCapability.MATTER_CELL)
|
||||
val resolve = _tile.getCapability(MatteryCapability.MATTER_NODE)
|
||||
|
||||
return if (resolve.isPresent) {
|
||||
resolve.resolve().get().getAsMatterNode()
|
||||
|
@ -54,7 +54,7 @@ class StorageNetworkGraph : Abstract6Graph<IStorageGraphNode>() {
|
||||
tile.blockPos,
|
||||
node,
|
||||
fun(_tile): Graph6Node<IStorageGraphNode>? {
|
||||
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<IStorageGraphNode>() {
|
||||
tile.blockPos,
|
||||
node,
|
||||
fun(_tile): Graph6Node<IStorageGraphNode>? {
|
||||
val resolve = _tile.getCapability(MatteryCapability.STORAGE_CELL)
|
||||
val resolve = _tile.getCapability(MatteryCapability.STORAGE_NODE)
|
||||
|
||||
return if (resolve.isPresent) {
|
||||
resolve.resolve().get().getAsStorageNode()
|
||||
|
Loading…
Reference in New Issue
Block a user