GuiFlatPresets .java

net.minecraft.client.gui.GuiFlatPresets (class): members: FLAT_WORLD_PRESETS, field_146433_u, field_146434_t, field_146435_s, field_146436_r, presetsShare.

net.minecraft.client.guiclass282 linesclientextends GuiScreen13.6 KB

API Surface (14)

void initGui()
void handleMouseInput()
void onGuiClosed()
void mouseClicked(int mouseX, int mouseY, int mouseButton)
void keyTyped(char typedChar, int keyCode)
void actionPerformed(GuiButton button)
void drawScreen(int mouseX, int mouseY, float partialTicks)
void updateScreen()
void func_146426_g()
int getSize()
void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
boolean isSelected(int slotIndex)
void drawBackground()
void drawSlot(int entryID, int p_180791_2_, int p_180791_3_, int p_180791_4_, int mouseXIn, int mouseYIn)

Fields & Constants (8)

FLAT_WORLD_PRESETS
parentScreen
presetsTitle
presetsShare
field_146436_r
field_146435_s
field_146434_t
field_146433_u

String literals (22)

"createWorld.customize.presets.title"
"createWorld.customize.presets.share"
"createWorld.customize.presets.list"
"createWorld.customize.presets.select"
"gui.cancel"
"Classic Flat"
"village"
"Tunnelers\' Dream"
"biome_1"
"dungeon"
"decoration"
"stronghold"
"mineshaft"
"Water World"
"oceanmonument"
"Overworld"
"lake"
"lava_lake"
"Snowy Kingdom"
"Bottomless Pit"
"Desert"
"Redstone Ready"

Full Source

GuiFlatPresets.java282 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.gui;
2
3
import com.google.common.collect.Lists;
4
import com.google.common.collect.Maps;
5
import java.io.IOException;
6
import java.util.Arrays;
7
import java.util.List;
8
import net.minecraft.block.BlockTallGrass;
9
import net.minecraft.client.renderer.GlStateManager;
10
import net.minecraft.client.renderer.RenderHelper;
11
import net.minecraft.client.renderer.Tessellator;
12
import net.minecraft.client.renderer.WorldRenderer;
13
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
14
import net.minecraft.client.resources.I18n;
15
import net.minecraft.init.Blocks;
16
import net.minecraft.init.Items;
17
import net.minecraft.item.Item;
18
import net.minecraft.item.ItemStack;
19
import net.minecraft.world.biome.BiomeGenBase;
20
import net.minecraft.world.gen.FlatGeneratorInfo;
21
import net.minecraft.world.gen.FlatLayerInfo;
22
import org.lwjgl.input.Keyboard;
23
24
public class GuiFlatPresets extends GuiScreen
25
{
26
    private static final List<GuiFlatPresets.LayerItem> FLAT_WORLD_PRESETS = Lists.<GuiFlatPresets.LayerItem>newArrayList();
27
28
    /** The parent GUI */
29
    private final GuiCreateFlatWorld parentScreen;
30
    private String presetsTitle;
31
    private String presetsShare;
32
    private String field_146436_r;
33
    private GuiFlatPresets.ListSlot field_146435_s;
34
    private GuiButton field_146434_t;
35
    private GuiTextField field_146433_u;
36
37
    public GuiFlatPresets(GuiCreateFlatWorld p_i46318_1_)
38
    {
39
        this.parentScreen = p_i46318_1_;
40
    }
41
42
    /**
43
     * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
44
     * window resizes, the buttonList is cleared beforehand.
45
     */
46
    public void initGui()
47
    {
48
        this.buttonList.clear();
49
        Keyboard.enableRepeatEvents(true);
50
        this.presetsTitle = I18n.format("createWorld.customize.presets.title", new Object[0]);
51
        this.presetsShare = I18n.format("createWorld.customize.presets.share", new Object[0]);
52
        this.field_146436_r = I18n.format("createWorld.customize.presets.list", new Object[0]);
53
        this.field_146433_u = new GuiTextField(2, this.fontRendererObj, 50, 40, this.width - 100, 20);
54
        this.field_146435_s = new GuiFlatPresets.ListSlot();
55
        this.field_146433_u.setMaxStringLength(1230);
56
        this.field_146433_u.setText(this.parentScreen.func_146384_e());
57
        this.buttonList.add(this.field_146434_t = new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20, I18n.format("createWorld.customize.presets.select", new Object[0])));
58
        this.buttonList.add(new GuiButton(1, this.width / 2 + 5, this.height - 28, 150, 20, I18n.format("gui.cancel", new Object[0])));
59
        this.func_146426_g();
60
    }
