1.21.1 is so back
This commit is contained in:
@@ -2,20 +2,16 @@ package org.neoflock.neocomputers.block
|
||||
|
||||
import dev.architectury.registry.registries.RegistrySupplier
|
||||
import net.minecraft.core.registries.Registries
|
||||
import net.minecraft.resources.Identifier
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.resources.ResourceKey
|
||||
import net.minecraft.world.level.block.Block
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour
|
||||
import org.neoflock.neocomputers.NeoComputers
|
||||
import java.util.function.Supplier
|
||||
import com.google.common.base.Suppliers
|
||||
|
||||
open class BaseBlock : Block { // TODO: create a TieredBaseBlock class that extends this or something
|
||||
open class BaseBlock : Block(BlockBehaviour.Properties.of()) { // TODO: create a TieredBaseBlock class that extends this or something
|
||||
// val tier: Int
|
||||
|
||||
constructor(name: String):super(
|
||||
BlockBehaviour.Properties.of()
|
||||
.setId(ResourceKey
|
||||
.create(Registries.BLOCK, Identifier.fromNamespaceAndPath(NeoComputers.MODID, name))))
|
||||
|
||||
companion object Registry {
|
||||
fun register(name: String, sup: Supplier<BaseBlock>): RegistrySupplier<Block> = Blocks.BLOCKS.register(name, sup);
|
||||
|
||||
@@ -6,7 +6,7 @@ import dev.architectury.registry.registries.Registrar
|
||||
import dev.architectury.registry.registries.RegistrarManager
|
||||
import dev.architectury.registry.registries.RegistrySupplier
|
||||
import net.minecraft.core.registries.Registries
|
||||
import net.minecraft.resources.Identifier
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.resources.ResourceKey
|
||||
import net.minecraft.world.item.BlockItem
|
||||
import net.minecraft.world.item.Item
|
||||
@@ -25,13 +25,13 @@ object Blocks {
|
||||
|
||||
|
||||
val BLOCKS: DeferredRegister<Block> = DeferredRegister.create(NeoComputers.MODID, Registries.BLOCK)
|
||||
val TEST_BLOCK: RegistrySupplier<Block> = BaseBlock.register("test") { BaseBlock("test") }
|
||||
val SCREEN_BLOCK: RegistrySupplier<Block> = BaseBlock.register("screen") { ScreenBlock() }
|
||||
val CAPACITOR_BLOCK: RegistrySupplier<Block> = BaseBlock.register("capacitor") { CapacitorBlock() }
|
||||
|
||||
fun registerBlockItems() {
|
||||
BLOCKS.forEach(Consumer { sup: RegistrySupplier<Block> ->
|
||||
Items.ITEMS.register(sup.id.path) { BlockItem(sup.get()!!, Item.Properties().`arch$tab`(Tabs.TAB).setId(ResourceKey.create(Registries.ITEM, sup.id)))}
|
||||
val id = ResourceKey.create(Registries.ITEM, sup.id)
|
||||
Items.ITEMS.register(sup.id.path) { BlockItem(sup.get()!!, Item.Properties().`arch$tab`(Tabs.TAB))}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -8,31 +8,37 @@ import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.world.InteractionResult
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraft.world.level.block.Block
|
||||
import net.minecraft.world.level.block.EntityBlock
|
||||
import net.minecraft.world.level.block.entity.BlockEntity
|
||||
import net.minecraft.world.level.block.state.BlockState
|
||||
import net.minecraft.world.level.redstone.Orientation
|
||||
import net.minecraft.world.phys.BlockHitResult
|
||||
import org.neoflock.neocomputers.entity.BlockEntities
|
||||
import org.neoflock.neocomputers.network.Networking
|
||||
import org.neoflock.neocomputers.network.PowerRole
|
||||
import kotlin.math.min
|
||||
|
||||
class CapacitorEntity(pos: BlockPos, state: BlockState) : NodeBlockEntity(BlockEntities.CAPACITOR_ENTITY.get(), pos, state) {
|
||||
var amountStored: Double = 0.0
|
||||
val capacity = 20000.0
|
||||
var amountStored: Long = 0
|
||||
val capacity: Long = 20000
|
||||
|
||||
override val node = object : Networking.Node() {
|
||||
override fun getPowerRole() = PowerRole.PRODUCER
|
||||
override fun getEnergy() = amountStored
|
||||
override fun maxEnergyCapacity(): Double = capacity
|
||||
override fun setEnergy(energy: Double) {
|
||||
amountStored = energy
|
||||
override fun getEnergyCapacity() = capacity
|
||||
override fun giveEnergy(amount: Long): Long {
|
||||
val given = min(amount, capacity - amountStored)
|
||||
amountStored += given
|
||||
return given
|
||||
}
|
||||
|
||||
override fun withdrawEnergy(amount: Long): Long {
|
||||
val taken = min(amount, amountStored)
|
||||
amountStored -= taken
|
||||
return taken
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CapacitorBlock : NodeBlock("capacitor") {
|
||||
class CapacitorBlock : NodeBlock() {
|
||||
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity? {
|
||||
val cap = CapacitorEntity(blockPos, blockState)
|
||||
cap.initNetworking()
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.minecraft.world.level.block.entity.BlockEntity
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType
|
||||
import net.minecraft.world.level.block.state.BlockState
|
||||
import net.minecraft.world.level.redstone.Orientation
|
||||
import org.neoflock.neocomputers.network.Networking
|
||||
|
||||
abstract class NodeBlockEntity(blockEntityType: BlockEntityType<*>, blockPos: BlockPos, blockState: BlockState) : BlockEntity(blockEntityType, blockPos, blockState) {
|
||||
@@ -73,7 +72,7 @@ abstract class NodeBlockEntity(blockEntityType: BlockEntityType<*>, blockPos: Bl
|
||||
}
|
||||
}
|
||||
|
||||
abstract class NodeBlock(name: String): BaseBlock(name), EntityBlock {
|
||||
abstract class NodeBlock: BaseBlock(), EntityBlock {
|
||||
override fun <T : BlockEntity> getTicker(
|
||||
level: Level,
|
||||
blockState: BlockState,
|
||||
@@ -108,7 +107,7 @@ abstract class NodeBlock(name: String): BaseBlock(name), EntityBlock {
|
||||
level: Level,
|
||||
blockPos: BlockPos,
|
||||
block: Block,
|
||||
orientation: Orientation?,
|
||||
blockPos2: BlockPos,
|
||||
bl: Boolean
|
||||
) {
|
||||
if(!level.isClientSide) {
|
||||
@@ -118,6 +117,6 @@ abstract class NodeBlock(name: String): BaseBlock(name), EntityBlock {
|
||||
}
|
||||
|
||||
}
|
||||
super.neighborChanged(blockState, level, blockPos, block, orientation, bl)
|
||||
super.neighborChanged(blockState, level, blockPos, block, blockPos2, bl)
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import org.neoflock.neocomputers.entity.ScreenEntity
|
||||
import org.neoflock.neocomputers.gui.menu.Menus
|
||||
import org.neoflock.neocomputers.network.Networking
|
||||
|
||||
class ScreenBlock() : NodeBlock("screen") {
|
||||
class ScreenBlock() : NodeBlock() {
|
||||
|
||||
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity? {
|
||||
val scr = ScreenEntity(blockPos, blockState)
|
||||
@@ -39,7 +39,7 @@ class ScreenBlock() : NodeBlock("screen") {
|
||||
): InteractionResult {
|
||||
if(!level.isClientSide) {
|
||||
val screenState = level.getBlockEntity(blockPos, BlockEntities.SCREEN_ENTITY.get()).get()
|
||||
if(!screenState.node.consumeEnergy(5.0)) return InteractionResult.SUCCESS;
|
||||
if(!screenState.node.consumeEnergy(5)) return InteractionResult.SUCCESS;
|
||||
MenuRegistry.openMenu(player as ServerPlayer, object : MenuProvider {
|
||||
override fun getDisplayName(): Component = Component.literal("SCREEEEEN!")
|
||||
override fun createMenu(i: Int, inventory: Inventory, player: Player): AbstractContainerMenu {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package org.neoflock.neocomputers.block
|
||||
|
||||
class SolarGeneratorBlock : BaseBlock() {
|
||||
}
|
||||
Reference in New Issue
Block a user