Advertisement
Gwafu

doRender(args) problem

May 14th, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.20 KB | None | 0 0
  1. //MainModFile.class
  2. @SidedProxy(clientSide="mod.proxy.ClientProxy", serverSide="mod.proxy.ServerProxy")
  3. public static CommonProxy proxy;
  4.  
  5. @EventHandler
  6. public void init(FMLInitializationEvent event)
  7. {  
  8.     proxy.init();
  9. }
  10.  
  11. //CommonProxy.class
  12. public void init()
  13. {
  14.     EntityRegistry.registerModEntity(EntityRopeKnot.class, "rope", 1, Mod.instance, 160, Integer.MAX_VALUE, false);
  15. }
  16.  
  17. //ClientProxy.class
  18. //This extends CommonProxy.class
  19. public void init()
  20. {
  21.     super.init();
  22.  
  23.     RenderingRegistry.registerEntityRenderingHandler(EntityRopeKnot.class, new RenderRopeKnot());
  24. }
  25.  
  26. //ItemRope.class
  27. public class ItemRope extends Item
  28. {
  29.     public ItemRope(String name)
  30.     {
  31.         this.setUnlocalizedName(Mod.MODID + "." + name);
  32.         this.setCreativeTab(Mod.creativeTab);
  33.     }
  34.  
  35.     @Override
  36.     public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
  37.     {
  38.         Block block = worldIn.getBlockState(pos).getBlock();
  39.  
  40.         if (block instanceof BlockFence)
  41.         {
  42.             if (worldIn.isRemote)
  43.             {
  44.                 return true;
  45.             }
  46.             else
  47.             {
  48.                 return attach(playerIn, worldIn, pos);
  49.             }
  50.         }
  51.         else
  52.         {
  53.             return false;
  54.         }
  55.     }
  56.  
  57.     //checks if the fence already has a rope or leash attached to it
  58.     private boolean attach(EntityPlayer player, World worldIn, BlockPos fence)
  59.     {
  60.         EntityLeashKnot leash = EntityLeashKnot.getKnotForPosition(worldIn, fence);
  61.         EntityRopeKnot rope = EntityRopeKnot.getKnotForPosition(worldIn, fence);
  62.         if (leash == null && rope == null)
  63.         {
  64.             rope = EntityRopeKnot.createKnot(worldIn, fence);
  65.             return true;
  66.         }
  67.         return false;
  68.     }
  69. }
  70.  
  71. //EntityRopeKnot.class
  72. //Direct copy (+minor changes such as renaming etc.) of the EntityLeashKnot.class
  73. //The System.out.println("here") on onUpdate() is being called, meaning that the entity spawned.
  74. public class EntityRopeKnot extends EntityHanging
  75. {
  76.     public EntityRopeKnot(World worldIn)
  77.     {
  78.         super(worldIn);
  79.     }
  80.  
  81.     public EntityRopeKnot(World worldIn, BlockPos pos)
  82.     {
  83.         super(worldIn, pos);
  84.         this.setPosition((double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D);
  85.         float f = 0.125F;
  86.         float f1 = 0.1875F;
  87.         float f2 = 0.25F;
  88.         this.setEntityBoundingBox(new AxisAlignedBB(this.posX - 0.1875D, this.posY - 0.25D + 0.125D, this.posZ - 0.1875D, this.posX + 0.1875D, this.posY + 0.25D + 0.125D, this.posZ + 0.1875D));
  89.     }
  90.    
  91.     @Override
  92.     public void onUpdate()
  93.     {
  94.         super.onUpdate();
  95.         System.out.println("here");
  96.     }
  97.  
  98.     @Override
  99.     protected void entityInit()
  100.     {
  101.         super.entityInit();
  102.     }
  103.  
  104.     @Override
  105.     public void func_174859_a(EnumFacing enumfacing) {}
  106.  
  107.     @Override
  108.     public int getWidthPixels()
  109.     {
  110.         return 9;
  111.     }
  112.  
  113.     @Override
  114.     public int getHeightPixels()
  115.     {
  116.         return 9;
  117.     }
  118.  
  119.     @Override
  120.     public float getEyeHeight()
  121.     {
  122.         return -0.0625F;
  123.     }
  124.  
  125.     @Override
  126.     @SideOnly(Side.CLIENT)
  127.     public boolean isInRangeToRenderDist(double distance)
  128.     {
  129.         return distance < 1024.0D;
  130.     }
  131.  
  132.     @Override
  133.     public void onBroken(Entity entity) {}
  134.  
  135.     @Override
  136.     public boolean writeToNBTOptional(NBTTagCompound tagCompund)
  137.     {
  138.         return false;
  139.     }
  140.  
  141.     @Override
  142.     public void writeEntityToNBT(NBTTagCompound tagCompound) {}
  143.  
  144.     @Override
  145.     public void readEntityFromNBT(NBTTagCompound tagCompund) {}
  146.  
  147.     //Todo later
  148.     //@Override
  149.     //public boolean interactFirst(EntityPlayer playerIn)
  150.     //{
  151.     //  if (!this.worldObj.isRemote)
  152.     //  {
  153.     //      System.out.println("dead");
  154.     //      this.setDead();
  155.     //      this.dropItem(Mod.ropeItem, 1);
  156.     //  }
  157.     //
  158.     //  return true;
  159.     //}
  160.  
  161.     @Override
  162.     public boolean onValidSurface()
  163.     {
  164.         return this.worldObj.getBlockState(this.hangingPosition).getBlock() instanceof BlockFence;
  165.     }
  166.  
  167.     public static EntityRopeKnot createKnot(World worldIn, BlockPos fence)
  168.     {
  169.         EntityRopeKnot entityropeknot = new EntityRopeKnot(worldIn, fence);
  170.         entityropeknot.forceSpawn = true;
  171.         System.out.println("spawn");
  172.         worldIn.spawnEntityInWorld(entityropeknot);
  173.         return entityropeknot;
  174.     }
  175.  
  176.     public static EntityRopeKnot getKnotForPosition(World worldIn, BlockPos pos)
  177.     {
  178.         int i = pos.getX();
  179.         int j = pos.getY();
  180.         int k = pos.getZ();
  181.         List list = worldIn.getEntitiesWithinAABB(EntityRopeKnot.class, new AxisAlignedBB((double)i - 1.0D, (double)j - 1.0D, (double)k - 1.0D, (double)i + 1.0D, (double)j + 1.0D, (double)k + 1.0D));
  182.         Iterator iterator = list.iterator();
  183.         EntityRopeKnot entityropeknot;
  184.  
  185.         do
  186.         {
  187.             if (!iterator.hasNext())
  188.             {
  189.                 return null;
  190.             }
  191.  
  192.             entityropeknot = (EntityRopeKnot)iterator.next();
  193.         }
  194.         while (!entityropeknot.func_174857_n().equals(pos));
  195.  
  196.         return entityropeknot;
  197.     }
  198. }
  199.  
  200. //RenderRopeKnot.class
  201. //Again, a direct copy of RenderLeashKnot.class (just changed names and stuff)
  202. //Take a look at doRender(args).
  203. //The System.out.println("render"); never gets called.
  204. @SideOnly(Side.CLIENT)
  205. public class RenderRopeKnot extends Render
  206. {
  207.     private static final ResourceLocation TEXTURE = new ResourceLocation(Mod.MODID, "textures/entity/rope_knot.png");
  208.     private ModelRopeKnot MODEL = new ModelRopeKnot();
  209.  
  210.     public RenderRopeKnot()
  211.     {
  212.         super(Minecraft.getMinecraft().getRenderManager());
  213.     }
  214.  
  215.     private void render(EntityRopeKnot entityropeknot, double x, double y, double z, float f, float partialTicks)
  216.     {
  217.         GlStateManager.pushMatrix();
  218.         GlStateManager.disableCull();
  219.         GlStateManager.translate((float)x, (float)y, (float)z);
  220.         float f2 = 0.0625F;
  221.         GlStateManager.enableRescaleNormal();
  222.         GlStateManager.scale(-1.0F, -1.0F, 1.0F);
  223.         GlStateManager.enableAlpha();
  224.         this.bindEntityTexture(entityropeknot);
  225.         this.MODEL.render(entityropeknot, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, f2);
  226.         GlStateManager.popMatrix();
  227.         super.doRender(entityropeknot, x, y, z, f, partialTicks);
  228.     }
  229.  
  230.     protected ResourceLocation getEntityTexture(EntityRopeKnot entity)
  231.     {
  232.         return TEXTURE;
  233.     }
  234.  
  235.     @Override
  236.     protected ResourceLocation getEntityTexture(Entity entity)
  237.     {
  238.         return this.getEntityTexture((EntityRopeKnot)entity);
  239.     }
  240.  
  241.     @Override
  242.     public void doRender(Entity entity, double x, double y, double z, float f, float partialTicks)
  243.     {
  244.         System.out.println("render");
  245.         this.render((EntityRopeKnot)entity, x, y, z, f, partialTicks);
  246.     }
  247. }
  248.  
  249. //ModelRopeKnot.class
  250. //Yet another direct copy of ModelLeashKnot.class (just changed names and stuff)
  251. @SideOnly(Side.CLIENT)
  252. public class ModelRopeKnot extends ModelBase
  253. {
  254.     public ModelRenderer MODEL_RENDERER;
  255.  
  256.     public ModelRopeKnot()
  257.     {
  258.         this(0, 0, 32, 32);
  259.     }
  260.  
  261.     public ModelRopeKnot(int u1, int v1, int u2, int v2)
  262.     {
  263.         this.textureWidth = u2;
  264.         this.textureHeight = v2;
  265.         this.MODEL_RENDERER = new ModelRenderer(this, u1, v1);
  266.         this.MODEL_RENDERER.addBox(-3.0F, -6.0F, -3.0F, 6, 8, 6, 0.0F);
  267.         this.MODEL_RENDERER.setRotationPoint(0.0F, 0.0F, 0.0F);
  268.     }
  269.  
  270.     @Override
  271.     public void render(Entity entity, float f1, float f2, float f3, float f4, float f5, float f6)
  272.     {
  273.         this.setRotationAngles(f1, f2, f3, f4, f5, f6, entity);
  274.         this.MODEL_RENDERER.render(f6);
  275.     }
  276.  
  277.     @Override
  278.     public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
  279.     {
  280.         super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
  281.         this.MODEL_RENDERER.rotateAngleY = f3 / (180F / (float)Math.PI);
  282.         this.MODEL_RENDERER.rotateAngleX = f4 / (180F / (float)Math.PI);
  283.     }
  284. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement