Skip to content

Commit

Permalink
Merge pull request #71 from TPPI-Dev/Dev
Browse files Browse the repository at this point in the history
Merge for TPPI 1.0.4
  • Loading branch information
tterrag1098 committed May 26, 2014
2 parents d0f0439 + 43727d3 commit b2a4069
Show file tree
Hide file tree
Showing 18 changed files with 373 additions and 109 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ if (System.getenv().ARTIFACT_VERSION != null) {

version = "MC${config.minecraft_version}-${artifact_version}-${buildInfo.buildNum}"
def actualVersion = "${artifact_version}-${buildInfo.buildNum}"
archivesBaseName = "TPPI-Tweaks"

minecraft {
version = "1.6.4-9.11.1.964"
Expand Down
119 changes: 119 additions & 0 deletions src/main/java/tppitweaks/client/gui/IRCGui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package tppitweaks.client.gui;

import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import tppitweaks.TPPITweaks;
import tppitweaks.config.ConfigurationHandler;

public class IRCGui extends GuiScreen
{
private boolean configState;
private static final ResourceLocation bg = new ResourceLocation("tppitweaks", "textures/gui/TPPI.png");

@SuppressWarnings("unchecked")
@Override
public void initGui()
{
this.buttonList.add(new GuiButton(0, this.width / 2 - 144, this.height / 2 + 40, 140, 20, "Enable this Feature"));
this.buttonList.add(new GuiButton(1, this.width / 2 + 4, this.height / 2 + 40, 140, 20, "Disable this Feature"));
this.buttonList.add(new GuiButton(2, this.width / 2 - 144, this.height / 2 + 68, 140, 20, "Exit the Game"));
this.buttonList.add(new GuiButton(3, this.width / 2 + 4, this.height / 2 + 68, 140, 20, "Continue to the Game"));
this.buttonList.add(new GuiButton(4, this.width / 2 - 144, this.height / 2 + 96, 288, 20, "Don't Show this Again"));

((GuiButton) this.buttonList.get(2)).enabled = false;
configState = Boolean.parseBoolean(ConfigurationHandler.manuallyGetConfigValue("EiraIRC.cfg", "B:autoConnect"));
((GuiButton) this.buttonList.get(0)).enabled = !configState;
((GuiButton) this.buttonList.get(1)).enabled = configState;
}

@Override
public void drawScreen(int par1, int par2, float par3)
{
drawCustomBackground(0);

this.drawCenteredString(this.mc.fontRenderer, "This version of TPPI adds a new IRC feature!", this.width / 2, this.height / 2 - 105, 0xFFFFFF);
this.drawCenteredString(this.mc.fontRenderer, "Anyone playing the pack is able to live chat", this.width / 2, this.height / 2 - 90, 0xFFFFFF);
this.drawCenteredString(this.mc.fontRenderer, "with anyone else simultaneously.", this.width / 2, this.height / 2 - 80, 0xFFFFFF);
this.drawCenteredString(this.mc.fontRenderer, "If you do not desire this feature,", this.width / 2, this.height / 2 - 65, 0xFFFFFF);
this.drawCenteredString(this.mc.fontRenderer, "this is your chance to opt-out.", this.width / 2, this.height / 2 - 55, 0xFFFFFF);
this.drawCenteredString(this.mc.fontRenderer, "To do this, hit \"Disable this Feature\",", this.width / 2, this.height / 2 - 40, 0xFFFFFF);
this.drawCenteredString(this.mc.fontRenderer, "and then restart the game.", this.width / 2, this.height / 2 - 30, 0xFFFFFF);
this.drawCenteredString(this.mc.fontRenderer, "If you wish to leave this feature enabled,", this.width / 2, this.height / 2 - 15, 0xFFFFFF);
this.drawCenteredString(this.mc.fontRenderer, "simply hit \"Continue to the Game\"", this.width / 2, this.height / 2 - 5, 0xFFFFFF);
this.drawCenteredString(this.mc.fontRenderer, "\"Don't show this again\" will prevent this GUI", this.width / 2, this.height / 2 + 10, 0xFFFFFF);
this.drawCenteredString(this.mc.fontRenderer, "from showing in the future.", this.width / 2, this.height / 2 + 20, 0xFFFFFF);
super.drawScreen(par1, par2, par3);
}

@SuppressWarnings("unchecked")
@Override
protected void actionPerformed(GuiButton button)
{
switch (button.id)
{
case 0:
button.enabled = false;
if (ConfigurationHandler.manuallyChangeConfigValue("EiraIRC.cfg", "B:autoConnect", "false", "true"))
{
((GuiButton) buttonList.get(3)).enabled = configState;
((GuiButton) buttonList.get(2)).enabled = !configState;
}
((GuiButton) buttonList.get(1)).enabled = true;
break;
case 1:
button.enabled = false;
if (ConfigurationHandler.manuallyChangeConfigValue("EiraIRC.cfg", "B:autoConnect", "true", "false"))
{
((GuiButton) buttonList.get(3)).enabled = !configState;
((GuiButton) buttonList.get(2)).enabled = configState;
}
((GuiButton) buttonList.get(0)).enabled = true;
break;
case 2:
TPPITweaks.logger.info("Shutting down!");
Minecraft.getMinecraft().shutdown();
break;
case 3:
this.mc.displayGuiScreen(null);
break;
case 4:
dontShowAgain();
for (GuiButton b : (List<GuiButton>) buttonList)
{
if (b.id != 3 && b.id != 2)
b.enabled = false;
}
break;
default:
return;
}
}

@Override
protected void keyTyped(char par1, int par2)
{
; // do nothing
}

private void dontShowAgain()
{
TPPITweaks.logger.info("Disabling IRC GUI...");
ConfigurationHandler.manuallyChangeConfigValue("B:showIRCGui", "true", "false");
}

private void drawCustomBackground(int par1)
{
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_FOG);
this.mc.getTextureManager().bindTexture(bg);
GL11.glColor4f(0.18f, 0.18f, 0.18f, 1.0F);
this.drawTexturedModalRect(0, 0, 240, 240, this.width, this.height);
}
}
6 changes: 1 addition & 5 deletions src/main/java/tppitweaks/client/gui/UpdateGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,10 @@ public void initGui()
{
if (noShow)
{
System.out.println("not opening GUI");
TPPITweaks.logger.info("not opening GUI");
this.mc.displayGuiScreen(this.parentScreen);
return;
}
else
{

}

// Unsure exactly what this does but...it seems necessary
Keyboard.enableRepeatEvents(true);
Expand Down
91 changes: 52 additions & 39 deletions src/main/java/tppitweaks/command/CommandTPPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void initValidCommandArguments(InputStream file)
validCommands.add("changelog");
validCommands.add("guide");
validCommands.add("removeBooks");

supportedModsAndList.add("list");

supportedModsAndList.addAll(TxtParser.getSupportedMods(file));
Expand All @@ -72,7 +72,7 @@ public String getCommandUsage(ICommandSender icommandsender)
{
return "tppi <arg>";
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender par1iCommandSender)
{
Expand Down Expand Up @@ -111,15 +111,25 @@ public void processCommand(ICommandSender icommandsender, String[] astring)
else if (astring[0].equalsIgnoreCase("mods"))
{
processCommandMods(icommandsender, astring);
}else if(astring[0].equalsIgnoreCase("ores")) {
}
else if (astring[0].equalsIgnoreCase("ores"))
{
processVanillaBookCommand("TPPI Ore Generation Guide", "OreGen.txt", icommandsender, astring);
}else if(astring[0].equalsIgnoreCase("getInvolved")) {
}
else if (astring[0].equalsIgnoreCase("getInvolved"))
{
processVanillaBookCommand("Getting Involved In TPPI", "GetInvolved.txt", icommandsender, astring);
}else if(astring[0].equalsIgnoreCase("changelog")) {
}
else if (astring[0].equalsIgnoreCase("changelog"))
{
processCommandChangelog(icommandsender);
}else if(astring[0].equalsIgnoreCase("guide")) {
}
else if (astring[0].equalsIgnoreCase("guide"))
{
processCommandGuide(icommandsender);
}else if(astring[0].equalsIgnoreCase("removeBooks")) {
}
else if (astring[0].equalsIgnoreCase("removeBooks"))
{
removeGuideBooks(icommandsender);
}

Expand All @@ -141,34 +151,39 @@ else if (astring[0].equalsIgnoreCase("mods"))

}

private void removeGuideBooks(ICommandSender command) {
private void removeGuideBooks(ICommandSender command)
{
EntityPlayer player = command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName());
ItemStack[] inv = player.inventory.mainInventory;
for (int i = 0; i < inv.length; i++)
{
if (inv[i] != null && // no null itemstack
inv[i].stackTagCompound != null && // no null stack tag
inv[i].stackTagCompound.toString().contains(ConfigurationHandler.bookAuthor) && // has the author
inv[i].itemID == Item.writtenBook.itemID) // is a vanilla book

inv[i] = null;
inv[i].stackTagCompound != null && // no null stack tag
inv[i].stackTagCompound.toString().contains(ConfigurationHandler.bookAuthor) && // has
// the
// author
inv[i].itemID == Item.writtenBook.itemID) // is a vanilla
// book

inv[i] = null;
}
}

private void processCommandGuide(ICommandSender command)
{
ItemStack stack = new ItemStack(ModItems.tppiBook, 1, 2);

if (!command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).inventory.addItemStackToInventory(stack))
command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).entityDropItem(stack, 0);
}

