Created
October 13, 2024 18:51
-
-
Save Leclowndu93150/0883e8c3c6fbfb5755fa423d24928454 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public InteractionResult useOn(UseOnContext context) { | |
Player player = context.getPlayer(); | |
ItemStack stack = context.getItemInHand(); | |
if(stack.get(CBDataComponents.ACTIVE)){ | |
return InteractionResult.FAIL; | |
} | |
if(player.isShiftKeyDown() && player.getMainHandItem() == stack){ | |
if(context.getLevel().getBlockState(context.getClickedPos()).is(Blocks.ENCHANTING_TABLE)){ | |
if(context.getLevel().getBlockState(context.getClickedPos().north()).is(Blocks.REDSTONE_WIRE) && | |
context.getLevel().getBlockState(context.getClickedPos().south()).is(Blocks.REDSTONE_WIRE) && | |
context.getLevel().getBlockState(context.getClickedPos().east()).is(Blocks.REDSTONE_WIRE) && | |
context.getLevel().getBlockState(context.getClickedPos().west()).is(Blocks.REDSTONE_WIRE) && | |
context.getLevel().getBlockState(context.getClickedPos().north().east()).is(Blocks.REDSTONE_WIRE) && | |
context.getLevel().getBlockState(context.getClickedPos().north().west()).is(Blocks.REDSTONE_WIRE) && | |
context.getLevel().getBlockState(context.getClickedPos().south().east()).is(Blocks.REDSTONE_WIRE) && | |
context.getLevel().getBlockState(context.getClickedPos().south().west()).is(Blocks.REDSTONE_WIRE)) | |
{ | |
Optional<LivingEntity> optionalEntity = context.getLevel().getEntities(null, new AABB(context.getClickedPos().above())).stream() | |
.filter(entity -> entity instanceof LivingEntity) | |
.map(entity -> (LivingEntity) entity) | |
.findFirst(); | |
if (optionalEntity.isPresent()) { | |
LivingEntity livingEntity = optionalEntity.get(); | |
if (context.getLevel().isNight()) { | |
Vec3 entityPos = livingEntity.position(); | |
LightningBolt lightning = EntityType.LIGHTNING_BOLT.create(context.getLevel()); | |
if (lightning != null) { | |
lightning.moveTo(entityPos); | |
context.getLevel().addFreshEntity(lightning); | |
Holder<DamageType> lightningDamageType = context.getLevel().registryAccess() | |
.registryOrThrow(Registries.DAMAGE_TYPE) | |
.getHolderOrThrow(DamageTypes.LIGHTNING_BOLT); | |
livingEntity.hurt(new DamageSource(lightningDamageType), livingEntity.getMaxHealth() * 2); | |
stack.set(CBDataComponents.ACTIVE, true); | |
return InteractionResult.SUCCESS; | |
} | |
} | |
} | |
} | |
} | |
} | |
return super.useOn(context); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment