Skip to content

Commit c99c00c

Browse files
committed
1.11 compatibility for [WorldRegion].breakBlockForResult
1 parent cbfdca6 commit c99c00c

3 files changed

Lines changed: 46 additions & 17 deletions

File tree

BlockEngine.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ declare class WorldRegion {
153153
breakBlock(x: number, y: number, z: number, allowDrop: boolean, entity: number, item: ItemInstance): void;
154154
/**
155155
* Same as breakBlock, but returns object containing drop and experince.
156-
* 1.16 only!
156+
* Has reverse compatibility with 1.11 but it doesn't suppot experience and
157+
* based on BlockRegistry.getBlockDrop.
157158
* @param x X coord of the block
158159
* @param y Y coord of the block
159160
* @param z Z coord of the block

BlockEngine.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,27 @@ var WorldRegion = /** @class */ (function () {
407407
}
408408
};
409409
WorldRegion.prototype.breakBlockForResult = function (x, y, z, player, item) {
410-
if (typeof x === "number") {
410+
if (typeof x === "object") {
411+
var pos = x;
412+
player = y;
413+
item = z;
414+
return this.breakBlockForResult(pos.x, pos.y, pos.z, player, item);
415+
}
416+
if (BlockEngine.getMainGameVersion() >= 16) {
411417
return this.blockSource.breakBlockForJsResult(x, y, z, player, item);
412418
}
413-
var pos = x;
414-
player = y;
415-
item = z;
416-
return this.blockSource.breakBlockForJsResult(pos.x, pos.y, pos.z, player, item);
419+
var block = this.blockSource.getBlock(x, y, z);
420+
this.blockSource.setBlock(x, y, z, 0, 0);
421+
var level = ToolAPI.getToolLevelViaBlock(item.id, block.id);
422+
var drop = BlockRegistry.getBlockDrop(x, y, z, block, level, item, this.blockSource);
423+
var items = [];
424+
if (drop) {
425+
for (var _i = 0, drop_2 = drop; _i < drop_2.length; _i++) {
426+
var item_1 = drop_2[_i];
427+
items.push(new ItemStack(item_1[0], item_1[1], item_1[2], item_1[3]));
428+
}
429+
}
430+
return { items: items, experience: 0 };
417431
};
418432
WorldRegion.prototype.getNativeTileEntity = function (x, y, z) {
419433
if (typeof x === "number") {
@@ -1082,9 +1096,9 @@ var BlockRegistry;
10821096
var item = new ItemStack();
10831097
//@ts-ignore
10841098
var drop = dropFunc(coords, block.id, block.data, 127, enchant, item, region);
1085-
for (var _i = 0, drop_2 = drop; _i < drop_2.length; _i++) {
1086-
var item_1 = drop_2[_i];
1087-
region.spawnDroppedItem(coords.x + .5, coords.y + .5, coords.z + .5, item_1[0], item_1[1], item_1[2], item_1[3] || null);
1099+
for (var _i = 0, drop_3 = drop; _i < drop_3.length; _i++) {
1100+
var item_2 = drop_3[_i];
1101+
region.spawnDroppedItem(coords.x + .5, coords.y + .5, coords.z + .5, item_2[0], item_2[1], item_2[2], item_2[3] || null);
10881102
}
10891103
});
10901104
}
@@ -1160,8 +1174,8 @@ var BlockRegistry;
11601174
if (id == VanillaTileID.campfire) {
11611175
if (enchant.silk)
11621176
return [[id, 1, 0]];
1163-
var item_2 = IDConverter.getIDData("charcoal");
1164-
return [[item_2.id, 1, item_2.data]];
1177+
var item_3 = IDConverter.getIDData("charcoal");
1178+
return [[item_3.id, 1, item_3.data]];
11651179
}
11661180
if (id == VanillaTileID.soul_campfire) {
11671181
if (enchant.silk)
@@ -1482,7 +1496,7 @@ var ItemArmor = /** @class */ (function (_super) {
14821496
texture: _this.texture,
14831497
isTech: true
14841498
});
1485-
_this.inCreative = inCreative;
1499+
_this.setCategory(ItemCategory.EQUIPMENT);
14861500
if (params.material)
14871501
_this.setMaterial(params.material);
14881502
if (inCreative)
@@ -1826,7 +1840,7 @@ var ItemRegistry;
18261840
}
18271841
ItemRegistry.registerItemFuncs = registerItemFuncs;
18281842
function createItem(stringID, params) {
1829-
var item = getInstanceOf(stringID);
1843+
var item;
18301844
if (params.type == "food") {
18311845
item = new ItemFood(stringID, params.name, params.icon, params.food, params.inCreative);
18321846
}

source/WorldRegion.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ class WorldRegion {
197197

198198
/**
199199
* Same as breakBlock, but returns object containing drop and experince.
200-
* 1.16 only!
200+
* Has reverse compatibility with 1.11 but it doesn't suppot experience and
201+
* based on BlockRegistry.getBlockDrop.
201202
* @param x X coord of the block
202203
* @param y Y coord of the block
203204
* @param z Z coord of the block
@@ -207,11 +208,24 @@ class WorldRegion {
207208
breakBlockForResult(coords: Vector, player: number, item: ItemInstance): {items: ItemInstance[], experience: number};
208209
breakBlockForResult(x: number, y: number, z: number, player: number, item: ItemInstance): {items: ItemInstance[], experience: number};
209210
breakBlockForResult(x: any, y: any, z: any, player?: number, item?: ItemInstance): {items: ItemInstance[], experience: number} {
210-
if (typeof x === "number") {
211+
if (typeof x === "object") {
212+
const pos = x; player = y; item = z;
213+
return this.breakBlockForResult(pos.x, pos.y, pos.z, player, item);
214+
}
215+
if (BlockEngine.getMainGameVersion() >= 16) {
211216
return this.blockSource.breakBlockForJsResult(x, y, z, player, item);
212217
}
213-
const pos = x; player = y; item = z;
214-
return this.blockSource.breakBlockForJsResult(pos.x, pos.y, pos.z, player, item);
218+
const block = this.blockSource.getBlock(x, y, z);
219+
this.blockSource.setBlock(x, y, z, 0, 0);
220+
const level = ToolAPI.getToolLevelViaBlock(item.id, block.id);
221+
const drop = BlockRegistry.getBlockDrop(x, y, z, block, level, item, this.blockSource);
222+
const items: ItemInstance[] = [];
223+
if (drop) {
224+
for (let item of drop) {
225+
items.push(new ItemStack(item[0], item[1], item[2], item[3]));
226+
}
227+
}
228+
return {items: items, experience: 0};
215229
}
216230

217231
/**

0 commit comments

Comments
 (0)