Jump to content

Recommended Posts

Posted

I need some help. I want a block to display a gui when right clicked. The GUI is the ending game cutscene, but i'll be editing to my advantage(different words), but i cant seem to get it to work. Im in 1.5.1, and I'm not using a tile entity. Because, mojang didn't, and I'm using that class, so, yeah.

?Here is my code.

Main mod file(PortalBallMain)

 

 

package mods.portalball_mod;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.Init;

import cpw.mods.fml.common.Mod.Instance;

import cpw.mods.fml.common.event.FMLInitializationEvent;

import cpw.mods.fml.common.network.NetworkMod;

import cpw.mods.fml.common.network.NetworkRegistry;

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.registry.LanguageRegistry;

 

@Mod(modid = "PortalBallMain.modid", name = "PortalBall", version = "1.0")

@NetworkMod(clientSideRequired = true, serverSideRequired = false)

public class PortalBallMain

{

 

@Instance("PortalBallMain")

public static PortalBallMain instance;

 

public static final String modid = "PortalBall_portalballmod";

 

public static Block Opener;

 

public static CreativeTabs tabCustom = new CreativeTabs("tabPortalBall") {

          public ItemStack getIconItemStack() {

                  return new ItemStack(Item.writtenBook, 1, 0);

          }

         

  };

 

 

 

 

@Init

public void load(FMLInitializationEvent event)

{

//blocks

Opener = (new Block(251, Material.rock)).setHardness(2.0F).setResistance(10.0F).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("Opener").setCreativeTab(CreativeTabs.tabBlock);

//LAnguageRegistry

LanguageRegistry.instance().addStringLocalization("itemGroup.tabPortalBall", "en_US", "PortalBall Mod");

LanguageRegistry.addName(Opener, "Story");

//GameRegistry

GameRegistry.registerBlock(Opener);

}

}

 

 

 

 

