Jump to content

[1.5.2] Gui won't render


VitezKolya

Recommended Posts

I've been try to figure out why this gui won't open when I click/use the block it's attached to. Here is the code for the block, gui and the proxy code.

 

package altenergy.client.gui;

import org.lwjgl.opengl.GL11;

import altenergy.content.controllers.TileControllerPC;
import altenergy.core.misc.PowerCoreState;
import altenergy.lib.Textures;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;

public class GuiControllerPC extends GuiScreen{

private TileControllerPC tileEntity;

private int containerWidth;
private int contrainerHeight;
private EntityPlayer player;
private boolean isActive = false;
private int xSize;
private int ySize;


public GuiControllerPC(EntityPlayer player, World world, int x, int y, int z) {
	System.out.println("Gui open");
	this.tileEntity = (TileControllerPC) world.getBlockTileEntity(x, y, z);
	this.player = player;
	this.xSize = 146;
	this.ySize = 67;
}

@Override
    public void drawScreen(int x, int y, float f) {
	drawGuiContainerBackgroundLayer();
	drawGuiContainerForegroundLayer();
}

protected void drawGuiContainerForegroundLayer() {

	this.fontRenderer.drawString("Power Core Controller", 44, 8, 4210752);

	String stateText = "";
	String displayText = "";

	if(this.tileEntity.getStatus() == PowerCoreState.Idle) {
		stateText = "Idle";
	} else if(this.tileEntity.getStatus() == PowerCoreState.Generate) {
		stateText = "Generating";
	} else if(this.tileEntity.getStatus() == PowerCoreState.Overload) {
		stateText = "Warning: Overload";
	} else if(this.tileEntity.getStatus() == PowerCoreState.Vent) {
		stateText = "Warning: Venting";
	}
	displayText = "100000.0Watt";//ElectricityDisplay.getDisplay(tileEntity.generateWatts, ElectricUnit.WATT);
	this.fontRenderer.drawString("Status: " + stateText, (int) (33), 24, 4210752);
	this.fontRenderer.drawString("Output: " + displayText, (int) (30 - displayText.length() * 1.25), 44, 4210752);
}

protected void drawGuiContainerBackgroundLayer() {

	this.mc.renderEngine.bindTexture(Textures.GUI_MINI_POWERCORE);
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

	containerWidth = (this.width - this.xSize) / 2;
	contrainerHeight = (this.height - this.ySize) / 2;

	this.drawTexturedModalRect(containerWidth, contrainerHeight, 0, 0, this.xSize, this.ySize);
	if(this.isActive) {
		this.drawTexturedModalRect(containerWidth + 133, contrainerHeight + 18, 171, 25, 9, 7);
		player.closeScreen();
	} else {
		this.drawTexturedModalRect(containerWidth + 133, contrainerHeight + 18, 171, 16, 9, 7);
	}
}

private boolean toggleButton() {
	return !isActive;
}

@Override
protected void mouseClicked(int x, int y, int buttonID) {
	super.mouseClicked(x,y,buttonID);
	int xAxis= (x - (width - xSize) / 2);
	int yAxis= (y - (height - ySize) / 2);

	if(xAxis > 133 && xAxis < 141 && yAxis > 18 && yAxis < 24) {
		toggleButton();
	}

}

}

 

package altenergy.content.controllers;

import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.prefab.block.BlockAdvanced;
import altenergy.AltEnergy;
import altenergy.core.misc.TilePowerCoreBase;
//import altenergy.content.controllers.TileControllerPC;
import altenergy.lib.GuiIds;
import altenergy.lib.RenderIds;
import altenergy.lib.Strings;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockControllerPC extends BlockAdvanced {

public BlockControllerPC(int id) {

	super(id, Material.iron);
	setUnlocalizedName(Strings.BLOCK_CONTROLLER_PC);
	setCreativeTab(AltEnergy.tabsAE);
}

@Override
public TileEntity createNewTileEntity(World world) {

	return new TileControllerPC();
}

@Override
public boolean renderAsNormalBlock() {

	return false;
}

@Override
public boolean isOpaqueCube() {

	return false;
}

@Override
public int getRenderType() {

	return RenderIds.controllerPC;
}

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) {

}

