the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 138 lines 3.4 kB view raw
1#include "stdafx.h" 2#include "UI.h" 3#include "UIControl_EnchantmentBook.h" 4#include "..\..\Minecraft.h" 5#include "..\..\TileEntityRenderDispatcher.h" 6#include "..\..\EnchantTableRenderer.h" 7#include "..\..\Lighting.h" 8#include "..\..\BookModel.h" 9#include "..\..\..\Minecraft.World\net.minecraft.world.level.tile.entity.h" 10#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h" 11 12UIControl_EnchantmentBook::UIControl_EnchantmentBook() 13{ 14 UIControl::setControlType(UIControl::eEnchantmentBook); 15 model = NULL; 16 last = nullptr; 17 18 time = 0; 19 flip = oFlip = flipT = flipA = 0.0f; 20 open = oOpen = 0.0f; 21} 22 23void UIControl_EnchantmentBook::render(IggyCustomDrawCallbackRegion *region) 24{ 25 glPushMatrix(); 26 float width = region->x1 - region->x0; 27 float height = region->y1 - region->y0; 28 29 // Revert the scale from the setup 30 float ssX = width/m_width; 31 float ssY = height/m_height; 32 glScalef(ssX, ssY,1.0f); 33 34 glTranslatef(m_width/2, m_height/2, 50.0f); 35 36 // Add a uniform scale 37 glScalef(-57/ssX, 57/ssX, 360.0f); 38 39 glRotatef(45 + 90, 0, 1, 0); 40 Lighting::turnOn(); 41 glRotatef(-45 - 90, 0, 1, 0); 42 43 //float sss = 4; 44 45 //glTranslatef(0, 3.3f, -16); 46 //glScalef(sss, sss, sss); 47 48 Minecraft *pMinecraft = Minecraft::GetInstance(); 49 int tex = pMinecraft->textures->loadTexture(TN_ITEM_BOOK); // 4J was L"/1_2_2/item/book.png" 50 pMinecraft->textures->bind(tex); 51 52 glRotatef(20, 1, 0, 0); 53 54 float a = 1; 55 float o = oOpen + (open - oOpen) * a; 56 glTranslatef((1 - o) * 0.2f, (1 - o) * 0.1f, (1 - o) * 0.25f); 57 glRotatef(-(1 - o) * 90 - 90, 0, 1, 0); 58 glRotatef(180, 1, 0, 0); 59 60 float ff1 = oFlip + (flip - oFlip) * a + 0.25f; 61 float ff2 = oFlip + (flip - oFlip) * a + 0.75f; 62 ff1 = (ff1 - floor(ff1)) * 1.6f - 0.3f; 63 ff2 = (ff2 - floor(ff2)) * 1.6f - 0.3f; 64 65 if (ff1 < 0) ff1 = 0; 66 if (ff2 < 0) ff2 = 0; 67 if (ff1 > 1) ff1 = 1; 68 if (ff2 > 1) ff2 = 1; 69 70 glEnable(GL_CULL_FACE); 71 72 if(model == NULL) 73 { 74 // Share the model the the EnchantTableRenderer 75 76 EnchantTableRenderer *etr = (EnchantTableRenderer*)TileEntityRenderDispatcher::instance->getRenderer(eTYPE_ENCHANTMENTTABLEENTITY); 77 if(etr != NULL) 78 { 79 model = etr->bookModel; 80 } 81 else 82 { 83 model = new BookModel(); 84 } 85 } 86 87 model->render(nullptr, 0, ff1, ff2, o, 0, 1 / 16.0f,true); 88 glDisable(GL_CULL_FACE); 89 90 glPopMatrix(); 91 Lighting::turnOff(); 92 glDisable(GL_RESCALE_NORMAL); 93 94 tickBook(); 95} 96 97void UIControl_EnchantmentBook::tickBook() 98{ 99 UIScene_EnchantingMenu *m_containerScene = (UIScene_EnchantingMenu *)m_parentScene; 100 EnchantmentMenu *menu = m_containerScene->getMenu(); 101 shared_ptr<ItemInstance> current = menu->getSlot(0)->getItem(); 102 if (!ItemInstance::matches(current, last)) 103 { 104 last = current; 105 106 do 107 { 108 flipT += random.nextInt(4) - random.nextInt(4); 109 } while (flip <= flipT + 1 && flip >= flipT - 1); 110 } 111 112 time++; 113 oFlip = flip; 114 oOpen = open; 115 116 bool shouldBeOpen = false; 117 for (int i = 0; i < 3; i++) 118 { 119 if (menu->costs[i] != 0) 120 { 121 shouldBeOpen = true; 122 } 123 } 124 125 if (shouldBeOpen) open += 0.2f; 126 else open -= 0.2f; 127 if (open < 0) open = 0; 128 if (open > 1) open = 1; 129 130 131 float diff = (flipT - flip) * 0.4f; 132 float max = 0.2f; 133 if (diff < -max) diff = -max; 134 if (diff > +max) diff = +max; 135 flipA += (diff - flipA) * 0.9f; 136 137 flip = flip + flipA; 138}