From be2424055d0132d8971811dde54c58d87ebd0f69 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 5 Aug 2023 21:13:55 +0700 Subject: [PATCH] Infinite water source block --- .../mc/otm/datagen/lang/English.kt | 1 + .../mc/otm/datagen/lang/Russian.kt | 1 + .../mc/otm/datagen/loot/LootTablesData.kt | 2 + .../datagen/recipes/CraftingTableRecipes.kt | 7 +++ .../dbotthepony/mc/otm/datagen/tags/Tags.kt | 2 + .../decorative/InfiniteWaterSourceBlock.kt | 25 ++++++++ .../InfiniteWaterSourceBlockEntity.kt | 61 +++++++++++++++++++ .../mc/otm/registry/MBlockEntities.kt | 2 + .../ru/dbotthepony/mc/otm/registry/MBlocks.kt | 2 + .../ru/dbotthepony/mc/otm/registry/MItems.kt | 6 +- .../ru/dbotthepony/mc/otm/registry/MNames.kt | 1 + 11 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/InfiniteWaterSourceBlock.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/InfiniteWaterSourceBlockEntity.kt diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt index da3651e91..1cb2eabec 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt @@ -400,6 +400,7 @@ private fun blocks(provider: MatteryLanguageProvider) { add(MBlocks.DRIVE_VIEWER, "Drive Viewer") add(MBlocks.BLACK_HOLE, "Local Anomalous Spacetime Dilation Singular Point") add(MBlocks.COBBLESTONE_GENERATOR, "Cobblestone Generator") + add(MBlocks.INFINITE_WATER_SOURCE, "Infinite Water Source") add(MBlocks.ESSENCE_STORAGE, "Essence Storage") add(MBlocks.ESSENCE_STORAGE, "desc", "Allows to store and retrieve experience levels") add(MBlocks.MATTER_RECONSTRUCTOR, "Matter Reconstructor") diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt index 0e601f7f6..330c03ccc 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt @@ -403,6 +403,7 @@ private fun blocks(provider: MatteryLanguageProvider) { add(MBlocks.DRIVE_VIEWER, "Просмотрщик дисков конденсации") add(MBlocks.BLACK_HOLE, "Локализированная сингулярная точка аномального искажения пространства-времени") add(MBlocks.COBBLESTONE_GENERATOR, "Генератор булыжника") + add(MBlocks.INFINITE_WATER_SOURCE, "Неиссякаемый источник воды") add(MBlocks.ESSENCE_STORAGE, "Хранилище эссенции") add(MBlocks.ESSENCE_STORAGE, "desc", "Позволяет хранить очки опыта") add(MBlocks.MATTER_RECONSTRUCTOR, "Материальный реконструктор") diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTablesData.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTablesData.kt index 996aaa641..e5c1b8f4c 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTablesData.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTablesData.kt @@ -51,6 +51,8 @@ fun addLootTables(lootTables: LootTables) { lootTables.dropsSelf(MBlocks.TRITANIUM_INGOT_BLOCK) { condition(ExplosionCondition.survivesExplosion()) } lootTables.dropsSelf(MBlocks.TRITANIUM_BARS) { condition(ExplosionCondition.survivesExplosion()) } + lootTables.dropsSelf(MBlocks.INFINITE_WATER_SOURCE) { condition(ExplosionCondition.survivesExplosion()) } + lootTables.dropsSelf(MBlocks.ENGINE) { condition(ExplosionCondition.survivesExplosion()) } for (block in MBlocks.TRITANIUM_ANVIL) diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/CraftingTableRecipes.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/CraftingTableRecipes.kt index 0510dfb3d..be441943c 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/CraftingTableRecipes.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/recipes/CraftingTableRecipes.kt @@ -426,4 +426,11 @@ fun addCraftingTableRecipes(consumer: Consumer) { .row(MItems.ELECTROMAGNET, Items.FURNACE, MItems.ELECTROMAGNET) .unlockedBy(MItems.MACHINE_FRAME) .build(consumer) + + MatteryRecipe(MItems.INFINITE_WATER_SOURCE, category = machinesCategory) + .row(MItemTags.IRON_PLATES, MItemTags.IRON_PLATES, MItemTags.IRON_PLATES) + .rowAC(Items.WATER_BUCKET, Items.WATER_BUCKET) + .row(MItemTags.IRON_PLATES, MItemTags.IRON_PLATES, MItemTags.IRON_PLATES) + .unlockedBy(Items.WATER_BUCKET) + .build(consumer) } diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/tags/Tags.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/tags/Tags.kt index 33d5d407b..c266a923c 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/tags/Tags.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/tags/Tags.kt @@ -204,6 +204,8 @@ fun addTags(tagsProvider: TagsProvider) { tagsProvider.requiresPickaxe(MBlocks.TRITANIUM_STRIPED_SLAB, Tiers.IRON) tagsProvider.requiresPickaxe(MBlocks.CARBON_FIBRE_BLOCK, Tiers.IRON) + tagsProvider.requiresPickaxe(MBlocks.INFINITE_WATER_SOURCE, Tiers.STONE) + tagsProvider.requiresPickaxe(MRegistry.CARGO_CRATES.allBlocks.values, Tiers.IRON) tagsProvider.requiresPickaxe(MRegistry.VENT.allBlocks.values, Tiers.IRON) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/InfiniteWaterSourceBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/InfiniteWaterSourceBlock.kt new file mode 100644 index 000000000..faab35e82 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/InfiniteWaterSourceBlock.kt @@ -0,0 +1,25 @@ +package ru.dbotthepony.mc.otm.block.decorative + +import net.minecraft.core.BlockPos +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.EntityBlock +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.material.MapColor +import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock +import ru.dbotthepony.mc.otm.block.entity.decorative.InfiniteWaterSourceBlockEntity + +class InfiniteWaterSourceBlock : RotatableMatteryBlock(Properties.of().destroyTime(1.5f).explosionResistance(10f).requiresCorrectToolForDrops().mapColor(MapColor.WATER)), EntityBlock { + override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity { + return InfiniteWaterSourceBlockEntity(p_153215_, p_153216_) + } + + override fun getTicker(p_153212_: Level, p_153213_: BlockState, p_153214_: BlockEntityType): BlockEntityTicker? { + if (p_153212_.isClientSide) + return null + + return BlockEntityTicker { _, _, _, p_155256_ -> if (p_155256_ is InfiniteWaterSourceBlockEntity) p_155256_.tick() } + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/InfiniteWaterSourceBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/InfiniteWaterSourceBlockEntity.kt new file mode 100644 index 000000000..7a5e54219 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/InfiniteWaterSourceBlockEntity.kt @@ -0,0 +1,61 @@ +package ru.dbotthepony.mc.otm.block.entity.decorative + +import net.minecraft.core.BlockPos +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.material.Fluids +import net.minecraftforge.common.capabilities.ForgeCapabilities +import net.minecraftforge.fluids.FluidStack +import net.minecraftforge.fluids.capability.IFluidHandler +import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity +import ru.dbotthepony.mc.otm.core.ifPresentK +import ru.dbotthepony.mc.otm.registry.MBlockEntities + +class InfiniteWaterSourceBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryBlockEntity(MBlockEntities.INFINITE_WATER_SOURCE, blockPos, blockState), IFluidHandler { + override fun getTanks(): Int { + return 1 + } + + override fun getFluidInTank(tank: Int): FluidStack { + return FluidStack(Fluids.WATER, Int.MAX_VALUE) + } + + override fun getTankCapacity(tank: Int): Int { + return Int.MAX_VALUE + } + + override fun isFluidValid(tank: Int, stack: FluidStack): Boolean { + return false + } + + override fun fill(resource: FluidStack, action: IFluidHandler.FluidAction): Int { + return 0 + } + + override fun drain(resource: FluidStack, action: IFluidHandler.FluidAction): FluidStack { + if (resource.fluid == Fluids.WATER || resource.fluid == Fluids.FLOWING_WATER) { + return resource.copy() + } + + return FluidStack.EMPTY + } + + override fun drain(maxDrain: Int, action: IFluidHandler.FluidAction): FluidStack { + return FluidStack(Fluids.WATER, maxDrain) + } + + init { + exposeGlobally(ForgeCapabilities.FLUID_HANDLER, this) + + for (side in sides.values) { + val tracker = side.track(ForgeCapabilities.FLUID_HANDLER) + + val ticker = tickList.Ticker { + tracker.get().ifPresentK { + it.fill(FluidStack(Fluids.WATER, Int.MAX_VALUE), IFluidHandler.FluidAction.EXECUTE) + } + } + + tracker.addListener { ticker.isEnabled = it.isPresent } + } + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlockEntities.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlockEntities.kt index 5a2dfde67..1094cc4a6 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlockEntities.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlockEntities.kt @@ -15,6 +15,7 @@ import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntitySphereDebugger import ru.dbotthepony.mc.otm.block.entity.decorative.CargoCrateBlockEntity import ru.dbotthepony.mc.otm.block.entity.decorative.FluidTankBlockEntity import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity +import ru.dbotthepony.mc.otm.block.entity.decorative.InfiniteWaterSourceBlockEntity import ru.dbotthepony.mc.otm.block.entity.matter.* import ru.dbotthepony.mc.otm.block.entity.storage.* import ru.dbotthepony.mc.otm.block.entity.tech.AndroidStationBlockEntity @@ -58,6 +59,7 @@ object MBlockEntities { val ANDROID_CHARGER: BlockEntityType by registry.register(MNames.ANDROID_CHARGER) { BlockEntityType.Builder.of(::AndroidChargerBlockEntity, MBlocks.ANDROID_CHARGER).build(null) } val ANDROID_CHARGER_MIDDLE: BlockEntityType by registry.register(MNames.ANDROID_CHARGER + "_middle") { BlockEntityType.Builder.of(::AndroidChargerMiddleBlockEntity, MBlocks.ANDROID_CHARGER).build(null) } val ANDROID_CHARGER_TOP: BlockEntityType by registry.register(MNames.ANDROID_CHARGER + "_top") { BlockEntityType.Builder.of(::AndroidChargerTopBlockEntity, MBlocks.ANDROID_CHARGER).build(null) } + val INFINITE_WATER_SOURCE: BlockEntityType by registry.register(MNames.INFINITE_WATER_SOURCE) { BlockEntityType.Builder.of(::InfiniteWaterSourceBlockEntity, MBlocks.INFINITE_WATER_SOURCE).build(null) } val POWERED_FURNACE: BlockEntityType by registry.register(MNames.POWERED_FURNACE) { BlockEntityType.Builder.of({ a, b -> MBlocks.POWERED_FURNACE.newBlockEntity(a, b) }, MBlocks.POWERED_FURNACE).build(null) } val POWERED_BLAST_FURNACE: BlockEntityType by registry.register(MNames.POWERED_BLAST_FURNACE) { BlockEntityType.Builder.of({ a, b -> MBlocks.POWERED_BLAST_FURNACE.newBlockEntity(a, b) }, MBlocks.POWERED_BLAST_FURNACE).build(null) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlocks.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlocks.kt index 7dc016d49..a437245d5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlocks.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlocks.kt @@ -42,6 +42,7 @@ import ru.dbotthepony.mc.otm.block.StorageCableBlock import ru.dbotthepony.mc.otm.block.decorative.EngineBlock import ru.dbotthepony.mc.otm.block.decorative.FluidTankBlock import ru.dbotthepony.mc.otm.block.decorative.HoloSignBlock +import ru.dbotthepony.mc.otm.block.decorative.InfiniteWaterSourceBlock import ru.dbotthepony.mc.otm.block.matter.MatterReconstructorBlock import ru.dbotthepony.mc.otm.block.matter.MatterBottlerBlock import ru.dbotthepony.mc.otm.block.matter.MatterCapacitorBankBlock @@ -95,6 +96,7 @@ object MBlocks { val MATTER_RECYCLER: Block by registry.register(MNames.MATTER_RECYCLER) { MatterRecyclerBlock() } val ENERGY_SERVO: Block by registry.register(MNames.ENERGY_SERVO) { EnergyServoBlock() } val COBBLESTONE_GENERATOR: Block by registry.register(MNames.COBBLESTONE_GENERATOR) { CobblerBlock() } + val INFINITE_WATER_SOURCE: Block by registry.register(MNames.INFINITE_WATER_SOURCE) { InfiniteWaterSourceBlock() } val ESSENCE_STORAGE: EssenceStorageBlock by registry.register(MNames.ESSENCE_STORAGE) { EssenceStorageBlock() } val MATTER_RECONSTRUCTOR: MatterReconstructorBlock by registry.register(MNames.MATTER_RECONSTRUCTOR) { MatterReconstructorBlock() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MItems.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MItems.kt index 7fe271ea3..443b08dbd 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MItems.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MItems.kt @@ -122,6 +122,8 @@ object MItems { } } + val INFINITE_WATER_SOURCE: BlockItem by registry.register(MNames.INFINITE_WATER_SOURCE) { BlockItem(MBlocks.INFINITE_WATER_SOURCE, DEFAULT_PROPERTIES) } + val ESSENCE_STORAGE: BlockItem by registry.register(MNames.ESSENCE_STORAGE) { object : BlockItem(MBlocks.ESSENCE_STORAGE, DEFAULT_PROPERTIES) { override fun appendHoverText(p_40572_: ItemStack, p_40573_: Level?, p_40574_: MutableList, p_40575_: TooltipFlag) { @@ -148,8 +150,8 @@ object MItems { // ::STORAGE_BUS, ::STORAGE_IMPORTER, ::STORAGE_EXPORTER, ::DRIVE_VIEWER, // ::DRIVE_RACK, ::ITEM_MONITOR, ::STORAGE_CABLE, ::STORAGE_POWER_SUPPLIER, ::ENERGY_SERVO, - ::PHANTOM_ATTRACTOR, ::GRAVITATION_STABILIZER, ::COBBLESTONE_GENERATOR, ::ESSENCE_STORAGE, - ::MATTER_RECONSTRUCTOR + ::PHANTOM_ATTRACTOR, ::GRAVITATION_STABILIZER, ::COBBLESTONE_GENERATOR, ::INFINITE_WATER_SOURCE, + ::ESSENCE_STORAGE, ::MATTER_RECONSTRUCTOR ) val DEBUG_EXPLOSION_SMALL: Item by registry.register(MNames.DEBUG_EXPLOSION_SMALL) { BlockItem(MBlocks.DEBUG_EXPLOSION_SMALL, Item.Properties().stacksTo(64)) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MNames.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MNames.kt index 2cf4382a0..633047e10 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MNames.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MNames.kt @@ -13,6 +13,7 @@ object MNames { const val HOLO_SIGN = "holo_sign" const val FLUID_TANK = "fluid_tank" const val ANDROID_CHARGER = "android_charger" + const val INFINITE_WATER_SOURCE = "infinite_water_source" // blocks const val ANDROID_STATION = "android_station"