@Override
public void breakBlock(World world, int x, int y, int z, int id, int data) {

	TileControllerPC tileEntity = (TileControllerPC) world.getBlockTileEntity(x, y, z);
	super.breakBlock(world, x, y, z, id, data);

	if (tileEntity == null) {
		System.out.printf("BlockControllerPC.breakBlock: No tile entity at (%d,%d,%d)\n", x, y, z);
	} else if (tileEntity.isLinked) {
		TilePowerCoreBase core = (TilePowerCoreBase) tileEntity.getLinked();
		if (core != null) {
			core.clearLink();
		}
	}
}

@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving player, ItemStack stack) {

	super.onBlockPlacedBy(world, x, y, z, player, stack);
	TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
	if (tileEntity instanceof TileControllerPC) {
		((TileControllerPC) tileEntity).linkToControlled();
	}
}

@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX,
		float hitY, float hitZ) {

	if (player.isSneaking()) {
		return false;
	} else {
		if (!world.isRemote) {
			TileControllerPC tileEntity = (TileControllerPC) world.getBlockTileEntity(x, y, z);
			tileEntity.findControlled();
			if (tileEntity != null) {
				player.openGui(AltEnergy.instance, GuiIds.CONTROLLER_PC, world, x, y, z);
			}
		}
		return true;
	}
}
}

 

package altenergy.core.proxy;

import altenergy.client.gui.GuiMachine;
import altenergy.client.gui.GuiMiniPowerCore;
import altenergy.client.gui.GuiControllerPC;
import altenergy.content.minipowercore.ContainerMiniPowerCore;
import altenergy.content.minipowercore.TileMiniPowerCore;
import altenergy.core.misc.ContrainerMachine;
import altenergy.lib.GuiIds;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import cpw.mods.fml.common.network.IGuiHandler;

public class CommonProxy implements IGuiHandler{


public void registerSoundHandler() {

}

public void initRenderingAndTextures() {

}

public void registerTileEntities() {

}

public void sendRequestEventPacket(byte eventType, int originX, int originY, int originZ, byte sideHit, byte rangeX, byte rangeY, byte rangeZ, String data) {

    }

    public void handleTileEntityPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName) {

    }

    public void handleTileWithItemPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int itemID, int metaData, int stackSize, int color) {

    }
    
    public void bindTexture(String texture) {
}

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

	if(ID == GuiIds.MINI_POWERCORE) {
			return new ContainerMiniPowerCore(player.inventory, world, x, y, z);
	} else if(ID == GuiIds.MACHINE) {
			return new ContrainerMachine(player.inventory, world, z, z, z);
	}

	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	System.out.println("ID: " + ID);
	if(ID == GuiIds.MINI_POWERCORE) {
			return new GuiMiniPowerCore(player, world, x, y, z);
	} else if(ID == GuiIds.CONTROLLER_PC) {
			System.out.println("Opening Controller Gui");
			return new GuiControllerPC(player, world, x, y, z);
	} else if(ID == GuiIds.MACHINE) {
			return new GuiMachine(player, world, x, y, z);
	}

	return null;
}

}

Link to comment
Share on other sites

What do you mean by opening correctly?

 

Do you mean using this code?

player.openGui(AltEnergy.instance, GuiIds.CONTROLLER_PC, world, x, y, z);

 

Or is there something else I'm missing?

 

I have another gui that works and both block files are just about identical. Other then the code for the controller to link to the powercore.

Link to comment
Share on other sites

Ah that what you ment. No they don't print in the eclipse console. In fact the println in the getClientGuiElement at GuiIds.CONTROLLER_PC doesn't print ether. It's like the player.openGui never gets called at all, but when I have println on both sides of player.openGui they both print. I've been pounding my head agenst this problem for a few days.

 

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	System.out.println("ID: " + ID);
	if(ID == GuiIds.MINI_POWERCORE) {
			return new GuiMiniPowerCore(player, world, x, y, z);
	} else if(ID == GuiIds.CONTROLLER_PC) {
			System.out.println("Opening Controller Gui");
			return new GuiControllerPC(player, world, x, y, z);
	} else if(ID == GuiIds.MACHINE) {
			return new GuiMachine(player, world, x, y, z);
	}

	return null;
}

Link to comment
Share on other sites

