Skip to content

Commit 468dc86

Browse files
Allow accessing block nbt from placeholders (#4161)
1 parent 555c9df commit 468dc86

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

src/generated/resources/assets/gtceu/lang/en_ud.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,6 +3542,10 @@
35423542
"gtceu.placeholder_info.block.0": "˙)█( ןoqɯʎs ʞɔoןq ǝɥʇ suɹnʇǝᴚ",
35433543
"gtceu.placeholder_info.block.1": ":ǝbɐs∩",
35443544
"gtceu.placeholder_info.block.2": ",█, >- }ʞɔoןq{ ",
3545+
"gtceu.placeholder_info.blockNbt.0": "ʎʇıʇuǝ ʞɔoןq ǝɥʇ ɟo ⟘ᗺN ǝɥʇ suɹnʇǝᴚ",
3546+
"gtceu.placeholder_info.blockNbt.1": ":ǝbɐs∩",
3547+
"gtceu.placeholder_info.blockNbt.2": "ʇqu ʎʇıʇuǝ ʞɔoןq ןןnɟ >- }ʇqNʞɔoןq{ ",
3548+
"gtceu.placeholder_info.blockNbt.3": "ʇqu ǝɥʇ ɟo ʇɹɐd >- }˙˙˙ ]ᄅʎǝʞ[ ]Ɩʎǝʞ[ ʇqNʞɔoןq{ ",
35453549
"gtceu.placeholder_info.bufferText.0": "ʇɟɐɹƆɹǝʇndɯoƆ ʎq ǝןqıssǝɔɔɐ ɹǝɟɟnq ɐ ɯoɹɟ ʇxǝʇ ǝɥʇ suɹnʇǝᴚ",
35463550
"gtceu.placeholder_info.bufferText.1": ":ǝbɐs∩",
35473551
"gtceu.placeholder_info.bufferText.2": ")00Ɩ-Ɩ sı ǝuıן( ǝuıן pǝıɟıɔǝds ǝɥʇ uo ɹǝɟɟnq ǝɥʇ ɯoɹɟ ʇxǝʇ >- }>ǝuıן< ʇxǝ⟘ɹǝɟɟnq{ ",

src/generated/resources/assets/gtceu/lang/en_us.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,6 +3542,10 @@
35423542
"gtceu.placeholder_info.block.0": "Returns the block symbol (█).",
35433543
"gtceu.placeholder_info.block.1": "Usage:",
35443544
"gtceu.placeholder_info.block.2": " {block} -> '█'",
3545+
"gtceu.placeholder_info.blockNbt.0": "Returns the NBT of the block entity",
3546+
"gtceu.placeholder_info.blockNbt.1": "Usage:",
3547+
"gtceu.placeholder_info.blockNbt.2": " {blockNbt} -> full block entity nbt",
3548+
"gtceu.placeholder_info.blockNbt.3": " {blockNbt [key1] [key2] ...} -> part of the nbt",
35453549
"gtceu.placeholder_info.bufferText.0": "Returns the text from a buffer accessible by ComputerCraft",
35463550
"gtceu.placeholder_info.bufferText.1": "Usage:",
35473551
"gtceu.placeholder_info.bufferText.2": " {bufferText <line>} -> text from the buffer on the specified line (line is 1-100)",

src/main/java/com/gregtechceu/gtceu/common/data/GTPlaceholders.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import net.minecraft.server.level.ServerLevel;
3636
import net.minecraft.server.level.ServerPlayer;
3737
import net.minecraft.world.item.ItemStack;
38+
import net.minecraft.world.level.block.entity.BlockEntity;
3839
import net.minecraft.world.phys.Vec2;
3940
import net.minecraft.world.phys.Vec3;
4041
import net.minecraftforge.fluids.FluidStack;
@@ -831,5 +832,27 @@ public MultiLineComponent apply(PlaceholderContext ctx,
831832
return PlaceholderHandler.processPlaceholders(args.get(0).toString(), ctx);
832833
}
833834
});
835+
PlaceholderHandler.addPlaceholder(new Placeholder("blockNbt") {
836+
837+
@Override
838+
public MultiLineComponent apply(PlaceholderContext ctx, List<MultiLineComponent> args) {
839+
BlockEntity blockEntity = ctx.level().getBlockEntity(ctx.pos());
840+
if (blockEntity == null) return MultiLineComponent.empty();
841+
Tag tag = blockEntity.saveWithFullMetadata();
842+
if (tag instanceof CompoundTag compoundTag && compoundTag.contains("cover")) {
843+
CompoundTag coverTag = compoundTag.getCompound("cover");
844+
if (coverTag.contains(ctx.side().getName())) {
845+
CompoundTag cover = coverTag.getCompound(ctx.side().getName()).getCompound("payload")
846+
.getCompound("d");
847+
cover.putString("text", "[REMOVED]");
848+
}
849+
}
850+
for (MultiLineComponent arg : args) {
851+
if (!(tag instanceof CompoundTag compoundTag)) return MultiLineComponent.empty();
852+
tag = compoundTag.get(arg.toString());
853+
}
854+
return tag == null ? MultiLineComponent.empty() : MultiLineComponent.literal(tag.toString());
855+
}
856+
});
834857
}
835858
}

src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,11 @@ public static void init(RegistrateLangProvider provider) {
16431643
"Returns the text from a buffer accessible by ComputerCraft",
16441644
"Usage:",
16451645
" {bufferText <line>} -> text from the buffer on the specified line (line is 1-100)");
1646+
multiLang(provider, "gtceu.placeholder_info.blockNbt",
1647+
"Returns the NBT of the block entity",
1648+
"Usage:",
1649+
" {blockNbt} -> full block entity nbt",
1650+
" {blockNbt [key1] [key2] ...} -> part of the nbt");
16461651
provider.add("gtceu.ender_item_link_cover.title", "Ender Item Link");
16471652
provider.add("gtceu.ender_item_link_cover.tooltip",
16481653
"§7Transports §fItems§7 with a §fWireless §dEnder§f Connection§7 as §fCover§7.");
@@ -1679,7 +1684,7 @@ public static void init(RegistrateLangProvider provider) {
16791684
"Slot number: %d");
16801685
multiLang(provider, "gtceu.gui.computer_monitor_cover.second_page_textbox_tooltip",
16811686
"Input placeholder to be used in place of %s '{}' here.",
1682-
"For example, you can have a string 'Energy: {}/{} EU' and 'energy' and 'energyCapacity' in these text boxes.");
1687+
"For example, you can have a string 'Energy: {}/{} EU' and 'energy' and 'energyCapacity' in these text boxes.");;
16831688
provider.add("gtceu.computer_monitor_cover.error.no_placeholder", "No such placeholder: '%s'!");
16841689
provider.add("gtceu.computer_monitor_cover.error.unclosed_bracket", "Unclosed bracket!");
16851690
provider.add("gtceu.computer_monitor_cover.error.unexpected_bracket", "Unexpected closing bracket!");

0 commit comments

Comments
 (0)