GuiEnchantment .java

net.minecraft.client.gui.GuiEnchantment (class, 355 lines): members: ENCHANTMENT_TABLE_BOOK_TEXTURE, ENCHANTMENT_TABLE_GUI_TEXTURE, field_147069_w, random.

net.minecraft.client.guiclass355 linesclientextends GuiContainer13.5 KB

API Surface (6)

void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
void updateScreen()
void mouseClicked(int mouseX, int mouseY, int mouseButton)
void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
void drawScreen(int mouseX, int mouseY, float partialTicks)
void func_147068_g()

Fields & Constants (15)

ENCHANTMENT_TABLE_GUI_TEXTURE
ENCHANTMENT_TABLE_BOOK_TEXTURE
MODEL_BOOK
playerInventory
random
container
field_147073_u
field_147071_v
field_147069_w
field_147082_x
field_147081_y
field_147080_z
field_147076_A
field_147077_B
field_175380_I

String literals (8)

"textures/gui/container/enchanting_table.png"
"textures/entity/enchanting_table_book.png"
"container.enchant.clue"
"Level Requirement: "
"container.enchant.lapis.one"
"container.enchant.lapis.many"
"container.enchant.level.one"
"container.enchant.level.many"

Full Source

GuiEnchantment.java355 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.gui;
2
3
import com.google.common.collect.Lists;
4
import java.io.IOException;
5
import java.util.List;
6
import java.util.Random;
7
import net.minecraft.client.gui.inventory.GuiContainer;
8
import net.minecraft.client.model.ModelBook;
9
import net.minecraft.client.renderer.GlStateManager;
10
import net.minecraft.client.renderer.RenderHelper;
11
import net.minecraft.client.resources.I18n;
12
import net.minecraft.enchantment.Enchantment;
13
import net.minecraft.entity.Entity;
14
import net.minecraft.entity.player.InventoryPlayer;
15
import net.minecraft.inventory.ContainerEnchantment;
16
import net.minecraft.item.ItemStack;
17
import net.minecraft.util.EnchantmentNameParts;
18
import net.minecraft.util.EnumChatFormatting;
19
import net.minecraft.util.MathHelper;
20
import net.minecraft.util.ResourceLocation;
21
import net.minecraft.world.IWorldNameable;
22
import net.minecraft.world.World;
23
import org.lwjgl.util.glu.Project;
24
25
public class GuiEnchantment extends GuiContainer
26
{
27
    /** The ResourceLocation containing the Enchantment GUI texture location */
28
    private static final ResourceLocation ENCHANTMENT_TABLE_GUI_TEXTURE = new ResourceLocation("textures/gui/container/enchanting_table.png");
29
30
    /**
31
     * The ResourceLocation containing the texture for the Book rendered above the enchantment table
32
     */
33
    private static final ResourceLocation ENCHANTMENT_TABLE_BOOK_TEXTURE = new ResourceLocation("textures/entity/enchanting_table_book.png");
34
35
    /**
36
     * The ModelBook instance used for rendering the book on the Enchantment table
37
     */
38
    private static final ModelBook MODEL_BOOK = new ModelBook();
39
40
    /** The player inventory currently bound to this GuiEnchantment instance. */
41
    private final InventoryPlayer playerInventory;
42
43
    /** A Random instance for use with the enchantment gui */
44
    private Random random = new Random();
45
    private ContainerEnchantment container;
46
    public int field_147073_u;
47
    public float field_147071_v;
48
    public float field_147069_w;
49
    public float field_147082_x;
50
    public float field_147081_y;
51
    public float field_147080_z;
52
    public float field_147076_A;
53
    ItemStack field_147077_B;
54
    private final IWorldNameable field_175380_I;
55
56
    public GuiEnchantment(InventoryPlayer inventory, World worldIn, IWorldNameable p_i45502_3_)
57
    {
58
        super(new ContainerEnchantment(inventory, worldIn));
59
        this.playerInventory = inventory;
60
        this.container = (ContainerEnchantment)this.inventorySlots;
61
        this.field_175380_I = p_i45502_3_;
62
    }
63
64
    /**
65
     * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
66
     */
67
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
68
    {
69
        this.fontRendererObj.drawString(this.field_175380_I.getDisplayName().getUnformattedText(), 12, 5, 4210752);
70
        this.fontRendererObj.drawString(this.playerInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
71
    }
72
73
    /**
74
     * Called from the main game loop to update the screen.
75
     */
76
    public void updateScreen()
77
    {
78
        super.updateScreen();
79
        this.func_147068_g();
80
    }
81
82
    /**
83
     * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
84
     */
85
    protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
86
    {
87
        super.mouseClicked(mouseX, mouseY, mouseButton);
88
        int i = (this.width - this.xSize) / 2;
89
        int j = (this.height - this.ySize) / 2;
90
91
        for (int k = 0; k < 3; ++k)
92
        {
93
            int l = mouseX - (i + 60);
94
            int i1 = mouseY - (j + 14 + 19 * k);
95
96
            if (l >= 0 && i1 >= 0 && l < 108 && i1 < 19 && this.container.enchantItem(this.mc.thePlayer, k))
97
            {
98
                this.mc.playerController.sendEnchantPacket(this.container.windowId, k);
99
            }
100
        }
101
    }
102
103
    /**
104
     * Args : renderPartialTicks, mouseX, mouseY
105
     */
106
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
107
    {
108
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
109
        this.mc.getTextureManager().bindTexture(ENCHANTMENT_TABLE_GUI_TEXTURE);
110
        int i = (this.width - this.xSize) / 2;
111
        int j = (this.height - this.ySize) / 2;
112
        this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
113
        GlStateManager.pushMatrix();
114
        GlStateManager.matrixMode(5889);
115
        GlStateManager.pushMatrix();
116
        GlStateManager.loadIdentity();
117
        ScaledResolution scaledresolution = new ScaledResolution(this.mc);
118
        GlStateManager.viewport((scaledresolution.getScaledWidth() - 320) / 2 * scaledresolution.getScaleFactor(), (scaledresolution.getScaledHeight() - 240) / 2 * scaledresolution.getScaleFactor(), 320 * scaledresolution.getScaleFactor(), 240 * scaledresolution.getScaleFactor());
119
        GlStateManager.translate(-0.34F, 0.23F, 0.0F);
120
        Project.gluPerspective(90.0F, 1.3333334F, 9.0F, 80.0F);
121
        float f = 1.0F;
122
        GlStateManager.matrixMode(5888);
123
        GlStateManager.loadIdentity();
124
        RenderHelper.enableStandardItemLighting();
125
        GlStateManager.translate(0.0F, 3.3F, -16.0F);
126
        GlStateManager.scale(f, f, f);
127
        float f1 = 5.0F;
128
        GlStateManager.scale(f1, f1, f1);
129
        GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F);
130
        this.mc.getTextureManager().bindTexture(ENCHANTMENT_TABLE_BOOK_TEXTURE);
131
        GlStateManager.rotate(20.0F, 1.0F, 0.0F, 0.0F);
132
        float f2 = this.field_147076_A + (this.field_147080_z - this.field_147076_A) * partialTicks;
133
        GlStateManager.translate((1.0F - f2) * 0.2F, (1.0F - f2) * 0.1F, (1.0F - f2) * 0.25F);
134
        GlStateManager.rotate(-(1.0F - f2) * 90.0F - 90.0F, 0.0F, 1.0F, 0.0F);
135
        GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F);
136
        float f3 = this.field_147069_w + (this.field_147071_v - this.field_147069_w) * partialTicks + 0.25F;
137
        float f4 = this.field_147069_w + (this.field_147071_v - this.field_147069_w) * partialTicks + 0.75F;
138
        f3 = (f3 - (float)MathHelper.truncateDoubleToInt((double)f3)) * 1.6F - 0.3F;
139
        f4 = (f4 - (float)MathHelper.truncateDoubleToInt((double)f4)) * 1.6F - 0.3F;
140
141
        if (f3 < 0.0F)
142
        {
143
            f3 = 0.0F;
144
        }
145
146
        if (f4 < 0.0F)
147
        {
148
            f4 = 0.0F;
149
        }
150
151
        if (f3 > 1.0F)
152
        {
153
            f3 = 1.0F;
154
        }
155
156
        if (f4 > 1.0F)
157
        {
158
            f4 = 1.0F;
159
        }
160
161
        GlStateManager.enableRescaleNormal();
162
        MODEL_BOOK.render((Entity)null, 0.0F, f3, f4, f2, 0.0F, 0.0625F);
163
        GlStateManager.disableRescaleNormal();
164
        RenderHelper.disableStandardItemLighting();
165
        GlStateManager.matrixMode(5889);
166
        GlStateManager.viewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);
