投射物构建 - WhiseNT/EntityJS_cnWiki GitHub Wiki
The Projectile Builder in EntityJS allows you to create custom projectiles, offering flexibility in defining ranged attacks or environmental effects within Minecraft. This builder enables you to configure various attributes and behaviors for your projectiles.
<td>调整例如尺寸,渲染比例,和更新间隔等属性.</td>
<td>在玩家互动、tick事件、和消失条件中使用回调(箭头)函数来对投射物的行为进行微调.</td>
🔧 自定义投射物特性 | |
🎯 定义命中行为 | 确定在和方块或者实体碰撞时的独特效果和交互效果. |
🎨 渲染条件 | 根据玩家的距离或其他条件进行渲染. |
💨 自定义路径逻辑 | 添加速度和线性插值行为来得到精确的投射物运动路径. |
🔁 利用回调(箭头) |
EntityJS的Arrow Builder允许你创建自定义的箭矢实体,提供了在自定义特性和行为方面上的灵活性来增加战斗机制和基于投射物的游戏体验.
💥设置伤害和击退效果 | 调整基础伤害和击退值来影响战斗力 |
👁️渲染选项 | 控制尺寸和基于玩家距离或其他情况的可视性. |
🛡️自定义命中效果 | 定义与不同实体交互和碰撞时候的效果. |
🎯拾箭情况 | 指定玩家能够拾取箭矢的情况,控制物品取回的机制. |
🏹自定义路径 | 为动态的投射物轨迹设定Lerping和移动能力. |
1.19.2
StartupEvents.registry('entity_type', event => {
event.create('projectile', 'entityjs:projectile')
/**
* One-Off values set at the startup of the game.
*/
.clientTrackingRange(8)
.isAttackable(true)
.mobCategory('misc')
.item(item => {
item.canThrow(true)
})
.sized(1, 1)
.renderOffset(0, 0, 0)
.renderScale(1, 1, 1)
.updateInterval(3)
//在这使用.noItem()将会导致Builder完全跳过item的构建
//由于Builder会自动地注册物品,这是在此处阻止对应物品创建的唯一方法
//.noItem()
/**
* 如果值和所需的结果不匹配的话,则下列的这些方法需要设定一个返回值
* it will automatically default to the super method in the entity builder and output an error in logs>kubejs>startup.log.
*
* 记住,这里所有的回调(箭头)函数可以使用全局事件来进行实时编辑!
*
* 示例:
* global.hit = entity => {
* // 自定义条件,以确定箭矢是否可以击中特定实体
* return entity.type == "minecraft:zombie"
* }
*
* .canHitEntity(entity => global.hit(entity)) //请用/kubejs reload startup_scripts来重载这个
*/
.canHitEntity(entity => {
// 自定义条件,以确定箭矢是否可以击中特定实体
return entity.type == "minecraft:zombie"; // 只允许箭矢击中僵尸
})
.shouldRenderAtSqrDistance(context => {
const { entity, distanceToPlayer } = context;
// 自定义箭矢根据距离进行渲染的逻辑,例如,只为距离在100格以内的玩家渲染.
return distanceToPlayer < 100;
})
/**
* 下列所有的方法返回void,意思是他们不需要设置返回值就能工作.
* 这些大多都和KubeJS的正常事件相似,你可以对实体调用的某些事件进行操作!
*/
.move(context => {
const { entity, moverType, position } = context;
// 自定义路径逻辑c,例如,增加箭矢的速度.
entity.setDeltaMovement(0, 0.1, 0);
})
.onHitBlock(context => {
const { entity, result } = context;
// 自定义箭矢命中实体或者方块后的逻辑,例如,生成粒子.
entity.level.addParticle('minecraft:campfire_cosy_smoke', entity.getX(), entity.getY(), entity.getZ(), 0, 0, 0);
})
.onHitEntity(context => {
const { entity, result } = context;
// 自定义箭矢击中实体的行为,例如,添加药水效果
if (result.entity.living) {
let potion = result.entity.potionEffects
potion.add('minecraft:luck', 200, 1, false, true)
}
})
.playerTouch(context => {
const { player, entity } = context;
// Custom behavior when a player touches the arrow, for example, setting the player on fire.
if (entity.age > 5) {
player.setRemainingFireTicks(20)
entity.remove('discarded')
}
})
.tick(entity => {
// 自定义tick逻辑,例如,检查箭矢是否在熔岩中,是则点燃箭矢.
if (entity.level.getBlockState(entity.blockPosition()).getBlock().id == "minecraft:lava") {
entity.setSecondsOnFire(5);
}
})
.lerpTo(context => {
const { entity, yaw, x, y, z, teleport, posRotationIncrements, pitch } = context;
// 自定义Lerping行为,例如,将箭矢传送到一个新位置
entity.teleportTo(x, y, z);
})
})
1.20.1
StartupEvents.registry('entity_type', event => {
event.create('projectile', 'entityjs:projectile')
/**
* One-Off values set at the startup of the game.
*/
.clientTrackingRange(8)
.isAttackable(true)
.mobCategory('misc')
.item(item => {
item.canThrow(true)
})
.sized(1, 1)
.renderOffset(0, 0, 0)
.renderScale(1, 1, 1)
.updateInterval(3)
//在这使用.noItem()将会导致Builder完全跳过item的构建
//由于Builder会自动地注册物品,这是在此处阻止对应物品创建的唯一方法
//.noItem()
/**
* 如果值和所需的结果不匹配的话,则下列的这些方法需要设定一个返回值
* it will automatically default to the super method in the entity builder and output an error in logs>kubejs>startup.log.
*
* 记住,这里所有的回调(箭头)函数可以使用全局事件来进行实时编辑!
*
* 示例:
* global.hit = entity => {
* // 自定义条件,以确定箭矢是否可以击中特定实体
* return entity.type == "minecraft:zombie"
* }
*
* .canHitEntity(entity => global.hit(entity)) //请用/kubejs reload startup_scripts来重载这个
*/
.canHitEntity(entity => {
// 自定义条件,以确定箭矢是否可以击中特定实体
return entity.type == "minecraft:zombie"; // 只允许箭矢击中僵尸
})
.shouldRenderAtSqrDistance(context => {
const { entity, distanceToPlayer } = context;
// 自定义箭矢根据距离进行渲染的逻辑,例如,只为距离在100格以内的玩家渲染.
return distanceToPlayer < 100;
})
/**
* 下列所有的方法返回void,意思是他们不需要设置返回值就能工作.
* 这些大多都和KubeJS的正常事件相似,你可以对实体调用的某些事件进行操作!
*/
.move(context => {
const { entity, moverType, position } = context;
// 自定义路径逻辑c,例如,增加箭矢的速度.
entity.setDeltaMovement(0, 0.1, 0);
})
.onHitBlock(context => {
const { entity, result } = context;
// 自定义箭矢命中实体或者方块后的逻辑,例如,生成粒子.
entity.level.addParticle('minecraft:campfire_cosy_smoke', entity.getX(), entity.getY(), entity.getZ(), 0, 0, 0);
})
.onHitEntity(context => {
const { entity, result } = context;
// 自定义箭矢击中实体的行为,例如,添加药水效果
if (result.entity.living) {
let potion = result.entity.potionEffects
potion.add('minecraft:luck', 200, 1, false, true)
}
})
.playerTouch(context => {
const { player, entity } = context;
// Custom behavior when a player touches the arrow, for example, setting the player on fire.
if (entity.age > 5) {
player.setRemainingFireTicks(20)
entity.remove('discarded')
}
})
.tick(entity => {
// 自定义tick逻辑,例如,检查箭矢是否在熔岩中,是则点燃箭矢.
if (entity.level.getBlockState(entity.blockPosition()).getBlock().id == "minecraft:lava") {
entity.setSecondsOnFire(5);
}
})
.lerpTo(context => {
const { entity, yaw, x, y, z, teleport, posRotationIncrements, pitch } = context;
// 自定义Lerping行为,例如,将箭矢传送到一个新位置
entity.teleportTo(x, y, z);
})
})
1.19.2
StartupEvents.registry('entity_type', event => {
event.create('arrow', 'entityjs:arrow')
/**
* One-Off values set at the startup of the game.
*/
.setKnockback(5) // 设置击退值为5
.setBaseDamage(8) // 设置基础伤害为8
.clientTrackingRange(8) // Set client tracking range to 8
.isAttackable(true) // 使箭矢可被攻击
.sized(1, 1) // 设置箭矢的尺寸为1x1
.updateInterval(3) // 设置更新间隔为3ticks
//在这使用.noItem()将会导致Builder完全跳过item的构建
//由于Builder会自动地注册物品,这是在此处阻止对应物品创建的唯一方法
//.noItem()
.defaultHitGroundSoundEvent("minecraft:entity.arrow.hit") // Set default hit ground sound event
.setWaterInertia(1) // Set water inertia to 1
.mobCategory('misc') // Set mob category to 'misc'
.item(item => {
item.maxStackSize(64); // Set maximum stack size of arrow item to 64
})
/**
* 如果值和所需结果不匹配,下列所有的方法会需要设定一个返回值
* it will automatically default to the super method in the entity builder and output an error in logs>kubejs>startup.log.
* 这有效的为你提供了有关该方法的信息
*
* Remember all callback functions are also able to be live-edited with global events!
*
* Example:
* global.hit = entity => {
* // 自定义条件,以确定箭矢是否可以击中特定实体
* return entity.type == "minecraft:zombie"
* }
*
* .canHitEntity(entity => global.hit(entity)) // Reload this with /kubejs reload startup_scripts
*/
.textureLocation(entity => {
//Change texture resource location depending on certain information about the arrow entity.
//Accepts both a new ResourceLocation or a String representation.
//new ResourceLocation("kubejs:textures/entity/projectiles/arrow.png")
return "kubejs:textures/entity/projectiles/arrow.png"
})
.setDamageFunction(entity => {
// Custom damage function based off the arrow entity
return true
})
.canHitEntity(entity => {
// 自定义条件,以确定箭矢是否可以击中特定实体
return entity.type == "minecraft:zombie"; // Allow arrow to hit zombies only
})
.shouldRenderAtSqrDistance(context => {
const { entity, distanceToPlayer } = context;
// 自定义箭矢根据距离进行渲染的逻辑,例如,只为距离在100格以内的玩家渲染.
return distanceToPlayer < 100;
})
.tryPickup(player => {
// 自定义拾取逻辑,用以确定玩家是否可以拾起箭矢,例如,只允许非创造玩家拾取.
return !context.player.isCreative();
})
/**
* 下列所有的方法返回void,意思是他们不需要设置返回值就能工作.
* 这些大多都和KubeJS的正常事件相似,你可以对实体调用的某些事件进行操作!
*/
.doPostHurtEffects(context => {
const { entity, arrow } = context;
// Custom post-hurt effects, for example, create an explosion
let explosion = entity.block.createExplosion()
explosion.strength(1)
explosion.damagesTerrain(true)
explosion.explode()
})
.lerpTo(context => {
const { entity, yaw, x, y, z, teleport, posRotationIncrements, pitch } = context;
// Custom lerping behavior, for example, teleporting the arrow to a new position
entity.teleportTo(x, y, z);
})
.move(context => {
const { entity, moverType, position } = context;
// Custom movement logic, for example, applying velocity to the arrow
entity.setDeltaMovement(0, 0.1, 0);
})
.onHitBlock(context => {
const { entity, result } = context;
// Custom behavior when the arrow hits a block, for example, spawning particles
entity.level.addParticle('minecraft:campfire_cosy_smoke', entity.getX(), entity.getY(), entity.getZ(), 0, 0, 0);
})
.onHitEntity(context => {
const { entity, result } = context;
// Custom behavior when the arrow hits an entity, for example, applying potion effects
if (result.entity.living) {
let potion = result.entity.potionEffects
potion.add('minecraft:luck', 200, 1, false, true)
}
})
.playerTouch(context => {
const { player, entity } = context;
// Custom behavior when a player touches the arrow, for example, giving the player the arrow
if (!entity.level.isClientSide() && (entity.isOnGround() || entity.noPhysics) && entity.shakeTime <= 0) {
player.take(entity, 1);
entity.discard();
}
})
.tick(entity => {
// Custom tick logic, for example, checking if the arrow is in lava and setting it on fire
if (entity.level.getBlockState(entity.blockPosition()).getBlock().id == "minecraft:lava") {
entity.setSecondsOnFire(5);
}
})
.tickDespawn(entity => {
// Custom logic for arrow despawn, for example, checking if the arrow has traveled a certain distance and despawning it
if (entity.getOwner() == null) return
if (entity.distanceToEntity(entity.getOwner()) > 100) {
entity.remove('discarded');
}
})
});
1.20.1
StartupEvents.registry('entity_type', event => {
event.create('arrow', 'entityjs:arrow')
/**
* One-Off values set at the startup of the game.
*/
.setKnockback(5) // 设置击退值为5
.setBaseDamage(8) // 设置基础伤害为8
.clientTrackingRange(8) // Set client tracking range to 8
.isAttackable(true) // 使箭矢可被攻击
.sized(1, 1) // 设置箭矢的尺寸为1x1
.updateInterval(3) // 设置更新间隔为3ticks
//在这使用.noItem()将会导致Builder完全跳过item的构建
//由于Builder会自动地注册物品,这是在此处阻止对应物品创建的唯一方法
//.noItem()
.defaultHitGroundSoundEvent("minecraft:entity.arrow.hit") //设置集中地面的默认音效
.setWaterInertia(1) // 设置水中惯性为1
.mobCategory('misc') // 设置mob类型为'misc'
.item(item => {
item.maxStackSize(64); // 设置箭矢物品的最大堆叠数为64
})
/**
* 如果值和所需结果不匹配,下列所有的方法会需要设定一个返回值
* it will automatically default to the super method in the entity builder and output an error in logs>kubejs>startup.log.
* This effectively prevents a crash and instead gives you info on the method.
*
* 记住,这里所有的回调(箭头)函数可以使用全局事件来进行实时编辑!
*
* Example:
* global.hit = entity => {
* // 自定义条件,以确定箭矢是否可以击中特定实体
* return entity.type == "minecraft:zombie"
* }
*
* .canHitEntity(entity => global.hit(entity)) // Reload this with /kubejs reload startup_scripts
*/
.textureLocation(entity => {
//根据箭矢实体的信息来更改其材质
//new ResourceLocation形式和String形式的资源位置都可以使用.
//new ResourceLocation("kubejs:textures/entity/projectiles/arrow.png")
return "kubejs:textures/entity/projectiles/arrow.png"
})
.setDamageFunction(entity => {
// 自定义基于箭矢实体的伤害函数
return true
})
.canHitEntity(entity => {
// 自定义条件,以确定箭矢是否可以击中特定实体
return entity.type == "minecraft:zombie"; // 只允许击中僵尸
})
.shouldRenderAtSqrDistance(context => {
const { entity, distanceToPlayer } = context;
// 自定义箭矢根据距离进行渲染的逻辑,例如,只为距离在100格以内的玩家渲染.
return distanceToPlayer < 100;
})
.tryPickup(context => {
// 自定义拾取逻辑,用以确定玩家是否可以拾起箭矢,例如,只允许非创造玩家拾取.
return !context.player.isCreative();
})
/**
* 下列所有的方法返回void,意思是他们不需要设置返回值就能工作.
* 这些大多都和KubeJS的正常事件相似,你可以对实体调用的某些事件进行操作!
*/
.doPostHurtEffects(context => {
const { entity, arrow } = context;
// 自定义造成伤害后的效果,例如,制造一个爆炸
let explosion = entity.block.createExplosion()
explosion.strength(1)
explosion.explosionMode('block')
explosion.explode()
})
.lerpTo(context => {
const { entity, yaw, x, y, z, teleport, posRotationIncrements, pitch } = context;
//自定义lerping行为,例如,传送箭矢到一个新的位置
entity.teleportTo(x, y, z);
})
.move(context => {
const { entity, moverType, position } = context;
// 自定义移动逻辑,例如,增加速度
entity.setDeltaMovement(0, 0.1, 0);
})
.onHitBlock(context => {
const { entity, result } = context;
// 自定义实体击中方块的逻辑,例如,生成粒子
entity.getLevel().addParticle('minecraft:campfire_cosy_smoke', entity.getX(), entity.getY(), entity.getZ(), 0, 0, 0);
})
.onHitEntity(context => {
const { entity, result } = context;
// 自定义实体击中实体的逻辑,例如,给予效果
if (result.entity.living) {
let potion = result.entity.potionEffects
potion.add('minecraft:luck', 200, 1, false, true)
}
})
.playerTouch(context => {
const { player, entity } = context;
// 自定义玩家接触箭矢时的行为,例如,给予玩家箭矢.
if (!entity.getLevel().isClientSide() && (entity.onGround() || entity.noPhysics) && entity.shakeTime <= 0) {
player.take(entity, 1);
entity.discard();
}
})
.tick(entity => {
// 自定义tick逻辑,例如,检查箭矢是否在熔岩中,若是,则为箭矢添加燃烧效果
if (entity.getLevel().getBlockState(entity.blockPosition()).getBlock().id == "minecraft:lava") {
entity.setSecondsOnFire(5);
}
})
.tickDespawn(entity => {
// 自定义箭矢消失的逻辑,例如,检查箭矢是否飞行得过远并移除.
if (entity.getOwner() == null) return
if (entity.distanceToEntity(entity.getOwner()) > 100) {
entity.remove('discarded');
}
})
});
这个Builder允许你创建自定义的末影之眼投射物.末影之眼在Minecraft通常被用于定位.你可以用这个Builder去自定义例如投掷时的行为和播放的声音等方面的内容. |
自定义行为 | 自定义你创建的末影之眼投掷后的行为,例如导航到特定位置. |
自定义声音 | 用自定义的声音来覆写投掷时播放的默认声音. |
物品管理 | 指定使用自定义的末影之眼的物品或是使用Minecraft默认的末影之眼. |
StartupEvents.registry('entity_type', event => {
event.create('projectile', "minecraft:eye_of_ender")
.item(item => {
item.signalTo(context => {
const { level, player, hand } = context
return // 投掷时能导航到一些BlockPos
})
item.playSoundOverride(null, "ambient.basalt_deltas.additions", "ambient", 1, 1)
})
.getItem(entity => {
return Item.of('minecraft:eye_of_ender') // 一些物品
})
})
- 使用`signalTo`方法来自定义末影之眼投掷时导航的位置 - 使用`playSoundOverride`来覆写默认播放的声音并使用新的声音. - 通过`getItem`方法来获取为末影之眼实体创建的物品. |