61
62
    /**
63
     * Handles mouse input.
64
     */
65
    public void handleMouseInput() throws IOException
66
    {
67
        super.handleMouseInput();
68
        this.field_146435_s.handleMouseInput();
69
    }
70
71
    /**
72
     * Called when the screen is unloaded. Used to disable keyboard repeat events
73
     */
74
    public void onGuiClosed()
75
    {
76
        Keyboard.enableRepeatEvents(false);
77
    }
78
79
    /**
80
     * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
81
     */
82
    protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
83
    {
84
        this.field_146433_u.mouseClicked(mouseX, mouseY, mouseButton);
85
        super.mouseClicked(mouseX, mouseY, mouseButton);
86
    }
87
88
    /**
89
     * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
90
     * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
91
     */
92
    protected void keyTyped(char typedChar, int keyCode) throws IOException
93
    {
94
        if (!this.field_146433_u.textboxKeyTyped(typedChar, keyCode))
95
        {
96
            super.keyTyped(typedChar, keyCode);
97
        }
98
    }
99
100
    /**
101
     * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
102
     */
103
    protected void actionPerformed(GuiButton button) throws IOException
104
    {
105
        if (button.id == 0 && this.func_146430_p())
106
        {
107
            this.parentScreen.func_146383_a(this.field_146433_u.getText());
108
            this.mc.displayGuiScreen(this.parentScreen);
109
        }
110
        else if (button.id == 1)
111
        {
112
            this.mc.displayGuiScreen(this.parentScreen);
113
        }
114
    }
115
116
    /**
117
     * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
118
     */
119
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
120
    {
121
        this.drawDefaultBackground();
122
        this.field_146435_s.drawScreen(mouseX, mouseY, partialTicks);
123
        this.drawCenteredString(this.fontRendererObj, this.presetsTitle, this.width / 2, 8, 16777215);
124
        this.drawString(this.fontRendererObj, this.presetsShare, 50, 30, 10526880);
125
        this.drawString(this.fontRendererObj, this.field_146436_r, 50, 70, 10526880);
126
        this.field_146433_u.drawTextBox();
127
        super.drawScreen(mouseX, mouseY, partialTicks);
128
    }
129
130
    /**
131
     * Called from the main game loop to update the screen.
132
     */
133
    public void updateScreen()
134
    {
135
        this.field_146433_u.updateCursorCounter();
136
        super.updateScreen();
137
    }
138
139
    public void func_146426_g()
140
    {
141
        boolean flag = this.func_146430_p();
142
        this.field_146434_t.enabled = flag;
143
    }
144
145
    private boolean func_146430_p()
146
    {
147
        return this.field_146435_s.field_148175_k > -1 && this.field_146435_s.field_148175_k < FLAT_WORLD_PRESETS.size() || this.field_146433_u.getText().length() > 1;
148
    }
149
150
    private static void func_146425_a(String p_146425_0_, Item p_146425_1_, BiomeGenBase p_146425_2_, FlatLayerInfo... p_146425_3_)
151
    {
152
        func_175354_a(p_146425_0_, p_146425_1_, 0, p_146425_2_, (List<String>)null, p_146425_3_);
153
    }
154
155
    private static void func_146421_a(String p_146421_0_, Item p_146421_1_, BiomeGenBase p_146421_2_, List<String> p_146421_3_, FlatLayerInfo... p_146421_4_)
156
    {
157
        func_175354_a(p_146421_0_, p_146421_1_, 0, p_146421_2_, p_146421_3_, p_146421_4_);
158
    }
159
160
    private static void func_175354_a(String p_175354_0_, Item p_175354_1_, int p_175354_2_, BiomeGenBase p_175354_3_, List<String> p_175354_4_, FlatLayerInfo... p_175354_5_)
161
    {
162
        FlatGeneratorInfo flatgeneratorinfo = new FlatGeneratorInfo();
163
164
        for (int i = p_175354_5_.length - 1; i >= 0; --i)
165
        {
166
            flatgeneratorinfo.getFlatLayers().add(p_175354_5_[i]);
167
        }
168
169
        flatgeneratorinfo.setBiome(p_175354_3_.biomeID);
170
        flatgeneratorinfo.func_82645_d();
171
172
        if (p_175354_4_ != null)
173
        {
174
            for (String s : p_175354_4_)
175
            {
176
                flatgeneratorinfo.getWorldFeatures().put(s, Maps.<String, String>newHashMap());
177
            }
178
        }
179
180
        FLAT_WORLD_PRESETS.add(new GuiFlatPresets.LayerItem(p_175354_1_, p_175354_2_, p_175354_0_, flatgeneratorinfo.toString()));
181
    }