private void processVanillaBookCommand(String title, String textFileName, ICommandSender command, String[] astring) {

InputStream file = TPPITweaks.class.getResourceAsStream("/assets/tppitweaks/lang/"+textFileName);
private void processVanillaBookCommand(String title, String textFileName, ICommandSender command, String[] astring)
{

InputStream file = TPPITweaks.class.getResourceAsStream("/assets/tppitweaks/lang/" + textFileName);
List<String> vanillaBookText = file == null ? new ArrayList<String>() : TxtParser.parseFileMain(file);
ItemStack book = new ItemStack(Item.writtenBook);

book.setTagInfo("author", new NBTTagString("author", ConfigurationHandler.bookAuthor));
book.setTagInfo("title", new NBTTagString("title", title));

Expand All @@ -182,10 +197,10 @@ private void processVanillaBookCommand(String title, String textFileName, IComma

nbttagcompound.setTag("pages", bookPages);
nbttagcompound.setString("version", TPPITweaks.VERSION);

if (!command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).inventory.addItemStackToInventory(book))
command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).entityDropItem(book, 0);

}

private boolean processCommandMods(ICommandSender command, String[] args)
Expand Down Expand Up @@ -233,20 +248,21 @@ private boolean processCommandDownload(ICommandSender command, String[] args)
PacketDispatcher.sendPacketToPlayer(packet, (Player) command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()));
return true;
}

