Приближение при стрельбе

Всем привет! Тут у меня вопросик касательно лука- как сделать приближение во время зажатия(прицеливания)?
как вообще приближать и отдалять камеру?
 
Ты скорее всего имел виду про радиус взгляда. Вот набросок:
Код:
@SubscribeEvent
public void otherFov(FOVUpdateEvent e) {

if (e.entity instanceof EntityPlayer) {

EntityPlayer player_to = (EntityPlayer)e.entity;
ItemStack current = e.entity.getCurrentEquippedItem();

if (current != null && current.getItem() instanceof YouItem && player_to.isUsingItem()) {
e.newfov -= 0.25F;
}

}

}
(для клиентской части этот эвант)
Где "YouItem" это класс твоего предмета.

В предмете примерно должно типа этого:
Код:
public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player) {
    player.setItemInUse(is, getMaxItemUseDuration(is));
    return is;
}
 
Сделал! Но вот беда не видит player_to.isUsingItem() - что должно быть вместо player_to
 
Ранее я немного подправил свой предыдущий пост.
 
Тогда я не знаю в чём у тебя там проблема.
 
код рендера
Код:
package ru.lightway.render.items;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
import net.minecraftforge.client.IItemRenderer.ItemRendererHelper;
import net.minecraftforge.client.event.FOVUpdateEvent;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import ru.lightway.items.ItemModBow;

public class RenderBow implements IItemRenderer
{
    public static ResourceLocation texture = new ResourceLocation("%blur%/misc/glint.png");
    @Override
    public boolean handleRenderType(ItemStack item, ItemRenderType type) {
        if(type == ItemRenderType.EQUIPPED) return true;
        return false;
    }

