use of net.minecraft.entity.effect.LightningBoltEntity in project Overloaded by CJ-MC-Mods.
the class ItemRayGun method handleMessage.
public void handleMessage(ServerPlayerEntity player, RayGunMessage message) {
ItemStack itemStack = player.getItemInHand(Hand.MAIN_HAND);
if (itemStack.getItem() != this) {
return;
}
LazyOptional<IEnergyStorage> opEnergy = itemStack.getCapability(ENERGY);
if (!opEnergy.isPresent()) {
Overloaded.logger.warn("Railgun has no Energy Capability? NBT: " + itemStack.getTag());
return;
}
IEnergyStorage energy = opEnergy.orElseThrow(() -> new RuntimeException("Impossible Condition"));
if (energy.getEnergyStored() < OverloadedConfig.INSTANCE.rayGun.energyPerShot) {
player.displayClientMessage(new StringTextComponent("Not enough power to fire."), true);
return;
}
Vector3d eyePos = player.getEyePosition(1);
if (eyePos.distanceTo(message.vector) > OverloadedConfig.INSTANCE.rayGun.maxRange) {
player.displayClientMessage(new StringTextComponent("Target out of range."), true);
return;
}
BlockRayTraceResult sanityCheckVec = player.level.clip(new RayTraceContext(eyePos, message.vector, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, player));
if (sanityCheckVec.getType() != RayTraceResult.Type.MISS) {
player.displayClientMessage(new StringTextComponent("Target no longer in sight."), true);
return;
}
energy.extractEnergy(OverloadedConfig.INSTANCE.rayGun.energyPerShot, false);
LightningBoltEntity entity = new LightningBoltEntity(EntityType.LIGHTNING_BOLT, player.level);
entity.moveTo(message.vector.x, message.vector.y, message.vector.z, 0, 0);
player.level.addFreshEntity(entity);
}
Aggregations