-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There are currently three levels levels, 0, 1 and 2 (1, 2 and 3 for the user). The levels add more energy and upgrade slots for the upcoming upgrades, since there might not be enough space when they're implemented. While the third level gives 10 upgrade slots, which really won't have anything to fill them for a while, the system for expanding the slot amount easily is implemented, so when some upgrades DO come, there will already be place for them. The upgrades are done by the two new upgrade items. They have slightly different colors and names, inspired by the upgrades in Thermal Expansion. The block model now selects the the appropriate data for the blockstate in getActualState, getting it from the tile entity. Same thing happens for the ItemStack name and the custom mesh definition. For reasons unknown, the "inventory" variation has to stay in the blockstate, because oterwise the game throws an exception about it not beign there, albeit everything else working normally.
- Loading branch information
Showing
18 changed files
with
284 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/org/kotobank/kuarry/item/KuarryItemBlock.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.kotobank.kuarry.item | ||
|
||
import net.minecraft.block.Block | ||
import net.minecraft.item.ItemBlock | ||
import net.minecraft.item.ItemStack | ||
|
||
class KuarryItemBlock(block: Block) : ItemBlock(block) { | ||
override fun getUnlocalizedName(stack: ItemStack): String { | ||
val blockName = super.getUnlocalizedName(stack) | ||
|
||
// Get the name based on the level | ||
return when (val level = stack.tagCompound?.getInteger("upgrade_level") ?: 0) { | ||
1, 2 -> | ||
"${blockName}.level_${level + 1}" | ||
else -> super.getUnlocalizedName(stack) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.kotobank.kuarry.item | ||
|
||
import net.minecraft.entity.player.EntityPlayer | ||
import net.minecraft.init.SoundEvents | ||
import net.minecraft.item.Item | ||
import net.minecraft.util.* | ||
import net.minecraft.util.math.BlockPos | ||
import net.minecraft.world.World | ||
import org.kotobank.kuarry.tile_entity.KuarryTileEntity | ||
|
||
/** Data storage for various level-dependant things of the [KuarryTileEntity]. */ | ||
data class LevelProperties(val energy: Int, val upgradeSlotLines: Int) | ||
|
||
/** Data for all levels. */ | ||
val LevelValues = arrayOf( | ||
// Base | ||
LevelProperties(100_000, 3), | ||
// Hardened | ||
LevelProperties(200_000, 4), | ||
// Reinforced | ||
LevelProperties(300_000, 5) | ||
) | ||
|
||
sealed class LevelUpgrade : Item() { | ||
abstract val level: Int | ||
|
||
/** Whether the upgrade should apply. | ||
* | ||
* Currently the only condition is that the machine is of the level directly below the upgrade level. | ||
*/ | ||
fun shouldUpgrade(te: KuarryTileEntity) = level - 1 == te.upgradeLevel | ||
|
||
override fun onItemUse(player: EntityPlayer, worldIn: World, pos: BlockPos, hand: EnumHand, facing: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): EnumActionResult { | ||
val itemstack = player.getHeldItem(hand) | ||
|
||
if (itemstack.item == this) { | ||
val te = worldIn.getTileEntity(pos) | ||
if (te is KuarryTileEntity) { | ||
if (shouldUpgrade(te)) { | ||
// Set the level and shrink the amount of upgrades | ||
te.upgradeLevel = level | ||
itemstack.shrink(1) | ||
|
||
// Play the upgrade sound, pass null as a player so it plays for everyone | ||
worldIn.playSound(null, pos, SoundEvents.BLOCK_ANVIL_USE, SoundCategory.PLAYERS, 1f, 1f) | ||
|
||
return EnumActionResult.SUCCESS | ||
} | ||
} | ||
} | ||
|
||
return EnumActionResult.PASS | ||
} | ||
} | ||
|
||
class HardenedUpgrade : LevelUpgrade() { | ||
override val level = 1 | ||
} | ||
|
||
class ReinforcedUpgrade : LevelUpgrade() { | ||
override val level = 2 | ||
} |
Oops, something went wrong.