182
183
    static
184
    {
185
        func_146421_a("Classic Flat", Item.getItemFromBlock(Blocks.grass), BiomeGenBase.plains, Arrays.<String>asList(new String[] {"village"}), new FlatLayerInfo[] {new FlatLayerInfo(1, Blocks.grass), new FlatLayerInfo(2, Blocks.dirt), new FlatLayerInfo(1, Blocks.bedrock)});
186
        func_146421_a("Tunnelers\' Dream", Item.getItemFromBlock(Blocks.stone), BiomeGenBase.extremeHills, Arrays.<String>asList(new String[] {"biome_1", "dungeon", "decoration", "stronghold", "mineshaft"}), new FlatLayerInfo[] {new FlatLayerInfo(1, Blocks.grass), new FlatLayerInfo(5, Blocks.dirt), new FlatLayerInfo(230, Blocks.stone), new FlatLayerInfo(1, Blocks.bedrock)});
187
        func_146421_a("Water World", Items.water_bucket, BiomeGenBase.deepOcean, Arrays.<String>asList(new String[] {"biome_1", "oceanmonument"}), new FlatLayerInfo[] {new FlatLayerInfo(90, Blocks.water), new FlatLayerInfo(5, Blocks.sand), new FlatLayerInfo(5, Blocks.dirt), new FlatLayerInfo(5, Blocks.stone), new FlatLayerInfo(1, Blocks.bedrock)});
188
        func_175354_a("Overworld", Item.getItemFromBlock(Blocks.tallgrass), BlockTallGrass.EnumType.GRASS.getMeta(), BiomeGenBase.plains, Arrays.<String>asList(new String[] {"village", "biome_1", "decoration", "stronghold", "mineshaft", "dungeon", "lake", "lava_lake"}), new FlatLayerInfo[] {new FlatLayerInfo(1, Blocks.grass), new FlatLayerInfo(3, Blocks.dirt), new FlatLayerInfo(59, Blocks.stone), new FlatLayerInfo(1, Blocks.bedrock)});
189
        func_146421_a("Snowy Kingdom", Item.getItemFromBlock(Blocks.snow_layer), BiomeGenBase.icePlains, Arrays.<String>asList(new String[] {"village", "biome_1"}), new FlatLayerInfo[] {new FlatLayerInfo(1, Blocks.snow_layer), new FlatLayerInfo(1, Blocks.grass), new FlatLayerInfo(3, Blocks.dirt), new FlatLayerInfo(59, Blocks.stone), new FlatLayerInfo(1, Blocks.bedrock)});
190
        func_146421_a("Bottomless Pit", Items.feather, BiomeGenBase.plains, Arrays.<String>asList(new String[] {"village", "biome_1"}), new FlatLayerInfo[] {new FlatLayerInfo(1, Blocks.grass), new FlatLayerInfo(3, Blocks.dirt), new FlatLayerInfo(2, Blocks.cobblestone)});
191
        func_146421_a("Desert", Item.getItemFromBlock(Blocks.sand), BiomeGenBase.desert, Arrays.<String>asList(new String[] {"village", "biome_1", "decoration", "stronghold", "mineshaft", "dungeon"}), new FlatLayerInfo[] {new FlatLayerInfo(8, Blocks.sand), new FlatLayerInfo(52, Blocks.sandstone), new FlatLayerInfo(3, Blocks.stone), new FlatLayerInfo(1, Blocks.bedrock)});
192
        func_146425_a("Redstone Ready", Items.redstone, BiomeGenBase.desert, new FlatLayerInfo[] {new FlatLayerInfo(52, Blocks.sandstone), new FlatLayerInfo(3, Blocks.stone), new FlatLayerInfo(1, Blocks.bedrock)});
193
    }
194
195
    static class LayerItem
196
    {
197
        public Item field_148234_a;
198
        public int field_179037_b;
199
        public String field_148232_b;
200
        public String field_148233_c;
201
202
        public LayerItem(Item p_i45518_1_, int p_i45518_2_, String p_i45518_3_, String p_i45518_4_)
203
        {
204
            this.field_148234_a = p_i45518_1_;
205
            this.field_179037_b = p_i45518_2_;
206
            this.field_148232_b = p_i45518_3_;
207
            this.field_148233_c = p_i45518_4_;
208
        }
209
    }
210
211
    class ListSlot extends GuiSlot