Yep. Right here.

 

package altenergy;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

import universalelectricity.core.UniversalElectricity;
import universalelectricity.prefab.network.PacketManager;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.common.DimensionManager;
import altenergy.blocks.ModBlocks;
import altenergy.configuration.ConfigurationHandler;
import altenergy.content.ModContent;
import altenergy.core.handlers.AltEnergyHooks;
import altenergy.core.handlers.LocalizationHandler;
import altenergy.core.proxy.CommonProxy;
import altenergy.creativetab.CreativeTabAE;
import altenergy.items.ModItems;
import altenergy.lib.DimensionIds;
import altenergy.lib.Reference;
import altenergy.world.WorldProviderTerra;
import altenergy.world.gen.WorldGenManager;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.Metadata;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;

/**
* AltEnergy
* 
* AltEnergy
* 
* @author VitezKolya
* @license GNU Public License v3 (http://www.gnu.org/licenses/gpl.html)
* 
*/

@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION, certificateFingerprint = Reference.FINGERPRINT)
@NetworkMod(channels={Reference.CHANNEL_NAME}, clientSideRequired=true, serverSideRequired=false, packetHandler = PacketManager.class)
public class AltEnergy {

@Instance(Reference.MOD_ID)
public static AltEnergy instance;

@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
public static CommonProxy proxy;

public static CreativeTabs tabsAE = new CreativeTabAE(CreativeTabs.getNextID(), Reference.MOD_ID);

public static WorldGenManager genManager = new WorldGenManager();

public static AltEnergyHooks hooks;

@Metadata(Reference.MOD_ID)
    public static ModMetadata meta;

public static Logger AELogger = Logger.getLogger(Reference.MOD_ID);

public static void log(Level level, String msg, String... replacements) {
	for(String replace: replacements) {
		msg = msg.replace("%s", replace);
	}

	AELogger.log(level, msg);
}

/**
 * This is were you load up blocks/items
 * 
 * @param event
 */
@PreInit
public void preInit(FMLPreInitializationEvent event) {

	log(Level.INFO, "PreInitializing " + Reference.MOD_ID + " version: " + meta.version);

	LocalizationHandler.loadLanguages();

	// Initialize the configuration
	ConfigurationHandler.init(new File(event.getModConfigurationDirectory().getAbsolutePath() + File.separator
			+ Reference.CHANNEL_NAME + File.separator + Reference.MOD_ID + ".cfg"));

	ModBlocks.init();
	ModItems.init();
	ModContent.init();

	GameRegistry.registerWorldGenerator(genManager);

	NetworkRegistry.instance().registerGuiHandler(this, proxy);
}

@Init
public void init(FMLInitializationEvent event) {

	log(Level.INFO, "Initializing " + Reference.MOD_ID + " version: " + meta.version);

	proxy.registerTileEntities();

	proxy.initRenderingAndTextures();



	/*if (!useUeVoltageSensitivity) {
            UniversalElectricity.isVoltageSensitive = true;
           //EELogger.finest("Successfully toggled Voltage Sensitivity!");
        }*/

	UniversalElectricity.isNetworkActive = true;

	DimensionManager.registerProviderType(DimensionIds.TERRA, WorldProviderTerra.class, false);
	DimensionManager.registerDimension(DimensionIds.TERRA, DimensionIds.TERRA);
}

@PostInit
public void postInit(FMLPostInitializationEvent event) {

	log(Level.INFO, "PostInitializing " + Reference.MOD_ID + " version: " + meta.version);
}
}

Link to comment
Share on other sites

oh i know, you are doing a !world.isRemote before you open your gui but getServerElemetn doesnt return anything for ControllerPC so it doesnt send the message to the client to open the gui, just remove the !world.isRemote

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

like i said, its becasue getServerElement doesnt return anything so it never send the message to the client to open the gui, your other 2 gui have containers so once the container is opened the server send the message to the client to open X gui

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

like i said, its becasue getServerElement doesnt return anything so it never send the message to the client to open the gui, your other 2 gui have containers so once the container is opened the server send the message to the client to open X gui

Ah so basicly if my gui doesn't have a container don't use world.isRemote around the player.openGui.

 

Thanks for your help!

Link to comment
Share on other sites

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.