use of net.minecraft.world.entity.projectile.SmallFireball in project Create by Creators-of-Create.
the class IMovedDispenseItemBehaviour method init.
static void init() {
MovedProjectileDispenserBehaviour movedPotionDispenseItemBehaviour = new MovedProjectileDispenserBehaviour() {
@Override
protected Projectile getProjectileEntity(Level world, double x, double y, double z, ItemStack itemStack) {
return Util.make(new ThrownPotion(world, x, y, z), (p_218411_1_) -> p_218411_1_.setItem(itemStack));
}
protected float getProjectileInaccuracy() {
return super.getProjectileInaccuracy() * 0.5F;
}
protected float getProjectileVelocity() {
return super.getProjectileVelocity() * .5F;
}
};
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.SPLASH_POTION, movedPotionDispenseItemBehaviour);
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.LINGERING_POTION, movedPotionDispenseItemBehaviour);
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.TNT, new MovedDefaultDispenseItemBehaviour() {
@Override
protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
double x = pos.getX() + facing.x * .7 + .5;
double y = pos.getY() + facing.y * .7 + .5;
double z = pos.getZ() + facing.z * .7 + .5;
PrimedTnt tntentity = new PrimedTnt(context.world, x, y, z, null);
tntentity.push(context.motion.x, context.motion.y, context.motion.z);
context.world.addFreshEntity(tntentity);
context.world.playSound(null, tntentity.getX(), tntentity.getY(), tntentity.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
itemStack.shrink(1);
return itemStack;
}
});
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.FIREWORK_ROCKET, new MovedDefaultDispenseItemBehaviour() {
@Override
protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
double x = pos.getX() + facing.x * .7 + .5;
double y = pos.getY() + facing.y * .7 + .5;
double z = pos.getZ() + facing.z * .7 + .5;
FireworkRocketEntity fireworkrocketentity = new FireworkRocketEntity(context.world, itemStack, x, y, z, true);
fireworkrocketentity.shoot(facing.x, facing.y, facing.z, 0.5F, 1.0F);
context.world.addFreshEntity(fireworkrocketentity);
itemStack.shrink(1);
return itemStack;
}
@Override
protected void playDispenseSound(LevelAccessor world, BlockPos pos) {
world.levelEvent(1004, pos, 0);
}
});
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.FIRE_CHARGE, new MovedDefaultDispenseItemBehaviour() {
@Override
protected void playDispenseSound(LevelAccessor world, BlockPos pos) {
world.levelEvent(1018, pos, 0);
}
@Override
protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
Random random = context.world.random;
double x = pos.getX() + facing.x * .7 + .5;
double y = pos.getY() + facing.y * .7 + .5;
double z = pos.getZ() + facing.z * .7 + .5;
context.world.addFreshEntity(Util.make(new SmallFireball(context.world, x, y, z, random.nextGaussian() * 0.05D + facing.x + context.motion.x, random.nextGaussian() * 0.05D + facing.y + context.motion.y, random.nextGaussian() * 0.05D + facing.z + context.motion.z), (p_229425_1_) -> p_229425_1_.setItem(itemStack)));
itemStack.shrink(1);
return itemStack;
}
});
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.GLASS_BOTTLE, new MovedOptionalDispenseBehaviour() {
@Override
protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
this.successful = false;
BlockPos interactAt = pos.relative(getClosestFacingDirection(facing));
BlockState state = context.world.getBlockState(interactAt);
Block block = state.getBlock();
if (state.is(BlockTags.BEEHIVES) && state.getValue(BeehiveBlock.HONEY_LEVEL) >= 5) {
((BeehiveBlock) block).releaseBeesAndResetHoneyLevel(context.world, state, interactAt, null, BeehiveBlockEntity.BeeReleaseStatus.BEE_RELEASED);
this.successful = true;
return placeItemInInventory(itemStack, new ItemStack(Items.HONEY_BOTTLE), context, pos, facing);
} else if (context.world.getFluidState(interactAt).is(FluidTags.WATER)) {
this.successful = true;
return placeItemInInventory(itemStack, PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER), context, pos, facing);
} else {
return super.dispenseStack(itemStack, context, pos, facing);
}
}
});
DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.BUCKET, new MovedDefaultDispenseItemBehaviour() {
@Override
protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
BlockPos interactAt = pos.relative(getClosestFacingDirection(facing));
BlockState state = context.world.getBlockState(interactAt);
Block block = state.getBlock();
if (block instanceof BucketPickup) {
ItemStack bucket = ((BucketPickup) block).pickupBlock(context.world, interactAt, state);
return placeItemInInventory(itemStack, bucket, context, pos, facing);
}
return super.dispenseStack(itemStack, context, pos, facing);
}
});
}
use of net.minecraft.world.entity.projectile.SmallFireball in project simple-planes by przemykomo.
the class ShooterUpgrade method onItemRightClick.
@Override
public void onItemRightClick(PlayerInteractEvent.RightClickItem event) {
Player player = event.getPlayer();
ItemStack itemStack = player.getItemInHand(event.getHand());
Vector3f motion1 = planeEntity.transformPos(new Vector3f(0, 0, (float) (1 + planeEntity.getDeltaMovement().length())));
Vec3 motion = new Vec3(motion1);
Level world = event.getWorld();
Random random = world.random;
Vector3f pos = planeEntity.transformPos(new Vector3f(shootSide ? 0.8f : -0.8f, 0.8f, 0.8f));
shootSide = !shootSide;
updateClient();
double x = pos.x() + planeEntity.getX();
double y = pos.y() + planeEntity.getY();
double z = pos.z() + planeEntity.getZ();
Item item = itemStack.getItem();
if (item == Items.FIREWORK_ROCKET) {
FireworkRocketEntity fireworkrocketentity = new FireworkRocketEntity(world, itemStack, x, y, z, true);
fireworkrocketentity.shoot(-motion.x, -motion.y, -motion.z, -(float) Math.max(0.5F, motion.length() * 1.5), 1.0F);
world.addFreshEntity(fireworkrocketentity);
if (!player.isCreative()) {
itemStack.shrink(1);
}
} else if (item == Items.FIRE_CHARGE) {
double d3 = random.nextGaussian() * 0.05D + 2 * motion.x;
double d4 = random.nextGaussian() * 0.05D;
double d5 = random.nextGaussian() * 0.05D + 2 * motion.z;
Fireball fireBallEntity = Util.make(new SmallFireball(world, player, d3, d4, d5), (p_229425_1_) -> p_229425_1_.setItem(itemStack));
fireBallEntity.setPos(x, y, z);
fireBallEntity.setDeltaMovement(motion.scale(2));
world.addFreshEntity(fireBallEntity);
if (!player.isCreative()) {
itemStack.shrink(1);
}
} else if (item == Items.ARROW) {
Arrow arrowEntity = new Arrow(world, x, y, z);
arrowEntity.setOwner(player);
arrowEntity.setDeltaMovement(motion.scale(Math.max(motion.length() * 1.5, 3) / motion.length()));
if (!player.isCreative()) {
itemStack.shrink(1);
arrowEntity.pickup = AbstractArrow.Pickup.ALLOWED;
}
world.addFreshEntity(arrowEntity);
} else if (item == Items.TIPPED_ARROW) {
Arrow arrowEntity = new Arrow(world, x, y, z);
arrowEntity.setOwner(player);
arrowEntity.setEffectsFromItem(itemStack);
arrowEntity.setDeltaMovement(motion.scale(Math.max(motion.length() * 1.5, 3) / motion.length()));
if (!player.isCreative()) {
itemStack.shrink(1);
arrowEntity.pickup = AbstractArrow.Pickup.ALLOWED;
}
world.addFreshEntity(arrowEntity);
} else if (item == Items.SPECTRAL_ARROW) {
SpectralArrow arrowEntity = new SpectralArrow(world, x, y, z);
arrowEntity.setOwner(player);
arrowEntity.setDeltaMovement(motion.scale(Math.max(motion.length() * 1.5, 3) / motion.length()));
if (!player.isCreative()) {
itemStack.shrink(1);
arrowEntity.pickup = AbstractArrow.Pickup.ALLOWED;
}
world.addFreshEntity(arrowEntity);
}
}
use of net.minecraft.world.entity.projectile.SmallFireball in project LivingThings by tristankechlo.
the class AncientBlazeEntity method performRangedAttack.
@Override
public void performRangedAttack(LivingEntity target, float distanceFactor) {
// don't attack if disabled in config
boolean peaceful = (this.level.getDifficulty() == Difficulty.PEACEFUL);
boolean ambientMode = LivingThingsConfig.GENERAL.ambientMode.get();
if (peaceful || ambientMode || !LivingThingsConfig.ANCIENT_BLAZE.canAttack.get()) {
return;
}
double d1 = target.getX() - this.getX();
double d2 = target.getY(0.5D) - this.getY(0.5D);
double d3 = target.getZ() - this.getZ();
int shoots = this.getShoots();
double chance = (double) LivingThingsConfig.ANCIENT_BLAZE.largeFireballChance.get() / 100.0D;
if (this.random.nextDouble() < chance && shoots > 0) {
this.setShoots((byte) (shoots - 1));
LargeFireball fireballentity = new LargeFireball(this.level, this, d1, d2, d3, 1);
fireballentity.setPos(fireballentity.getX(), this.getY(0.5D) + 0.5D, fireballentity.getZ());
this.level.addFreshEntity(fireballentity);
} else {
SmallFireball smallfireballentity = new SmallFireball(this.level, this, d1, d2, d3);
smallfireballentity.setPos(smallfireballentity.getX(), this.getY(0.5D) + 0.5D, smallfireballentity.getZ());
this.level.addFreshEntity(smallfireballentity);
}
if (!this.level.isClientSide()) {
this.level.playSound(null, this.blockPosition(), ModSounds.ANCIENT_BLAZE_SHOOT.get(), SoundSource.HOSTILE, 2.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
}
}
use of net.minecraft.world.entity.projectile.SmallFireball in project TinkersConstruct by SlimeKnights.
the class FirebreathModifier method startArmorInteract.
@Override
public boolean startArmorInteract(IToolStackView tool, int level, Player player, EquipmentSlot slot) {
// stopped by water and by cooldown
if (!player.isShiftKeyDown() && !player.hasEffect(TinkerModifiers.fireballCooldownEffect.get()) && !player.isInWaterRainOrBubble()) {
// if not creative, this costs a fire charge
boolean hasFireball = true;
if (!player.isCreative()) {
hasFireball = false;
Inventory inventory = player.getInventory();
for (int i = 0; i < inventory.getContainerSize(); i++) {
ItemStack stack = inventory.getItem(i);
if (!stack.isEmpty() && TinkerTags.Items.FIREBALLS.contains(stack.getItem())) {
hasFireball = true;
if (!player.level.isClientSide) {
stack.shrink(1);
if (stack.isEmpty()) {
inventory.setItem(i, ItemStack.EMPTY);
}
}
break;
}
}
}
// if we found a fireball, fire it
if (hasFireball) {
player.playNotifySound(SoundEvents.BLAZE_SHOOT, SoundSource.PLAYERS, 2.0F, (RANDOM.nextFloat() - RANDOM.nextFloat()) * 0.2F + 1.0F);
if (!player.level.isClientSide) {
Vec3 lookVec = player.getLookAngle().multiply(2.0f, 2.0f, 2.0f);
SmallFireball fireball = new SmallFireball(player.level, player, lookVec.x + player.getRandom().nextGaussian() / 16, lookVec.y, lookVec.z + player.getRandom().nextGaussian() / 16);
fireball.setPos(fireball.getX(), player.getY(0.5D) + 0.5D, fireball.getZ());
player.level.addFreshEntity(fireball);
TinkerModifiers.fireballCooldownEffect.get().apply(player, 100, 0, true);
}
return true;
}
}
return false;
}
use of net.minecraft.world.entity.projectile.SmallFireball in project kit-api by HGLabor.
the class LaborPathfinderGoalBlazeFireball method tick.
@Override
public void tick() {
--this.attackTime;
LivingEntity livingEntity = this.blaze.getTarget();
if (livingEntity != null) {
boolean bl = this.blaze.getSensing().hasLineOfSight(livingEntity);
if (bl) {
this.lastSeen = 0;
} else {
++this.lastSeen;
}
double d = this.blaze.distanceToSqr(livingEntity);
if (d < 4.0D) {
if (!bl) {
return;
}
if (this.attackTime <= 0) {
this.attackTime = 20;
this.blaze.doHurtTarget(livingEntity);
}
this.blaze.getMoveControl().setWantedPosition(livingEntity.getX(), livingEntity.getY(), livingEntity.getZ(), 1.0D);
} else if (d < this.getFollowDistance() * this.getFollowDistance() && bl) {
double e = livingEntity.getX() - this.blaze.getX();
double f = livingEntity.getY(0.5D) - this.blaze.getY(0.5D);
double g = livingEntity.getZ() - this.blaze.getZ();
if (this.attackTime <= 0) {
++this.attackStep;
if (this.attackStep == 1) {
this.attackTime = 60;
// this.blaze.setCharged(true);
} else if (this.attackStep <= 4) {
this.attackTime = 6;
} else {
this.attackTime = 100;
this.attackStep = 0;
// this.blaze.setCharged(false);
}
if (this.attackStep > 1) {
double h = Math.sqrt(Math.sqrt(d)) * 0.5D;
if (!this.blaze.isSilent()) {
this.blaze.level.levelEvent((Player) null, 1018, this.blaze.blockPosition(), 0);
}
for (int i = 0; i < 1; ++i) {
SmallFireball smallFireball = new SmallFireball(this.blaze.level, this.blaze, e + this.blaze.getRandom().nextGaussian() * h, f, g + this.blaze.getRandom().nextGaussian() * h);
smallFireball.setPos(smallFireball.getX(), this.blaze.getY(0.5D) + 0.5D, smallFireball.getZ());
this.blaze.level.addFreshEntity(smallFireball);
}
}
}
this.blaze.getLookControl().setLookAt(livingEntity, 10.0F, 10.0F);
} else if (this.lastSeen < 5) {
this.blaze.getMoveControl().setWantedPosition(livingEntity.getX(), livingEntity.getY(), livingEntity.getZ(), 1.0D);
}
super.tick();
}
}
Aggregations