212
    {
213
        public int field_148175_k = -1;
214
215
        public ListSlot()
216
        {
217
            super(GuiFlatPresets.this.mc, GuiFlatPresets.this.width, GuiFlatPresets.this.height, 80, GuiFlatPresets.this.height - 37, 24);
218
        }
219
220
        private void func_178054_a(int p_178054_1_, int p_178054_2_, Item p_178054_3_, int p_178054_4_)
221
        {
222
            this.func_148173_e(p_178054_1_ + 1, p_178054_2_ + 1);
223
            GlStateManager.enableRescaleNormal();
224
            RenderHelper.enableGUIStandardItemLighting();
225
            GuiFlatPresets.this.itemRender.renderItemIntoGUI(new ItemStack(p_178054_3_, 1, p_178054_4_), p_178054_1_ + 2, p_178054_2_ + 2);
226
            RenderHelper.disableStandardItemLighting();
227
            GlStateManager.disableRescaleNormal();
228
        }
229
230
        private void func_148173_e(int p_148173_1_, int p_148173_2_)
231
        {
232
            this.func_148171_c(p_148173_1_, p_148173_2_, 0, 0);
233
        }
234
235
        private void func_148171_c(int p_148171_1_, int p_148171_2_, int p_148171_3_, int p_148171_4_)
236
        {
237
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
238
            this.mc.getTextureManager().bindTexture(Gui.statIcons);
239
            float f = 0.0078125F;
240
            float f1 = 0.0078125F;
241
            int i = 18;
242
            int j = 18;
243
            Tessellator tessellator = Tessellator.getInstance();
244
            WorldRenderer worldrenderer = tessellator.getWorldRenderer();
245
            worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
246
            worldrenderer.pos((double)(p_148171_1_ + 0), (double)(p_148171_2_ + 18), (double)GuiFlatPresets.this.zLevel).tex((double)((float)(p_148171_3_ + 0) * 0.0078125F), (double)((float)(p_148171_4_ + 18) * 0.0078125F)).endVertex();
247
            worldrenderer.pos((double)(p_148171_1_ + 18), (double)(p_148171_2_ + 18), (double)GuiFlatPresets.this.zLevel).tex((double)((float)(p_148171_3_ + 18) * 0.0078125F), (double)((float)(p_148171_4_ + 18) * 0.0078125F)).endVertex();
248
            worldrenderer.pos((double)(p_148171_1_ + 18), (double)(p_148171_2_ + 0), (double)GuiFlatPresets.this.zLevel).tex((double)((float)(p_148171_3_ + 18) * 0.0078125F), (double)((float)(p_148171_4_ + 0) * 0.0078125F)).endVertex();
249
            worldrenderer.pos((double)(p_148171_1_ + 0), (double)(p_148171_2_ + 0), (double)GuiFlatPresets.this.zLevel).tex((double)((float)(p_148171_3_ + 0) * 0.0078125F), (double)((float)(p_148171_4_ + 0) * 0.0078125F)).endVertex();
250
            tessellator.draw();
251
        }
252
253
        protected int getSize()
254
        {
255
            return GuiFlatPresets.FLAT_WORLD_PRESETS.size();
256
        }
257
258
        protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
259
        {
260
            this.field_148175_k = slotIndex;
261
            GuiFlatPresets.this.func_146426_g();
262
            GuiFlatPresets.this.field_146433_u.setText(((GuiFlatPresets.LayerItem)GuiFlatPresets.FLAT_WORLD_PRESETS.get(GuiFlatPresets.this.field_146435_s.field_148175_k)).field_148233_c);
263
        }
264
265
        protected boolean isSelected(int slotIndex)
266
        {
267
            return slotIndex == this.field_148175_k;
268
        }
269
270
        protected void drawBackground()
271
        {
272
        }
273
274
        protected void drawSlot(int entryID, int p_180791_2_, int p_180791_3_, int p_180791_4_, int mouseXIn, int mouseYIn)
275
        {
276
            GuiFlatPresets.LayerItem guiflatpresets$layeritem = (GuiFlatPresets.LayerItem)GuiFlatPresets.FLAT_WORLD_PRESETS.get(entryID);
277
            this.func_178054_a(p_180791_2_, p_180791_3_, guiflatpresets$layeritem.field_148234_a, guiflatpresets$layeritem.field_179037_b);
278
            GuiFlatPresets.this.fontRendererObj.drawString(guiflatpresets$layeritem.field_148232_b, p_180791_2_ + 18 + 5, p_180791_3_ + 6, 16777215);
279
        }
280
    }
281
}
282

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