167
        GlStateManager.popMatrix();
168
        GlStateManager.matrixMode(5888);
169
        GlStateManager.popMatrix();
170
        RenderHelper.disableStandardItemLighting();
171
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
172
        EnchantmentNameParts.getInstance().reseedRandomGenerator((long)this.container.xpSeed);
173
        int k = this.container.getLapisAmount();
174
175
        for (int l = 0; l < 3; ++l)
176
        {
177
            int i1 = i + 60;
178
            int j1 = i1 + 20;
179
            int k1 = 86;
180
            String s = EnchantmentNameParts.getInstance().generateNewRandomName();
181
            this.zLevel = 0.0F;
182
            this.mc.getTextureManager().bindTexture(ENCHANTMENT_TABLE_GUI_TEXTURE);
183
            int l1 = this.container.enchantLevels[l];
184
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
185
186
            if (l1 == 0)
187
            {
188
                this.drawTexturedModalRect(i1, j + 14 + 19 * l, 0, 185, 108, 19);
189
            }
190
            else
191
            {
192
                String s1 = "" + l1;
193
                FontRenderer fontrenderer = this.mc.standardGalacticFontRenderer;
194
                int i2 = 6839882;
195
196
                if ((k < l + 1 || this.mc.thePlayer.experienceLevel < l1) && !this.mc.thePlayer.capabilities.isCreativeMode)
197
                {
198
                    this.drawTexturedModalRect(i1, j + 14 + 19 * l, 0, 185, 108, 19);
199
                    this.drawTexturedModalRect(i1 + 1, j + 15 + 19 * l, 16 * l, 239, 16, 16);
200
                    fontrenderer.drawSplitString(s, j1, j + 16 + 19 * l, k1, (i2 & 16711422) >> 1);
201
                    i2 = 4226832;
202
                }
203
                else
204
                {
205
                    int j2 = mouseX - (i + 60);
206
                    int k2 = mouseY - (j + 14 + 19 * l);
207
208
                    if (j2 >= 0 && k2 >= 0 && j2 < 108 && k2 < 19)
209
                    {
210
                        this.drawTexturedModalRect(i1, j + 14 + 19 * l, 0, 204, 108, 19);
211
                        i2 = 16777088;
212
                    }
213
                    else
214
                    {
215
                        this.drawTexturedModalRect(i1, j + 14 + 19 * l, 0, 166, 108, 19);
216
                    }
217
218
                    this.drawTexturedModalRect(i1 + 1, j + 15 + 19 * l, 16 * l, 223, 16, 16);
219
                    fontrenderer.drawSplitString(s, j1, j + 16 + 19 * l, k1, i2);
220
                    i2 = 8453920;
221
                }
222
223
                fontrenderer = this.mc.fontRendererObj;
224
                fontrenderer.drawStringWithShadow(s1, (float)(j1 + 86 - fontrenderer.getStringWidth(s1)), (float)(j + 16 + 19 * l + 7), i2);
225
            }
226
        }
