Untitled

mail@pastecode.io avatarunknown
java
2 months ago
1.2 kB
2
Indexable
Never
@SubscribeEvent
        public static void capacitorExplode(LivingDamageEvent event) {
            LivingEntity entity = event.getEntity();
            ItemStack capacitor = ModItems.OVERCHARGED_CAPACITOR.get().getDefaultInstance();
            ItemStack air = new ItemStack(Items.AIR);
            ItemStack hand = entity.getItemInHand(InteractionHand.MAIN_HAND);
            System.out.println("oww");
            System.out.println(hand);
            System.out.println(capacitor);
            System.out.println(hand.equals(capacitor));
            entity.setItemInHand(InteractionHand.OFF_HAND, air);
            if (hand.equals(capacitor)) {
                entity.setItemInHand(InteractionHand.MAIN_HAND, air);
                entity.level().playSound(null, entity.getX(), entity.getY(), entity.getZ(), SoundEvents.GENERIC_EXPLODE,
                        SoundSource.PLAYERS, 1.0F, 1F);
                ((ServerLevel)entity.level()).sendParticles(ParticleTypes.EXPLOSION, entity.getX(), entity.getY(0.5D),
                        entity.getZ(), 20, 0.1, 0.1, 0.1, 0.0D);
                entity.hurt(entity.damageSources().explosion(entity, entity), 30);
            }
        }