use of net.minecraft.world.phys.Vec3 in project SolarCraftRepository by FINDERFEED.
the class MeteoriteProjectile method onHit.
@Override
protected void onHit(HitResult p_70227_1_) {
if (!this.level.isClientSide) {
Vec3 velocityVector = this.getDeltaMovement().multiply(8, 8, 8);
this.level.explode(null, DamageSource.DRAGON_BREATH, null, this.position().x, this.position().y, this.position().z, 10, true, Explosion.BlockInteraction.DESTROY);
this.level.explode(null, DamageSource.DRAGON_BREATH, null, this.position().x + velocityVector.x / 5, this.position().y + velocityVector.y / 15, this.position().z + velocityVector.z / 10, 10, true, Explosion.BlockInteraction.DESTROY);
double radius = this.level.random.nextFloat() * 1 + 4;
for (int i = (int) -Math.ceil(radius); i < Math.ceil(radius); i++) {
for (int g = (int) -Math.ceil(radius); g < Math.ceil(radius); g++) {
for (int h = (int) -Math.ceil(radius); h < Math.ceil(radius); h++) {
if (SolarStrikeEntity.checkTochkaVEllipse(i, g, h, radius, radius, radius)) {
BlockPos pos = this.getOnPos().offset((int) Math.floor(i), (int) Math.floor(g), (int) Math.floor(h)).offset((int) Math.ceil(velocityVector.x), (int) Math.ceil(velocityVector.y), (int) Math.ceil(velocityVector.z));
if (this.level.random.nextFloat() < 0.8) {
if (this.level.getBlockState(pos).getDestroySpeed(this.level, pos) >= 0 && this.level.getBlockState(pos).getDestroySpeed(this.level, pos) <= 100) {
this.level.setBlock(pos, Blocks.OBSIDIAN.defaultBlockState(), 3);
}
} else {
if (this.level.getBlockState(pos).getDestroySpeed(this.level, pos) >= 0 && this.level.getBlockState(pos).getDestroySpeed(this.level, pos) <= 100) {
this.level.setBlock(pos, Blocks.MAGMA_BLOCK.defaultBlockState(), 3);
}
}
}
}
}
}
}
this.remove(RemovalReason.KILLED);
}
use of net.minecraft.world.phys.Vec3 in project SolarCraftRepository by FINDERFEED.
the class MeteoriteAbility method cast.
@Override
public void cast(ServerPlayer entity, ServerLevel world) {
super.cast(entity, world);
if (allowed) {
Vec3 vec = entity.getLookAngle().multiply(200, 200, 200);
ClipContext ctx = new ClipContext(entity.position().add(0, 1.5, 0), entity.position().add(0, 1.5, 0).add(vec), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity);
BlockHitResult result = world.clip(ctx);
if (result.getType() == HitResult.Type.BLOCK) {
BlockPos pos = result.getBlockPos();
if (world.canSeeSky(pos.above())) {
MeteoriteProjectile proj = new MeteoriteProjectile(entity, world);
Vector3f posVect = new Vector3f((float) entity.position().x - (float) entity.getLookAngle().x * 20, (float) entity.position().y + 64, (float) entity.position().z - (float) entity.getLookAngle().z * 20);
proj.setPos(posVect.x(), posVect.y(), posVect.z());
Vec3 velocity = new Vec3(pos.offset(0.5, 0, 0.5).getX() - posVect.x(), pos.offset(0.5, 0, 0.5).getY() - posVect.y(), pos.offset(0.5, 0, 0.5).getZ() - posVect.z());
proj.setDeltaMovement(velocity.normalize());
world.addFreshEntity(proj);
} else {
if (!entity.isCreative()) {
refund(entity);
}
}
}
}
}
use of net.minecraft.world.phys.Vec3 in project SolarCraftRepository by FINDERFEED.
the class SolarStrikeAbility method cast.
@Override
public void cast(ServerPlayer entity, ServerLevel world) {
super.cast(entity, world);
if (allowed) {
Vec3 vec = entity.getLookAngle().multiply(200, 200, 200);
ClipContext ctx = new ClipContext(entity.position().add(0, 1.5, 0), entity.position().add(0, 1.5, 0).add(vec), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity);
BlockHitResult result = world.clip(ctx);
if (result.getType() == HitResult.Type.BLOCK) {
BlockPos pos = result.getBlockPos();
if (world.canSeeSky(pos.above())) {
SolarStrikeEntity entityBolt = new SolarStrikeEntity(SolarForge.SOLAR_STRIKE_ENTITY_REG.get(), world);
entityBolt.setPos(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5);
world.addFreshEntity(entityBolt);
} else {
if (!entity.isCreative()) {
refund(entity);
}
}
}
}
}
use of net.minecraft.world.phys.Vec3 in project SolarCraftRepository by FINDERFEED.
the class ZapTurretTile method tick.
public static void tick(Level world, BlockPos pos, BlockState state, ZapTurretTile tile) {
if (tile.isWorking()) {
if (!world.isClientSide && tile.attackTick++ > 60) {
tile.attackTick = 0;
tile.targets.clear();
tile.attack = false;
List<LivingEntity> targets = FinderfeedMathHelper.TargetFinding.getAllValidTargetsFromVec(LivingEntity.class, 20, world, FinderfeedMathHelper.TileEntityThings.getTileEntityCenter(tile), (entity) -> {
return !(entity instanceof Player);
});
if (targets.size() != 0) {
LivingEntity lastTarget = targets.get(world.random.nextInt(targets.size()));
lastTarget.hurt(DamageSource.MAGIC, 5);
List<LivingEntity> invalidTargets = new ArrayList<>();
invalidTargets.add(lastTarget);
for (int i = 0; i < 4; i++) {
List<LivingEntity> secondaryTargets = FinderfeedMathHelper.TargetFinding.getAllValidTargetsFromVec(LivingEntity.class, 20, world, lastTarget.position().add(0, lastTarget.getBbHeight() * 1.1 / 2, 0), (entity) -> {
return !(entity instanceof Player) && !invalidTargets.contains(entity);
});
if (secondaryTargets.size() != 0) {
lastTarget = secondaryTargets.get(world.random.nextInt(secondaryTargets.size()));
lastTarget.hurt(DamageSource.MAGIC, 5);
invalidTargets.add(lastTarget);
} else {
break;
}
}
tile.targets.add(FinderfeedMathHelper.TileEntityThings.getTileEntityCenter(pos));
invalidTargets.forEach((trg) -> {
tile.targets.add(trg.position().add(0, trg.getBbHeight() / 2, 0));
});
world.playSound(null, pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f, Sounds.ZAP_TURRET_SHOT.get(), SoundSource.AMBIENT, 1f, 0.7f);
tile.attack = true;
world.sendBlockUpdated(pos, state, state, 3);
}
}
if (world.isClientSide) {
if (tile.attack) {
tile.attack = false;
for (int i = 0; i < tile.targets.size() - 1; i++) {
Vec3 between = tile.targets.get(i + 1).subtract(tile.targets.get(i));
float multiplier = 3;
Vec3 normal = between.normalize().multiply(1 / multiplier, 1 / multiplier, 1 / multiplier);
for (float g = 1; g < between.length() * multiplier; g++) {
Vec3 position = tile.targets.get(i).add(normal.multiply(g, g, g));
world.addParticle(ParticleTypesRegistry.SMALL_SOLAR_STRIKE_PARTICLE.get(), position.x, position.y, position.z, 0, 0, 0);
}
if (i != 0) {
Helpers.createSmallSolarStrikeParticleExplosion(world, tile.targets.get(i), 2, 0.04f, 1f);
}
}
Helpers.createSmallSolarStrikeParticleExplosion(world, tile.targets.get(tile.targets.size() - 1), 2, 0.04f, 1f);
tile.targets.clear();
}
}
}
}
use of net.minecraft.world.phys.Vec3 in project SolarCraftRepository by FINDERFEED.
the class EnchanterBlockEntity method tick.
public static void tick(Level world, BlockState state, BlockPos pos, EnchanterBlockEntity enchanter) {
if (!world.isClientSide) {
if (enchanter.enchantingInProgress()) {
ItemStack stack = enchanter.getStackInSlot(0);
int enchLevelCurrent = EnchantmentHelper.getItemEnchantmentLevel(enchanter.processingEnchantment, stack);
if (!stack.isEmpty() && stack.canApplyAtEnchantingTable(enchanter.processingEnchantment) && enchLevelCurrent < enchanter.procesingEnchantmentLevel) {
enchanter.setChanged();
world.sendBlockUpdated(pos, state, state, 3);
if (SERVERSIDE_CONFIG == null)
SERVERSIDE_CONFIG = parseJson(EnchantmentsConfig.SERVERSIDE_JSON);
Map<RunicEnergy.Type, Double> defaultCosts = SERVERSIDE_CONFIG.get(enchanter.processingEnchantment);
if (enchanter.hasEnoughRunicEnergy(defaultCosts, enchanter.procesingEnchantmentLevel)) {
if (enchanter.enchantingTicks++ > MAX_ENCHANTING_TICKS) {
Map<Enchantment, Integer> enchs = new HashMap<>(EnchantmentHelper.getEnchantments(stack));
if (enchs.containsKey(enchanter.processingEnchantment)) {
enchs.remove(enchanter.processingEnchantment);
enchs.put(enchanter.processingEnchantment, enchanter.procesingEnchantmentLevel);
EnchantmentHelper.setEnchantments(enchs, stack);
} else {
stack.enchant(enchanter.processingEnchantment, enchanter.procesingEnchantmentLevel);
}
enchanter.spendEnergy(defaultCosts, enchanter.procesingEnchantmentLevel);
enchanter.reset();
enchanter.level.playSound(null, enchanter.worldPosition.getX(), enchanter.worldPosition.getY(), enchanter.worldPosition.getZ(), SoundEvents.ENCHANTMENT_TABLE_USE, SoundSource.BLOCKS, 1, 1);
}
enchanter.nullOrGiverPositionForClient.clear();
enchanter.onRemove();
enchanter.clearWays();
} else {
enchanter.requestRunicEnergy(defaultCosts, enchanter.procesingEnchantmentLevel);
}
} else {
enchanter.reset();
enchanter.setChanged();
world.sendBlockUpdated(pos, state, state, 3);
}
} else {
enchanter.reset();
}
} else {
if (enchanter.enchantingInProgress()) {
Vec3 center = Helpers.getBlockCenter(pos);
ClientHelpers.ParticleAnimationHelper.verticalCircle(ParticleTypesRegistry.SMALL_SOLAR_STRIKE_PARTICLE.get(), center.add(0, -0.25, 0), 0.75, 3, new float[] { 0, 0, 0 }, () -> 255, () -> 255, () -> 0, 0.25f);
for (int i = 0; i < 3; i++) {
double[] xz = FinderfeedMathHelper.rotatePointDegrees(0.5, 0, i * 120 + 120 * Math.sin(world.getGameTime() / 20f));
ClientHelpers.ParticleAnimationHelper.createParticle(ParticleTypesRegistry.SMALL_SOLAR_STRIKE_PARTICLE.get(), center.x + xz[0], center.y - 0.2, center.z + xz[1], 0, 0.07, 0, () -> 255, () -> 255, () -> 0, 0.25f);
}
}
}
}
Aggregations