    @Override
    public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
        return false;
    }

    @SubscribeEvent
    public void otherFov(FOVUpdateEvent e) {

    if (e.entity instanceof EntityPlayer) {

    EntityPlayer player_to = (EntityPlayer)e.entity;
    ItemStack current = e.entity.getCurrentEquippedItem();

    if (current != null && current.getItem() instanceof ItemModBow && player_to.isUsingItem()) {
    e.newfov -= 0.25F;
    }

    }

    }
    
    
    @Override
    public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
        EntityLivingBase e = (EntityLivingBase) data[1];

        GL11.glPopMatrix();
        
        boolean renderFirstPerson = false;
        if(e instanceof EntityPlayer && ((EntityPlayer)e).getCommandSenderName().equals(Minecraft.getMinecraft().thePlayer.getCommandSenderName()) && Minecraft.getMinecraft().gameSettings.thirdPersonView == 0) renderFirstPerson = true;
        
        float f22 = 0.375F;
          GL11.glRotatef(-20.0F, 0.0F, 0.0F, 1.0F);
        GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
        GL11.glRotatef(-60.0F, 0.0F, 0.0F, 1.0F);
        GL11.glScalef(1.0f/f22, 1.0f/f22, 1.0f/f22);
        GL11.glTranslatef(-0.25F, -0.1875F, 0.1875F);

        float f2 = 0.625F;
        GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
        GL11.glRotatef(-20.0F, 0.0F, 1.0F, 0.0F);
        GL11.glScalef(f2, -f2, f2);
        GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
        GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);

        this.renderItem(e, item, 0);
        GL11.glPushMatrix();
    }

    public void renderItem(EntityLivingBase par1EntityLiving, ItemStack par2ItemStack, int par3) {
        GL11.glPushMatrix();

        IIcon icon = par1EntityLiving.getItemIcon(par2ItemStack, par3);

        if (icon == null) {
            GL11.glPopMatrix();
            return;
        }

        Tessellator tess = Tessellator.instance;
        float f = icon.getMinU();
        float f1 = icon.getMaxU();
        float f2 = icon.getMinV();
        float f3 = icon.getMaxV();
        float f4 = 0.0F;
        float f5 = 0.3F;
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glTranslatef(-f4, -f5, 0.0F);
        float f6 = 1.5F;
        GL11.glScalef(f6, f6, f6);
        GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
        GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);
        ItemRenderer.renderItemIn2D(tess, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 0.0625F);

        if (par2ItemStack != null && par2ItemStack.hasEffect(1) && par3 == 0)
        {
            GL11.glDepthFunc(GL11.GL_EQUAL);
            GL11.glDisable(GL11.GL_LIGHTING);
            Minecraft.getMinecraft().renderEngine.bindTexture(texture);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
            float f7 = 0.76F;
            GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F);
            GL11.glMatrixMode(GL11.GL_TEXTURE);
            GL11.glPushMatrix();
            float f8 = 0.125F;
            GL11.glScalef(f8, f8, f8);
            float f9 = (float)(Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F;
            GL11.glTranslatef(f9, 0.0F, 0.0F);
            GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
            ItemRenderer.renderItemIn2D(tess, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
            GL11.glPopMatrix();
            GL11.glPushMatrix();
            GL11.glScalef(f8, f8, f8);
            f9 = (float)(Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F;
            GL11.glTranslatef(-f9, 0.0F, 0.0F);
            GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
            ItemRenderer.renderItemIn2D(tess, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
            GL11.glPopMatrix();
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glDepthFunc(GL11.GL_LEQUAL);

            GL11.glDisable(GL12.GL_RESCALE_NORMAL);
        }

        GL11.glPopMatrix();
    }
}
[merge_posts_bbcode]Добавлено: 09.07.2015 17:30:39[/merge_posts_bbcode]

код лука
Код:
package ru.lightway.items;

import java.util.ArrayList;
import java.util.List;

import ru.lightway.entity.EntityLightwayArrow;
import ru.lightway.mod.Modinfo;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
import net.minecraftforge.event.entity.player.ArrowNockEvent;

public class ItemModBow extends ItemBow {
    public static List<Item> bowList = new ArrayList<Item>();
    public static final int                DEFAULT_MAX_USE_DURATION = 72000;
    @SideOnly(Side.CLIENT)
    protected IIcon[]                      IIconArray;
    protected String                       name;
    protected String                       textureName;
    protected final String[]               texture;
    protected int                          damageMin;
    protected int                           damageMax;
    protected int                          maxUseDuration;
    protected boolean                      unbreakable;
    protected Item                         arrow;
    protected boolean                      needArrow = true;
    protected String arrowTex;
    private String sound = "random.bow";
    private boolean vethean = false;

    public ItemModBow(String name, int uses, int damageMin, int damageMax, Item arrow) {
        this(name, uses, damageMin, damageMax, DEFAULT_MAX_USE_DURATION, arrow);
    }
    
    public ItemModBow(String name, int uses, int damageMin, int damageMax, String arrowTex) {
        this(name, uses, damageMin, damageMax, DEFAULT_MAX_USE_DURATION, null);
        this.arrowTex = arrowTex;
    }
    
    public ItemModBow(String name, int uses, int damageMin, int damageMax, Item arrow, String arrowTex) {
        this(name, uses, damageMin, damageMax, DEFAULT_MAX_USE_DURATION, arrow);
        this.arrowTex = arrowTex;
    }
    
    public ItemModBow(String name, int uses, int damageMin, int damageMax, int maxUseDuraction) {
        this(name, uses, damageMin, damageMax, maxUseDuraction, null);
    }
    
    public ItemModBow(String name, int uses, int damageMin, int damageMax, int maxUseDuraction, Item arrow, String arrowTex) {
        this(name, uses, damageMin, damageMax, maxUseDuraction, arrow);
        this.arrowTex = arrowTex;
    }

    public ItemModBow(String name, int uses, int damageMin, int damageMax, int maxUseDuraction, Item arrow) {
        setMaxDurability(uses);
        this.name = name;
        this.textureName = Modinfo.PREFIX + name;
        if (arrow == null) needArrow = false;
        else this.arrow = arrow;
        this.damageMin = damageMin;
        this.damageMax = damageMax;
        this.maxUseDuration = maxUseDuraction;
        unbreakable = true;
        this.maxStackSize = 1;
        this.setCreativeTab(CreativeTabs.tabCombat);
        this.texture = new String[] { textureName + "_standby", textureName + "_0", textureName + "_1", textureName + "_2" };
        setUnlocalizedName(name);
        GameRegistry.registerItem(this, name);
        
        bowList.add(this);
    }

    private void setMaxDurability(int uses) {
    
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void registerIcons(IIconRegister icon) {
        itemIcon = icon.registerIcon(texture[0]);
        IIconArray = new IIcon[texture.length];
        for(int i = 0; i < texture.length; i++)
            IIconArray[i] = icon.registerIcon(texture[i]);
    }

    @Override
    @SideOnly(Side.CLIENT)
    public IIcon getItemIconForUseDuration(int icon) {
        return IIconArray[icon];
    }

    @Override
    public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
        if (player.getItemInUse() == null) return itemIcon;
        int pulling = stack.getMaxItemUseDuration() - useRemaining;
        if (pulling >= 18/(DEFAULT_MAX_USE_DURATION/this.getMaxItemUseDuration(stack))) return IIconArray[3];
        if (pulling > 13/(DEFAULT_MAX_USE_DURATION/this.getMaxItemUseDuration(stack))) return IIconArray[2];
        if (pulling > 0) return IIconArray[1];
        return IIconArray[0];
    }

    @Override
    public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int itemUseCount) {
        int maxItemUse = getMaxItemUseDuration(stack) - itemUseCount;
        ArrowLooseEvent event = new ArrowLooseEvent(player, stack, maxItemUse);
        MinecraftForge.EVENT_BUS.post(event);
        if (event.isCanceled()) return;
        maxItemUse = event.charge;
        boolean infiniteAmmo = !needArrow || player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
        if (infiniteAmmo || player.inventory.hasItem(arrow)) {
            float timeRatio = DEFAULT_MAX_USE_DURATION/this.getMaxItemUseDuration(stack);
            float scaledItemUse = ((float) maxItemUse / 20.0F)*timeRatio;
            scaledItemUse = (scaledItemUse * scaledItemUse + scaledItemUse * 2) / 3;
            if ((double) scaledItemUse < 0.1) return;
            if (scaledItemUse > 1) scaledItemUse = 1;
            EntityLightwayArrow entityarrow;
            if(this.arrow != null && this.arrowTex == null) entityarrow = new EntityLightwayArrow(world, player, scaledItemUse*2, damageMin, damageMax, arrow.getUnlocalizedName().replace("item.", ""));
            else entityarrow = new EntityLightwayArrow(world, player, scaledItemUse*2, damageMin, damageMax, this.arrowTex);
            entityarrow.setAmmoItem(arrow);
            if (scaledItemUse == 1) entityarrow.setIsCritical(true);
            int powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
            if (powerLevel > 0) entityarrow.setDamage(entityarrow.getDamage() + (double) powerLevel * 0.5 + 0.5);
            int punchLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
            if (punchLevel > 0) entityarrow.setKnockbackStrength(punchLevel);
            if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) entityarrow.setFire(100);
            if (!unbreakable) stack.damageItem(1, player);
            world.playSoundAtEntity(player, this.sound, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + scaledItemUse * 0.5F);
            if (infiniteAmmo) entityarrow.canBePickedUp = 2;
            else player.inventory.consumeInventoryItem(arrow);
            if (!world.isRemote) world.spawnEntityInWorld(entityarrow);
        }
    }

    @Override
    public int getMaxItemUseDuration(ItemStack stack) {
        return maxUseDuration;
    }

   

    @Override
    public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
        ArrowNockEvent nockEvent = new ArrowNockEvent(player, stack);
        MinecraftForge.EVENT_BUS.post(nockEvent);
        if (nockEvent.isCanceled()) return nockEvent.result;
        boolean infiniteAmmo = !needArrow || player.capabilities.isCreativeMode || (EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0 && player.inventory.hasItem(arrow));
        if (infiniteAmmo || player.inventory.hasItem(arrow))
            player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
        return stack;
    }
    
    public ItemModBow setSound(String newSound) {
        this.sound = newSound;
        return this;
    }
    
    public ItemModBow setVethean() {
        this.setCreativeTab(CreativeTabs.tabCombat);
        this.vethean = true;
        return this;
    }
}

[merge_posts_bbcode]Добавлено: 09.07.2015 17:31:04[/merge_posts_bbcode]

извиняюсь за переписывание
 
Бессмысленное переписывание.
Код с перехватом события (otherFov) должен находиться либо в ClientProxy (если ты регистрируешь его в шину событий), либо в каком-нибудь хандлере, который регистрируется в ClientProxy.
 
Oldestkon написал(а):
Бессмысленное переписывание.
Код с перехватом события (otherEvent) должен находиться либо в ClientProxy (если ты регистрируешь его в шину событий), либо в каком-нибудь хандлере, который регистрируется в ClientProxy.
понял- попробую
 
Назад
Сверху