Skip to content

Commit

Permalink
intermediate commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dries007 committed Oct 12, 2016
1 parent ede51a1 commit 4b54330
Show file tree
Hide file tree
Showing 36 changed files with 1,098 additions and 404 deletions.
12 changes: 2 additions & 10 deletions src/main/java/net/doubledoordev/mtrm/GuiHandler.java
Expand Up @@ -2,7 +2,6 @@

import net.doubledoordev.mtrm.client.GuiMain;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;

Expand All @@ -14,19 +13,12 @@ public class GuiHandler implements IGuiHandler
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
return new Container()
{
@Override
public boolean canInteractWith(EntityPlayer playerIn)
{
return true;
}
};
return new InventoryContainer(player);
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
return new GuiMain();
return new GuiMain(new InventoryContainer(player));
}
}
40 changes: 26 additions & 14 deletions src/main/java/net/doubledoordev/mtrm/Helper.java
@@ -1,8 +1,8 @@
package net.doubledoordev.mtrm;

import com.google.common.base.Joiner;
import com.google.common.io.Files;
import net.doubledoordev.mtrm.xml.XmlParser;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.Loader;
import org.apache.commons.io.FileUtils;
Expand All @@ -16,7 +16,6 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
Expand All @@ -40,32 +39,28 @@ public static File getScriptFile() throws IOException
if (!file.exists())
{
Files.touch(file);
BufferedWriter w = writeHeader(Files.newWriter(file, Charset.defaultCharset()), "<SERVER>");
w.write("print(\"Now loading the MineTweakerRecipeMaker script file\");");
w.close();
writeHeader(Files.newWriter(file, Charset.defaultCharset()), "<SERVER>").close();
}
return file;
}

public static BufferedWriter writeHeader(BufferedWriter br, String name) throws IOException
{
br.write("// File generated by MineTweakerRecipeMaker\r\n");
br.write("// This file is automatically managed by MineTweakerRecipeMaker.\r\n");
br.write("// File generated by MineTweakerRecipeMaker (MTRM) by DoubleDoorDevelopment\r\n");
br.write("// This file is automatically managed by MTRM.\r\n");
br.write("// Try not to touch it if you don't absolutely have to.\r\n");
br.write("// Last edit at ");
br.write(DATE_TIME.format(new Date()));
br.write(" by ");
br.write(name);
br.write("\r\n// Try not to touch it if you don't absolutely have to.\r\n");
br.write("// If you have too, leave the markers alone. They look like this:\r\n");
br.write("//\r\n");
br.write("// #MTRM MARKER <number here>\r\n");
br.write("//\r\n");
br.write("// ================================================================================\r\n");
br.write("print(\"Loading the MineTweakerRecipeMaker (MTRM) script file.\");");
br.write("// HERE BE DRAGONS\r\n\r\n");
return br;
}

/**
* Recursive XML file finder. Always returns the given list.
* @param folder
* @param list
* @return the list parameter
*/
public static List<File> findXMLFiles(File folder, List<File> list)
Expand Down Expand Up @@ -133,4 +128,21 @@ public static String truncate(String text, int width)
{
return text.length() < width ? text : text.substring(0, width) + "...";
}

public static String itemstackToString(ItemStack stack)
{
if (stack == null) return "null";
StringBuilder sb = new StringBuilder("<");
sb.append(stack.getItem().getRegistryName());
int meta = stack.getMetadata();
if (meta != 0) sb.append(meta);
sb.append('>');
if (stack.stackSize != 1) sb.append('*').append(stack.stackSize);
return sb.toString();
}

public static double round(double in, double precision)
{
return precision * Math.floor(in / precision);
}
}
30 changes: 30 additions & 0 deletions src/main/java/net/doubledoordev/mtrm/InventoryContainer.java
@@ -0,0 +1,30 @@
package net.doubledoordev.mtrm;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;

