#Allow a block to deal damage, i.e. like cacti or magma
25 messages · Page 1 of 1 (latest)
in vanilla soruce code:
@Override
public void stepOn(Level level, BlockPos blockPos, BlockState blockState, Entity entity) {
if (!entity.isSteppingCarefully() && entity instanceof LivingEntity && !EnchantmentHelper.hasFrostWalker((LivingEntity)entity)) {
entity.hurt(level.damageSources().hotFloor(), 1.0f);
}
super.stepOn(level, blockPos, blockState, entity);
}
``` then you can do this is kubejs```js
StartupEvents.registry("block", (event) => {
event.create("magma").steppedOn((callback) => {
const { entity, level } = callback;
if (!entity.steppingCarefully && entity.living && entity.feetArmorItem.hasEnchantment("frost_walker")) {
entity.attack(level.damageSources().hotFloor(), 1);
}
});
});
those method are from https://github.com/KubeJS-Mods/KubeJS/pull/675
This block is meant to damage, regardless of what you are wearing
It is a block meant for an SMP I have an idea for. The idea for the block is that it is so pure no one can touch it without burning
So it ends up being more of an obstacle when mining, to be worked around (it also can't be broken or mined)
Or maybe a way to trap your foes by pushing them into it
StartupEvents.registry("block", (event) => {
event.create("magma").steppedOn((callback) => {
const { entity, level } = callback;
if (entity.living) {
entity.attack(level.damageSources().hotFloor(), 1);
}
});
});
Something like this may be closer to what I have in mind, but I will have to edit the damage source, since apparently there is a way to define custom damage sources in KubeJS, if one example script is to be believed
What line would I define the block that is meant to inflict this, though? First or second?
@ivory ibex
I think you can registry a damage source?
[➤](#1221944869807849603 message)
Hi all, hope this isn't too much of a weird one.
I'm working on a "burned mouth" effect that occurs when someone eats a certain food. The idea is, if you eat "hot food", then you get the burned mouth effect: this deals a small amount of damage just once, and then prevents the player from eating any food as long as the player has the effect.
I have it almost completely working, but there's one part I don't know how to do: is there a way to get a status effect to deal damage just once, instead of damage over time? I want the amount of damage to depend on the level of the effect, and the damage should be a custom damage type (so that if the player dies from it, they get a custom death message). Here is what I have so far:
Startup script:
const $ResourceKey = Java.loadClass("net.minecraft.resources.ResourceKey");
const DAMAGE_TYPE = $ResourceKey.createRegistryKey("damage_type");
global.pizzaHotEffect = (entity, lvl) => {
// Create damage source
const damageSource = getDamageSource(entity.getLevel(), "kubejs:pizza_hot");
// Check if the global is run on the client. If so, return
if (entity.getLevel().clientSide) return;
// Damage based on level
entity.attack(damageSource, (lvl - 0.2) + 1);
}
function getDamageSource(/** @type {Internal.Level}*/ level, /** @type {Internal.DamageType_}*/ damageType){
const resourceKey = $ResourceKey.create(DAMAGE_TYPE, Utils.id(damageType));
const holder = level.registryAccess().registryOrThrow(DAMAGE_TYPE).getHolderOrThrow(resourceKey);
return new DamageSource(holder);
}
StartupEvents.registry('mob_effect', event => {
event.create('burned_mouth')
.displayName(Component.gold('Burned Mouth'))
.color(0x521206)
.harmful()
.effectTick((entity, lvl) => global.pizzaHotEffect(entity, lvl));
});
Server script:
ServerEvents.highPriorityData(event => {
event.addJson("kubejs:damage_type/pizza_hot", {
"effects": "hurt",
"exhaustion": 0.5,
"message_id": "pizzaHotKill",
"scaling": "when_caused_by_living_non_player"
});
});
EntityEvents.hurt(event => {
if (!(event.entity.age % 10 == 0)) return
if (event.source.getType().toString() == 'pizzaHotKill'){
event.entity.invulnerableTime = 1;
};
});
ItemEvents.foodEaten(event => {
if(event.player.hasEffect("kubejs:burned_mouth")){
event.cancel();
};
});
Client script:
ClientEvents.lang('en_us', (event) => {
event.add("death.attack.pizzaHotKill", "%1$s didn't wait for the pizza to cool down");
});
Yeah, I've seen this script, or something similar @ivory ibex
I'm trying to figure out where I should put this though, so a specific block deals damage
@ivory ibex how would I apply the damage source to the block? Need it for reference since I’ll be away for a little bit today
I have created the script but uh…
Not sure where I would place a call for the block meant to damage
Well, I'm gonna test the script anyways
Looks like that didn't work. Something is missing.
Wait
What version are these events for?
Oh. Should still work.
I see the problem now