Why won't my setblock command which summons a chest put the items inside I told it too? - minecraft

So I am making a Minecraft command with /setblock. It is supposed to put a 32K diamond sword in the first slot, and a 32K diamond axe on the second slot. Here is my command (it's ver big):
setblock ~ ~1 ~ chest{Items:[{id:"diamond_sword",slot:0,Count:1,tag:{Enchantments:[{id:"bane_of_arthropods",lvl:32768},{id:"fire_aspect",lvl:32768},{id:"knockback",lvl:32768},{id:"mending",lvl:32768},{id:"sharpness",lvl:32768},{id:"smite",lvl:32768},{id:"sweeping_edge",lvl:32768},{id:"unbreaking",lvl:32768}]}},{id:"diamond_axe",slot:1,Count:1,tag:{Enchantments:[{id:"bane_of_arthropods",lvl:32768},{id:"efficiency",lvl:32768},{id:"mending",lvl:32768},{id:"sharpness",lvl:32768},{id:"silk_touch",lvl:32768},{id:"smite",lvl:32768},{id:"unbreaking",lvl:32768}]}}]} replace
This however, only puts the 32K axe in the first slot, not the 32K sword in the first, and the 32K axe in the second. Please help!

You need a "b" after the slot number. Try the following:
setblock ~ ~1 ~ minecraft:chest{Items:[{Slot:0b,id:"minecraft:diamond_sword",Count:1b,tag:{Enchantments:[{lvl:32768,id:"bane_of_arthropods"},{lvl:32768,id:"fire_aspect"},{lvl:32768,id:"knockback"},{lvl:32768,id:"mending"},{lvl:32768,id:"sharpness"},{lvl:32768,id:"smite"},{lvl:32768,id:"sweeping_edge"},{lvl:32768,id:"unbreaking"}]}},{Slot:1b,id:"minecraft:diamond_axe",Count:1b,tag:{Enchantments:[{lvl:32768,id:"bane_of_arthropods"},{lvl:32768,id:"efficiency"},{lvl:32768,id:"mending"},{lvl:32768,id:"sharpness"},{lvl:32768,id:"silk_touch"},{lvl:32768,id:"smite"},{lvl:32768,id:"unbreaking"}]}}]}
Also consider posting on gaming.stackexchange.com in the future.

Related

Some questions about ELF file format

I am trying to learn how ELF files are structured and probably how to make one manually.
I am working on aarch64 Linux OS, the ELF files I am inspecting are of elf64-littleaarch64 format.
Also I try to learn by myself, however I got stuck with some questions...
When I do xxd code, the first number in each line of the output specifies the address of bytes in the file. But when objdump -D code, the first number is something like 4000b0, however corresponds to 000000b0 in xxd. Why is there a four at the beginning?
In objdump, the bytecode is for example 11000a94, which 'means'
add w20, w20, #2 in assembly. I know, that 11 is the opcode, but what does 000a94 mean? I thought, it should be the parameters, but I am adding the value 2 and can't find the number 2 in it.
If you have a good article to read, or can help me explain this, I will be very grateful!
xxd shows the offset of the bytes within the file on disk. objdump -D shows (tentatively) the address in memory where those bytes will be loaded when the program is run. It is common for them to differ by a round number. In particular, 0x400000 may correspond to one higher-level page table entry; see Why Linux/gnu linker chose address 0x400000? which is for x86-64 but I think ARM64 is similar (haven't checked). It doesn't have anything to do with the fact that 0x40 is ASCII #; that's just a coincidence.
Note that if ASLR is in use, the actual memory address will be randomly chosen every time the program is run, and will not match what objdump shows you, though the difference will still be a multiple of the page size.
Well, I was too fast asking this question, but now, I will answer it too.
40 at the beginning of the addresses in objdump is the hex representation of the char "#", which means "at" and points to an address, very simple!
Little Endian has CPU addresses stored in 5 bits instead of 6 or 8. That means, that I should look for the binary value of the objdump code: 11000a94 --> 10001000000000000101010010100, where it can be divided into [10001][00000000000010][10100][10100] with [opcode][value][first address][second address]
Both answers are wrong, see the accepted answer.
I will still let them here, though

Tmux pad format string

I want to pad a format string to a certain length. For example, the Tmux Battery plugin introduces the battery_percentage format string. I can use this in the status bar as #{battery_percentage}. The battery percentage values can be:
Between 0% and 9% (One Digit).
Between 11% and 99% (Two Digits).
Exactly 100% (Three Digits).
I want the format string to always be displayed 3 digits, padded with spaces at the end, how can I achieve that?
I saw that there is the format #{pN:variable} in this page, but it did not work when I tried to use it with format strings, even though at the end they are variables. Maybe I just did not know how to use it, I don't know...
Looking at the plugin startup code, battery.tmux, you can see that ${battery_percentage} is actually converted to #($CURRENT_DIR/scripts/battery_percentage.sh), which is a request to run a script. I don't know if #{p3:#(...)} can be made to work since this is not a simple variable.
You could always edit the plugin shell script to return the padded string (assuming tmux keeps the leading spaces).

How to awk to read a dictionary and replace words in a file?

We have a source file ("source-A") that looks like this (if you see blue text, it comes from stackoverflow, not the text file):
The container of white spirit was made of aluminium.
We will use an aromatic method to analyse properties of white spirit.
No one drank white spirit at stag night.
Many people think that a potato crisp is savoury, but some would rather eat mashed potato.
...
more sentences
Each sentence in "source-A" is on its own line and terminates with a newline (\n)
We have a dictionary/conversion file ("converse-B") that looks like this:
aluminium<tab>aluminum
analyse<tab>analyze
white spirit<tab>mineral spirits
stag night<tab>bachelor party
savoury<tab>savory
potato crisp<tab>potato chip
mashed potato<tab>mashed potatoes
"converse-B" is a two column, tab delimited file.
Each equivalence map (term-on-left<tab>term-on-right) is on its own line and terminates with a newline (\n)
How to read "converse-B", and replace terms in "source-A" where a term in "converse-B" column-1 is replaced with the term in column-2, and then write to an output file ("output-C")?
For example, the "output-C" would look like this:
The container of mineral spirits was made of aluminum.
We will use an aromatic method to analyze properties of mineral spirits.
No one drank mineral spirits at bachelor party.
Many people think that a potato chip is savory, but some would rather eat mashed potatoes.
The tricky part is the term potato.
If a "simple" awk solution cannot handle a singular term (potato) and a plural term (potatoes), we'll use a manual substitution method. The awk solution can skip that use case.
In other words, an awk solution can stipulate that it only works for an unambiguous word or a term composed of space separated, unambiguous words.
An awk solution will get us to a 90% completion rate; we'll do the remaining 10% manually.
sed probably suits better since since it's only phrase/word replacements. Note that if the same words appear in multiple phrases first come first serve; so change your dictionary order accordingly.
$ sed -f <(sed -E 's_(.+)\t(.+)_s/\1/\2/g_' dict) content
The container of mineral spirits was made of aluminum.
We will use an aromatic method to analyze properties of mineral spirits.
No one drank mineral spirits at bachelor party.
Many people think that a potato chip is savory, but some would rather eat mashed potatoes.
...
more sentences
file substitute sed statement converts dictionary entries into sed expressions and the main sed uses them for the content replacements.
NB: Note that production quality script should take of word cases and also word boundaries to eliminate unwanted substring substitution, which are ignored here.

group lines with a tag

Each written line belongs to the first tag upward.
For instance: ' The trucker is drunk ' belongs to AN8. I want to group all written lines belonging to the corresponding tag. Lines should remain in the same order.
input:
AN9
the cow is eating way too much
AN8
The trucker is drunk
AN9
The field are running out of herbs.
AN8
the truck is not going that staight
well of course the road is in curve
AN9
and
another line
AN8
The cop needs to check this out
AN9
now the cow is soooo big dude !
output:
AN9
the cow is eating way too much
The field are running out of herbs.
and
another line
now the cow is soooo big dude !
AN8
The trucker is drunk
the truck is not going that staight
well of course the road is in curve
The cop needs to check this out
Here is one awk
awk '/^AN/ {id=$0;next} {a[id]=a[id]"\n"$0} END {for (i in a) print i,a[i]}' file
AN8
The trucker is drunk
the truck is not going that staight
well of course the road is in curve
The cop needs to check this out
AN9
the cow is eating way too much
The field are running out of herbs.
and
another line
now the cow is soooo big dude !
If line starts with AN, use the info in the line as ID for array a.
Then store all lines in array a. Finally print all data in array a

Batch Scripting Help - Replace Substring of a DelayedExpansion Var with another DelayedExpansion Var

Basically I'm trying to do !var1:SomeText=!var2!! but this code doesn't work.
What am I missing?
The order of expansion is critical when doing a search and replace operation that uses a variable for the search and/or the replace. The inner variable must be expanded before the outer search and replace expansion takes place. Trying to used delayed expansion for both obviously can't work because the delayed expansion occurs at one point in time.
The classic method for expansion of a variable within another variable uses delayed expansion for the outer, and normal for the inner: echo !var1:SomeText=%var2%!"
I am going to assume you wanted to use delayed expansion for both for a reason. Perhaps the expansion occurs within a block of code and one of the variables was set in the same block. Normal expansion won't work because it can't see the value that was assigned within the block until after the block concludes.
Solution 1
One way to solve the problem is to use CALL:
call echo %%var1:SomeText=!var2!%%
This works as follows:
The percent phase of the parser converts double percents into single percents, resulting in
call echo %var1:SomeText=!var2!%
The delayed expansion expands !var2!, resulting in
call echo %var1:SomeText=ReplacementText%
The CALL ECHO is executed and an additional level of percent processing takes place. The search and replace expansion is executed, resulting in ResultOfSearchAndReplace being echoed to the screen.
This works, but it is relatively slow. It also can have problems if the expanded value has special characters like >, & or |. I rarely use this technique.
Solution 2
The fast and more reliable method is to do the expansion in two steps. First transfer the value of !var2! to a FOR variable. You can then use the FOR variable as the replacement string and use delayed expansion for the second step. This completely avoids the more brittle percent expansion.
for /f "delims=" %%A in ("!var2!") do echo !var1:SomeText=%%A!
The above works because FOR variable expansion takes place before delayed expansion.
This is by far my preferred method to attack this problem.
For a more thorough explanation of the various phases of the batch parser, refer to jeb's answer to How does the Windows Command Interpreter (CMD.EXE) parse scripts?