Jump to content

How to switch Gui/render when an item is present?


XxArchangelz

Recommended Posts

I have 2 items, a tile entity/block/container and a container/item. I have it so far that the block (altar) will only accept the item (book), but I want to have it so that when the book is present in the altar, the block will render a different model and the gui will switch (if book is in slot make altar have book on top and new gui otherwise show original gui with empty slot and empty altar without book)

I figure I need to do if statements but I don't know where and how to go about it. I was thinking it needed to be in GuiAltar or ItemAltarRender but I don't know.

GuiAltar

 

package archangel.necromancy.client.gui.inventory;

 

import net.minecraft.client.gui.inventory.GuiContainer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.util.StatCollector;

 

import org.lwjgl.opengl.GL11;

 

import archangel.necromancy.inventory.ContainerAltar;

import archangel.necromancy.lib.Sprites;

import archangel.necromancy.lib.Strings;

import archangel.necromancy.tileentity.TileAltar;

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

 

public class GuiAltar extends GuiContainer {

 

    private TileAltar altar;

 

    public GuiAltar(InventoryPlayer player, TileAltar altar) {

 

        super(new ContainerAltar(player, altar));

        this.ySize = 176;

        this.altar = altar;

    }

 

    protected void drawGuiContainerForegroundLayer() {

 

        this.fontRenderer.drawString(LanguageRegistry.instance().getStringLocalization(Strings.GUI_ALTAR_NAME), 60, 6, 4210752);

        this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);

    }

 

    protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {

 

        int var4 = this.mc.renderEngine.getTexture(Sprites.GUI_SHEET_LOCATION + Sprites.ALTAR_MODEL_TEXTURE);

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

        this.mc.renderEngine.bindTexture(var4);

        int var5 = (this.width - this.xSize) / 2;

        int var6 = (this.height - this.ySize) / 2;

        this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);

        int var7;

    }

 

}

 

 

ItemAltarRender

 

package archangel.necromancy.client.renderer;

 

import net.minecraft.client.renderer.Tessellator;

import net.minecraft.item.ItemStack;

import net.minecraftforge.client.ForgeHooksClient;

import net.minecraftforge.client.IItemRenderer;

 

import org.lwjgl.opengl.GL11;

 

import archangel.necromancy.client.model.ModelAltar;

import archangel.necromancy.lib.Sprites;

 

public class ItemAltarRenderer implements IItemRenderer {

 

    private ModelAltar altarModel;

 

    public ItemAltarRenderer() {

 

        altarModel = new ModelAltar(1 / 16F);

    }

 

    @Override

    public boolean handleRenderType(ItemStack item, ItemRenderType type) {

 

        return true;

    }

 

    @Override

    public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {

 

        return true;

    }

 

    @Override

    public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

 

        switch (type) {

            case ENTITY: {

                renderAltar(-0.5F, 0F, -0.5F);

                break;

            }

            case EQUIPPED: {

                renderAltar(0F, 0.4F, 0F);

                break;

            }

            case INVENTORY: {

                renderAltar(1F, 0.65F, 1F);

                break;

            }

            default:

                break;

        }

 

    }

 

    private void renderAltar(float x, float y, float z) {

 

        Tessellator tesselator = Tessellator.instance;

        ForgeHooksClient.bindTexture(Sprites.SPRITE_SHEET_LOCATION + Sprites.ALTAR_MODEL_TEXTURE, 0);

        GL11.glPushMatrix(); //start

        GL11.glTranslatef(x, y, z); //size

        altarModel.render(0.0625F);

        GL11.glPopMatrix(); //end

    }

 

}

 

 

I don't know squat about OpenGL and i'm still fairly new to modding so I am trying to learn as much as I can to better myself as modding and java. Thanks for the help

Link to comment
Share on other sites

I'm sorry not entirely sure what I am doing. I have this for my block class

 

package archangel.necromancy.block;

 

import net.minecraft.block.material.Material;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

import archangel.necromancy.Necromancy;

import archangel.necromancy.lib.GuiIds;

import archangel.necromancy.lib.RenderIds;

import archangel.necromancy.lib.Strings;

import archangel.necromancy.tileentity.TileAltar;

 

public class BlockAltar extends BlockNC {

 

public BlockAltar(int id) {

 

super(id, Material.rock);

this.setBlockName(Strings.ALTAR_NAME);

this.setCreativeTab(Necromancy.tabsNecro);

this.setHardness(5F);

}

 

@Override

public TileEntity createNewTileEntity(World var1) {

 

return new TileAltar();

}

 

@Override

public boolean renderAsNormalBlock() {

 

return false;

}

 

@Override

public boolean isOpaqueCube() {

 

return false;

}

 

@Override

public int getRenderType() {

 

return RenderIds.altarRenderId;

}

 

@Override

public int getBlockTexture(IBlockAccess blockAccess, int x, int y, int z, int side){

this.getBlockTileEntity(int i, int j, int k)

}

 

// @Override

// public int getBlockTextureFromSide(int par1) {

 

// return 1;

// }

 

public boolean onBlockActivated(World world, int x, int y, int z,

EntityPlayer player, int par6, float par7, float par8, float par9) {

 

if (!world.isRemote) {

TileAltar tileAltar = (TileAltar) world.getBlockTileEntity(x, y, z);

 

if (tileAltar != null) {

player.openGui(Necromancy.instance, GuiIds.ALTAR, world, x, y,

z);

}

}

 

return true;

 

}

 

}

 

 

I don't know if I'm putting this correctly, but I am getting syntax errors on the variables and I don't know how to word it to make it change the texture and the gui when the item is present.

Link to comment
Share on other sites

Oh duh my bad, I thought that was the entire thing so I never put it with the method. Now with SLOT_NO, I'm thinking that means SlotNecronomicon from my container class that is set to only allow a certain item in the slot, should be placed there, or no? Because when I try that it tells me that it cannot be resolved to a variable, so would I need to make a variable for it, and like how?

Also when I try to call the texture file assigned in my Sprites class, it throws me an error because the method is an int and to call it from my sprites class would require it be a string.

Link to comment
Share on other sites

Okay I see, I got that all working now thanks so much. I have one last problem. I made it in my proxy to switch GUI's if an item is present with a similar method and separate gui classes, but the gui only switches after opening and closing the gui. Where would I have to do this to make it work instantly?

Link to comment
Share on other sites

A texture is just a number ( the index of the texture in the sheet).

You need to return a different number depending on whether there is an Item in the slot or not.

I'm using a custom rendered item though so I have two image files (one with one without), I got it working in the ModelAltar class, but when you disconnect/reconnect the block shows up as it were empty then switches back to having a book when you right click it opening the gui.

Link to comment
Share on other sites

A texture is just a number ( the index of the texture in the sheet).

You need to return a different number depending on whether there is an Item in the slot or not.

I'm using a custom rendered item though so I have two image files (one with one without), I got it working in the ModelAltar class, but when you disconnect/reconnect the block shows up as it were empty then switches back to having a book when you right click it opening the gui.

you need to save the texture witch the block is using (not the file, just the name) to the nbt, also to switch gui just put this on onBlockActivacted (or where u call the gui)

 

 

Item equipped = par5Entityplayer.getCurrentEquippedItem() != null ? par5Entityplayer.getCurrentEquippedItem().getItem() : null;

if (equipped instanceof MYITEM1){

par5EntityPlayer.openGui(MYMOD.instance, GuiId1, par1World, par2, par3, par4);

}

if(equipped instanceof MYITEM2){

par5EntityPlayer.openGui(MYMOD.instance, GuiId2, par1World, par2, par3, par4);

}

else {

//more stuff

}

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

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