the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 85 lines 2.7 kB view raw
1#include "stdafx.h" 2#include "ItemSpriteRenderer.h" 3#include "EntityRenderDispatcher.h" 4#include "TextureAtlas.h" 5#include "..\Minecraft.World\net.minecraft.world.entity.projectile.h" 6#include "..\Minecraft.World\net.minecraft.world.item.alchemy.h" 7#include "..\Minecraft.World\net.minecraft.world.item.h" 8#include "..\Minecraft.World\net.minecraft.world.h" 9 10ItemSpriteRenderer::ItemSpriteRenderer(Item *sourceItem, int sourceItemAuxValue /*= 0*/) : EntityRenderer() 11{ 12 this->sourceItem = sourceItem; 13 this->sourceItemAuxValue = sourceItemAuxValue; 14} 15 16//ItemSpriteRenderer::ItemSpriteRenderer(int icon) : EntityRenderer() 17//{ 18// this(sourceItem, 0); 19//} 20 21void ItemSpriteRenderer::render(shared_ptr<Entity> e, double x, double y, double z, float rot, float a) 22{ 23 // the icon is already cached in the item object, so there should not be any performance impact by not caching it here 24 Icon *icon = sourceItem->getIcon(sourceItemAuxValue); 25 if (icon == NULL) 26 { 27 return; 28 } 29 30 glPushMatrix(); 31 32 glTranslatef((float) x, (float) y, (float) z); 33 glEnable(GL_RESCALE_NORMAL); 34 glScalef(1 / 2.0f, 1 / 2.0f, 1 / 2.0f); 35 bindTexture(e); 36 Tesselator *t = Tesselator::getInstance(); 37 38 if (icon == PotionItem::getTexture(PotionItem::THROWABLE_ICON) ) 39 { 40 41 int col = PotionBrewing::getColorValue((dynamic_pointer_cast<ThrownPotion>(e) )->getPotionValue(), false); 42 float red = ((col >> 16) & 0xff) / 255.0f; 43 float g = ((col >> 8) & 0xff) / 255.0f; 44 float b = ((col) & 0xff) / 255.0f; 45 46 47 glColor3f(red, g, b); 48 glPushMatrix(); 49 renderIcon(t, PotionItem::getTexture(PotionItem::CONTENTS_ICON)); 50 glPopMatrix(); 51 glColor3f(1, 1, 1); 52 } 53 54 renderIcon(t, icon); 55 56 glDisable(GL_RESCALE_NORMAL); 57 glPopMatrix(); 58} 59 60void ItemSpriteRenderer::renderIcon(Tesselator *t, Icon *icon) 61{ 62 float u0 = icon->getU0(); 63 float u1 = icon->getU1(); 64 float v0 = icon->getV0(); 65 float v1 = icon->getV1(); 66 67 float r = 1.0f; 68 float xo = 0.5f; 69 float yo = 0.25f; 70 71 glRotatef(180 - entityRenderDispatcher->playerRotY, 0, 1, 0); 72 glRotatef(-entityRenderDispatcher->playerRotX, 1, 0, 0); 73 t->begin(); 74 t->normal(0, 1, 0); 75 t->vertexUV((float)(0 - xo), (float)( 0 - yo), (float)( 0), (float)( u0), (float)( v1)); 76 t->vertexUV((float)(r - xo), (float)( 0 - yo), (float)( 0), (float)( u1), (float)( v1)); 77 t->vertexUV((float)(r - xo), (float)( r - yo), (float)( 0), (float)( u1), (float)( v0)); 78 t->vertexUV((float)(0 - xo), (float)( r - yo), (float)( 0), (float)( u0), (float)( v0)); 79 t->end(); 80} 81 82ResourceLocation *ItemSpriteRenderer::getTextureLocation(shared_ptr<Entity> mob) 83{ 84 return &TextureAtlas::LOCATION_ITEMS; 85}