BlockOpener(the block that opens the gui.

 

 

package mods.portalball_mod;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

 

public class BlockOpener extends Block

{

    protected BlockOpener(int par1)

    {

        super(par1, Material.ground);

        this.setCreativeTab(PortalBallMain.tabCustom);

    }

   

public boolean onBlockActivated(World world, int x, int y, int z,EntityPlayer player, int idk, float what, float these, float are) {

TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

if (tileEntity == null || player.isSneaking()) {

            return false;

}

 

player.openGui(PortalBallMain.instance, 0, world, x, y, z);

return true;

}

}

 

 

 

 

GUIOpening(the gui)

 

 

package mods.portalball_mod;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.nio.charset.Charset;

import java.util.ArrayList;

import java.util.List;

import java.util.Random;

 

import net.minecraft.client.gui.GuiScreen;

import net.minecraft.client.renderer.Tessellator;

import net.minecraft.network.packet.Packet205ClientCommand;

import net.minecraft.util.EnumChatFormatting;

import org.lwjgl.opengl.GL11;

 

@SideOnly(Side.CLIENT)

public class GuiOpening extends GuiScreen

{

    /** Counts the number of screen updates. */

    private int updateCounter = 0;

 

    /** List of lines on the ending poem and credits. */

    private List lines;

    private int field_73989_c = 0;

    private float field_73987_d = 0.5F;

 

    /**

    * Called from the main game loop to update the screen.

    */

    public void updateScreen()

    {

        ++this.updateCounter;

        float f = (float)(this.field_73989_c + this.height + this.height + 24) / this.field_73987_d;

 

        if ((float)this.updateCounter > f)

        {

            this.respawnPlayer();

        }

    }

 

    /**

    * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).

    */

    protected void keyTyped(char par1, int par2)

    {

        if (par2 == 1)

        {

            this.respawnPlayer();

        }

    }

 

    /**

    * Respawns the player.

    */

    private void respawnPlayer()

    {

        this.mc.thePlayer.sendQueue.addToSendQueue(new Packet205ClientCommand(1));

        this.mc.displayGuiScreen((GuiScreen)null);

    }

 

    /**

    * Returns true if this GUI should pause the game when it is displayed in single-player

    */

    public boolean doesGuiPauseGame()

    {

        return true;

    }

 

    /**

    * Adds the buttons (and other controls) to the screen in question.

    */

    public void initGui()

    {

        if (this.lines == null)

        {

            this.lines = new ArrayList();

 

            try

            {

                String s = "";

                String s1 = "" + EnumChatFormatting.WHITE + EnumChatFormatting.OBFUSCATED + EnumChatFormatting.GREEN + EnumChatFormatting.AQUA;

                short short1 = 274;

                BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(GuiOpening.class.getResourceAsStream("/title/win.txt"), Charset.forName("UTF-8")));

                Random random = new Random(8124371L);

                int i;

 

                while ((s = bufferedreader.readLine()) != null)

                {

                    String s2;

                    String s3;

 

                    for (s = s.replaceAll("PLAYERNAME", this.mc.session.username); s.contains(s1); s = s2 + EnumChatFormatting.WHITE + EnumChatFormatting.OBFUSCATED + "XXXXXXXX".substring(0, random.nextInt(4) + 3) + s3)

                    {

                        i = s.indexOf(s1);

                        s2 = s.substring(0, i);

                        s3 = s.substring(i + s1.length());

                    }

 

                    this.lines.addAll(this.mc.fontRenderer.listFormattedStringToWidth(s, short1));

                    this.lines.add("");

                }

 

                for (i = 0; i < 8; ++i)

                {

                    this.lines.add("");

                }

 

                bufferedreader = new BufferedReader(new InputStreamReader(GuiOpening.class.getResourceAsStream("/title/credits.txt"), Charset.forName("UTF-8")));

 

                while ((s = bufferedreader.readLine()) != null)

                {

                    s = s.replaceAll("PLAYERNAME", this.mc.session.username);

                    s = s.replaceAll("\t", "    ");

                    this.lines.addAll(this.mc.fontRenderer.listFormattedStringToWidth(s, short1));

                    this.lines.add("");

                }

 

                this.field_73989_c = this.lines.size() * 12;

            }

            catch (Exception exception)

            {

                exception.printStackTrace();

            }

        }

    }

 

    private void func_73986_b(int par1, int par2, float par3)

    {

        Tessellator tessellator = Tessellator.instance;

        this.mc.renderEngine.bindTexture("%blur%/gui/background.png");

        tessellator.startDrawingQuads();

        tessellator.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1.0F);

        int k = this.width;

        float f1 = 0.0F - ((float)this.updateCounter + par3) * 0.5F * this.field_73987_d;

        float f2 = (float)this.height - ((float)this.updateCounter + par3) * 0.5F * this.field_73987_d;

        float f3 = 0.015625F;

        float f4 = ((float)this.updateCounter + par3 - 0.0F) * 0.02F;

        float f5 = (float)(this.field_73989_c + this.height + this.height + 24) / this.field_73987_d;

        float f6 = (f5 - 20.0F - ((float)this.updateCounter + par3)) * 0.005F;

 

        if (f6 < f4)

        {

            f4 = f6;

        }

 

        if (f4 > 1.0F)

        {

            f4 = 1.0F;

        }

 

        f4 *= f4;

        f4 = f4 * 96.0F / 255.0F;

        tessellator.setColorOpaque_F(f4, f4, f4);

        tessellator.addVertexWithUV(0.0D, (double)this.height, (double)this.zLevel, 0.0D, (double)(f1 * f3));

        tessellator.addVertexWithUV((double)k, (double)this.height, (double)this.zLevel, (double)((float)k * f3), (double)(f1 * f3));

        tessellator.addVertexWithUV((double)k, 0.0D, (double)this.zLevel, (double)((float)k * f3), (double)(f2 * f3));

        tessellator.addVertexWithUV(0.0D, 0.0D, (double)this.zLevel, 0.0D, (double)(f2 * f3));

        tessellator.draw();

    }

 

    /**

    * Draws the screen and all the components in it.

    */

    public void drawScreen(int par1, int par2, float par3)

    {

        this.func_73986_b(par1, par2, par3);

        Tessellator tessellator = Tessellator.instance;

        short short1 = 274;

        int k = this.width / 2 - short1 / 2;

        int l = this.height + 50;

        float f1 = -((float)this.updateCounter + par3) * this.field_73987_d;

        GL11.glPushMatrix();

        GL11.glTranslatef(0.0F, f1, 0.0F);

        this.mc.renderEngine.bindTexture("/title/mclogo.png");

        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

        this.drawTexturedModalRect(k, l, 0, 0, 155, 44);

        this.drawTexturedModalRect(k + 155, l, 0, 45, 155, 44);

        tessellator.setColorOpaque_I(16777215);

        int i1 = l + 200;

        int j1;

 

        for (j1 = 0; j1 < this.lines.size(); ++j1)

        {

            if (j1 == this.lines.size() - 1)

            {

                float f2 = (float)i1 + f1 - (float)(this.height / 2 - 6);

 

                if (f2 < 0.0F)

                {

                    GL11.glTranslatef(0.0F, -f2, 0.0F);

                }

            }

 

            if ((float)i1 + f1 + 12.0F + 8.0F > 0.0F && (float)i1 + f1 < (float)this.height)

            {

                String s = (String)this.lines.get(j1);

 

                if (s.startsWith("[C]"))

                {

                    this.fontRenderer.drawStringWithShadow(s.substring(3), k + (short1 - this.fontRenderer.getStringWidth(s.substring(3))) / 2, i1, 16777215);

                }

                else

                {

                    this.fontRenderer.fontRandom.setSeed((long)j1 * 4238972211L + (long)(this.updateCounter / 4));

                    this.fontRenderer.drawStringWithShadow(s, k, i1, 16777215);

                }

            }

 

            i1 += 12;

        }

 

        GL11.glPopMatrix();

        this.mc.renderEngine.bindTexture("%blur%/misc/vignette.png");

        GL11.glEnable(GL11.GL_BLEND);

        GL11.glBlendFunc(GL11.GL_ZERO, GL11.GL_ONE_MINUS_SRC_COLOR);

        tessellator.startDrawingQuads();

        tessellator.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1.0F);

        j1 = this.width;

        int k1 = this.height;

        tessellator.addVertexWithUV(0.0D, (double)k1, (double)this.zLevel, 0.0D, 1.0D);

        tessellator.addVertexWithUV((double)j1, (double)k1, (double)this.zLevel, 1.0D, 1.0D);

        tessellator.addVertexWithUV((double)j1, 0.0D, (double)this.zLevel, 1.0D, 0.0D);

        tessellator.addVertexWithUV(0.0D, 0.0D, (double)this.zLevel, 0.0D, 0.0D);

        tessellator.draw();

        GL11.glDisable(GL11.GL_BLEND);

        super.drawScreen(par1, par2, par3);

    }

}

 

 

 

