Advertisement
Guest User

1

a guest
Jan 18th, 2019
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.99 KB | None | 0 0
  1. package ru.batthert.client.render;
  2.  
  3. import java.util.Random;
  4.  
  5. import org.lwjgl.input.Mouse;
  6. import org.lwjgl.opengl.GL11;
  7.  
  8. import cpw.mods.fml.client.FMLClientHandler;
  9. import net.minecraft.client.Minecraft;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.util.MathHelper;
  13. import net.minecraft.util.ResourceLocation;
  14. import net.minecraftforge.client.IItemRenderer;
  15. import net.minecraftforge.client.model.AdvancedModelLoader;
  16. import net.minecraftforge.client.model.IModelCustom;
  17. import ru.batthert.client.render.models.ModelHand;
  18. import ru.batthert.client.render.models.Shoot;
  19. import ru.batthert.common.ModBase;
  20. import ru.batthert.common.items.ItemWeapon;
  21.  
  22. public class TestGunRender implements IItemRenderer {
  23.    
  24.     public static final IModelCustom model = AdvancedModelLoader.loadModel(new ResourceLocation("batmod", "models/aug.obj"));
  25.     public static final ResourceLocation tex = new ResourceLocation("batmod", "textures/models/aug.png");
  26.     public static final ResourceLocation shoot1 = new ResourceLocation("batmod", "textures/shoot1.png");
  27.     public static final ResourceLocation shoot2 = new ResourceLocation("batmod", "textures/shoot2.png");
  28.     public static final ResourceLocation shoot3 = new ResourceLocation("batmod", "textures/shoot3.png");
  29.     public static final ResourceLocation shoot4 = new ResourceLocation("batmod", "textures/shoot4.png");
  30.  
  31.     Shoot shoot = new Shoot();
  32.     private static ModelHand model1;
  33.     public ItemWeapon weapon;
  34.     public static boolean aiming;
  35.     public boolean shooting;
  36.      Random rand = new Random();
  37.     int progress = 0;
  38.     public static float smoothing;
  39.     public static final Integer MAX_AIMING_TIMER = 5;
  40.     public static float runProgress = 0F, lastRunProgress = 0F;
  41.     public static float run1Progress = 0F, lastRun1Progress = 0F;
  42.     public static float run2Progress = 0F, lastRun2Progress = 0F;
  43.     public TestGunRender() {
  44.         model1 = new ModelHand();
  45.        
  46.     }
  47.  
  48.     float f5;
  49.     public float aimSpeed = 0;
  50.     public boolean handleRenderType(ItemStack is, ItemRenderType type) {
  51.         switch (type) {
  52.         case ENTITY:
  53.             return true;
  54.         case EQUIPPED:
  55.             return true;
  56.         case EQUIPPED_FIRST_PERSON:
  57.             return true;
  58.         default:
  59.             return false;
  60.         }
  61.     }
  62.     public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack is, ItemRendererHelper helper) {
  63.         return true;
  64.     }
  65.  
  66.    
  67.    
  68.    
  69.     public void renderItem(ItemRenderType type, ItemStack is, Object ... data) {
  70.         EntityPlayer player = Minecraft.getMinecraft().thePlayer;
  71.        
  72.    
  73.         int shootTimer = ItemWeapon.otdachaTimer;
  74.         ItemWeapon weapon = null;
  75.         float shotDelay = 0;
  76.          Minecraft mc = Minecraft.getMinecraft();
  77.         int i;
  78.        
  79.         if ((FMLClientHandler.instance().getClientPlayerEntity().inventory
  80.                 .getCurrentItem() != null)
  81.                 && (FMLClientHandler.instance().getClientPlayerEntity().inventory
  82.                         .getCurrentItem().getItem() instanceof ItemWeapon)
  83.                 && (Mouse.isButtonDown(1))
  84.                 && (!FMLClientHandler.instance().getClientPlayerEntity()
  85.                         .isSprinting() && (FMLClientHandler.instance()
  86.                         .getClient().currentScreen == null))) {
  87.            
  88.             aiming = true;
  89.         } else {
  90.             aiming = false;
  91.         }
  92.         lastRun1Progress = run1Progress;
  93.         if(!FMLClientHandler.instance().getClientPlayerEntity()
  94.                 .isSprinting()){
  95.             run1Progress *= 0.5F;
  96.         }
  97.         else{
  98.             run1Progress = 1F - (1F - run1Progress) * 0.65F;
  99.         }
  100.        
  101.         lastRunProgress = runProgress;
  102.         if(!aiming){
  103.             runProgress *= 0.8F;
  104.         }
  105.         else{
  106.             runProgress = 1F - (1F - runProgress) * 0.65F;
  107.         }
  108.        
  109.         lastRun2Progress = run2Progress;
  110.         if(shootTimer == 1){
  111.             run2Progress *= 0.5F;
  112.         }
  113.         else{
  114.             run2Progress = 1F - (1F - run2Progress) * 0.5F;
  115.         }
  116.        
  117.         //анимация прицеливания
  118.         float runSwitch = this.lastRunProgress + (this.runProgress - this.lastRunProgress);
  119.         //анимация бега
  120.         float run1Switch = this.lastRun1Progress + (this.run1Progress - this.lastRun1Progress);
  121.         //анимация выстрела
  122.         float run2Switch = this.lastRun2Progress + (this.run2Progress - this.lastRun2Progress);
  123.        
  124.         switch (type) {
  125.         case EQUIPPED_FIRST_PERSON: {
  126.            
  127.            
  128.             GL11.glPushMatrix();
  129.              
  130.             GL11.glScalef(1, 1, 1);
  131.             if(aiming)
  132.                 GL11.glTranslatef(-0.105F * runSwitch, 1.53F * runSwitch, -0.85F * runSwitch);
  133.             else
  134.                 GL11.glTranslatef(0.445F, 1.41F, -0.85F);
  135.            
  136.             GL11.glRotatef(-35, 0.0F, 1.0F, 0.0F);
  137.             if(shootTimer == 1){
  138.             i = this.rand.nextInt(3);
  139.             if(i == 0) {
  140.                mc.renderEngine.bindTexture(shoot1);
  141.                this.shoot.render();
  142.                
  143.             } else if(i == 1) {
  144.                mc.renderEngine.bindTexture(shoot2);
  145.                this.shoot.render();
  146.              
  147.             } else if(i == 2) {
  148.                mc.renderEngine.bindTexture(shoot3);
  149.                this.shoot.render();
  150.                
  151.             } else {
  152.                mc.renderEngine.bindTexture(shoot4);
  153.                this.shoot.render();
  154.              
  155.             }
  156.             }
  157.            
  158.             GL11.glPopMatrix();
  159.            
  160.             GL11.glPushMatrix();
  161.             GL11.glEnable(3042);
  162.             GL11.glBlendFunc(770, 771);
  163.             GL11.glTranslatef(-0.75F, 0.95F, 0.4F);
  164.             GL11.glRotatef(0.0F, 0.0F, 0.0F, 1.0F);
  165.             GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
  166.             GL11.glRotatef(0.0F, 1.0F, 0.0F, 0.0F);
  167.             GL11.glScalef(0.032F, 0.032F, 0.032F);
  168.            
  169.                 GL11.glRotatef(45.0F * run1Switch, 0.0F, 1.0F, 0.0F);
  170.                 GL11.glTranslatef(5F  * run1Switch, 0F, -15F  * run1Switch);
  171.            
  172.        
  173.                 GL11.glTranslatef(1F * run2Switch, 0F, 0F);
  174.                  
  175.            
  176.            
  177.            
  178.             //GL11.glTranslatef(-0.35F / 0.032F, 0.09F / 0.032F, -0.46F / 0.032F);
  179.            
  180.            
  181.                 GL11.glTranslatef(-12.02F * runSwitch, 2.75F * runSwitch, -14.38F * runSwitch);
  182.            
  183.            
  184.             Minecraft.getMinecraft().renderEngine.bindTexture(tex);
  185.             model.renderAll();
  186.             GL11.glDisable(3042);
  187.             GL11.glPopMatrix();
  188.             if(type == ItemRenderType.EQUIPPED) {
  189.                 GL11.glPushMatrix();
  190.                 GL11.glEnable(3042);
  191.                 GL11.glBlendFunc(770, 771);
  192.                 GL11.glTranslatef(-0.52F, 1.22F, 0.5F);
  193.                 GL11.glRotatef(0.0F, 0.0F, 0.0F, 1.0F);
  194.                 GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
  195.                 GL11.glRotatef(0.0F, 1.0F, 0.0F, 0.0F);
  196.                 GL11.glScaled(0.065D, 0.065D, 0.075D);
  197.                
  198.                    
  199.                 Minecraft.getMinecraft().renderEngine.bindTexture(tex);
  200.                 model.renderAll();
  201.                 GL11.glDisable(3042);
  202.                 GL11.glPopMatrix();
  203.             }
  204.         }
  205.         break;
  206.         case EQUIPPED: {
  207.             GL11.glPushMatrix();
  208.             GL11.glEnable(3042);
  209.             GL11.glBlendFunc(770, 771);
  210.             GL11.glTranslatef(1.0F, 0.4F, 1.0F);
  211.             GL11.glRotatef(-105.0F, 0.0F, 0.0F, 1.0F);
  212.             GL11.glRotatef(15.0F, 0.0F, 1.0F, 0.0F);
  213.             GL11.glRotatef(-135.0F, 1.0F, 0.0F, 0.0F);
  214.             GL11.glScalef(0.04F, 0.04F, 0.04F);
  215.             Minecraft.getMinecraft().renderEngine.bindTexture(tex);
  216.             model.renderAll();
  217.             GL11.glDisable(3042);
  218.             GL11.glPopMatrix();
  219.         }
  220.         break;
  221.         case ENTITY: {
  222.             GL11.glPushMatrix();
  223.             GL11.glEnable(3042);
  224.             GL11.glBlendFunc(770, 771);
  225.             GL11.glTranslatef(0F, 0F, 0F);
  226.             GL11.glRotatef(0.0F, 0.0F, 0.0F, 1.0F);
  227.             GL11.glRotatef(0.0F, 0.0F, 1.0F, 0.0F);
  228.             GL11.glRotatef(0.0F, 1.0F, 0.0F, 0.0F);
  229.             GL11.glScaled(0.02D, 0.02D, 0.02D);
  230.             Minecraft.getMinecraft().renderEngine.bindTexture(tex);
  231.             model.renderAll();
  232.             GL11.glDisable(3042);
  233.             GL11.glPopMatrix();
  234.         }
  235.         break;
  236.         default:
  237.             break;
  238.         }
  239.         if(type == ItemRenderType.EQUIPPED_FIRST_PERSON) {
  240.             GL11.glPushMatrix();
  241.             GL11.glTranslatef(0.3F, 1.47F, -0.47F);
  242.             GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
  243.             GL11.glRotatef(-130.0F, 0.0F, 1.0F, 0.0F);
  244.             GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
  245.             GL11.glTranslatef(-0.35F, -2.1F, -0.3F);
  246.             GL11.glScaled(1.0D, 1.0D, 1.0D);
  247.            
  248.                 GL11.glRotatef(45.0F * run1Switch, 0.0F, 0.0F, 1.0F);
  249.                 GL11.glTranslatef(-0.08F * run1Switch, -0.5F * run1Switch, 0.02F * run1Switch);
  250.            
  251.            
  252.                 GL11.glTranslatef(0F, 0.02F * run2Switch, 0F);
  253.            
  254.            
  255.                 GL11.glTranslatef(-0.42F * runSwitch, 0.0F * runSwitch, 0.15F * runSwitch);
  256.            
  257.             Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation("textures/entity/steve.png"));
  258.             model1.render_left();
  259.             GL11.glPopMatrix();
  260.             GL11.glPushMatrix();
  261.             GL11.glTranslatef(0.65F, 1.38F, -0.8F);
  262.             GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
  263.             GL11.glRotatef(-105.0F, 0.0F, 1.0F, 0.0F);
  264.             GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
  265.             GL11.glTranslatef(0.9F, -2.55F, -0.15F);
  266.             GL11.glScaled(1.0D, 1.9D, 1.0D);
  267.            
  268.                 GL11.glRotatef(45.0F * run1Switch, 0.0F, 0F, 1.0F);
  269.                 GL11.glScaled(0.9D, 1.0D, 1D);
  270.                 GL11.glTranslatef(0.05F * run1Switch, 0.25F * run1Switch, -0.1F * run1Switch);
  271.            
  272.            
  273.                 GL11.glTranslatef(-0.02F * run2Switch, 0.02F * run2Switch, 0F);
  274.            
  275.            
  276.                 GL11.glTranslatef(-0.25F * runSwitch, 0.0F, -0.3F * runSwitch);
  277.                 GL11.glRotatef(25.0F * runSwitch, 0.0F, 0.0F, 1.0F);
  278.                 GL11.glRotatef(25.0F * runSwitch, 0.0F, 1.0F, 0.0F);
  279.                 GL11.glRotatef(25.0F * runSwitch, 1.0F, 0.0F, 0.0F);
  280.            
  281.             Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation("textures/entity/steve.png"));
  282.             model1.render_right();
  283.             GL11.glPopMatrix();
  284.         }
  285.     }
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement