Search in sources :

Example 1 with SmallFireball

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);
        }
    });
}
Also used : PrimedTnt(net.minecraft.world.entity.item.PrimedTnt) LevelAccessor(net.minecraft.world.level.LevelAccessor) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) BucketPickup(net.minecraft.world.level.block.BucketPickup) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) Vec3(net.minecraft.world.phys.Vec3) ThrownPotion(net.minecraft.world.entity.projectile.ThrownPotion) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock) Block(net.minecraft.world.level.block.Block) ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) SmallFireball(net.minecraft.world.entity.projectile.SmallFireball) ItemStack(net.minecraft.world.item.ItemStack) MovementContext(com.simibubi.create.content.contraptions.components.structureMovement.MovementContext)

Example 2 with SmallFireball

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);
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) SimplePlanesUpgrades(xyz.przemyk.simpleplanes.setup.SimplePlanesUpgrades) Items(net.minecraft.world.item.Items) Item(net.minecraft.world.item.Item) SmallFireball(net.minecraft.world.entity.projectile.SmallFireball) Random(java.util.Random) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Vector3f(com.mojang.math.Vector3f) PlaneEntity(xyz.przemyk.simpleplanes.entities.PlaneEntity) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) Upgrade(xyz.przemyk.simpleplanes.upgrades.Upgrade) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) UpgradesModels(xyz.przemyk.simpleplanes.client.render.UpgradesModels) SpectralArrow(net.minecraft.world.entity.projectile.SpectralArrow) SimplePlanesMod(xyz.przemyk.simpleplanes.SimplePlanesMod) Fireball(net.minecraft.world.entity.projectile.Fireball) Player(net.minecraft.world.entity.player.Player) AbstractArrow(net.minecraft.world.entity.projectile.AbstractArrow) Util(net.minecraft.Util) Arrow(net.minecraft.world.entity.projectile.Arrow) Vec3(net.minecraft.world.phys.Vec3) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) MultiBufferSource(net.minecraft.client.renderer.MultiBufferSource) OverlayTexture(net.minecraft.client.renderer.texture.OverlayTexture) SpectralArrow(net.minecraft.world.entity.projectile.SpectralArrow) AbstractArrow(net.minecraft.world.entity.projectile.AbstractArrow) Arrow(net.minecraft.world.entity.projectile.Arrow) Player(net.minecraft.world.entity.player.Player) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) SpectralArrow(net.minecraft.world.entity.projectile.SpectralArrow) Item(net.minecraft.world.item.Item) SmallFireball(net.minecraft.world.entity.projectile.SmallFireball) Fireball(net.minecraft.world.entity.projectile.Fireball) Random(java.util.Random) Vector3f(com.mojang.math.Vector3f) Vec3(net.minecraft.world.phys.Vec3) Level(net.minecraft.world.level.Level) SmallFireball(net.minecraft.world.entity.projectile.SmallFireball) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with SmallFireball

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);
    }
}
Also used : SmallFireball(net.minecraft.world.entity.projectile.SmallFireball) LargeFireball(net.minecraft.world.entity.projectile.LargeFireball)

Example 4 with SmallFireball

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;
}
Also used : Vec3(net.minecraft.world.phys.Vec3) SmallFireball(net.minecraft.world.entity.projectile.SmallFireball) ItemStack(net.minecraft.world.item.ItemStack) Inventory(net.minecraft.world.entity.player.Inventory)

Example 5 with SmallFireball

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();
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) Player(net.minecraft.world.entity.player.Player) SmallFireball(net.minecraft.world.entity.projectile.SmallFireball)

Aggregations

SmallFireball (net.minecraft.world.entity.projectile.SmallFireball)6 ItemStack (net.minecraft.world.item.ItemStack)3 Vec3 (net.minecraft.world.phys.Vec3)3 Random (java.util.Random)2 Player (net.minecraft.world.entity.player.Player)2 FireworkRocketEntity (net.minecraft.world.entity.projectile.FireworkRocketEntity)2 LargeFireball (net.minecraft.world.entity.projectile.LargeFireball)2 Level (net.minecraft.world.level.Level)2 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)1 Vector3f (com.mojang.math.Vector3f)1 MovementContext (com.simibubi.create.content.contraptions.components.structureMovement.MovementContext)1 Util (net.minecraft.Util)1 MultiBufferSource (net.minecraft.client.renderer.MultiBufferSource)1 OverlayTexture (net.minecraft.client.renderer.texture.OverlayTexture)1 BlockPos (net.minecraft.core.BlockPos)1 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 LivingEntity (net.minecraft.world.entity.LivingEntity)1