| 1 | package net.minecraft.client.gui;
|
| 2 |
|
| 3 | import java.io.IOException;
|
| 4 | import net.minecraft.block.Block;
|
| 5 | import net.minecraft.block.state.IBlockState;
|
| 6 | import net.minecraft.client.renderer.GlStateManager;
|
| 7 | import net.minecraft.client.renderer.RenderHelper;
|
| 8 | import net.minecraft.client.renderer.Tessellator;
|
| 9 | import net.minecraft.client.renderer.WorldRenderer;
|
| 10 | import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
| 11 | import net.minecraft.client.resources.I18n;
|
| 12 | import net.minecraft.init.Blocks;
|
| 13 | import net.minecraft.init.Items;
|
| 14 | import net.minecraft.item.Item;
|
| 15 | import net.minecraft.item.ItemStack;
|
| 16 | import net.minecraft.world.gen.FlatGeneratorInfo;
|
| 17 | import net.minecraft.world.gen.FlatLayerInfo;
|
| 18 |
|
| 19 | public class GuiCreateFlatWorld extends GuiScreen
|
| 20 | {
|
| 21 | private final GuiCreateWorld createWorldGui;
|
| 22 | private FlatGeneratorInfo theFlatGeneratorInfo = FlatGeneratorInfo.getDefaultFlatGenerator();
|
| 23 |
|
| 24 | /** The title given to the flat world currently in creation */
|
| 25 | private String flatWorldTitle;
|
| 26 | private String field_146394_i;
|
| 27 | private String field_146391_r;
|
| 28 | private GuiCreateFlatWorld.Details createFlatWorldListSlotGui;
|
| 29 | private GuiButton field_146389_t;
|
| 30 | private GuiButton field_146388_u;
|
| 31 | private GuiButton field_146386_v;
|
| 32 |
|
| 33 | public GuiCreateFlatWorld(GuiCreateWorld createWorldGuiIn, String p_i1029_2_)
|
| 34 | {
|
| 35 | this.createWorldGui = createWorldGuiIn;
|
| 36 | this.func_146383_a(p_i1029_2_);
|
| 37 | }
|
| 38 |
|
| 39 | public String func_146384_e()
|
| 40 | {
|
| 41 | return this.theFlatGeneratorInfo.toString();
|
| 42 | }
|
| 43 |
|
| 44 | public void func_146383_a(String p_146383_1_)
|
| 45 | {
|
| 46 | this.theFlatGeneratorInfo = FlatGeneratorInfo.createFlatGeneratorFromString(p_146383_1_);
|
| 47 | }
|
| 48 |
|
| 49 | /**
|
| 50 | * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
|
| 51 | * window resizes, the buttonList is cleared beforehand.
|
| 52 | */
|
| 53 | public void initGui()
|
| 54 | {
|
| 55 | this.buttonList.clear();
|
| 56 | this.flatWorldTitle = I18n.format("createWorld.customize.flat.title", new Object[0]);
|
| 57 | this.field_146394_i = I18n.format("createWorld.customize.flat.tile", new Object[0]);
|
| 58 | this.field_146391_r = I18n.format("createWorld.customize.flat.height", new Object[0]);
|
| 59 | this.createFlatWorldListSlotGui = new GuiCreateFlatWorld.Details();
|
| 60 | this.buttonList.add(this.field_146389_t = new GuiButton(2, this.width / 2 - 154, this.height - 52, 100, 20, I18n.format("createWorld.customize.flat.addLayer", new Object[0]) + " (NYI)"));
|
| 61 | this.buttonList.add(this.field_146388_u = new GuiButton(3, this.width / 2 - 50, this.height - 52, 100, 20, I18n.format("createWorld.customize.flat.editLayer", new Object[0]) + " (NYI)"));
|
| 62 | this.buttonList.add(this.field_146386_v = new GuiButton(4, this.width / 2 - 155, this.height - 52, 150, 20, I18n.format("createWorld.customize.flat.removeLayer", new Object[0])));
|
| 63 | this.buttonList.add(new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20, I18n.format("gui.done", new Object[0])));
|
| 64 | this.buttonList.add(new GuiButton(5, this.width / 2 + 5, this.height - 52, 150, 20, I18n.format("createWorld.customize.presets", new Object[0])));
|
| 65 | this.buttonList.add(new GuiButton(1, this.width / 2 + 5, this.height - 28, 150, 20, I18n.format("gui.cancel", new Object[0])));
|
| 66 | this.field_146389_t.visible = this.field_146388_u.visible = false;
|
| 67 | this.theFlatGeneratorInfo.func_82645_d();
|
| 68 | this.func_146375_g();
|
| 69 | }
|
| 70 |
|
| 71 | /**
|
| 72 | * Handles mouse input.
|
| 73 | */
|
| 74 | public void handleMouseInput() throws IOException
|
| 75 | {
|
| 76 | super.handleMouseInput();
|
| 77 | this.createFlatWorldListSlotGui.handleMouseInput();
|
| 78 | }
|
| 79 |
|
| 80 | /**
|
| 81 | * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
|
| 82 | */
|
| 83 | protected void actionPerformed(GuiButton button) throws IOException
|
| 84 | {
|
| 85 | int i = this.theFlatGeneratorInfo.getFlatLayers().size() - this.createFlatWorldListSlotGui.field_148228_k - 1;
|
| 86 |
|
| 87 | if (button.id == 1)
|
| 88 | {
|
| 89 | this.mc.displayGuiScreen(this.createWorldGui);
|
| 90 | }
|
| 91 | else if (button.id == 0)
|
| 92 | {
|
| 93 | this.createWorldGui.chunkProviderSettingsJson = this.func_146384_e();
|
| 94 | this.mc.displayGuiScreen(this.createWorldGui);
|
| 95 | }
|
| 96 | else if (button.id == 5)
|
| 97 | {
|
| 98 | this.mc.displayGuiScreen(new GuiFlatPresets(this));
|
| 99 | }
|
| 100 | else if (button.id == 4 && this.func_146382_i())
|
| 101 | {
|
| 102 | this.theFlatGeneratorInfo.getFlatLayers().remove(i);
|
| 103 | this.createFlatWorldListSlotGui.field_148228_k = Math.min(this.createFlatWorldListSlotGui.field_148228_k, this.theFlatGeneratorInfo.getFlatLayers().size() - 1);
|
| 104 | }
|
| 105 |
|
| 106 | this.theFlatGeneratorInfo.func_82645_d();
|
| 107 | this.func_146375_g();
|
| 108 | }
|
| 109 |
|
| 110 | public void func_146375_g()
|
| 111 | {
|
| 112 | boolean flag = this.func_146382_i();
|
| 113 | this.field_146386_v.enabled = flag;
|
| 114 | this.field_146388_u.enabled = flag;
|
| 115 | this.field_146388_u.enabled = false;
|
| 116 | this.field_146389_t.enabled = false;
|
| 117 | }
|
| 118 |
|
| 119 | private boolean func_146382_i()
|
| 120 | {
|
| 121 | return this.createFlatWorldListSlotGui.field_148228_k > -1 && this.createFlatWorldListSlotGui.field_148228_k < this.theFlatGeneratorInfo.getFlatLayers().size();
|
| 122 | }
|
| 123 |
|
| 124 | /**
|
| 125 | * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
|
| 126 | */
|
| 127 | public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
| 128 | {
|
| 129 | this.drawDefaultBackground();
|
| 130 | this.createFlatWorldListSlotGui.drawScreen(mouseX, mouseY, partialTicks);
|
| 131 | this.drawCenteredString(this.fontRendererObj, this.flatWorldTitle, this.width / 2, 8, 16777215);
|
| 132 | int i = this.width / 2 - 92 - 16;
|
| 133 | this.drawString(this.fontRendererObj, this.field_146394_i, i, 32, 16777215);
|
| 134 | this.drawString(this.fontRendererObj, this.field_146391_r, i + 2 + 213 - this.fontRendererObj.getStringWidth(this.field_146391_r), 32, 16777215);
|
| 135 | super.drawScreen(mouseX, mouseY, partialTicks);
|
| 136 | }
|
| 137 |
|
| 138 | class Details extends GuiSlot
|
| 139 | {
|
| 140 | public int field_148228_k = -1;
|
| 141 |
|
| 142 | public Details()
|
| 143 | {
|
| 144 | super(GuiCreateFlatWorld.this.mc, GuiCreateFlatWorld.this.width, GuiCreateFlatWorld.this.height, 43, GuiCreateFlatWorld.this.height - 60, 24);
|
| 145 | }
|
| 146 |
|
| 147 | private void func_148225_a(int p_148225_1_, int p_148225_2_, ItemStack p_148225_3_)
|
| 148 | {
|
| 149 | this.func_148226_e(p_148225_1_ + 1, p_148225_2_ + 1);
|
| 150 | GlStateManager.enableRescaleNormal();
|
| 151 |
|
| 152 | if (p_148225_3_ != null && p_148225_3_.getItem() != null)
|
| 153 | {
|
| 154 | RenderHelper.enableGUIStandardItemLighting();
|
| 155 | GuiCreateFlatWorld.this.itemRender.renderItemIntoGUI(p_148225_3_, p_148225_1_ + 2, p_148225_2_ + 2);
|
| 156 | RenderHelper.disableStandardItemLighting();
|
| 157 | }
|
| 158 |
|
| 159 | GlStateManager.disableRescaleNormal();
|
| 160 | }
|
| 161 |
|
| 162 | private void func_148226_e(int p_148226_1_, int p_148226_2_)
|
| 163 | {
|
| 164 | this.func_148224_c(p_148226_1_, p_148226_2_, 0, 0);
|
| 165 | }
|
| 166 |
|
| 167 | private void func_148224_c(int p_148224_1_, int p_148224_2_, int p_148224_3_, int p_148224_4_)
|
| 168 | {
|
| 169 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 170 | this.mc.getTextureManager().bindTexture(Gui.statIcons);
|
| 171 | float f = 0.0078125F;
|
| 172 | float f1 = 0.0078125F;
|
| 173 | int i = 18;
|
| 174 | int j = 18;
|
| 175 | Tessellator tessellator = Tessellator.getInstance();
|
| 176 | WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
| 177 | worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
| 178 | worldrenderer.pos((double)(p_148224_1_ + 0), (double)(p_148224_2_ + 18), (double)GuiCreateFlatWorld.this.zLevel).tex((double)((float)(p_148224_3_ + 0) * 0.0078125F), (double)((float)(p_148224_4_ + 18) * 0.0078125F)).endVertex();
|
| 179 | worldrenderer.pos((double)(p_148224_1_ + 18), (double)(p_148224_2_ + 18), (double)GuiCreateFlatWorld.this.zLevel).tex((double)((float)(p_148224_3_ + 18) * 0.0078125F), (double)((float)(p_148224_4_ + 18) * 0.0078125F)).endVertex();
|
| 180 | worldrenderer.pos((double)(p_148224_1_ + 18), (double)(p_148224_2_ + 0), (double)GuiCreateFlatWorld.this.zLevel).tex((double)((float)(p_148224_3_ + 18) * 0.0078125F), (double)((float)(p_148224_4_ + 0) * 0.0078125F)).endVertex();
|
| 181 | worldrenderer.pos((double)(p_148224_1_ + 0), (double)(p_148224_2_ + 0), (double)GuiCreateFlatWorld.this.zLevel).tex((double)((float)(p_148224_3_ + 0) * 0.0078125F), (double)((float)(p_148224_4_ + 0) * 0.0078125F)).endVertex();
|
| 182 | tessellator.draw();
|
| 183 | }
|
| 184 |
|
| 185 | protected int getSize()
|
| 186 | {
|
| 187 | return GuiCreateFlatWorld.this.theFlatGeneratorInfo.getFlatLayers().size();
|
| 188 | }
|
| 189 |
|
| 190 | protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
|
| 191 | {
|
| 192 | this.field_148228_k = slotIndex;
|
| 193 | GuiCreateFlatWorld.this.func_146375_g();
|
| 194 | }
|
| 195 |
|
| 196 | protected boolean isSelected(int slotIndex)
|
| 197 | {
|
| 198 | return slotIndex == this.field_148228_k;
|
| 199 | }
|
| 200 |
|
| 201 | protected void drawBackground()
|
| 202 | {
|
| 203 | }
|
| 204 |
|
| 205 | protected void drawSlot(int entryID, int p_180791_2_, int p_180791_3_, int p_180791_4_, int mouseXIn, int mouseYIn)
|
| 206 | {
|
| 207 | FlatLayerInfo flatlayerinfo = (FlatLayerInfo)GuiCreateFlatWorld.this.theFlatGeneratorInfo.getFlatLayers().get(GuiCreateFlatWorld.this.theFlatGeneratorInfo.getFlatLayers().size() - entryID - 1);
|
| 208 | IBlockState iblockstate = flatlayerinfo.getLayerMaterial();
|
| 209 | Block block = iblockstate.getBlock();
|
| 210 | Item item = Item.getItemFromBlock(block);
|
| 211 | ItemStack itemstack = block != Blocks.air && item != null ? new ItemStack(item, 1, block.getMetaFromState(iblockstate)) : null;
|
| 212 | String s = itemstack == null ? "Air" : item.getItemStackDisplayName(itemstack);
|
| 213 |
|
| 214 | if (item == null)
|
| 215 | {
|
| 216 | if (block != Blocks.water && block != Blocks.flowing_water)
|
| 217 | {
|
| 218 | if (block == Blocks.lava || block == Blocks.flowing_lava)
|
| 219 | {
|
| 220 | item = Items.lava_bucket;
|
| 221 | }
|
| 222 | }
|
| 223 | else
|
| 224 | {
|
| 225 | item = Items.water_bucket;
|
| 226 | }
|
| 227 |
|
| 228 | if (item != null)
|
| 229 | {
|
| 230 | itemstack = new ItemStack(item, 1, block.getMetaFromState(iblockstate));
|
| 231 | s = block.getLocalizedName();
|
| 232 | }
|
| 233 | }
|
| 234 |
|
| 235 | this.func_148225_a(p_180791_2_, p_180791_3_, itemstack);
|
| 236 | GuiCreateFlatWorld.this.fontRendererObj.drawString(s, p_180791_2_ + 18 + 5, p_180791_3_ + 3, 16777215);
|
| 237 | String s1;
|
| 238 |
|
| 239 | if (entryID == 0)
|
| 240 | {
|
| 241 | s1 = I18n.format("createWorld.customize.flat.layer.top", new Object[] {Integer.valueOf(flatlayerinfo.getLayerCount())});
|
| 242 | }
|
| 243 | else if (entryID == GuiCreateFlatWorld.this.theFlatGeneratorInfo.getFlatLayers().size() - 1)
|
| 244 | {
|
| 245 | s1 = I18n.format("createWorld.customize.flat.layer.bottom", new Object[] {Integer.valueOf(flatlayerinfo.getLayerCount())});
|
| 246 | }
|
| 247 | else
|
| 248 | {
|
| 249 | s1 = I18n.format("createWorld.customize.flat.layer", new Object[] {Integer.valueOf(flatlayerinfo.getLayerCount())});
|
| 250 | }
|
| 251 |
|
| 252 | GuiCreateFlatWorld.this.fontRendererObj.drawString(s1, p_180791_2_ + 2 + 213 - GuiCreateFlatWorld.this.fontRendererObj.getStringWidth(s1), p_180791_3_ + 3, 16777215);
|
| 253 | }
|
| 254 |
|
| 255 | protected int getScrollBarX()
|
| 256 | {
|
| 257 | return this.width - 70;
|
| 258 | }
|
| 259 | }
|
| 260 | }
|
| 261 |
|