From aafae9e8ce049d8b74e271e48d47d99ebe35fdc0 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Thu, 11 May 2023 19:21:11 +0200 Subject: [PATCH] Added recipes, small changes --- build.gradle | 1 - .../kotlin/de/mattv/quarry/QuarryBlock.kt | 31 +++++++++---------- src/main/kotlin/de/mattv/quarry/QuarryMod.kt | 10 +----- src/main/kotlin/de/mattv/quarry/QuarryTile.kt | 30 ++++++++++++------ .../mquarry/loot_tables/blocks/quarry.json | 14 --------- .../data/mquarry/recipes/controller.json | 14 +++++++++ .../data/mquarry/recipes/quarry.json | 19 ++++++++++++ .../data/mquarry/recipes/upgrade_fortune.json | 15 +++++++++ .../data/mquarry/recipes/upgrade_speed.json | 15 +++++++++ 9 files changed, 99 insertions(+), 50 deletions(-) delete mode 100644 src/main/resources/data/mquarry/loot_tables/blocks/quarry.json create mode 100644 src/main/resources/data/mquarry/recipes/controller.json create mode 100644 src/main/resources/data/mquarry/recipes/quarry.json create mode 100644 src/main/resources/data/mquarry/recipes/upgrade_fortune.json create mode 100644 src/main/resources/data/mquarry/recipes/upgrade_speed.json diff --git a/build.gradle b/build.gradle index a1a2b5c..7090f43 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,6 @@ plugins { id 'net.minecraftforge.gradle' version '5.1.+' id 'org.jetbrains.kotlin.jvm' version '1.8.21' - id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.21' } diff --git a/src/main/kotlin/de/mattv/quarry/QuarryBlock.kt b/src/main/kotlin/de/mattv/quarry/QuarryBlock.kt index 326dec2..385cea8 100644 --- a/src/main/kotlin/de/mattv/quarry/QuarryBlock.kt +++ b/src/main/kotlin/de/mattv/quarry/QuarryBlock.kt @@ -8,6 +8,7 @@ import net.minecraft.core.BlockPos import net.minecraft.network.chat.TextComponent import net.minecraft.world.InteractionHand import net.minecraft.world.InteractionResult +import net.minecraft.world.entity.LivingEntity import net.minecraft.world.entity.item.ItemEntity import net.minecraft.world.entity.player.Player import net.minecraft.world.item.Item @@ -38,24 +39,10 @@ class QuarryBlock : Block(Properties.of(Material.STONE).sound(SoundType.METAL).s return super.use(state, level, pos, player, hand, result) } - private fun dropUpgradeItem(level: Level, pos: BlockPos, count: Int, item: Item) { - val x = pos.x.toDouble() - val y = pos.y.toDouble() - val z = pos.z.toDouble() - var toDrop = count - while (toDrop > 64) { - level.addFreshEntity(ItemEntity(level, x, y, z, ItemStack(item, 64))) - toDrop -= 64 - } - if (toDrop > 0) - level.addFreshEntity(ItemEntity(level, x, y, z, ItemStack(item, toDrop))) - } - override fun playerDestroy(level: Level, player: Player, pos: BlockPos, state: BlockState, be: BlockEntity?, tool: ItemStack) { if (!level.isClientSide() && be is QuarryTile) { - val toDrop = be.getUpgradesToDrop() - dropUpgradeItem(level, pos, toDrop.a, QuarryMod.QUARRY_SPEED_UPGRADE.get()) - dropUpgradeItem(level, pos, toDrop.b, QuarryMod.QUARRY_FORTUNE_UPGRADE.get()) + val toDrop = be.getDropItem() + level.addFreshEntity(ItemEntity(level, pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble(), toDrop)) } super.playerDestroy(level, player, pos, state, be, tool) } @@ -65,4 +52,16 @@ class QuarryBlock : Block(Properties.of(Material.STONE).sound(SoundType.METAL).s if (be is QuarryTile) be.probeInfo(info!!) } + + override fun setPlacedBy( + level: Level, + pos: BlockPos, + state: BlockState, + entity: LivingEntity?, + item: ItemStack + ) { + val be = level.getBlockEntity(pos) as QuarryTile + if (item.hasTag()) + be.loadFromItem(item.tag!!) + } } \ No newline at end of file diff --git a/src/main/kotlin/de/mattv/quarry/QuarryMod.kt b/src/main/kotlin/de/mattv/quarry/QuarryMod.kt index ed3584e..03eca0a 100644 --- a/src/main/kotlin/de/mattv/quarry/QuarryMod.kt +++ b/src/main/kotlin/de/mattv/quarry/QuarryMod.kt @@ -29,6 +29,7 @@ object QuarryMod { val QUARRY_TILE = TILES_REGISTRY.registerObject("quarry") { BlockEntityType.Builder.of(::QuarryTile, QUARRY_BLOCK.get()).build(null) } val QUARRY_SPEED_UPGRADE = ITEM_REGISTRY.registerObject("upgrade_speed") { QuarryUpgrade(QuarryUpgrade.Type.SPEED) } val QUARRY_FORTUNE_UPGRADE = ITEM_REGISTRY.registerObject("upgrade_fortune") { QuarryUpgrade(QuarryUpgrade.Type.FORTUNE) } + val QUARRY_ITEM = ITEM_REGISTRY.registerObject("quarry") { BlockItem(QUARRY_BLOCK.get(), Item.Properties().tab(CreativeModeTab.TAB_MISC)) } init { ITEM_REGISTRY.registerObject("controller", ::QuarryController) @@ -37,13 +38,4 @@ object QuarryMod { TILES_REGISTRY.register(MOD_BUS) ITEM_REGISTRY.register(MOD_BUS) } - - @SubscribeEvent - fun onRegisterItems(event: RegistryEvent.Register) { - for (entry in BLOCK_REGISTRY.entries.stream().map(RegistryObject::get)) { - val item = BlockItem(entry, Item.Properties().tab(CreativeModeTab.TAB_MISC)) - item.setRegistryName(entry.registryName) - event.registry.register(item) - } - } } \ No newline at end of file diff --git a/src/main/kotlin/de/mattv/quarry/QuarryTile.kt b/src/main/kotlin/de/mattv/quarry/QuarryTile.kt index 5e017d2..f22797e 100644 --- a/src/main/kotlin/de/mattv/quarry/QuarryTile.kt +++ b/src/main/kotlin/de/mattv/quarry/QuarryTile.kt @@ -174,7 +174,7 @@ class QuarryTile(private val myPos: BlockPos, state: BlockState) : BlockEntity(Q speedUpgradesNeeded -= used if (speedUpgradesNeeded == 0) { speedLevel++ - speedUpgradesNeeded = (2.0).pow(speedLevel).toInt() + speedUpgradesNeeded = speedLevel.toFloat().pow(1.5f).toInt() player.displayClientMessage(TextComponent("New speed level: $speedLevel, upgrades needed for next level: $speedUpgradesNeeded"), true) } else player.displayClientMessage(TextComponent("Upgrades needed for next level: $speedUpgradesNeeded"), true) @@ -184,19 +184,29 @@ class QuarryTile(private val myPos: BlockPos, state: BlockState) : BlockEntity(Q fortuneUpgradesNeeded -= used if (fortuneUpgradesNeeded == 0) { fortuneLevel++ - fortuneUpgradesNeeded = (2.0).pow(fortuneLevel).toInt() + fortuneUpgradesNeeded = fortuneLevel.toFloat().pow(1.5f).toInt() player.displayClientMessage(TextComponent("New fortune level: $fortuneLevel, upgrades needed for next level: $fortuneUpgradesNeeded"), true) } else player.displayClientMessage(TextComponent("Upgrades needed for next level: $fortuneUpgradesNeeded"), true) } } - fun getUpgradesToDrop() : Tuple { - var speed = (2.0).pow(speedLevel).toInt() - speedUpgradesNeeded - for (i in 1..speedLevel) speed += (2.0).pow(i-1).toInt() - var fortune = (2.0).pow(fortuneLevel).toInt() - fortuneUpgradesNeeded - for (i in 1..fortuneLevel) fortune += (2.0).pow(i-1).toInt() - return Tuple(speed, fortune) + fun loadFromItem(tag: CompoundTag) { + speedLevel = tag.getInt("speedLevel") + fortuneLevel = tag.getInt("fortuneLevel") + speedUpgradesNeeded = tag.getInt("speedUpgradesNeeded") + fortuneUpgradesNeeded = tag.getInt("fortuneUpgradesNeeded") + } + + fun getDropItem(): ItemStack { + val tag = CompoundTag() + tag.putInt("speedLevel", speedLevel) + tag.putInt("fortuneLevel", fortuneLevel) + tag.putInt("speedUpgradesNeeded", speedUpgradesNeeded) + tag.putInt("fortuneUpgradesNeeded", fortuneUpgradesNeeded) + val item = ItemStack(QuarryMod.QUARRY_ITEM.get(), 1) + item.tag = tag + return item } fun addChunk(chunk: QuarryChunk) = chunksTodo.add(chunk) @@ -270,7 +280,7 @@ class QuarryTile(private val myPos: BlockPos, state: BlockState) : BlockEntity(Q companion object { const val QUARRY_MAX_ENERGY: Int = 100_000_000 - const val ENERGY_BASE = 1000 - const val ENERGY_PER_STRENGTH = 500 + const val ENERGY_BASE = 2000 + const val ENERGY_PER_STRENGTH = 1000 } } \ No newline at end of file diff --git a/src/main/resources/data/mquarry/loot_tables/blocks/quarry.json b/src/main/resources/data/mquarry/loot_tables/blocks/quarry.json deleted file mode 100644 index 28196c4..0000000 --- a/src/main/resources/data/mquarry/loot_tables/blocks/quarry.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1.0, - "entries": [ - { - "type": "minecraft:item", - "name": "mquarry:quarry" - } - ] - } - ] -} \ No newline at end of file diff --git a/src/main/resources/data/mquarry/recipes/controller.json b/src/main/resources/data/mquarry/recipes/controller.json new file mode 100644 index 0000000..9a2c7a4 --- /dev/null +++ b/src/main/resources/data/mquarry/recipes/controller.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "i i", + "rrr", + " d " + ], + "key": { + "i": { "item": "minecraft:iron_ingot" }, + "r": { "item": "minecraft:redstone" }, + "d": { "item": "minecraft:diamond" } + }, + "result": { "item": "mquarry:controller" } +} \ No newline at end of file diff --git a/src/main/resources/data/mquarry/recipes/quarry.json b/src/main/resources/data/mquarry/recipes/quarry.json new file mode 100644 index 0000000..4ebd83f --- /dev/null +++ b/src/main/resources/data/mquarry/recipes/quarry.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "eEe", + "pRs", + "DGI" + ], + "key": { + "e": { "item": "minecraft:ender_pearl" }, + "p": { "item": "minecraft:netherite_pickaxe" }, + "s": { "item": "minecraft:netherite_shovel" }, + "E": { "item": "minecraft:emerald_block" }, + "R": { "item": "minecraft:redstone_block" }, + "D": { "item": "minecraft:diamond_block" }, + "G": { "item": "minecraft:gold_block" }, + "I": { "item": "minecraft:iron_block" } + }, + "result": { "item": "mquarry:quarry" } +} \ No newline at end of file diff --git a/src/main/resources/data/mquarry/recipes/upgrade_fortune.json b/src/main/resources/data/mquarry/recipes/upgrade_fortune.json new file mode 100644 index 0000000..4364f55 --- /dev/null +++ b/src/main/resources/data/mquarry/recipes/upgrade_fortune.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "LLL", + "eRe", + "RIR" + ], + "key": { + "L": { "item": "minecraft:lapis_block" }, + "e": { "item": "minecraft:emerald" }, + "R": { "item": "minecraft:redstone_block" }, + "I": { "item": "minecraft:iron_block" } + }, + "result": { "item": "mquarry:upgrade_fortune" } +} diff --git a/src/main/resources/data/mquarry/recipes/upgrade_speed.json b/src/main/resources/data/mquarry/recipes/upgrade_speed.json new file mode 100644 index 0000000..658ce7b --- /dev/null +++ b/src/main/resources/data/mquarry/recipes/upgrade_speed.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "sss", + "dRd", + "RIR" + ], + "key": { + "s": { "item": "minecraft:sugar" }, + "d": { "item": "minecraft:diamond" }, + "R": { "item": "minecraft:redstone_block" }, + "I": { "item": "minecraft:iron_block" } + }, + "result": { "item": "mquarry:upgrade_speed" } +}