1
0
mirror of https://github.com/chylex/Hardcore-Ender-Expansion-2.git synced 2025-04-11 03:15:44 +02:00

Add base class for Table Core items

This commit is contained in:
chylex 2020-02-27 16:35:23 +01:00
parent 9c82e4db2a
commit c02078074b
3 changed files with 57 additions and 2 deletions
src/main
java/chylex/hee/game
resources/assets/hee/lang

View File

@ -5,6 +5,4 @@ class BlockTableBase(builder: BlockBuilder, tier: Int, firstTier: Int) : BlockAb
override fun getTranslationKey(): String{
return "block.hee.table_base"
}
// TODO
}

View File

@ -0,0 +1,55 @@
package chylex.hee.game.item
import chylex.hee.game.block.BlockAbstractTableTile
import chylex.hee.game.block.BlockTableBase
import chylex.hee.game.world.util.BlockEditor
import chylex.hee.system.migration.forge.Side
import chylex.hee.system.migration.forge.Sided
import chylex.hee.system.migration.vanilla.TextComponentTranslation
import chylex.hee.system.util.breakBlock
import chylex.hee.system.util.getBlock
import chylex.hee.system.util.setBlock
import net.minecraft.client.util.ITooltipFlag
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.item.ItemUseContext
import net.minecraft.util.ActionResultType
import net.minecraft.util.ActionResultType.FAIL
import net.minecraft.util.ActionResultType.PASS
import net.minecraft.util.ActionResultType.SUCCESS
import net.minecraft.util.text.ITextComponent
import net.minecraft.world.World
class ItemTableCore(private val tableBlocks: Array<BlockAbstractTableTile<*>>, properties: Properties) : Item(properties){
override fun onItemUse(context: ItemUseContext): ActionResultType{
val player = context.player ?: return FAIL
val world = context.world
val pos = context.pos
val heldItem = player.getHeldItem(context.hand)
if (!BlockEditor.canEdit(pos, player, heldItem)){
return FAIL
}
val block = pos.getBlock(world)
if (block is BlockTableBase){
val table = tableBlocks.find { it.tier == block.tier } ?: return FAIL
if (!world.isRemote){
pos.breakBlock(world, false)
pos.setBlock(world, table)
}
heldItem.shrink(1)
return SUCCESS
}
return PASS
}
@Sided(Side.CLIENT)
override fun addInformation(stack: ItemStack, world: World?, lines: MutableList<ITextComponent>, flags: ITooltipFlag){
lines.add(TextComponentTranslation("item.tooltip.hee.table_core.tooltip", tableBlocks.map { it.tier }.min()))
}
}

View File

@ -219,6 +219,8 @@
"item.tooltip.hee.trinket.not_in_slot.charged": "§cMust be placed in Trinket slot",
"item.tooltip.hee.trinket.not_in_slot.uncharged": "§cMust be charged and placed in Trinket slot",
"item.tooltip.hee.table_core.tooltip": "§7Minimum Tier: %s",
"fluid.hee.ender_goo": "Ender Goo",
"fluid.hee.purified_ender_goo": "Purified Ender Goo",