优化mobeffect

This commit is contained in:
17146 2025-02-04 02:52:13 +08:00
parent 05cacbe570
commit 24e67ef912
2 changed files with 8 additions and 10 deletions

View file

@ -1,10 +1,10 @@
package com.atsuishio.superbwarfare.mobeffect; package com.atsuishio.superbwarfare.mobeffect;
import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage;
import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModMobEffects; import com.atsuishio.superbwarfare.init.ModMobEffects;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
@ -23,6 +23,7 @@ import net.minecraftforge.network.PacketDistributor;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
public class BurnMobEffect extends MobEffect { public class BurnMobEffect extends MobEffect {
public BurnMobEffect() { public BurnMobEffect() {
super(MobEffectCategory.HARMFUL, -12708330); super(MobEffectCategory.HARMFUL, -12708330);
} }
@ -36,7 +37,7 @@ public class BurnMobEffect extends MobEffect {
attacker = entity.level().getEntity(entity.getPersistentData().getInt("BurnAttacker")); attacker = entity.level().getEntity(entity.getPersistentData().getInt("BurnAttacker"));
} }
entity.hurt(new DamageSource(entity.level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(ModDamageTypes.BURN), attacker), 0.6f + (0.3f * amplifier)); entity.hurt(ModDamageTypes.causeBurnDamage(entity.level().registryAccess(), attacker), 0.6f + (0.3f * amplifier));
entity.invulnerableTime = 0; entity.invulnerableTime = 0;
if (attacker instanceof ServerPlayer player) { if (attacker instanceof ServerPlayer player) {

View file

@ -1,10 +1,10 @@
package com.atsuishio.superbwarfare.mobeffect; package com.atsuishio.superbwarfare.mobeffect;
import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage;
import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModMobEffects; import com.atsuishio.superbwarfare.init.ModMobEffects;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
@ -28,6 +28,7 @@ import net.minecraftforge.network.PacketDistributor;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
public class ShockMobEffect extends MobEffect { public class ShockMobEffect extends MobEffect {
public ShockMobEffect() { public ShockMobEffect() {
super(MobEffectCategory.HARMFUL, -256); super(MobEffectCategory.HARMFUL, -256);
addAttributeModifier(Attributes.MOVEMENT_SPEED, "7107DE5E-7CE8-4030-940E-514C1F160890", -10.0F, AttributeModifier.Operation.ADDITION); addAttributeModifier(Attributes.MOVEMENT_SPEED, "7107DE5E-7CE8-4030-940E-514C1F160890", -10.0F, AttributeModifier.Operation.ADDITION);
@ -124,16 +125,12 @@ public class ShockMobEffect extends MobEffect {
if (event == null || event.getEntity() == null) { if (event == null || event.getEntity() == null) {
return; return;
} }
shockCancelDamage(event);
}
private static void shockCancelDamage(LivingAttackEvent event) {
DamageSource source = event.getSource(); DamageSource source = event.getSource();
Entity sourceentity = source.getDirectEntity(); Entity entity = source.getDirectEntity();
if (sourceentity == null) { if (entity == null) {
return; return;
} }
if (sourceentity instanceof LivingEntity living && living.hasEffect(ModMobEffects.SHOCK.get())) { if (entity instanceof LivingEntity living && living.hasEffect(ModMobEffects.SHOCK.get())) {
event.setCanceled(true); event.setCanceled(true);
} }
} }