nbt_utils 0.0.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/ci.yml +24 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/.rubocop.yml +37 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +49 -4
- data/LICENSE +7 -0
- data/README.md +16 -18
- data/Rakefile +8 -0
- data/doc/bigtest_uncompressed.nbt +0 -0
- data/doc/test_uncompressed.nbt +0 -0
- data/lib/nbt_utils/file.rb +25 -8
- data/lib/nbt_utils/tag/byte.rb +4 -1
- data/lib/nbt_utils/tag/byte_array.rb +9 -7
- data/lib/nbt_utils/tag/compound.rb +22 -17
- data/lib/nbt_utils/tag/double.rb +4 -1
- data/lib/nbt_utils/tag/end.rb +6 -4
- data/lib/nbt_utils/tag/exceptions.rb +3 -1
- data/lib/nbt_utils/tag/float.rb +4 -1
- data/lib/nbt_utils/tag/int.rb +4 -1
- data/lib/nbt_utils/tag/int_array.rb +37 -0
- data/lib/nbt_utils/tag/list.rb +20 -15
- data/lib/nbt_utils/tag/long.rb +4 -1
- data/lib/nbt_utils/tag/short.rb +4 -1
- data/lib/nbt_utils/tag/string.rb +2 -0
- data/lib/nbt_utils/tag.rb +13 -17
- data/lib/nbt_utils/tag_name.rb +5 -3
- data/lib/nbt_utils/version.rb +3 -1
- data/lib/nbt_utils.rb +3 -0
- data/nbt_utils.gemspec +17 -11
- data/script.rb +21 -19
- data/spec/nbt_utils/file_spec.rb +60 -0
- data/spec/nbt_utils/tag/byte_array_spec.rb +5 -0
- data/spec/nbt_utils/tag/byte_spec.rb +5 -0
- data/spec/nbt_utils/tag/compound_spec.rb +5 -0
- data/spec/nbt_utils/tag/double_spec.rb +5 -0
- data/spec/nbt_utils/tag/end_spec.rb +5 -0
- data/spec/nbt_utils/tag/float_spec.rb +5 -0
- data/spec/nbt_utils/tag/int_array_spec.rb +5 -0
- data/spec/nbt_utils/tag/int_spec.rb +5 -0
- data/spec/nbt_utils/tag/list_spec.rb +5 -0
- data/spec/nbt_utils/tag/long_spec.rb +5 -0
- data/spec/nbt_utils/tag/short_spec.rb +5 -0
- data/spec/nbt_utils/tag/string_spec.rb +5 -0
- data/spec/nbt_utils/tag_name_spec.rb +20 -0
- data/spec/spec_helper.rb +102 -0
- data/spec/support/shared_examples/a_tag.rb +8 -0
- metadata +116 -54
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2cd4381d03d4fbcfe77b3be94f2d52d66899f8e89d1095cfbb359f3455f153d2
|
4
|
+
data.tar.gz: 1b9f9ccbaf59dc071093bc5f3d50035a54717f8fffc0cd7cc5d45e51027577e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b9422f9cf06b75d5b85483857a96dd1a674888fd353e25305c6182c83997ca2685c401b08977eca36725f62af353a2b3fe1f0649219b77a9c9066397efd2624
|
7
|
+
data.tar.gz: 58a8fe25760a2bb28655d4f11b66ffa6ef8ae0f6e450f49d768a3fa54db81f95a1c3f238c964add962a94b49e087758b9b163045d7213bceaf05aefb29659481
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: CI
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches: [ master ]
|
5
|
+
pull_request:
|
6
|
+
branches: [ master ]
|
7
|
+
|
8
|
+
env:
|
9
|
+
CARGO_TERM_COLOR: always
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
ci:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
steps:
|
15
|
+
- name: Checkout
|
16
|
+
uses: actions/checkout@v3
|
17
|
+
- name: Setup Ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
bundler-cache: true
|
21
|
+
- name: Run Rubocop
|
22
|
+
run: bundle exec rubocop
|
23
|
+
- name: Run Specs
|
24
|
+
run: rake spec
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: '2.7.0'
|
7
|
+
NewCops: enable
|
8
|
+
|
9
|
+
Layout/LineLength:
|
10
|
+
Max: 120
|
11
|
+
|
12
|
+
Metrics/AbcSize:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Metrics/BlockLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/CyclomaticComplexity:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Metrics/PerceivedComplexity:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Metrics/MethodLength:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
RSpec/ExampleLength:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
RSpec/MultipleExpectations:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Style/Documentation:
|
37
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.2
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,17 +1,62 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nbt_utils (0.0
|
5
|
-
bindata (~>
|
4
|
+
nbt_utils (0.5.0)
|
5
|
+
bindata (~> 2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
10
|
+
ast (2.4.2)
|
11
|
+
bindata (2.4.10)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
parallel (1.22.1)
|
14
|
+
parser (3.1.2.0)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
rainbow (3.1.1)
|
17
|
+
regexp_parser (2.5.0)
|
18
|
+
rexml (3.2.5)
|
19
|
+
rspec (3.11.0)
|
20
|
+
rspec-core (~> 3.11.0)
|
21
|
+
rspec-expectations (~> 3.11.0)
|
22
|
+
rspec-mocks (~> 3.11.0)
|
23
|
+
rspec-core (3.11.0)
|
24
|
+
rspec-support (~> 3.11.0)
|
25
|
+
rspec-expectations (3.11.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.11.0)
|
28
|
+
rspec-mocks (3.11.1)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.11.0)
|
31
|
+
rspec-support (3.11.0)
|
32
|
+
rubocop (1.30.1)
|
33
|
+
parallel (~> 1.10)
|
34
|
+
parser (>= 3.1.0.0)
|
35
|
+
rainbow (>= 2.2.2, < 4.0)
|
36
|
+
regexp_parser (>= 1.8, < 3.0)
|
37
|
+
rexml (>= 3.2.5, < 4.0)
|
38
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
39
|
+
ruby-progressbar (~> 1.7)
|
40
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
41
|
+
rubocop-ast (1.18.0)
|
42
|
+
parser (>= 3.1.1.0)
|
43
|
+
rubocop-performance (1.14.2)
|
44
|
+
rubocop (>= 1.7.0, < 2.0)
|
45
|
+
rubocop-ast (>= 0.4.0)
|
46
|
+
rubocop-rspec (2.11.1)
|
47
|
+
rubocop (~> 1.19)
|
48
|
+
ruby-progressbar (1.11.0)
|
49
|
+
unicode-display_width (2.1.0)
|
11
50
|
|
12
51
|
PLATFORMS
|
13
52
|
ruby
|
14
53
|
|
15
54
|
DEPENDENCIES
|
16
|
-
bundler (>= 1.0.0)
|
17
55
|
nbt_utils!
|
56
|
+
rspec (~> 3)
|
57
|
+
rubocop (~> 1)
|
58
|
+
rubocop-performance (~> 1)
|
59
|
+
rubocop-rspec (~> 2)
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
2.3.15
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2021 Michael Dungan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,30 +1,28 @@
|
|
1
|
-
nbt_utils
|
2
|
-
=========
|
1
|
+
# nbt_utils
|
3
2
|
|
4
|
-
Some classes for handling [Minecraft](http://minecraft.net)
|
3
|
+
Some classes for handling [Minecraft](http://minecraft.net) `.nbt` files.
|
5
4
|
|
6
|
-
See
|
5
|
+
See the spec (`NBT.txt` in doc directory) for more info.
|
7
6
|
|
8
|
-
Installation
|
9
|
-
============
|
7
|
+
## Installation
|
10
8
|
|
11
|
-
Requires
|
9
|
+
Requires Ruby 2.7 minimum.
|
12
10
|
|
13
11
|
gem install nbt_utils
|
14
12
|
|
15
|
-
|
13
|
+
## Use
|
16
14
|
|
17
|
-
|
18
|
-
|
15
|
+
```ruby
|
16
|
+
require 'nbt_utils'
|
19
17
|
|
20
|
-
|
18
|
+
@file = NBTUtils::File.new
|
19
|
+
@tag = @file.read('some_nbt_file.nbt')
|
20
|
+
puts @tag.to_s
|
21
|
+
@file.write('some_new_path.nbt', @tag, true) # true / false to gzip automatically
|
22
|
+
```
|
21
23
|
|
22
|
-
|
23
|
-
puts @tag.to_s
|
24
|
+
### Copyright
|
24
25
|
|
25
|
-
Copyright
|
26
|
-
=========
|
26
|
+
Copyright Michael Dungan, mpd@jesters-court.net, released under the MIT license.
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
The files `NBT.txt`, `test.nbt`, and `bigtest.nbt` in the doc directory are mirrored from the Minecraft website and not covered under the above license.
|
28
|
+
The files `NBT.txt`, `test.nbt`, `test_uncompressed.nbt`, `bigtest.nbt`, and `bigtest_uncompressed.nbt` in the doc directory are mirrored from the Minecraft website and not covered under the above license.
|
data/Rakefile
CHANGED
Binary file
|
Binary file
|
data/lib/nbt_utils/file.rb
CHANGED
@@ -1,23 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module NBTUtils
|
2
4
|
class File
|
5
|
+
attr_reader :path, :content, :compressed, :tag
|
6
|
+
|
3
7
|
def initialize(path = nil)
|
4
8
|
@path = path
|
5
9
|
end
|
6
10
|
|
7
|
-
def read(
|
8
|
-
Zlib
|
9
|
-
|
11
|
+
def read(read_path = path)
|
12
|
+
# Zlib does not provide a way to test a file for compressed, and I'm
|
13
|
+
# not going to tool around with magic numbers, so I guess we use
|
14
|
+
# exceptions for flow control.
|
15
|
+
begin
|
16
|
+
Zlib::GzipReader.open(read_path) do |f|
|
17
|
+
@content = StringIO.new(f.read)
|
18
|
+
end
|
19
|
+
@compressed = true
|
20
|
+
rescue Zlib::GzipFile::Error
|
21
|
+
@content = StringIO.new(::File.read(read_path))
|
22
|
+
@compressed = false
|
10
23
|
end
|
11
24
|
|
12
|
-
last_byte =
|
25
|
+
last_byte = content.read(1).bytes.first
|
13
26
|
klass = NBTUtils::Tag.tag_type_to_class(last_byte)
|
14
27
|
|
15
|
-
@tag = klass.new(
|
28
|
+
@tag = klass.new(content, named: true)
|
16
29
|
end
|
17
30
|
|
18
|
-
def write(
|
19
|
-
|
20
|
-
|
31
|
+
def write(write_path = path, write_tag = tag, write_compressed = compressed)
|
32
|
+
if write_compressed
|
33
|
+
Zlib::GzipWriter.open(write_path) do |gz|
|
34
|
+
gz.write write_tag.to_nbt_string
|
35
|
+
end
|
36
|
+
else
|
37
|
+
::File.write(write_path, write_tag.to_nbt_string)
|
21
38
|
end
|
22
39
|
end
|
23
40
|
end
|
data/lib/nbt_utils/tag/byte.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module NBTUtils
|
2
4
|
module Tag
|
3
5
|
class ByteArray
|
@@ -5,31 +7,31 @@ module NBTUtils
|
|
5
7
|
|
6
8
|
type_id 7
|
7
9
|
|
8
|
-
def initialize(io, named
|
10
|
+
def initialize(io, named: true)
|
9
11
|
read_name(io) if named
|
10
12
|
|
11
13
|
len = ::BinData::Int32be.new.read(io).value
|
12
14
|
# use single string for the payload because an array means each byte is a
|
13
15
|
# separate object which is incredibly SLOW
|
14
|
-
@payload = ::BinData::String.new(:
|
16
|
+
@payload = ::BinData::String.new(read_length: len).read(io)
|
15
17
|
end
|
16
18
|
|
17
19
|
def to_s(indent = 0)
|
18
|
-
(' ' * indent) + "TAG_Byte_Array#{
|
20
|
+
(' ' * indent) + "TAG_Byte_Array#{name ? "(\"#{name}\")" : ''}: [#{payload.length} bytes]"
|
19
21
|
end
|
20
22
|
|
21
|
-
def to_nbt_string(named
|
23
|
+
def to_nbt_string(named: true)
|
22
24
|
result = named ? binary_type_id + name_to_nbt_string : ''
|
23
25
|
len = ::BinData::Int32be.new
|
24
|
-
len.value =
|
26
|
+
len.value = payload.length
|
25
27
|
result << len.to_binary_s
|
26
|
-
result +
|
28
|
+
result + payload.to_binary_s
|
27
29
|
end
|
28
30
|
|
29
31
|
def set_value(new_value, index)
|
30
32
|
b = ::BinData::Uint8.new
|
31
33
|
b.value = new_value
|
32
|
-
|
34
|
+
payload[index] = b.to_binary_s
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module NBTUtils
|
2
4
|
module Tag
|
3
5
|
class Compound
|
@@ -5,55 +7,58 @@ module NBTUtils
|
|
5
7
|
|
6
8
|
type_id 10
|
7
9
|
|
8
|
-
|
10
|
+
attr_reader :tag_names
|
11
|
+
|
12
|
+
def initialize(io, named: true)
|
9
13
|
@payload = []
|
10
14
|
@tag_names = []
|
11
15
|
read_name(io) if named
|
12
16
|
|
13
17
|
until (last_byte = io.read(1).bytes.first) == NBTUtils::Tag::End.type_id
|
14
18
|
klass = tag_type_to_class(last_byte)
|
15
|
-
add_tag klass.new(io, true)
|
19
|
+
add_tag klass.new(io, named: true)
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def to_s(indent = 0)
|
20
|
-
ret = (' ' * indent) + "TAG_Compound#{
|
21
|
-
ret << (' ' * indent
|
22
|
-
|
24
|
+
ret = (' ' * indent) + "TAG_Compound#{name ? "(\"#{name}\")" : ''}: #{payload.length} entries\n"
|
25
|
+
ret << ("#{' ' * indent}{\n")
|
26
|
+
payload.each do |load|
|
23
27
|
ret << "#{load.to_s(indent + 2)}\n"
|
24
28
|
end
|
25
|
-
ret << (' ' * indent
|
29
|
+
ret << ("#{' ' * indent}}")
|
26
30
|
|
27
31
|
ret
|
28
32
|
end
|
29
33
|
|
30
|
-
def to_nbt_string(named
|
34
|
+
def to_nbt_string(named: true)
|
31
35
|
result = named ? binary_type_id + name_to_nbt_string : ''
|
32
36
|
|
33
|
-
result =
|
34
|
-
r + load.to_nbt_string(true)
|
37
|
+
result = payload.inject(result) do |r, load|
|
38
|
+
r + load.to_nbt_string(named: true)
|
35
39
|
end
|
36
40
|
|
37
41
|
result + NBTUtils::Tag::End.new(nil).to_nbt_string
|
38
42
|
end
|
39
43
|
|
40
44
|
def find_tag(name)
|
41
|
-
if name.
|
42
|
-
|
45
|
+
if name.is_a?(Regexp)
|
46
|
+
payload.detect { |tag| tag.name.to_s =~ /#{name}/ }
|
43
47
|
else
|
44
|
-
|
48
|
+
payload.detect { |tag| tag.name.to_s == name }
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
48
52
|
def find_tags(name)
|
49
|
-
|
53
|
+
payload.select { |tag| tag.name.to_s =~ /#{name}/ }
|
50
54
|
end
|
51
55
|
|
52
56
|
def add_tag(tag)
|
53
57
|
raise MissingCompoundPayloadTagNameError if tag.name.nil?
|
54
|
-
raise DuplicateCompoundPayloadTagNameError if
|
55
|
-
|
56
|
-
|
58
|
+
raise DuplicateCompoundPayloadTagNameError if tag_names.include?(tag.name)
|
59
|
+
|
60
|
+
tag_names << tag.name
|
61
|
+
payload << tag
|
57
62
|
end
|
58
63
|
|
59
64
|
# update one of my tags indirectly
|
@@ -68,7 +73,7 @@ module NBTUtils
|
|
68
73
|
end
|
69
74
|
|
70
75
|
def remove_tag(name)
|
71
|
-
|
76
|
+
payload.delete find_tag(name)
|
72
77
|
end
|
73
78
|
end
|
74
79
|
end
|
data/lib/nbt_utils/tag/double.rb
CHANGED
data/lib/nbt_utils/tag/end.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module NBTUtils
|
2
4
|
module Tag
|
3
5
|
class End
|
@@ -5,17 +7,17 @@ module NBTUtils
|
|
5
7
|
|
6
8
|
type_id 0
|
7
9
|
|
8
|
-
def initialize(
|
10
|
+
def initialize(...)
|
9
11
|
@name = ''
|
10
12
|
end
|
11
13
|
|
12
|
-
def to_s(
|
14
|
+
def to_s(...)
|
13
15
|
''
|
14
16
|
end
|
15
17
|
|
16
|
-
def to_nbt_string(
|
18
|
+
def to_nbt_string(...)
|
17
19
|
binary_type_id
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
21
|
-
end
|
23
|
+
end
|
data/lib/nbt_utils/tag/float.rb
CHANGED
data/lib/nbt_utils/tag/int.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NBTUtils
|
4
|
+
module Tag
|
5
|
+
class IntArray
|
6
|
+
include NBTUtils::Tag
|
7
|
+
|
8
|
+
type_id 11
|
9
|
+
|
10
|
+
def initialize(io, named: true)
|
11
|
+
read_name(io) if named
|
12
|
+
|
13
|
+
len = ::BinData::Int32be.new.read(io).value
|
14
|
+
|
15
|
+
@payload = ::BinData::Array.new(type: :int32be, initial_length: len).read(io)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s(indent = 0)
|
19
|
+
(' ' * indent) + "TAG_Int_Array#{name ? "(\"#{name}\")" : ''}: [#{payload.length} bytes]"
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_nbt_string(named: true)
|
23
|
+
result = named ? binary_type_id + name_to_nbt_string : ''
|
24
|
+
len = ::BinData::Int32be.new
|
25
|
+
len.value = payload.length
|
26
|
+
result << len.to_binary_s
|
27
|
+
result + payload.to_binary_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_value(new_value, index)
|
31
|
+
b = ::BinData::Int32be.new
|
32
|
+
b.value = new_value
|
33
|
+
payload[index] = b.to_binary_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/nbt_utils/tag/list.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module NBTUtils
|
2
4
|
module Tag
|
3
5
|
class List
|
@@ -5,7 +7,9 @@ module NBTUtils
|
|
5
7
|
|
6
8
|
type_id 9
|
7
9
|
|
8
|
-
|
10
|
+
attr_reader :tag_type
|
11
|
+
|
12
|
+
def initialize(io, named: true)
|
9
13
|
@payload = []
|
10
14
|
read_name(io) if named
|
11
15
|
|
@@ -13,41 +17,42 @@ module NBTUtils
|
|
13
17
|
@tag_type = NBTUtils::Tag.tag_type_to_class(tag_id)
|
14
18
|
len = ::BinData::Int32be.new.read(io).value
|
15
19
|
len.times do
|
16
|
-
|
20
|
+
payload << tag_type.new(io, named: false)
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
24
|
def to_s(indent = 0)
|
21
|
-
ret =
|
22
|
-
|
23
|
-
|
25
|
+
ret = "#{' ' * indent}TAG_List#{name ? "(\"#{name}\")" : ''}: #{payload.length} entries of "\
|
26
|
+
"type TAG_#{tag_type.to_s.split('::').last}\n"
|
27
|
+
ret << ("#{' ' * indent}{\n")
|
28
|
+
payload.each do |load|
|
24
29
|
ret << "#{load.to_s(indent + 2)}\n"
|
25
30
|
end
|
26
|
-
ret << (' ' * indent
|
31
|
+
ret << ("#{' ' * indent}}")
|
27
32
|
ret
|
28
33
|
end
|
29
34
|
|
30
|
-
def to_nbt_string(named
|
35
|
+
def to_nbt_string(named: true)
|
31
36
|
result = named ? binary_type_id + name_to_nbt_string : ''
|
32
37
|
type = ::BinData::Int8be.new
|
33
|
-
type.value =
|
38
|
+
type.value = tag_type.type_id
|
34
39
|
result << type.to_binary_s
|
35
40
|
len = ::BinData::Int32be.new
|
36
|
-
len.value =
|
41
|
+
len.value = payload.length
|
37
42
|
result << len.to_binary_s
|
38
|
-
|
39
|
-
r + load.to_nbt_string(false)
|
43
|
+
payload.inject(result) do |r, load|
|
44
|
+
r + load.to_nbt_string(named: false)
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
43
48
|
def set_value(new_value, index)
|
44
|
-
unless new_value.
|
45
|
-
t =
|
49
|
+
unless new_value.is_a?(NBTUtils::Tag)
|
50
|
+
t = tag_type.new
|
46
51
|
t.value = new_value
|
47
52
|
new_value = t
|
48
53
|
end
|
49
|
-
|
50
|
-
|
54
|
+
|
55
|
+
payload[index] = new_value
|
51
56
|
end
|
52
57
|
end
|
53
58
|
end
|
data/lib/nbt_utils/tag/long.rb
CHANGED
data/lib/nbt_utils/tag/short.rb
CHANGED