From f2fa61c1abd1c16ac6c1b82b000a4c4dde706b09 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 1 Oct 2022 22:00:39 +0700 Subject: [PATCH] Tritanium pressure plate #84 --- .../mc/otm/datagen/lang/English.kt | 4 ++ .../mc/otm/datagen/loot/LootTablesData.kt | 1 + .../datagen/recipes/CraftingTableRecipes.kt | 5 ++ .../dbotthepony/mc/otm/datagen/tags/Tags.kt | 1 + .../mc/otm/block/TritaniumPressurePlate.kt | 64 +++++++++++++++++++ .../kotlin/ru/dbotthepony/mc/otm/core/Ext.kt | 9 ++- .../ru/dbotthepony/mc/otm/registry/MBlocks.kt | 38 +++++++++-- .../ru/dbotthepony/mc/otm/registry/MItems.kt | 1 + .../ru/dbotthepony/mc/otm/registry/MNames.kt | 1 + 9 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/block/TritaniumPressurePlate.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 3305aade1..4f7d1274e 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 @@ -359,6 +359,10 @@ private fun blocks(provider: MatteryLanguageProvider) { add(MBlocks.TRITANIUM_TRAPDOOR, "Tritanium Trapdoor") add(MBlocks.TRITANIUM_TRAPDOOR, "description0", "High blast resistance door with redstone latch...") add(MBlocks.TRITANIUM_TRAPDOOR, "description1", "...feeling safe now?") + + add(MBlocks.TRITANIUM_PRESSURE_PLATE, "Tritanium Pressure Plate") + add(MBlocks.TRITANIUM_PRESSURE_PLATE, "description0", "Activates only if player steps on it") + add(MBlocks.TRITANIUM_PRESSURE_PLATE, "description1", "High blast resistance") } } 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 7e9edfb22..6d0446ba9 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 @@ -45,6 +45,7 @@ fun addLootTables(lootTables: LootTables) { lootTables.dropsSelf(MBlocks.METAL_BEAM) lootTables.dropsSelf(MBlocks.TRITANIUM_TRAPDOOR) + lootTables.dropsSelf(MBlocks.TRITANIUM_PRESSURE_PLATE) lootTables.blockSimple(MBlocks.PHANTOM_ATTRACTOR) { it.add(LootItem.lootTableItem(MBlocks.PHANTOM_ATTRACTOR) 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 f24a172b5..9d8529546 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 @@ -56,6 +56,11 @@ fun addCraftingTableRecipes(consumer: Consumer) { .unlockedBy(MItemTags.TRITANIUM_PLATES) .build(consumer) + MatteryRecipe(MBlocks.TRITANIUM_PRESSURE_PLATE) + .row(MItemTags.TRITANIUM_PLATES, MItemTags.BASIC_CIRCUIT, MItemTags.TRITANIUM_PLATES) + .unlockedBy(MItemTags.TRITANIUM_PLATES) + .build(consumer) + MatteryRecipe(MBlocks.PLATE_PRESS) .row(MItems.ELECTRIC_PARTS, MItems.ENERGY_BUS, MItems.ELECTRIC_PARTS) .row(MItemTags.TRITANIUM_INGOTS, Items.BLAST_FURNACE, MItemTags.TRITANIUM_INGOTS) 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 37c7ce061..d3d30ab5f 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 @@ -99,6 +99,7 @@ fun addTags(tagsProvider: TagsProvider) { MBlocks.TRITANIUM_DOOR, MBlocks.TRITANIUM_TRAPDOOR, + MBlocks.TRITANIUM_PRESSURE_PLATE, ), Tiers.IRON) tagsProvider.requiresPickaxe(MBlocks.TRITANIUM_ORE, Tiers.IRON) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/TritaniumPressurePlate.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/TritaniumPressurePlate.kt new file mode 100644 index 000000000..59d69ae73 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/TritaniumPressurePlate.kt @@ -0,0 +1,64 @@ +package ru.dbotthepony.mc.otm.block + +import net.minecraft.ChatFormatting +import net.minecraft.core.BlockPos +import net.minecraft.network.chat.Component +import net.minecraft.server.level.ServerPlayer +import net.minecraft.sounds.SoundEvents +import net.minecraft.sounds.SoundSource +import net.minecraft.world.item.DyeColor +import net.minecraft.world.item.ItemStack +import net.minecraft.world.item.TooltipFlag +import net.minecraft.world.level.BlockGetter +import net.minecraft.world.level.Level +import net.minecraft.world.level.LevelAccessor +import net.minecraft.world.level.block.BasePressurePlateBlock +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.block.state.StateDefinition +import net.minecraft.world.level.block.state.properties.BlockStateProperties +import net.minecraft.world.level.material.Material +import ru.dbotthepony.mc.otm.core.TranslatableComponent +import ru.dbotthepony.mc.otm.core.get + +class TritaniumPressurePlate : BasePressurePlateBlock(Properties.of(Material.METAL, DyeColor.LIGHT_BLUE).explosionResistance(80f).noOcclusion().destroyTime(3f).requiresCorrectToolForDrops()) { + override fun appendHoverText( + p_49816_: ItemStack, + p_49817_: BlockGetter?, + p_49818_: MutableList, + p_49819_: TooltipFlag + ) { + super.appendHoverText(p_49816_, p_49817_, p_49818_, p_49819_) + p_49818_.add(TranslatableComponent("$descriptionId.description0").withStyle(ChatFormatting.DARK_GRAY)) + p_49818_.add(TranslatableComponent("$descriptionId.description1").withStyle(ChatFormatting.DARK_GRAY)) + } + + override fun createBlockStateDefinition(p_49915_: StateDefinition.Builder) { + super.createBlockStateDefinition(p_49915_) + p_49915_.add(BlockStateProperties.POWERED) + } + + override fun playOnSound(level: LevelAccessor, pos: BlockPos) { + level.playSound(null, pos, SoundEvents.METAL_PRESSURE_PLATE_CLICK_ON, SoundSource.BLOCKS, 0.3f, 0.9f) + } + + override fun playOffSound(level: LevelAccessor, pos: BlockPos) { + level.playSound(null, pos, SoundEvents.METAL_PRESSURE_PLATE_CLICK_OFF, SoundSource.BLOCKS, 0.3f, 0.9f) + } + + override fun getSignalStrength(level: Level, pos: BlockPos): Int { + if (level.getEntitiesOfClass(ServerPlayer::class.java, TOUCH_AABB.move(pos)).isNotEmpty()) { + return 15 + } else { + return 0 + } + } + + override fun getSignalForState(state: BlockState): Int { + return if (state[BlockStateProperties.POWERED]) 15 else 0 + } + + override fun setSignalForState(state: BlockState, signal: Int): BlockState { + return state.setValue(BlockStateProperties.POWERED, signal > 0) + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/Ext.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/Ext.kt index 177896ff8..512d2482f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/Ext.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/Ext.kt @@ -336,8 +336,13 @@ fun FriendlyByteBuf.readItemType(): Item? { return ForgeRegistries.ITEMS.getValue(readInt()) } -operator fun > StateHolder<*, *>.get(value: Property): T { - return getValue(value) +operator fun > StateHolder<*, *>.get(property: Property): T { + return getValue(property) +} + +operator fun , T : Comparable> S.set(property: Property, value: T): S { + setValue(property, value) + return this } fun List.toImmutableList(): List { 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 81c7e1748..a15d4944c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlocks.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlocks.kt @@ -19,12 +19,40 @@ import net.minecraftforge.eventbus.api.IEventBus import net.minecraftforge.registries.DeferredRegister import net.minecraftforge.registries.ForgeRegistries import ru.dbotthepony.mc.otm.OverdriveThatMatters -import ru.dbotthepony.mc.otm.block.* -import ru.dbotthepony.mc.otm.block.matter.* -import ru.dbotthepony.mc.otm.block.storage.* +import ru.dbotthepony.mc.otm.block.AndroidStationBlock +import ru.dbotthepony.mc.otm.block.BatteryBankBlock +import ru.dbotthepony.mc.otm.block.BlackHoleBlock +import ru.dbotthepony.mc.otm.block.BlockExplosionDebugger +import ru.dbotthepony.mc.otm.block.BlockGravitationStabilizer +import ru.dbotthepony.mc.otm.block.BlockGravitationStabilizerLens +import ru.dbotthepony.mc.otm.block.BlockSphereDebugger +import ru.dbotthepony.mc.otm.block.ChemicalGeneratorBlock +import ru.dbotthepony.mc.otm.block.EnergyCounterBlock +import ru.dbotthepony.mc.otm.block.EnergyServoBlock +import ru.dbotthepony.mc.otm.block.LaboratoryLamp +import ru.dbotthepony.mc.otm.block.LaboratoryLampLight +import ru.dbotthepony.mc.otm.block.MatterCableBlock +import ru.dbotthepony.mc.otm.block.PhantomAttractorBlock +import ru.dbotthepony.mc.otm.block.PlatePressBlock +import ru.dbotthepony.mc.otm.block.StorageCableBlock +import ru.dbotthepony.mc.otm.block.TritaniumPressurePlate +import ru.dbotthepony.mc.otm.block.matter.MatterBottlerBlock +import ru.dbotthepony.mc.otm.block.matter.MatterCapacitorBankBlock +import ru.dbotthepony.mc.otm.block.matter.MatterDecomposerBlock +import ru.dbotthepony.mc.otm.block.matter.MatterPanelBlock +import ru.dbotthepony.mc.otm.block.matter.MatterRecyclerBlock +import ru.dbotthepony.mc.otm.block.matter.MatterReplicatorBlock +import ru.dbotthepony.mc.otm.block.matter.MatterScannerBlock +import ru.dbotthepony.mc.otm.block.matter.PatternStorageBlock +import ru.dbotthepony.mc.otm.block.storage.DriveRackBlock +import ru.dbotthepony.mc.otm.block.storage.DriveViewerBlock +import ru.dbotthepony.mc.otm.block.storage.ItemMonitorBlock +import ru.dbotthepony.mc.otm.block.storage.StorageBusBlock +import ru.dbotthepony.mc.otm.block.storage.StorageExporterBlock +import ru.dbotthepony.mc.otm.block.storage.StorageImporterBlock +import ru.dbotthepony.mc.otm.block.storage.StoragePowerSupplierBlock import ru.dbotthepony.mc.otm.core.TranslatableComponent - object MBlocks { private val registry = DeferredRegister.create(ForgeRegistries.BLOCKS, OverdriveThatMatters.MOD_ID) @@ -121,6 +149,8 @@ object MBlocks { } } } + val TRITANIUM_PRESSURE_PLATE: Block by registry.register(MNames.TRITANIUM_PRESSURE_PLATE) { TritaniumPressurePlate() } + init { MRegistry.CARGO_CRATES.registerBlocks(registry) MRegistry.TRITANIUM_BLOCK.registerBlocks(registry) 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 ea7e68a21..d88126f16 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MItems.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MItems.kt @@ -226,6 +226,7 @@ object MItems { val TRITANIUM_DOOR: Item by registry.register(MNames.TRITANIUM_DOOR) { DoubleHighBlockItem(MBlocks.TRITANIUM_DOOR, DEFAULT_PROPERTIES_DECORATIVE) } val TRITANIUM_TRAPDOOR: Item by registry.register(MNames.TRITANIUM_TRAPDOOR) { BlockItem(MBlocks.TRITANIUM_TRAPDOOR, DEFAULT_PROPERTIES_DECORATIVE) } + val TRITANIUM_PRESSURE_PLATE: Item by registry.register(MNames.TRITANIUM_TRAPDOOR) { BlockItem(MBlocks.TRITANIUM_PRESSURE_PLATE, DEFAULT_PROPERTIES_DECORATIVE) } // components val MATTER_IO_PORT: Item by registry.register(MNames.MATTER_IO_PORT) { Item(DEFAULT_PROPERTIES) } 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 d85c7e4c4..121477fe7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MNames.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MNames.kt @@ -229,6 +229,7 @@ object MNames { const val TRITANIUM_DOOR = "tritanium_door" const val TRITANIUM_TRAPDOOR = "tritanium_trapdoor" + const val TRITANIUM_PRESSURE_PLATE = "tritanium_pressure_plate" } object StatNames {