return false;
}

private boolean processCommandChangelog(ICommandSender command)
{
ItemStack changelog = ModItems.tppiBook.getChangelog();

if (changelog == null)
return false;

if (!command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).inventory.addItemStackToInventory(changelog));
command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).entityDropItem(changelog, 0);


if (!command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).inventory.addItemStackToInventory(changelog))
;
command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).entityDropItem(changelog, 0);

return true;
}

Expand Down Expand Up @@ -283,7 +299,7 @@ private void giveModBook(String modName, ICommandSender command)
NBTTagList bookPages = new NBTTagList("pages");

ArrayList<String> pages;

pages = TxtParser.parseFileMods(FileLoader.getSupportedModsFile(), modName + ", " + properName);

if (pages.get(0).startsWith("<") && pages.get(0).endsWith("> "))
Expand All @@ -302,21 +318,18 @@ private void giveModBook(String modName, ICommandSender command)
if (!command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).inventory.addItemStackToInventory(stack))
command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).entityDropItem(stack, 0);
}

public static String getProperName(String modid)
{
return modProperNames.get(modid);
}

@Override
public int compareTo(Object arg0)
{
return this.compareTo((ICommand) arg0);
}

@Override
public boolean equals(Object obj)
{
return this.compareTo(obj) == 0;
}
public int compareTo(Object o) {
if (o instanceof ICommand) {
return this.compareTo((ICommand) o);
} else {
return 0;
}
}
}
Loading

0 comments on commit b2a4069

Please sign in to comment.