227
    }
228
229
    /**
230
     * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
231
     */
232
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
233
    {
234
        super.drawScreen(mouseX, mouseY, partialTicks);
235
        boolean flag = this.mc.thePlayer.capabilities.isCreativeMode;
236
        int i = this.container.getLapisAmount();
237
238
        for (int j = 0; j < 3; ++j)
239
        {
240
            int k = this.container.enchantLevels[j];
241
            int l = this.container.enchantmentIds[j];
242
            int i1 = j + 1;
243
244
            if (this.isPointInRegion(60, 14 + 19 * j, 108, 17, mouseX, mouseY) && k > 0 && l >= 0)
245
            {
246
                List<String> list = Lists.<String>newArrayList();
247
248
                if (l >= 0 && Enchantment.getEnchantmentById(l & 255) != null)
249
                {
250
                    String s = Enchantment.getEnchantmentById(l & 255).getTranslatedName((l & 65280) >> 8);
251
                    list.add(EnumChatFormatting.WHITE.toString() + EnumChatFormatting.ITALIC.toString() + I18n.format("container.enchant.clue", new Object[] {s}));
252
                }
253
254
                if (!flag)
255
                {
256
                    if (l >= 0)
257
                    {
258
                        list.add("");
259
                    }
260
261
                    if (this.mc.thePlayer.experienceLevel < k)
262
                    {
263
                        list.add(EnumChatFormatting.RED.toString() + "Level Requirement: " + this.container.enchantLevels[j]);
264
                    }
265
                    else
266
                    {
267
                        String s1 = "";
268
269
                        if (i1 == 1)
270
                        {
271
                            s1 = I18n.format("container.enchant.lapis.one", new Object[0]);
272
                        }
273
                        else
274
                        {
275
                            s1 = I18n.format("container.enchant.lapis.many", new Object[] {Integer.valueOf(i1)});
276
                        }
277
278
                        if (i >= i1)
279
                        {
280
                            list.add(EnumChatFormatting.GRAY.toString() + "" + s1);
281
                        }
282
                        else
283
                        {
284
                            list.add(EnumChatFormatting.RED.toString() + "" + s1);
285
                        }
286
287
                        if (i1 == 1)
288
                        {
289
                            s1 = I18n.format("container.enchant.level.one", new Object[0]);
290
                        }
291
                        else
292
                        {
293
                            s1 = I18n.format("container.enchant.level.many", new Object[] {Integer.valueOf(i1)});
294
                        }
295
296
                        list.add(EnumChatFormatting.GRAY.toString() + "" + s1);
297
                    }
298
                }
299
300
                this.drawHoveringText(list, mouseX, mouseY);
301
                break;
302
            }
303
        }
304
    }