/**
* @author Dries007
*/
public class InventoryContainer extends Container
{
public final int offsetX = 217;
public final int offsetY = 48;

private final EntityPlayer player;

public InventoryContainer(EntityPlayer player)
{
this.player = player;

for (int x = 0; x < 3; ++x) for (int y = 0; y < 9; ++y) this.addSlotToContainer(new Slot(player.inventory, y + x * 9 + 9, offsetY + y * 18, x * 18 + offsetX));
for (int x = 0; x < 9; ++x) this.addSlotToContainer(new Slot(player.inventory, x, offsetY + x * 18, 58 + offsetX));
}

@Override
public boolean canInteractWith(EntityPlayer playerIn)
{
return player == playerIn;
}
}
11 changes: 9 additions & 2 deletions src/main/java/net/doubledoordev/mtrm/client/ClientHelper.java
Expand Up @@ -10,14 +10,19 @@
*/
public class ClientHelper
{
public static final int[] BTN_COLORS = {0x505050, 0xAAAAAA, 0xBDC6FF};
public static final int[] TEXT_COLORS = {0xA0A0A0, 0xE0E0E0, 0xFFFFA0};
public static final int[] BTN_COLORS = {0x505050, 0xAAAAAA, 0xBDC6FF, 0xFF9090};
public static final int[] TEXT_COLORS = {0xA0A0A0, 0xE0E0E0, 0xFFFFA0, 0xF0F0F0};

private ClientHelper()
{
}

public static List<String> split(FontRenderer renderer, String text, int width)
{
return split(renderer, text, width, Integer.MAX_VALUE);
}

public static List<String> split(FontRenderer renderer, String text, int width, int lineLimit)
{
if (text.length() == 0) return new ArrayList<>();
List<String> list = new ArrayList<>();
Expand All @@ -29,11 +34,13 @@ public static List<String> split(FontRenderer renderer, String text, int width)
if (c == '\n')
{
list.add(line.substring(0, line.length() - 1));
if (list.size() >= lineLimit--) return list;
line = new StringBuilder();
}
else if (w >= width)
{
list.add(line.substring(0, line.length() - 1) + '→');
if (list.size() >= lineLimit--) return list;
line = new StringBuilder();
line.append(c);
}
Expand Down
78 changes: 31 additions & 47 deletions src/main/java/net/doubledoordev/mtrm/client/GuiBase.java
Expand Up @@ -2,14 +2,11 @@

import net.doubledoordev.mtrm.client.parts.GuiIconButton;
import net.doubledoordev.mtrm.client.parts.Icon;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.inventory.Container;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import org.lwjgl.input.Keyboard;
Expand All @@ -20,16 +17,18 @@
/**
* @author Dries007
*/
@SuppressWarnings("WeakerAccess")
public abstract class GuiBase extends GuiScreen
public abstract class GuiBase extends GuiContainer
{
protected static final ResourceLocation BACKGROUND = new ResourceLocation("mtrm:gui/base.png");
public static final ResourceLocation BASE = new ResourceLocation("mtrm:gui/base.png");
public static final ResourceLocation INVENTORY = new ResourceLocation("mtrm:gui/inventory.png");
protected static final int ID_CANCEL = 0;
protected static final int BTN_OK = 1;
protected static final int BTN_CANCEL = 2;

protected final int xSize = 256;
protected final int ySize = 200;
{
xSize = 256;
ySize = 200;
}

//0 = top, 1 = bottom
protected float currentScroll;
Expand All @@ -43,23 +42,29 @@ public abstract class GuiBase extends GuiScreen
protected int guiLeft;
protected int guiTop;

public GuiBase(Container inventorySlotsIn)
{
super(inventorySlotsIn);

}

protected abstract void exit();

protected abstract void ok();

protected abstract boolean needsScrolling();

protected abstract void scrolled();

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
if (mc == null)
{
mc = Minecraft.getMinecraft();
fontRendererObj = mc.fontRendererObj;
}
mc.getTextureManager().bindTexture(INVENTORY);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
// 88 = 176/2 = width of inventory gui
drawTexturedModalRect(guiLeft + xSize/2 - 88, guiTop + ySize + 9, 0, 0, 176, 90);

mc.getTextureManager().bindTexture(BACKGROUND);
drawDefaultBackground();
mc.getTextureManager().bindTexture(BASE);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);

Expand All @@ -85,10 +90,14 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks)
this.scrolled();
}

this.mc.getTextureManager().bindTexture(BACKGROUND);
mc.getTextureManager().bindTexture(BASE);
drawTexturedModalRect(left, top + (int) ((bottom - top - 15) * currentScroll), this.needsScrolling() ? 0 : 12, 241, 12, 15);
}

super.drawScreen(mouseX, mouseY, partialTicks);
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
}

@Override
Expand All @@ -108,12 +117,6 @@ public void initGui()
btnOk.enabled = false;
}

@Override
public boolean doesGuiPauseGame()
{
return false;
}

@Override
public void handleMouseInput() throws IOException
{
Expand All @@ -131,11 +134,9 @@ public void handleMouseInput() throws IOException
}
}

protected abstract void scrolled();

protected void confirmExit()
{
this.mc.displayGuiScreen(new GuiYesNo(this, "Are you sure you want to leave?", "Changes won't be saved!", ID_CANCEL));
mc.displayGuiScreen(new GuiYesNo(this, "Are you sure you want to leave?", "Changes won't be saved!", ID_CANCEL));
}

@Override
Expand All @@ -145,7 +146,7 @@ public void confirmClicked(boolean result, int id)
{
case ID_CANCEL:
if (result) exit();
else this.mc.displayGuiScreen(this);
else mc.displayGuiScreen(this);
break;
default:
super.confirmClicked(result, id);
Expand Down Expand Up @@ -178,21 +179,4 @@ protected void actionPerformed(GuiButton button) throws IOException
break;
}
}

@Override
public void drawBackground(int tint)
{
drawModalRectWithCustomSizedTexture(0, 0, 0, 0, 250, 250, 250, 250);
GlStateManager.disableLighting();
GlStateManager.disableFog();
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer vertexbuffer = tessellator.getBuffer();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
vertexbuffer.pos(0.0D, (double) height, 0.0D).tex(0.0D, (double) ((float) height / 32.0F + (float) tint)).color(64, 64, 64, 255).endVertex();
vertexbuffer.pos((double) width, (double) height, 0.0D).tex((double) ((float) width / 32.0F), (double) ((float) height / 32.0F + (float) tint)).color(64, 64, 64, 255).endVertex();
vertexbuffer.pos((double) width, 0.0D, 0.0D).tex((double) ((float) width / 32.0F), (double) tint).color(64, 64, 64, 255).endVertex();
vertexbuffer.pos(0.0D, 0.0D, 0.0D).tex(0.0D, (double) tint).color(64, 64, 64, 255).endVertex();
tessellator.draw();
}
}

0 comments on commit 4b54330

Please sign in to comment.