// 记录下落物品方块的数据
let itemFallList = {};
// 记录配方
let fallItem = [
{
inputItem: "minecraft:cobblestone",
outputItem: 'minecraft:gravel',
spaceBetween: 10
}
]
EntityEvents.spawned("item", event => {
/**
* @type {Internal.ItemEntity}
*/
let itemEntity = event.getEntity();
fallItem.forEach(value => {
// 判断物品
if (itemEntity.getItem().getId() != value.inputItem) return;
// 设置物品可被捡起时间为32767主要用处为无法合并(副作用无法捡起)
itemEntity.pickUpDelay = 32767;
// 记录实体掉落物的数量
let count = itemEntity.getNbt().get("Item").getInt("Count")
// 传值
itemFallList[itemEntity.getUuid()] = {
dimension: event.getLevel().getDimension(),
y: itemEntity.getY(),
output: value.outputItem,
count: count,
spaceBetween: value.spaceBetween
}
})
})
LevelEvents.tick(event => {
if (event.server.tickCount % 5 != 0) return
if (Object.keys(itemFallList).length == 0) return
for (let key in itemFallList) {
let fallValue = itemFallList[key];
if (fallValue.dimension == event.getLevel().getDimension()) {
try {
let entity = event.getLevel().getEntity(key)
if (entity.onGround()) {
if (fallValue.y - entity.getY() >= fallValue.spaceBetween) {
entity.setItem(Item.of(fallValue.output, fallValue.count))
}
entity.pickUpDelay = 20;
delete itemFallList[key]
}
} catch (e) {
console.warn(e);
delete itemFallList[key]
}
}
}
})