305
306
    public void func_147068_g()
307
    {
308
        ItemStack itemstack = this.inventorySlots.getSlot(0).getStack();
309
310
        if (!ItemStack.areItemStacksEqual(itemstack, this.field_147077_B))
311
        {
312
            this.field_147077_B = itemstack;
313
314
            while (true)
315
            {
316
                this.field_147082_x += (float)(this.random.nextInt(4) - this.random.nextInt(4));
317
318
                if (this.field_147071_v > this.field_147082_x + 1.0F || this.field_147071_v < this.field_147082_x - 1.0F)
319
                {
320
                    break;
321
                }
322
            }
323
        }
324
325
        ++this.field_147073_u;
326
        this.field_147069_w = this.field_147071_v;
327
        this.field_147076_A = this.field_147080_z;
328
        boolean flag = false;
329
330
        for (int i = 0; i < 3; ++i)
331
        {
332
            if (this.container.enchantLevels[i] != 0)
333
            {
334
                flag = true;
335
            }
336
        }
337
338
        if (flag)
339
        {
340
            this.field_147080_z += 0.2F;
341
        }
342
        else
343
        {
344
            this.field_147080_z -= 0.2F;
345
        }
346
347
        this.field_147080_z = MathHelper.clamp_float(this.field_147080_z, 0.0F, 1.0F);
348
        float f1 = (this.field_147082_x - this.field_147071_v) * 0.4F;
349
        float f = 0.2F;
350
        f1 = MathHelper.clamp_float(f1, -f, f);
351
        this.field_147081_y += (f1 - this.field_147081_y) * 0.9F;
352
        this.field_147071_v += this.field_147081_y;
353
    }
354
}
355

Deobfuscated MCP 1.8.9 source of GuiEnchantment from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/gui/GuiEnchantment.java), stored verbatim.