Skip to content

Commit 432695c

Browse files
author
ozelot379
committed
Improve particles convert and merge Java 1.13 and 1.14 variants
1 parent dfc4412 commit 432695c

4 files changed

Lines changed: 78 additions & 22 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [1.6.4]
44
- Fix convert water
5+
- Improve particles convert and merge Java 1.13 and 1.14 variants
56

67
## [1.6.3]
78
- Fix `publish` script
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import AbstractConverter from "./AbstractConverter";
2+
import Utils from "../Utils/Utils";
3+
4+
/**
5+
* Class Particles1_13Converter
6+
*/
7+
class Particles1_13Converter extends AbstractConverter {
8+
/**
9+
* @inheritDoc
10+
*/
11+
async convert() {
12+
for await (const [from, to] of this.getData()) {
13+
if (await this.output.exists(from)) {
14+
Utils.log(`Convert particles ${from}`);
15+
16+
const image = await this.readImage(from);
17+
18+
image.crop(0, 0, (image.getWidth() / 2), (image.getHeight() / 2)); // Bedrock only uses the first 25% of the image (Rest is transparent on Java)
19+
20+
await this.writeImage(to, image);
21+
}
22+
}
23+
24+
return [];
25+
}
26+
27+
/**
28+
* @inheritDoc
29+
*/
30+
async* getData() {
31+
const data = [
32+
["textures/particle/particles.png", "textures/particle/particles.png"]
33+
];
34+
35+
for (const date of data) {
36+
yield date;
37+
}
38+
}
39+
}
40+
41+
export default Particles1_13Converter;