HELP!

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Posted
and I'm not using a tile entity. Because, mojang didn't, and I'm using that class, so, yeah.

Then explain your code:

if (tileEntity == null || player.isSneaking()) {

            return false;

}

If you guys dont get it.. then well ya.. try harder...

Posted

and I'm not using a tile entity. Because, mojang didn't, and I'm using that class, so, yeah.

Then explain your code:

if (tileEntity == null || player.isSneaking()) {

            return false;

}

Well, thats me trying to open it.

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Posted

1. Do you understand what the code I quoted is doing??

Since you are not using a tE it seems to be quite weird for it to be there.

 

2. As he said above you need an GuiHandler it's a forgewiki page about Gui's and containers, if you learn that then skipp the tE and container (use GuiScreen) u should be good.

If you guys dont get it.. then well ya.. try harder...

Posted

Yeah, i read that post. I just could see how to work out the container/tE, its been a while since ive coded in java.

I'll look again and see if i can delete the code for the container and tE, but what do you mean by use GuiScreen, im already extending that. Do you mean instead of the tE?

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Posted

1. Do you understand what the code I quoted is doing??

Since you are not using a tE it seems to be quite weird for it to be there.

 

?

If you guys dont get it.. then well ya.. try harder...

Posted

Well my question was if you understood what the code was doing..

 

