Added recipes, small changes
This commit is contained in:
parent
614d7b9241
commit
aafae9e8ce
@ -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'
|
||||
}
|
||||
|
||||
|
||||
|
@ -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!!)
|
||||
}
|
||||
}
|
@ -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<Item>) {
|
||||
for (entry in BLOCK_REGISTRY.entries.stream().map(RegistryObject<Block>::get)) {
|
||||
val item = BlockItem(entry, Item.Properties().tab(CreativeModeTab.TAB_MISC))
|
||||
item.setRegistryName(entry.registryName)
|
||||
event.registry.register(item)
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Int, Int> {
|
||||
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
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1.0,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "mquarry:quarry"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
14
src/main/resources/data/mquarry/recipes/controller.json
Normal file
14
src/main/resources/data/mquarry/recipes/controller.json
Normal file
@ -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" }
|
||||
}
|
19
src/main/resources/data/mquarry/recipes/quarry.json
Normal file
19
src/main/resources/data/mquarry/recipes/quarry.json
Normal file
@ -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" }
|
||||
}
|
15
src/main/resources/data/mquarry/recipes/upgrade_fortune.json
Normal file
15
src/main/resources/data/mquarry/recipes/upgrade_fortune.json
Normal file
@ -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" }
|
||||
}
|
15
src/main/resources/data/mquarry/recipes/upgrade_speed.json
Normal file
15
src/main/resources/data/mquarry/recipes/upgrade_speed.json
Normal file
@ -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" }
|
||||
}
|
Loading…
Reference in New Issue
Block a user