‎src/Converter/SpriteConverter.js‎

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,36 @@ class SpriteConverter extends AbstractConverter {
1313
async convert() {
1414
const to_delete = [];
1515

16-
for await (const [width, height, sprites, to, scale = 1] of this.getData()) {
16+
for await (const [width, height, sprites, to, min_factor = 1] of this.getData()) {
1717
let image = null;
18+
let factor = null;
1819

19-
let factor = 1;
20+
if (await this.output.exists(to)) {
21+
Utils.log(`Convert sprite ${to}`);
2022

21-
for (const [sprite, x, y, factor_detect, not_scale] of sprites) {
23+
image = await this.readImage(to); // Load already exists sprites image - Some texture packs have may a mix with sprites (1.13) and separate images (1.14)
24+
25+
factor = (image.getWidth() / width);
26+
}
27+
28+
for (const [sprite, x, y, factor_detect] of sprites) {
2229
if (await this.output.exists(sprite)) {
2330
const image_sprite = await this.readImage(sprite);
2431

25-
factor = (image_sprite.getWidth() / factor_detect * scale);
32+
if (factor === null) {
33+
factor = Math.max((image_sprite.getWidth() / factor_detect), min_factor); // Take the factor of the first image
34+
}
2635

2736
if (image === null) {
2837
Utils.log(`Create sprite ${to}`);
2938

3039
image = await Jimp.create((width * factor), (height * factor));
3140
}
3241

33-
image.composite((scale > 1 && !not_scale ? image_sprite.scale(scale, "nearestNeighbor") : image_sprite), (x * factor), (y * factor));
42+
image.scan((x * factor), (y * factor), (factor_detect * factor), (factor_detect * factor), (x, y, idx) => {
43+
image.bitmap.data[idx] = image.bitmap.data[idx + 1] = image.bitmap.data[idx + 2] = image.bitmap.data[idx + 3] = 0; // Delete previous area, if the sprite already exists
44+
});
45+
image.composite(image_sprite.resize((factor_detect * factor), (factor_detect * factor), "nearestNeighbor"), (x * factor), (y * factor));
3446

3547
to_delete.push(sprite);
3648
}
@@ -182,22 +194,22 @@ class SpriteConverter extends AbstractConverter {
182194
["textures/particle/spell_5.png", 40, 72, 8],
183195
["textures/particle/spell_6.png", 48, 72, 8],
184196
["textures/particle/spell_7.png", 56, 72, 8],
185-
["textures/particle/explosion_0.png", 0, 80, 32, true],
186-
["textures/particle/explosion_1.png", 8, 80, 32, true],
187-
["textures/particle/explosion_2.png", 16, 80, 32, true],
188-
["textures/particle/explosion_3.png", 24, 80, 32, true],
189-
["textures/particle/explosion_4.png", 32, 80, 32, true],
190-
["textures/particle/explosion_5.png", 40, 80, 32, true],
191-
["textures/particle/explosion_6.png", 48, 80, 32, true],
192-
["textures/particle/explosion_7.png", 56, 80, 32, true],
193-
["textures/particle/explosion_8.png", 64, 80, 32, true],
194-
["textures/particle/explosion_9.png", 72, 80, 32, true],
195-
["textures/particle/explosion_10.png", 80, 80, 32, true],
196-
["textures/particle/explosion_11.png", 88, 80, 32, true],
197-
["textures/particle/explosion_12.png", 96, 80, 32, true],
198-
["textures/particle/explosion_13.png", 104, 80, 32, true],
199-
["textures/particle/explosion_14.png", 112, 80, 32, true],
200-
["textures/particle/explosion_15.png", 120, 80, 32, true],
197+
["textures/particle/explosion_0.png", 0, 80, 8],
198+
["textures/particle/explosion_1.png", 8, 80, 8],
199+
["textures/particle/explosion_2.png", 16, 80, 8],
200+
["textures/particle/explosion_3.png", 24, 80, 8],
201+
["textures/particle/explosion_4.png", 32, 80, 8],
202+
["textures/particle/explosion_5.png", 40, 80, 8],
203+
["textures/particle/explosion_6.png", 48, 80, 8],
204+
["textures/particle/explosion_7.png", 56, 80, 8],
205+
["textures/particle/explosion_8.png", 64, 80, 8],
206+
["textures/particle/explosion_9.png", 72, 80, 8],
207+
["textures/particle/explosion_10.png", 80, 80, 8],
208+
["textures/particle/explosion_11.png", 88, 80, 8],
209+
["textures/particle/explosion_12.png", 96, 80, 8],
210+
["textures/particle/explosion_13.png", 104, 80, 8],
211+
["textures/particle/explosion_14.png", 112, 80, 8],
212+
["textures/particle/explosion_15.png", 120, 80, 8],
201213
["textures/particle/glitter_0.png", 0, 88, 8],
202214
["textures/particle/glitter_1.png", 8, 88, 8],
203215
["textures/particle/glitter_2.png", 16, 88, 8],
@@ -240,7 +252,7 @@ class SpriteConverter extends AbstractConverter {
240252
["textures/particle/sga_x.png", 64, 120, 8],
241253
["textures/particle/sga_y.png", 72, 120, 8],
242254
["textures/particle/sga_z.png", 80, 120, 8]
243-
], "textures/particle/particles.png", 4],
255+
], "textures/particle/particles.png", 4 /* Needs a minimal 4x factor because the explosion images are bigger than the others */], // 1.14
244256
[16, 192, [
245257
["textures/particle/big_smoke_0.png", 0, 0, 16],
246258
["textures/particle/big_smoke_1.png", 0, 16, 16],

‎src/Converter/index.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import MapIconsConverter from "./MapIconsConverter";
1616
import MetadataConverter from "./MetadataConverter";
1717
import OpaqueConverter from "./OpaqueConverter";
1818
import OverlayToTranslateConverter from "./OverlayToTranslateConverter";
19+
import Particles1_13Converter from "./Particles1_13Converter";
1920
import PistonArmConverter from "./PistonArmConverter";
2021
import PlaceholderConverter from "./PlaceholderConverter";
2122
import PngToTgaConverter from "./PngToTgaConverter";
@@ -79,6 +80,7 @@ const converters = [
7980
[ColorizeOverlayConverter, []],
8081
[PlaceholderConverter, []],
8182
[SideRotateConverter, []],
83+
[Particles1_13Converter, []],
8284
[SpriteConverter, []],
8385
[PngToTgaConverter, []],
8486
[CopyConverter, []],

0 commit comments

Comments
 (0)