And you're first response was "Well, thats me trying to open it."

When the code is not showing player.openGUI but the code before that, and your statement did not tell me what the code actually is doing.

So do you know what these lines are doing? They explain why your program isn't crashing without a GuiHandler.

 

If you guys dont get it.. then well ya.. try harder...

Posted

wait? So, if i add a tile entity, that dosnt render anything to the screen, it might work?

And yes, i know what the code is doing somewhat, its trying to load up a tile entity, but not finding one, so it just returns null, and moves along.

Did I just Have a breakthrough? ;D

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Posted
And yes, i know what the code is doing somewhat, its trying to load up a tile entity, but not finding one, so it just returns null, and moves along.

if (tileEntity == null || player.isSneaking()) {
            return false;
}

 

No that's not what "return false" means.

When it says return it means, it will stop reading that method and return some value back to the caller.

This means that since you NEVER will have a tileEntity it will allways be NULL and therefore it will always read the "return false" line.

 

Therefore it will not crash when trying to open the GUI because it never tries to open your GUI since this line is NEVER read:

player.openGui(PortalBallMain.instance, 0, world, x, y, z);

 

 

Do you now understand why I nag about that little line? :)

If you guys dont get it.. then well ya.. try harder...

Posted

I'm sorry but before you that I need you to explain to me, one thing:

 

What do you think the java keyword 'return' means?

If you guys dont get it.. then well ya.. try harder...

Posted

send back variable(usually true or false) to caller.

Also, i tried returning true on the return statement between the tileentity crap and the player.openGui, and it didn't work.

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Posted

That's not the only thing it does mate.

 

You need to study some more programming basics before you continue with your modding :)

Else you will never get anywhere because the things you are having trouble with right now are at the core basics of programming.

You're time is much better spent learning Java, since if you learn the java basics now you will be able to create mods a lot faster when you understand what you are doing and aren't causing crashes every line you write :)

 

If you want I can give you a nice list of places to seek java knowledge, among'st them both short videos on every topic and a free university lecture on Java basics (this one you really should spend time on, it's awesome!)

So do you want to learn some java mate? :)

If you guys dont get it.. then well ya.. try harder...

Posted

i read up on return statements, and i still cant open my gui. I'm about to give up for a week. Can you stop being vague and just tell me! I's so simple, the tile entity draw things on screen that cant be interacted with, the gui renders things to the screen that can. All I'm trying to do is open a stupid gui! What do i do! I made a chest 2 months ago, but that had a tE! I also lost that file on my old computer!

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Posted

I told you that you needed to learn java, beacuse:

 

1. a TileEntity DOES NOT draw things on the screen.

 

2. you didn't understand return statements.

 

3. the Gui does not only render things you can interact with..

 

4. You don't have a GUI Handler as said earlier and you where given directions to go to the forgewiki to learn more about GUI's!

 

 

I said above that you needed to learn java and I believed that you understood that, well I guess you didn't I'm sorry if this seems rude and unhelpful but if you're not willing to learn Java and programming principles you got nothing to do inn here! As this board description states you are EXPECTED to know the basics of java and you don't!

 

There are several people here who could have replied to your questions above but chose not too, because the answer would be "learn some java" and people tend to rage at us when we tell them to go learn java which is the ONLY way to actually learn programming!

 

So I'm sorry you don't like the fact that I want you to learn Java, I'm not sorry that I do however as the alternative is you spending two weeks doing things that would have taken you 10 minutes when you know the basics! If you don't want to learn programming, don't want to learn modding then that's fine by all means, but then why are you here at all then? O.o

 

 

TL;DR:

You don't even grasp the basic concepts of Java and I told you above to learn it so here's a even less vague answer:

LEARN PROGRAMMING FUNDAMENTALS! LEARN TO CRAWL BEFORE YOU RUN!!!

If you guys dont get it.. then well ya.. try harder...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.