Search in sources :

Example 1 with SpectralArrow

use of net.minecraft.world.entity.projectile.SpectralArrow 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)

Aggregations

PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)1 Vector3f (com.mojang.math.Vector3f)1 Random (java.util.Random)1 Util (net.minecraft.Util)1 MultiBufferSource (net.minecraft.client.renderer.MultiBufferSource)1 OverlayTexture (net.minecraft.client.renderer.texture.OverlayTexture)1 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 Player (net.minecraft.world.entity.player.Player)1 AbstractArrow (net.minecraft.world.entity.projectile.AbstractArrow)1 Arrow (net.minecraft.world.entity.projectile.Arrow)1 Fireball (net.minecraft.world.entity.projectile.Fireball)1 FireworkRocketEntity (net.minecraft.world.entity.projectile.FireworkRocketEntity)1 SmallFireball (net.minecraft.world.entity.projectile.SmallFireball)1 SpectralArrow (net.minecraft.world.entity.projectile.SpectralArrow)1 Item (net.minecraft.world.item.Item)1 ItemStack (net.minecraft.world.item.ItemStack)1 Items (net.minecraft.world.item.Items)1 Level (net.minecraft.world.level.Level)1