diff --git a/src/main/kotlin/org/neoflock/neocomputers/NeoComputers.kt b/src/main/kotlin/org/neoflock/neocomputers/NeoComputers.kt index f4350d4..30a0a83 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/NeoComputers.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/NeoComputers.kt @@ -9,6 +9,7 @@ import org.neoflock.neocomputers.gui.buffer.BufferRenderer import org.neoflock.neocomputers.gui.menu.Menus import org.neoflock.neocomputers.gui.screen.ScreenScreen import dev.architectury.registry.menu.MenuRegistry +import net.minecraft.client.Minecraft import org.neoflock.neocomputers.item.Items import org.neoflock.neocomputers.item.Tabs import org.neoflock.neocomputers.network.Networking diff --git a/src/main/kotlin/org/neoflock/neocomputers/block/Blocks.kt b/src/main/kotlin/org/neoflock/neocomputers/block/Blocks.kt index 93e6d2b..416c86d 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/block/Blocks.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/block/Blocks.kt @@ -26,7 +26,9 @@ object Blocks { val BLOCKS: DeferredRegister = DeferredRegister.create(NeoComputers.MODID, Registries.BLOCK) val SCREEN_BLOCK: RegistrySupplier = BaseBlock.register("screen") { ScreenBlock() } - val CAPACITOR_BLOCK: RegistrySupplier = BaseBlock.register("capacitor") { CapacitorBlock() } + val CAPACITOR_BLOCK: RegistrySupplier = BaseBlock.register("capacitor") { CapacitorBlock(1) } + val CAPACITOR_BLOCK2: RegistrySupplier = BaseBlock.register("capacitor2") { CapacitorBlock(2) } + val CAPACITOR_BLOCK3: RegistrySupplier = BaseBlock.register("capacitor3") { CapacitorBlock(3) } val SOLARGEN_BLOCK: RegistrySupplier = BaseBlock.register("solargen") { SolarGeneratorBlock() } val COMBUSTGEN_BLOCK: RegistrySupplier = BaseBlock.register("combustgen") { CombustionGeneratorBlock() } diff --git a/src/main/kotlin/org/neoflock/neocomputers/block/Capacitor.kt b/src/main/kotlin/org/neoflock/neocomputers/block/Capacitor.kt index ae6f187..1384636 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/block/Capacitor.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/block/Capacitor.kt @@ -7,8 +7,10 @@ import net.minecraft.network.chat.PlayerChatMessage import net.minecraft.server.level.ServerPlayer import net.minecraft.world.InteractionResult import net.minecraft.world.entity.player.Player +import net.minecraft.world.item.Item import net.minecraft.world.level.Level import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.phys.BlockHitResult import org.neoflock.neocomputers.entity.BlockEntities @@ -16,9 +18,8 @@ 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) { +open class CapacitorEntity(val capacity: Long, type: BlockEntityType<*>, pos: BlockPos, state: BlockState) : NodeBlockEntity(type, pos, state) { var amountStored: Long = 0 - val capacity: Long = 20000 override val node = object : Networking.Node() { override fun getPowerRole() = PowerRole.STORAGE @@ -38,11 +39,19 @@ class CapacitorEntity(pos: BlockPos, state: BlockState) : NodeBlockEntity(BlockE } } -class CapacitorBlock : NodeBlock() { - override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity? { - val cap = CapacitorEntity(blockPos, blockState) - cap.initNetworking() - return cap +class CapacitorEntityTier1(pos: BlockPos, state: BlockState): CapacitorEntity(20000, BlockEntities.CAPACITOR_ENTITY.get(), pos, state) +class CapacitorEntityTier2(pos: BlockPos, state: BlockState): CapacitorEntity(50000, BlockEntities.CAPACITOR2_ENTITY.get(), pos, state) +class CapacitorEntityTier3(pos: BlockPos, state: BlockState): CapacitorEntity(100000, BlockEntities.CAPACITOR3_ENTITY.get(), pos, state) + +class CapacitorBlock(val tier: Int) : NodeBlock() { + override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity { + val cap: CapacitorEntity = when(tier) { + 1 -> CapacitorEntityTier1(blockPos, blockState) + 2 -> CapacitorEntityTier2(blockPos, blockState) + 3 -> CapacitorEntityTier3(blockPos, blockState) + else -> throw UnsupportedOperationException("unsupported tier: $tier") + } + return cap.initNetworking() } override fun useWithoutItem( @@ -54,11 +63,10 @@ class CapacitorBlock : NodeBlock() { ): InteractionResult { if(!level.isClientSide()) { val sp = player as ServerPlayer - val ent = level.getBlockEntity(blockPos, BlockEntities.CAPACITOR_ENTITY.get()) - if(ent.isPresent()) { - val cap = ent.get() - if(sp.isCrouching()) cap.amountStored++ - val msg = PlayerChatMessage.system("energy: ${cap.amountStored} / ${cap.capacity} (${cap.computeEdges().size} edges, ${cap.node.getReachable().size} connected)") + val ent = level.getBlockEntity(blockPos) + if(ent is CapacitorEntity) { + if(sp.isCrouching) ent.amountStored++ + val msg = PlayerChatMessage.system("energy: ${ent.amountStored} / ${ent.capacity} (${ent.computeEdges().size} edges, ${ent.node.getReachable().size} connected)") sp.sendChatMessage(OutgoingChatMessage.create(msg), false, ChatType.bind(ChatType.CHAT, player)) } } diff --git a/src/main/kotlin/org/neoflock/neocomputers/entity/BlockEntities.kt b/src/main/kotlin/org/neoflock/neocomputers/entity/BlockEntities.kt index ec699c1..fcc5f09 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/entity/BlockEntities.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/entity/BlockEntities.kt @@ -12,6 +12,9 @@ import net.minecraft.world.level.block.entity.BlockEntityType import org.neoflock.neocomputers.NeoComputers import org.neoflock.neocomputers.block.Blocks import org.neoflock.neocomputers.block.CapacitorEntity +import org.neoflock.neocomputers.block.CapacitorEntityTier1 +import org.neoflock.neocomputers.block.CapacitorEntityTier2 +import org.neoflock.neocomputers.block.CapacitorEntityTier3 import org.neoflock.neocomputers.network.PowerManager // complete fucking bullshit btw @@ -42,9 +45,19 @@ object BlockEntities { ::ScreenEntity, mutableSetOf(Blocks.SCREEN_BLOCK.get()), BullshitFix() ) } - val CAPACITOR_ENTITY: RegistrySupplier> = BLOCKENTITIES.register("capacitor_entity") { + val CAPACITOR_ENTITY: RegistrySupplier> = BLOCKENTITIES.register("capacitor_entity") { BlockEntityType( - ::CapacitorEntity, mutableSetOf(Blocks.CAPACITOR_BLOCK.get()), BullshitFix() + ::CapacitorEntityTier1, mutableSetOf(Blocks.CAPACITOR_BLOCK.get()), BullshitFix() + ) + } + val CAPACITOR2_ENTITY: RegistrySupplier> = BLOCKENTITIES.register("capacitor_entity2") { + BlockEntityType( + ::CapacitorEntityTier2, mutableSetOf(Blocks.CAPACITOR_BLOCK2.get()), BullshitFix() + ) + } + val CAPACITOR3_ENTITY: RegistrySupplier> = BLOCKENTITIES.register("capacitor_entity3") { + BlockEntityType( + ::CapacitorEntityTier3, mutableSetOf(Blocks.CAPACITOR_BLOCK3.get()), BullshitFix() ) } val SOLARGEN_ENTITY: RegistrySupplier> = BLOCKENTITIES.register("solargen_entity") { @@ -60,6 +73,8 @@ object BlockEntities { fun registerPowerBlocks() { PowerManager.registerPowerBlockEntity(CAPACITOR_ENTITY.get()) + PowerManager.registerPowerBlockEntity(CAPACITOR2_ENTITY.get()) + PowerManager.registerPowerBlockEntity(CAPACITOR3_ENTITY.get()) PowerManager.registerPowerBlockEntity(SOLARGEN_ENTITY.get()) PowerManager.registerPowerBlockEntity(COMBUSTGEN_ENTITY.get()) } diff --git a/src/main/resources/assets/neocomputers/blockstates/capacitor.json b/src/main/resources/assets/neocomputers/blockstates/capacitor.json new file mode 100644 index 0000000..2ff108c --- /dev/null +++ b/src/main/resources/assets/neocomputers/blockstates/capacitor.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "neocomputers:block/capacitor" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/blockstates/capacitor2.json b/src/main/resources/assets/neocomputers/blockstates/capacitor2.json new file mode 100644 index 0000000..970d3a2 --- /dev/null +++ b/src/main/resources/assets/neocomputers/blockstates/capacitor2.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "neocomputers:block/capacitor2" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/blockstates/capacitor3.json b/src/main/resources/assets/neocomputers/blockstates/capacitor3.json new file mode 100644 index 0000000..6427284 --- /dev/null +++ b/src/main/resources/assets/neocomputers/blockstates/capacitor3.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "neocomputers:block/capacitor3" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/models/block/capacitor.json b/src/main/resources/assets/neocomputers/models/block/capacitor.json new file mode 100644 index 0000000..4e08a1a --- /dev/null +++ b/src/main/resources/assets/neocomputers/models/block/capacitor.json @@ -0,0 +1,12 @@ +{ + "parent": "minecraft:block/cube", + "textures": { + "up": "neocomputers:block/capacitor_top", + "down": "neocomputers:block/capacitor_bottom", + "north": "neocomputers:block/capacitor_side", + "south": "neocomputers:block/capacitor_side", + "east": "neocomputers:block/capacitor_side", + "west": "neocomputers:block/capacitor_side", + "particle": "neocomputers:block/capacitor_top" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/models/block/capacitor2.json b/src/main/resources/assets/neocomputers/models/block/capacitor2.json new file mode 100644 index 0000000..82472fb --- /dev/null +++ b/src/main/resources/assets/neocomputers/models/block/capacitor2.json @@ -0,0 +1,12 @@ +{ + "parent": "minecraft:block/cube", + "textures": { + "up": "neocomputers:block/capacitor2_top", + "down": "neocomputers:block/capacitor_bottom", + "north": "neocomputers:block/capacitor2_side", + "south": "neocomputers:block/capacitor2_side", + "east": "neocomputers:block/capacitor2_side", + "west": "neocomputers:block/capacitor2_side", + "particle": "neocomputers:block/capacitor2_top" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/models/block/capacitor3.json b/src/main/resources/assets/neocomputers/models/block/capacitor3.json new file mode 100644 index 0000000..267297e --- /dev/null +++ b/src/main/resources/assets/neocomputers/models/block/capacitor3.json @@ -0,0 +1,12 @@ +{ + "parent": "minecraft:block/cube", + "textures": { + "up": "neocomputers:block/capacitor3_top", + "down": "neocomputers:block/capacitor_bottom", + "north": "neocomputers:block/capacitor3_side", + "south": "neocomputers:block/capacitor3_side", + "east": "neocomputers:block/capacitor3_side", + "west": "neocomputers:block/capacitor3_side", + "particle": "neocomputers:block/capacitor3_top" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/models/item/capacitor.json b/src/main/resources/assets/neocomputers/models/item/capacitor.json new file mode 100644 index 0000000..9a4f89f --- /dev/null +++ b/src/main/resources/assets/neocomputers/models/item/capacitor.json @@ -0,0 +1,3 @@ +{ + "parent": "neocomputers:block/capacitor" +} \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/models/item/capacitor2.json b/src/main/resources/assets/neocomputers/models/item/capacitor2.json new file mode 100644 index 0000000..57f5417 --- /dev/null +++ b/src/main/resources/assets/neocomputers/models/item/capacitor2.json @@ -0,0 +1,3 @@ +{ + "parent": "neocomputers:block/capacitor2" +} \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/models/item/capacitor3.json b/src/main/resources/assets/neocomputers/models/item/capacitor3.json new file mode 100644 index 0000000..82b15b6 --- /dev/null +++ b/src/main/resources/assets/neocomputers/models/item/capacitor3.json @@ -0,0 +1,3 @@ +{ + "parent": "neocomputers:block/capacitor3" +} \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/neocomputers.json5 b/src/main/resources/assets/neocomputers/neocomputers.json5 new file mode 100644 index 0000000..98ab618 --- /dev/null +++ b/src/main/resources/assets/neocomputers/neocomputers.json5 @@ -0,0 +1,16 @@ +{ + power: { + // amount of energy the different capacitor tiers can store + capacitors: [20000, 50000, 100000], + + // how much energy combustion generators make per tick + combustionGeneration: 50, + // the energy capacity of the combustion generator + combustionMaxPower: 50000, + + // how much energy solar generators make per tick + solarGeneration: 50, + // the energy capacity of the solar generator + solarMaxPower: 10000, + }, +} \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/textures/block/capacitor2_side.png b/src/main/resources/assets/neocomputers/textures/block/capacitor2_side.png new file mode 100644 index 0000000..43e3de8 Binary files /dev/null and b/src/main/resources/assets/neocomputers/textures/block/capacitor2_side.png differ diff --git a/src/main/resources/assets/neocomputers/textures/block/capacitor2_top.png b/src/main/resources/assets/neocomputers/textures/block/capacitor2_top.png new file mode 100644 index 0000000..eb82fe6 Binary files /dev/null and b/src/main/resources/assets/neocomputers/textures/block/capacitor2_top.png differ diff --git a/src/main/resources/assets/neocomputers/textures/block/capacitor3_side.png b/src/main/resources/assets/neocomputers/textures/block/capacitor3_side.png new file mode 100644 index 0000000..2287769 Binary files /dev/null and b/src/main/resources/assets/neocomputers/textures/block/capacitor3_side.png differ diff --git a/src/main/resources/assets/neocomputers/textures/block/capacitor3_top.png b/src/main/resources/assets/neocomputers/textures/block/capacitor3_top.png new file mode 100644 index 0000000..997818d Binary files /dev/null and b/src/main/resources/assets/neocomputers/textures/block/capacitor3_top.png differ diff --git a/src/main/resources/assets/neocomputers/textures/block/capacitor_bottom.png b/src/main/resources/assets/neocomputers/textures/block/capacitor_bottom.png new file mode 100644 index 0000000..699368b Binary files /dev/null and b/src/main/resources/assets/neocomputers/textures/block/capacitor_bottom.png differ diff --git a/src/main/resources/assets/neocomputers/textures/block/capacitor_side.png b/src/main/resources/assets/neocomputers/textures/block/capacitor_side.png new file mode 100644 index 0000000..5e7c32f Binary files /dev/null and b/src/main/resources/assets/neocomputers/textures/block/capacitor_side.png differ diff --git a/src/main/resources/assets/neocomputers/textures/block/capacitor_top.png b/src/main/resources/assets/neocomputers/textures/block/capacitor_top.png new file mode 100644 index 0000000..ecfbd12 Binary files /dev/null and b/src/main/resources/assets/neocomputers/textures/block/capacitor_top.png differ