Skip to content

Commit e91f50d

Browse files
committed
Use the splicing table block name in the casting button tooltip
1 parent 2c6ad05 commit e91f50d

File tree

9 files changed

+104
-15
lines changed

9 files changed

+104
-15
lines changed

Common/src/generated/resources/data/hexdebug/loot_tables/blocks/enlightened_splicing_table.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"entries": [
1212
{
1313
"type": "minecraft:item",
14+
"functions": [
15+
{
16+
"function": "minecraft:copy_name",
17+
"source": "block_entity"
18+
}
19+
],
1420
"name": "hexdebug:enlightened_splicing_table"
1521
}
1622
],

Common/src/generated/resources/data/hexdebug/loot_tables/blocks/splicing_table.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"entries": [
1212
{
1313
"type": "minecraft:item",
14+
"functions": [
15+
{
16+
"function": "minecraft:copy_name",
17+
"source": "block_entity"
18+
}
19+
],
1420
"name": "hexdebug:splicing_table"
1521
}
1622
],
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package gay.object.hexdebug.mixin;
2+
3+
import at.petrak.hexcasting.api.casting.RenderedSpell;
4+
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment;
5+
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
6+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
7+
import gay.object.hexdebug.blocks.splicing.SplicingTableBlockEntity;
8+
import net.minecraft.core.BlockPos;
9+
import net.minecraft.network.chat.Component;
10+
import net.minecraft.world.entity.Mob;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.gen.Invoker;
13+
14+
@Mixin(targets = "at.petrak.hexcasting.common.casting.actions.spells.great.OpBrainsweep$Spell")
15+
public abstract class MixinOpBrainsweepSpell implements RenderedSpell {
16+
@Invoker
17+
public abstract BlockPos callGetPos();
18+
19+
@Invoker
20+
public abstract Mob callGetSacrifice();
21+
22+
@WrapMethod(method = "cast(Lat/petrak/hexcasting/api/casting/eval/CastingEnvironment;)V", remap = false)
23+
private void hexdebug$copyVillagerNameToSplicingTable(CastingEnvironment env, Operation<Void> original) {
24+
Component customName = null;
25+
if (callGetSacrifice().hasCustomName()) {
26+
customName = callGetSacrifice().getCustomName();
27+
} else if (env.getWorld().getBlockEntity(callGetPos()) instanceof SplicingTableBlockEntity table) {
28+
customName = table.getCustomName();
29+
}
30+
31+
original.call(env);
32+
33+
if (
34+
env.getWorld().getBlockEntity(callGetPos()) instanceof SplicingTableBlockEntity table
35+
&& customName != null
36+
) {
37+
table.setCustomName(customName);
38+
table.sync();
39+
}
40+
}
41+
}

Common/src/main/kotlin/gay/object/hexdebug/blocks/splicing/SplicingTableBlock.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import net.minecraft.server.level.ServerPlayer
77
import net.minecraft.world.Containers
88
import net.minecraft.world.InteractionHand
99
import net.minecraft.world.InteractionResult
10+
import net.minecraft.world.entity.LivingEntity
1011
import net.minecraft.world.entity.player.Player
12+
import net.minecraft.world.item.ItemStack
1113
import net.minecraft.world.item.context.BlockPlaceContext
1214
import net.minecraft.world.level.Level
1315
import net.minecraft.world.level.block.*
@@ -48,6 +50,12 @@ class SplicingTableBlock(properties: Properties, val enlightened: Boolean) : Bas
4850

4951
override fun getRenderShape(state: BlockState) = RenderShape.MODEL
5052

