Untitled
java
2 months ago
1.4 kB
11
Indexable
Never
@SubscribeEvent public static void capacitorExplode(LivingDamageEvent event) { LivingEntity entity = event.getEntity(); ItemStack air = new ItemStack(Items.AIR); Item mainhand = entity.getItemInHand(InteractionHand.MAIN_HAND).getItem(); Item offhand = entity.getItemInHand(InteractionHand.OFF_HAND).getItem(); Item capacitor = ModItems.OVERCHARGED_CAPACITOR.get(); if (mainhand.equals(capacitor) || offhand.equals(capacitor)) { entity.level().playSound(null, entity.getX(), entity.getY(), entity.getZ(), SoundEvents.GENERIC_EXPLODE, SoundSource.PLAYERS, 1.0F, 1F); entity.level().playSound(null, entity.getX(), entity.getY(), entity.getZ(), SoundEvents.SHIELD_BREAK, SoundSource.PLAYERS, 1.0F, 1F); ((ServerLevel)entity.level()).sendParticles(ParticleTypes.EXPLOSION, entity.getX(), entity.getY(0.5D), entity.getZ(), 30, 0.2, 0.2, 0.2, 0.0D); entity.hurt(entity.damageSources().explosion(entity, entity), 30); } if (mainhand.equals(capacitor)) { entity.setItemInHand(InteractionHand.MAIN_HAND, air); } else if (offhand.equals(capacitor)) { entity.setItemInHand(InteractionHand.OFF_HAND, air); } }