punch master block while sneaking to revalidate network

closes #121
This commit is contained in:
deirn 2022-01-03 16:23:00 +07:00
parent 1feb0a499f
commit 15230f5023
3 changed files with 41 additions and 3 deletions

View file

@ -4,19 +4,30 @@ import badasintended.slotlink.block.entity.MasterBlockEntity
import badasintended.slotlink.init.BlockEntityTypes
import badasintended.slotlink.network.Connection
import badasintended.slotlink.network.Network
import badasintended.slotlink.util.actionBar
import net.fabricmc.fabric.api.block.BlockAttackInteractionAware
import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.block.entity.BlockEntity
import net.minecraft.block.entity.BlockEntityTicker
import net.minecraft.block.entity.BlockEntityType
import net.minecraft.client.item.TooltipContext
import net.minecraft.entity.LivingEntity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NbtList
import net.minecraft.sound.SoundEvents
import net.minecraft.text.Text
import net.minecraft.text.TranslatableText
import net.minecraft.util.Formatting
import net.minecraft.util.Hand
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Direction
import net.minecraft.world.BlockView
import net.minecraft.world.World
import net.minecraft.world.WorldAccess
class MasterBlock : ModBlock("master") {
class MasterBlock : ModBlock("master"), BlockAttackInteractionAware {
override fun createBlockEntity(pos: BlockPos, state: BlockState) = MasterBlockEntity(pos, state)
@ -69,4 +80,31 @@ class MasterBlock : ModBlock("master") {
}
}
override fun appendTooltip(
stack: ItemStack,
world: BlockView?,
tooltip: MutableList<Text>,
options: TooltipContext
) {
super.appendTooltip(stack, world, tooltip, options)
tooltip.add(TranslatableText("block.slotlink.master.tooltip").formatted(Formatting.GRAY))
}
override fun onAttackInteraction(
state: BlockState,
world: World,
pos: BlockPos,
player: PlayerEntity,
hand: Hand,
direction: Direction
): Boolean {
if (!player.isSpectator && player.isSneaking && player.getStackInHand(hand).isEmpty) {
Network.get(world, pos)?.validate()
if (!player.isCreative) player.playSound(SoundEvents.BLOCK_STONE_BREAK, 1.0f, 1.0f)
player.actionBar("block.slotlink.master.revalidated")
return !world.isClient
}
return false
}
}

View file

@ -1,7 +1,8 @@
{
"itemGroup.slotlink.group" : "slotlink",
"block.slotlink.master" : "Network Master",
"block.slotlink.master.tooltip" : "Heart of the storage connection. §5One per connection",
"block.slotlink.master.tooltip" : "Punch the block with empty hand while sneaking to revalidate the network",
"block.slotlink.master.revalidated" : "Storage network revalidated",
"block.slotlink.child.tooltip" : "Needs to be connected to master block to work",
"block.slotlink.request" : "Storage Request",
"block.slotlink.request.hasNoMaster" : "You need to connect it to a master block",

View file

@ -1,7 +1,6 @@
{
"itemGroup.slotlink.group" : "存储链接",
"block.slotlink.master" : "网络主机",
"block.slotlink.master.tooltip" : "存储链接的核心。§5每个存储网络都需要一个。",
"block.slotlink.child.tooltip" : "需要链接到主方块以开始工作",
"block.slotlink.request" : "存储请求器",
"block.slotlink.request.hasNoMaster" : "你需要将它与一个网络主机相链接。",