53+
override fun setPlacedBy(level: Level, pos: BlockPos, state: BlockState, placer: LivingEntity?, stack: ItemStack) {
54+
if (stack.hasCustomHoverName()) {
55+
getBlockEntity(level, pos)?.customName = stack.hoverName
56+
}
57+
}
58+
5159
override fun use(
5260
state: BlockState,
5361
level: Level,

Common/src/main/kotlin/gay/object/hexdebug/blocks/splicing/SplicingTableBlockEntity.kt

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ import at.petrak.hexcasting.api.casting.iota.ListIota
1313
import at.petrak.hexcasting.api.casting.iota.PatternIota
1414
import at.petrak.hexcasting.api.casting.math.HexPattern
1515
import at.petrak.hexcasting.api.pigment.FrozenPigment
16-
import at.petrak.hexcasting.api.utils.asCompound
17-
import at.petrak.hexcasting.api.utils.extractMedia
18-
import at.petrak.hexcasting.api.utils.getInt
19-
import at.petrak.hexcasting.api.utils.getList
16+
import at.petrak.hexcasting.api.utils.*
2017
import at.petrak.hexcasting.xplat.IXplatAbstractions
2118
import gay.`object`.hexdebug.api.HexDebugTags
2219
import gay.`object`.hexdebug.blocks.base.BaseContainer
@@ -35,12 +32,12 @@ import gay.`object`.hexdebug.utils.setPropertyIfChanged
3532
import net.minecraft.core.BlockPos
3633
import net.minecraft.nbt.CompoundTag
3734
import net.minecraft.nbt.ListTag
38-
import net.minecraft.nbt.Tag
3935
import net.minecraft.network.chat.Component
4036
import net.minecraft.server.level.ServerLevel
4137
import net.minecraft.server.level.ServerPlayer
4238
import net.minecraft.world.ContainerHelper
4339
import net.minecraft.world.MenuProvider
40+
import net.minecraft.world.Nameable
4441
import net.minecraft.world.entity.player.Inventory
4542
import net.minecraft.world.entity.player.Player
4643
import net.minecraft.world.inventory.SimpleContainerData
@@ -53,7 +50,7 @@ import kotlin.math.min
5350

5451
class SplicingTableBlockEntity(pos: BlockPos, state: BlockState) :
5552
HexBlockEntity(HexDebugBlockEntities.SPLICING_TABLE.value, pos, state),
56-
ISplicingTable, BaseContainer, MenuProvider, ADIotaHolder, ADMediaHolder
53+
ISplicingTable, BaseContainer, MenuProvider, Nameable, ADIotaHolder, ADMediaHolder
5754
{
5855
override val stacks = BaseContainer.withSize(SplicingTableItemSlot.container_size)
5956

@@ -105,6 +102,9 @@ class SplicingTableBlockEntity(pos: BlockPos, state: BlockState) :
105102

106103
var pigment: FrozenPigment? = null
107104

105+
// https://youtrack.jetbrains.com/issue/KT-6653
106+
private var customNameInner: Component? = null
107+
108108
val enlightened get() = (blockState.block as? SplicingTableBlock)?.enlightened ?: false
109109

110110
init {
@@ -134,8 +134,9 @@ class SplicingTableBlockEntity(pos: BlockPos, state: BlockState) :
134134
to = tag.getInt("selectionTo", -1),
135135
)
136136
viewStartIndex = tag.getInt("viewStartIndex")
137-
hexTag = if (tag.contains("hex")) tag.getList("hex", Tag.TAG_COMPOUND) else null
138-
pigment = if (tag.contains("pigment")) FrozenPigment.fromNBT(tag.getCompound("pigment")) else null
137+
hexTag = tag.get("hex")?.asList
138+
pigment = tag.get("pigment")?.asCompound?.let(FrozenPigment::fromNBT)
139+
customNameInner = tag.get("CustomName")?.asString?.let(Component.Serializer::fromJson)
139140
}
140141

141142
override fun saveModData(tag: CompoundTag) {
@@ -146,12 +147,27 @@ class SplicingTableBlockEntity(pos: BlockPos, state: BlockState) :
146147
tag.putInt("viewStartIndex", viewStartIndex)
147148
hexTag?.let { tag.put("hex", it) }
148149
pigment?.let { tag.put("pigment", it.serializeToNBT()) }
150+
customNameInner?.let { tag.putString("CustomName", Component.Serializer.toJson(it)) }
149151
}
150152

153+
// MenuProvider
154+
151155
override fun createMenu(i: Int, inventory: Inventory, player: Player) =
152156
SplicingTableMenu(i, inventory, this, containerData)
153157

154-
override fun getDisplayName() = Component.translatable(blockState.block.descriptionId)
158+
override fun getDisplayName() = name
159+
160+
// Nameable
161+
162+
override fun getName() = customName ?: blockState.block.descriptionId.asTranslatedComponent
163+
164+
override fun getCustomName() = customNameInner
165+
166+
fun setCustomName(value: Component?) {
167+
customNameInner = value
168+
}
169+
170+
// more BE stuff
155171

156172
override fun setChanged() {
157173
super.setChanged()

Common/src/main/kotlin/gay/object/hexdebug/gui/splicing/SplicingTableScreen.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,11 @@ class SplicingTableScreen(
394394
vOffset = 392,
395395
width = castButtonWidth,
396396
height = castButtonHeight,
397-
message = buttonText("cast", HexDebugClientConfig.config.splicingTableKeybinds.enlightened.cast),
397+
message = buttonText(
398+
"cast.named",
399+
HexDebugClientConfig.config.splicingTableKeybinds.enlightened.cast,
400+
title,
401+
),
398402
onPress = {
399403
menu.table.castHex(null)
400404
castingCooldown = maxCastingCooldown
@@ -841,8 +845,8 @@ class SplicingTableScreen(
841845
guiGraphics.blit(TEXTURE, x, y, uOffset.toFloat(), vOffset.toFloat(), width, height, 512, 512)
842846
}
843847

844-
fun buttonText(name: String, key: ConfigModifierKey?): Component {
845-
val text = buttonKey(name).asTranslatedComponent
848+
fun buttonText(name: String, key: ConfigModifierKey?, vararg args: Any): Component {
849+
val text = buttonKey(name).asTranslatedComponent(*args)
846850
if (key == null) return text
847851
return text.append("\n").append(key.inner.localizedName.copy().gray.italic)
848852
}

Common/src/main/resources/assets/hexdebug/lang/en_us.flatten.json5

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
4949
paste_verbatim: "Paste (Verbatim)",
5050
paste_splat: "Paste (Flattened)",
5151
export: "Export as .hexpattern",
52-
cast: "Activate Table",
52+
cast: {
53+
"": "Activate Mindsplice Table",
54+
named: "Activate %s",
55+
},
5356
},
5457
tooltip: {
5558
index: "Index: %d",

Common/src/main/resources/hexdebug-common.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"mixins": [
1111
"MixinDatagenMain",
1212
"MixinMsgShiftScrollC2S",
13+
"MixinOpBrainsweepSpell",
1314
"MixinOpEval",
1415
"MixinOpImpetusDir",
1516
"MixinOpImpetusPos",

Forge/src/main/kotlin/gay/object/hexdebug/forge/datagen/HexDebugBlockLootTables.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ import net.minecraft.world.level.block.Block
77

88
class HexDebugBlockLootTables : BlockLootSubProvider(setOf(), FeatureFlags.DEFAULT_FLAGS) {
99
override fun generate() {
10-
dropSelf(HexDebugBlocks.SPLICING_TABLE.value)
11-
dropSelf(HexDebugBlocks.ENLIGHTENED_SPLICING_TABLE.value)
10+
nameableBlockEntity(HexDebugBlocks.SPLICING_TABLE.value)
11+
nameableBlockEntity(HexDebugBlocks.ENLIGHTENED_SPLICING_TABLE.value)
1212
dropSelf(HexDebugBlocks.FOCUS_HOLDER.value)
1313
}
1414

1515
override fun getKnownBlocks(): MutableIterable<Block> {
1616
return HexDebugBlocks.entries.map { it.value }.toMutableList()
1717
}
18+
19+
private fun nameableBlockEntity(block: Block) {
20+
add(block, createNameableBlockEntityTable(block))
21+
}
1822
}

0 commit comments

Comments
 (0)