fix merge
This commit is contained in:
@@ -32,6 +32,7 @@ object Blocks {
|
|||||||
val SOLARGEN_BLOCK: RegistrySupplier<Block> = BaseBlock.register("solargen") { SolarGeneratorBlock() }
|
val SOLARGEN_BLOCK: RegistrySupplier<Block> = BaseBlock.register("solargen") { SolarGeneratorBlock() }
|
||||||
val COMBUSTGEN_BLOCK: RegistrySupplier<Block> = BaseBlock.register("combustgen") { CombustionGeneratorBlock() }
|
val COMBUSTGEN_BLOCK: RegistrySupplier<Block> = BaseBlock.register("combustgen") { CombustionGeneratorBlock() }
|
||||||
val CASE_BLOCK: RegistrySupplier<Block> = BaseBlock.register("case") { CaseBlock() }
|
val CASE_BLOCK: RegistrySupplier<Block> = BaseBlock.register("case") { CaseBlock() }
|
||||||
|
val REDSTONEIO_BLOCK: RegistrySupplier<Block> = BaseBlock.register("redio") { RedstoneIOBlock() }
|
||||||
|
|
||||||
fun registerBlockItems() {
|
fun registerBlockItems() {
|
||||||
BLOCKS.forEach(Consumer { sup: RegistrySupplier<Block> ->
|
BLOCKS.forEach(Consumer { sup: RegistrySupplier<Block> ->
|
||||||
|
|||||||
@@ -29,10 +29,12 @@ open class CapacitorEntity(val capacity: Long, type: BlockEntityType<*>, pos: Bl
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun loadAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) {
|
override fun loadAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) {
|
||||||
|
super.loadAdditional(compoundTag, provider)
|
||||||
node.energy = min(compoundTag.getLong("energy"), node.energyCapacity)
|
node.energy = min(compoundTag.getLong("energy"), node.energyCapacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun saveAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) {
|
override fun saveAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) {
|
||||||
|
super.saveAdditional(compoundTag, provider)
|
||||||
compoundTag.putLong("energy", node.energy)
|
compoundTag.putLong("energy", node.energy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import net.minecraft.server.level.ServerPlayer
|
|||||||
import net.minecraft.sounds.SoundEvents
|
import net.minecraft.sounds.SoundEvents
|
||||||
import net.minecraft.sounds.SoundSource
|
import net.minecraft.sounds.SoundSource
|
||||||
import net.minecraft.util.RandomSource
|
import net.minecraft.util.RandomSource
|
||||||
|
import net.minecraft.world.Containers
|
||||||
import net.minecraft.world.InteractionResult
|
import net.minecraft.world.InteractionResult
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
@@ -74,4 +75,15 @@ class CombustionGeneratorBlock : NodeBlock, EntityBlock {
|
|||||||
level.addParticle(ParticleTypes.FLAME, x+0.5, y+1, z+0.5, 0.0, 0.0, 0.0)
|
level.addParticle(ParticleTypes.FLAME, x+0.5, y+1, z+0.5, 0.0, 0.0, 0.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onRemove(
|
||||||
|
blockState: BlockState,
|
||||||
|
level: Level,
|
||||||
|
blockPos: BlockPos,
|
||||||
|
blockState2: BlockState,
|
||||||
|
bl: Boolean
|
||||||
|
) {
|
||||||
|
Containers.dropContentsOnDestroy(blockState, blockState2, level, blockPos)
|
||||||
|
super.onRemove(blockState, level, blockPos, blockState2, bl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,20 +190,22 @@ abstract class NodeBlock(properties: Properties = Properties.of()): BaseBlock(pr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setPlacedBy(
|
override fun onPlace(
|
||||||
|
blockState: BlockState,
|
||||||
level: Level,
|
level: Level,
|
||||||
blockPos: BlockPos,
|
blockPos: BlockPos,
|
||||||
blockState: BlockState,
|
blockState2: BlockState,
|
||||||
livingEntity: LivingEntity?,
|
bl: Boolean
|
||||||
itemStack: ItemStack
|
|
||||||
) {
|
) {
|
||||||
|
super.onPlace(blockState, level, blockPos, blockState2, bl)
|
||||||
if(!level.isClientSide) {
|
if(!level.isClientSide) {
|
||||||
val ent = level.getBlockEntity(blockPos)
|
val ent = level.getBlockEntity(blockPos)
|
||||||
if(ent is NodeBlockEntity) {
|
if(ent is NodeBlockEntity) {
|
||||||
ent.invalidateNodeState()
|
ent.invalidateNodeState()
|
||||||
|
ent.computeEdges().forEach { it.invalidateNodeState() }
|
||||||
}
|
}
|
||||||
|
level.updateNeighborsAt(blockPos, this)
|
||||||
}
|
}
|
||||||
super.setPlacedBy(level, blockPos, blockState, livingEntity, itemStack)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun neighborChanged(
|
override fun neighborChanged(
|
||||||
@@ -214,6 +216,7 @@ abstract class NodeBlock(properties: Properties = Properties.of()): BaseBlock(pr
|
|||||||
blockPos2: BlockPos,
|
blockPos2: BlockPos,
|
||||||
bl: Boolean
|
bl: Boolean
|
||||||
) {
|
) {
|
||||||
|
super.neighborChanged(blockState, level, blockPos, block, blockPos2, bl)
|
||||||
if(!level.isClientSide) {
|
if(!level.isClientSide) {
|
||||||
val ent = level.getBlockEntity(blockPos)
|
val ent = level.getBlockEntity(blockPos)
|
||||||
if(ent is NodeBlockEntity) {
|
if(ent is NodeBlockEntity) {
|
||||||
@@ -221,6 +224,5 @@ abstract class NodeBlock(properties: Properties = Properties.of()): BaseBlock(pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
super.neighborChanged(blockState, level, blockPos, block, blockPos2, bl)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
138
src/main/kotlin/org/neoflock/neocomputers/block/RedstoneIO.kt
Normal file
138
src/main/kotlin/org/neoflock/neocomputers/block/RedstoneIO.kt
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
package org.neoflock.neocomputers.block
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos
|
||||||
|
import net.minecraft.core.Direction
|
||||||
|
import net.minecraft.world.InteractionResult
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.level.BlockGetter
|
||||||
|
import net.minecraft.world.level.Level
|
||||||
|
import net.minecraft.world.level.block.Block
|
||||||
|
import net.minecraft.world.level.block.RedStoneWireBlock
|
||||||
|
import net.minecraft.world.level.block.RedstoneTorchBlock
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity
|
||||||
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
|
import net.minecraft.world.phys.BlockHitResult
|
||||||
|
import org.neoflock.neocomputers.NeoComputers
|
||||||
|
import org.neoflock.neocomputers.entity.BlockEntities
|
||||||
|
import org.neoflock.neocomputers.network.Networking
|
||||||
|
|
||||||
|
fun dirToIdx(direction: Direction) = Direction.entries.indexOf(direction)
|
||||||
|
|
||||||
|
class RedstoneIOEntity(blockPos: BlockPos, blockState: BlockState): NodeBlockEntity(BlockEntities.REDSTONEIO_ENTITY.get(), blockPos, blockState) {
|
||||||
|
val redstoneIn = Array<Int>(Direction.entries.size) {0}
|
||||||
|
val redstoneOut = Array<Int>(Direction.entries.size) {0}
|
||||||
|
|
||||||
|
// TODO: have redstone I/O node for component and shi
|
||||||
|
override val node = object : Networking.Node() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun refetch(dir: Direction) {
|
||||||
|
val src = blockPos.offset(dir.stepX, dir.stepY, dir.stepZ)
|
||||||
|
val cur = level?.getSignal(src, dir) ?: 0
|
||||||
|
val idx = dirToIdx(dir)
|
||||||
|
if(redstoneIn[idx] != cur) {
|
||||||
|
onRedstoneSignalChanged(dir, redstoneIn[idx], cur)
|
||||||
|
}
|
||||||
|
redstoneIn[idx] = cur
|
||||||
|
}
|
||||||
|
|
||||||
|
fun refetchAll() {
|
||||||
|
Direction.entries.forEach { refetch(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onRedstoneSignalChanged(dir: Direction, oldValue: Int, newValue: Int) {
|
||||||
|
Networking.emitMessage(node, Networking.ComputerUncheckedSignal(node, "redstone_changed", arrayOf(node.address.toString(), dirToIdx(dir), oldValue, newValue)))
|
||||||
|
NeoComputers.LOGGER.info("redstone in direction ${dir.name} changed from $oldValue to $newValue")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RedstoneIOBlock(): NodeBlock(Properties.of().isRedstoneConductor { state, getter, pos -> true }) {
|
||||||
|
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity = RedstoneIOEntity(blockPos, blockState)
|
||||||
|
|
||||||
|
fun getRedstoneIO(level: BlockGetter, blockPos: BlockPos): RedstoneIOEntity? {
|
||||||
|
val ent = level.getBlockEntity(blockPos)
|
||||||
|
if(ent is RedstoneIOEntity) return ent
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSignalSource(blockState: BlockState): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getSignal(
|
||||||
|
blockState: BlockState,
|
||||||
|
blockGetter: BlockGetter,
|
||||||
|
blockPos: BlockPos,
|
||||||
|
direction: Direction
|
||||||
|
): Int {
|
||||||
|
val redstoneIO = getRedstoneIO(blockGetter, blockPos)
|
||||||
|
if(redstoneIO != null) {
|
||||||
|
return redstoneIO.redstoneOut[dirToIdx(direction.opposite)]
|
||||||
|
}
|
||||||
|
return super.getSignal(blockState, blockGetter, blockPos, direction)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPlace(
|
||||||
|
blockState: BlockState,
|
||||||
|
level: Level,
|
||||||
|
blockPos: BlockPos,
|
||||||
|
blockState2: BlockState,
|
||||||
|
bl: Boolean
|
||||||
|
) {
|
||||||
|
if(!level.isClientSide) {
|
||||||
|
level.updateNeighborsAt(blockPos, this)
|
||||||
|
getRedstoneIO(level, blockPos)?.refetchAll()
|
||||||
|
}
|
||||||
|
super.onPlace(blockState, level, blockPos, blockState2, bl)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRemove(
|
||||||
|
blockState: BlockState,
|
||||||
|
level: Level,
|
||||||
|
blockPos: BlockPos,
|
||||||
|
blockState2: BlockState,
|
||||||
|
bl: Boolean
|
||||||
|
) {
|
||||||
|
if(!level.isClientSide) {
|
||||||
|
level.updateNeighborsAt(blockPos, this)
|
||||||
|
}
|
||||||
|
super.onRemove(blockState, level, blockPos, blockState2, bl)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun neighborChanged(
|
||||||
|
blockState: BlockState,
|
||||||
|
level: Level,
|
||||||
|
blockPos: BlockPos,
|
||||||
|
block: Block,
|
||||||
|
blockPos2: BlockPos,
|
||||||
|
bl: Boolean
|
||||||
|
) {
|
||||||
|
super.neighborChanged(blockState, level, blockPos, block, blockPos2, bl)
|
||||||
|
if(!level.isClientSide) {
|
||||||
|
val dir = Direction.getNearest(blockPos2.center.subtract(blockPos.center))
|
||||||
|
getRedstoneIO(level, blockPos)?.refetch(dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun useWithoutItem(
|
||||||
|
blockState: BlockState,
|
||||||
|
level: Level,
|
||||||
|
blockPos: BlockPos,
|
||||||
|
player: Player,
|
||||||
|
blockHitResult: BlockHitResult
|
||||||
|
): InteractionResult? {
|
||||||
|
if(!level.isClientSide) {
|
||||||
|
val redio = getRedstoneIO(level, blockPos)
|
||||||
|
val dir = blockHitResult.direction
|
||||||
|
if (redio != null) {
|
||||||
|
val idx = dirToIdx(dir)
|
||||||
|
redio.redstoneOut[idx]++
|
||||||
|
redio.redstoneOut[idx] %= 16
|
||||||
|
NeoComputers.LOGGER.info("outputting redstone level ${redio.redstoneOut[idx]} on ${dir.name}")
|
||||||
|
}
|
||||||
|
level.updateNeighborsAt(blockPos, this)
|
||||||
|
}
|
||||||
|
return super.useWithoutItem(blockState, level, blockPos, player, blockHitResult)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -70,6 +70,11 @@ object BlockEntities {
|
|||||||
::CombustionGeneratorBlockEntity, mutableSetOf(Blocks.COMBUSTGEN_BLOCK.get()), BullshitFix()
|
::CombustionGeneratorBlockEntity, mutableSetOf(Blocks.COMBUSTGEN_BLOCK.get()), BullshitFix()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
val REDSTONEIO_ENTITY: RegistrySupplier<BlockEntityType<CombustionGeneratorBlockEntity>> = BLOCKENTITIES.register("redio") {
|
||||||
|
BlockEntityType(
|
||||||
|
::CombustionGeneratorBlockEntity, mutableSetOf(Blocks.REDSTONEIO_BLOCK.get()), BullshitFix()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun registerPowerBlocks() {
|
fun registerPowerBlocks() {
|
||||||
PowerManager.registerPowerBlockEntity(CAPACITOR_ENTITY.get())
|
PowerManager.registerPowerBlockEntity(CAPACITOR_ENTITY.get())
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ import net.minecraft.network.chat.Component
|
|||||||
import net.minecraft.server.level.ServerPlayer
|
import net.minecraft.server.level.ServerPlayer
|
||||||
import net.minecraft.sounds.SoundEvents
|
import net.minecraft.sounds.SoundEvents
|
||||||
import net.minecraft.sounds.SoundSource
|
import net.minecraft.sounds.SoundSource
|
||||||
|
import net.minecraft.world.ContainerHelper
|
||||||
import net.minecraft.world.MenuProvider
|
import net.minecraft.world.MenuProvider
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu
|
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
|
import net.minecraft.world.level.block.ChestBlock
|
||||||
import net.minecraft.world.level.block.FurnaceBlock
|
import net.minecraft.world.level.block.FurnaceBlock
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import org.neoflock.neocomputers.block.CombustionGeneratorBlock
|
import org.neoflock.neocomputers.block.CombustionGeneratorBlock
|
||||||
@@ -88,12 +90,16 @@ class CombustionGeneratorBlockEntity(blockPos: BlockPos, blockState: BlockState)
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun loadAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) {
|
override fun loadAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) {
|
||||||
|
super.loadAdditional(compoundTag, provider)
|
||||||
node.energy = min(node.energyCapacity, compoundTag.getLong("energy"))
|
node.energy = min(node.energyCapacity, compoundTag.getLong("energy"))
|
||||||
burningTimeRemaining = compoundTag.getInt("burningTimeRemaining")
|
burningTimeRemaining = compoundTag.getInt("burningTimeRemaining")
|
||||||
|
ContainerHelper.loadAllItems(compoundTag, getItems(), provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun saveAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) {
|
override fun saveAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) {
|
||||||
|
super.saveAdditional(compoundTag, provider)
|
||||||
compoundTag.putLong("energy", node.energy)
|
compoundTag.putLong("energy", node.energy)
|
||||||
compoundTag.putInt("burningTimeRemaining", burningTimeRemaining)
|
compoundTag.putInt("burningTimeRemaining", burningTimeRemaining)
|
||||||
|
ContainerHelper.saveAllItems(compoundTag, getItems(), provider)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,10 +26,12 @@ class SolarGeneratorBlockEntity(blockPos: BlockPos, blockState: BlockState) : No
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun loadAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) {
|
override fun loadAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) {
|
||||||
|
super.loadAdditional(compoundTag, provider)
|
||||||
node.energy = compoundTag.getLong("energy")
|
node.energy = compoundTag.getLong("energy")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun saveAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) {
|
override fun saveAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) {
|
||||||
|
super.saveAdditional(compoundTag, provider)
|
||||||
compoundTag.putLong("energy", node.energy)
|
compoundTag.putLong("energy", node.energy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"": {
|
||||||
|
"model": "neocomputers:block/redio"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"neocomputers.confirm": "Confirm",
|
"neocomputers.confirm": "Confirm",
|
||||||
"neocomputers.cancel": "Cancel",
|
"neocomputers.cancel": "Cancel",
|
||||||
"block.neocomputers.combustgen": "Combustion Generator"
|
"block.neocomputers.combustgen": "Combustion Generator",
|
||||||
|
"block.neocomputers.redio": "Redstone I/O"
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:block/cube",
|
||||||
|
"textures": {
|
||||||
|
"up": "neocomputers:block/redio_top",
|
||||||
|
"down": "neocomputers:block/redio_bottom",
|
||||||
|
"north": "neocomputers:block/redio_north",
|
||||||
|
"south": "neocomputers:block/redio_south",
|
||||||
|
"west": "neocomputers:block/redio_west",
|
||||||
|
"east": "neocomputers:block/redio_east",
|
||||||
|
"particle": "minecraft:block/redstone_block"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"parent": "neocomputers:block/redio"
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 415 B |
Binary file not shown.
|
After Width: | Height: | Size: 552 B |
Binary file not shown.
|
After Width: | Height: | Size: 534 B |
Binary file not shown.
|
After Width: | Height: | Size: 539 B |
Binary file not shown.
|
After Width: | Height: | Size: 331 B |
Binary file not shown.
|
After Width: | Height: | Size: 546 B |
Reference in New Issue
Block a user