Jump to content

Recommended Posts

Posted

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;
}

}

Posted

What do you mean by opening correctly?

 

Do you mean using this code?

  Quote
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.

Posted

what i mean is, if you println inside the drawScreen function, do you see those inside your logs ?

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

-hydroflame, author of the forge revolution-

Posted

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;
}

Posted

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);
}
}

Posted

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-

Posted

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-

Posted
  On 8/28/2013 at 6:24 PM, hydroflame said:

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!

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Start by following the docs to get a workspace setup: https://docs.minecraftforge.net/en/latest/gettingstarted/ Then poke around some of the tutorials, https://www.mcjty.eu/docs/1.20/ used to be the goto, but not sure if there are any updates for regular forge or not, but if you've brushed up on Java, it will be enough to get you started. Poke around the Minecraft and Forge sources to see how things are done. Read the FAQ for information on how to post code/logs when you run into issues. Share as much info on issues you have as possible. Use github to host projects, chances of someone helping are higher when they can actually see all your code and/or build it themselves. And finally, keep it on the forums, don't direct message people with questions, most people do not provide personal support like that. Also keep in mind forums posts are not always immediately answered, if you're looking for a quicker response, you can always try the Minecraft Forge discord server.
    • Hello, I have a Forge Minecraft sever (I host it at g-portal.com) which has always worked fine and I had no problems, but today it doesn't wanna work anymore. Today I started the server and the status said online, but after a few seconds it said this: "Start failed". And then out of nowhere it restarted itself and the same thing happened again and again and now it's in an infinite loop where it just keeps failing and then restarts. Here's the download link for the server logs: https://www.mediafire.com/file/sq30dgoonjevib1/2025-07-06-1.log/file Does anyone know how to fix this? If yes I would really appreciate help. Best wishes, Gabs1107
    • I'm experiencing a critical issue on a dedicated Arch Linux server running the latest Forge for Minecraft 1.20.1. When a player exits a Nether portal (not enters, and not via /tp) or teleports into the End via portal, the server completely freezes for 1–10 minutes. During this time, all commands are unresponsive, and the game world essentially locks up. This is with watchdog disabled. Environment: OS: Arch Linux (latest packages) Java: OpenJDK 17 (up to date) Forge Version: Latest 1.20.1 (tested multiple versions from the past ~3 months) Mods: None (issue occurs on a clean install) Server Type: Proxmox VM with: 4 virtual cores 64 GB RAM (63 GB allocated via -Xmx and -Xms flags) Observed Behavior: Observed Behavior: The server freezes for 1–10 minutes when: Exiting a Nether portal (entering does not trigger the issue) Entering or exiting the End using a portal Teleporting using commands (e.g., /tp) works only for the Nether; teleporting to the End via command also causes a freeze The issue occurs anywhere in the world, not tied to specific coordinates or builds During the freeze: The server becomes completely unresponsive to all commands and player actions No crash reports, no errors, and no warnings are logged CPU usage remains under 50%, and RAM usage stays around 6–14 GB After 1–10 minutes, the server recovers automatically and resumes normal operation
  • Topics

×
×
  • Create New...

Important Information

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