Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2]Guihandler never called after call player.openGui


tt36999
 Share

Recommended Posts

I'm working for my mod,and when i want to make a gui to my block i got this problem.

When i right my block , onBlockActived method was run without any error.but my gui handler never called

this is main file

    @Mod.Instance
    public static BrewingCraft instance; 

	@Mod.EventHandler
    public void init(FMLInitializationEvent event) {
        proxy.onInit(event);
    }

this is commonproxy(some potion,player event code in this file,i think it's no need to show them)

	@Override
    public void onInit(FMLInitializationEvent event) {
        NetworkRegistry.INSTANCE.registerGuiHandler(BrewingCraft.instance, new BRCGuiHandler());
    }

here is GuiHandler

public class BRCGuiHandler implements IGuiHandler {
    @Nullable
    @Override
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        BrewingCraft.logger.info("Get server con " + ID);//never show in colsole
        switch (ID) {
            case 0:
                return new ContainerTestBlock(player.inventory, (TileEntityFluidContainer) world.getTileEntity(new BlockPos(x, y, z)));
        }
        BrewingCraft.logger.warn("[Warning] Can not get server gui container with id is " + ID);
        return null;
    }

    @Nullable
    @Override
    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        BrewingCraft.logger.info("Get client gui " + ID);//never show in colsole
        switch (ID) {
            case 0:
                return new GuiTestFluidContainer((ContainerBRC) getServerGuiElement(ID, player, world, x, y, z), player.inventory);
        }
        BrewingCraft.logger.warn("[Warning] Can not get client gui object with id is " + ID);
        return null;
    }

this is my block onBlockActive method

@Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
        final IFluidHandler fluidHandler = getFluidHandler(worldIn, pos);
        if (fluidHandler != null) {
            ItemStack heldItem = playerIn.getHeldItem(hand);
            if (!CapabilityUtils.hasCapability(heldItem, CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
                if (!worldIn.isRemote) {
                    if (hasGui()) {
                        BrewingCraft.logger.info("Open Gui " + getGui().getId());//this code line show text in colsole
                        //BrewingCraft.openGui(playerIn, getGui(), worldIn, pos.getX(), pos.getY(), pos.getZ());//forget this is just a test code
                        playerIn.openGui(BrewingCraft.instance, getGui().getId(), worldIn, pos.getX(), pos.getY(), pos.getZ());
                    } else {
                        IFluidTankProperties[] properties = fluidHandler.getTankProperties();
                        StringBuilder builder = new StringBuilder();
                        for (IFluidTankProperties tankProperties : properties)
                            builder.append(tankProperties.getContents().getLocalizedName() + ":" + tankProperties.getContents().amount + "/" + tankProperties.getCapacity());
                        playerIn.sendStatusMessage(new TextComponentString(builder.toString()), false);
                    }
                }
                return true;
            }
            FluidUtil.interactWithFluidHandler(playerIn, hand, fluidHandler);
            return FluidUtil.getFluidHandler(playerIn.getHeldItem(hand)) != null;
        }
        return false;
    }

any one know how to fix this?maybe i make some mistake in my code

Edited by diesieben07
syntax highlighting
Link to comment
Share on other sites

10 hours ago, tt36999 said:

this is commonproxy

CommonProxy makes no sense. Proxies exist to separate sided-only code. If your code is common then it goes into your main mod file. In fact I am pretty sure that this is the root cause of your problem.

 

10 hours ago, tt36999 said:

builder.append(tankProperties.getContents().getLocalizedName() + ":" + tankProperties.getContents().amount + "/" + tankProperties.getCapacity());

You can't do this on a server. Translations are a client-side only thing.

Link to comment
Share on other sites

10 hours ago, V0idWa1k3r said:

CommonProxy makes no sense. Proxies exist to separate sided-only code. If your code is common then it goes into your main mod file. In fact I am pretty sure that this is the root cause of your problem

OK,I just don't like write all my code in main file , ClientProxy was extends from CommonProxy, I has a ServerProxy too, if one side need different code , i just override it from CommonProxy

 

10 hours ago, V0idWa1k3r said:

You can't do this on a server. Translations are a client-side only thing.

I removed it, and do this in client

Link to comment
Share on other sites

12 minutes ago, tt36999 said:

OK,I just don't like write all my code in main file

Then have it anywhere else, just don't have a CommonProxy.

 

12 minutes ago, tt36999 said:

ClientProxy was extends from CommonProxy, I has a ServerProxy too, if one side need different code , i just override it from CommonProxy

You don't understand my issue here. It's not that having a common ancestral class is a bad thing, it's that the whole concept of a CommonProxy makes no sense whatsoever. It's bad coding practice. A proxy can't be common by definition of what a proxy is. It's like if the String class in Java derived from a Number class. Technically a string is a bunch of chars which are just unsigned shorts which are numbers and technically there may be nothing wrong with the implementation but it makes no sense. A String isn't a Number. A proxy can't be common. 

And I think the fact that you even have something being done in a common proxy is the whole reason you are having this issue. If you didn't have a common proxy you would not put any code in it and thus you wouldn't have any issues.

Edited by V0idWa1k3r
Link to comment
Share on other sites

28 minutes ago, V0idWa1k3r said:

You don't understand my issue here. It's not that having a common ancestral class is a bad thing, it's that the whole concept of a CommonProxy makes no sense whatsoever. It's bad coding practice. A proxy can't be common by definition of what a proxy is. It's like if the String class in Java derived from a Number class. Technically a string is a bunch of chars which are just unsigned shorts which are numbers and technically there may be nothing wrong with the implementation but it makes no sense. A String isn't a Number. A proxy can't be common. 

And I think the fact that you even have something being done in a common proxy is the whole reason you are having this issue. If you didn't have a common proxy you would not put any code in it and thus you wouldn't have any issues.

I don't think is no sense, in my mod most situation client need more code than server, and server proxy even hasn't any code then common. so i just make common to do what serverproxy do, and client extened it , so i can override it.

for example if someone write code in proxy to getServerGuiElement and getClientGuiElement(i won't do that , just for example)

in common it can return a container for server , and in clientproxy it can use common get container and return gui element.

client proxy will become an extension of common, and sometime will different from common

Link to comment
Share on other sites

4 minutes ago, tt36999 said:

server proxy even hasn't any code then common. so i just make common to do what serverproxy do, and client extened it

This makes no sense. Again - server proxy does server-side only stuff. The things that would crash the client. Like accessing the DedicatedServer class which is marked as @SideOnly(Side.SERVER). You can't make a common proxy do what a server proxy does, that would crash the client, similar to how registering a model would crash a server. If your code doesn't crash either the server or the client then it's common code and it goes anywhere else but your proxy. Again - proxies are side-specific classes. There can't be a common proxy because there is no common side. You are either on the client or on the server.

 

6 minutes ago, tt36999 said:

so i can override it.

You don't need a common ancestral class to use override. An interface does the job just fine and is in fact a preferred method of using a proxy.

 

7 minutes ago, tt36999 said:

or example if someone write code in proxy to getServerGuiElement and getClientGuiElement(i won't do that , just for example)

in common it can return a container for server , and in clientproxy it can use common get container and return gui element.

Just... no. IGuiHandler exists for a reason, and your proxy isn't one of them. Proxies are for separating PHYSICAL sides. IGuiHandler separates the thing needed to have a GUI/Container pair on the LOGICAL sides. There is a huge difference.

 

8 minutes ago, tt36999 said:

client proxy will become an extension of common, and sometime will different from common

Then your server must also become an extension of the common by the same logic, because you need to run that common code on both physical sides, right? Then why use the proxy in the first place? It is exactly the one thing proxies were made not to do. If your code must be ran on both sides run it in any other class that has nothing to do with proxies.

Link to comment
Share on other sites

Like @V0idWa1k3r said, the issue is most likely with your proxies. I am guessing you are overriding onInit in client and server proxy without calling super. Note: The fix is not to call super, it is to do what @V0idWa1k3r explained.

 

For the future: Please select the correct syntax highlighting option when posting code or preferably a code-hosting site such as Github.

And printing stuff to the console for debugging is a technique from 1985. You are programming Java, which has one of the best debugger interfaces out there. Hopefully you are using an IDE (such as IntelliJ or Eclipse), which takes advantage of this interface. Use the damn debugger! You are not writing a BASIC program for the Commodore 64.

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.

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Tried, still crashes with mods and no resourcepacks  
    • Ah, I'm dumb. Made a topic when explicitly told not to on the banner above. My bad.
    • 2021-10-28 15:22:50,623 WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream 2021-10-28 15:22:50,624 WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream [15:22:50] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLTweaker [15:22:50] [main/INFO] [LaunchWrapper]: Using primary tweak class name net.minecraftforge.fml.common.launcher.FMLTweaker [15:22:50] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLTweaker [15:22:50] [main/INFO] [FML]: Forge Mod Loader version 11.15.1.2318 for Minecraft 1.8.9 loading [15:22:50] [main/INFO] [FML]: Java is Java HotSpot(TM) 64-Bit Server VM, version 1.8.0_51, running on Windows 10:amd64:10.0, installed at C:\Users\silic\AppData\Roaming\.tlauncher\mojang_jre\jre-legacy\windows-x64\jre-legacy [15:22:50] [main/FATAL] [FML]: There appear to be jars extracted into the mods directory. This is VERY BAD and will almost NEVER WORK WELL [15:22:50] [main/FATAL] [FML]: You should place original jars only in the mods directory. NEVER extract them to the mods directory. [15:22:50] [main/FATAL] [FML]: The directories below appear to be extracted jar files. Fix this before you continue. [15:22:50] [main/FATAL] [FML]: Directory 1.17 contains [MANIFEST.MF] 2021-10-28 15:22:50,748 WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream 2021-10-28 15:22:50,759 WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream 2021-10-28 15:22:50,759 WARN Unable to instantiate org.fusesource.jansi.WindowsAnsiOutputStream [15:22:50] [main/ERROR] : Could not save crash report to C:\Users\silic\AppData\Roaming\.minecraft\crash-reports\fml-crash-2021-10-28_15:22:50.txt java.io.FileNotFoundException: C:\Users\silic\AppData\Roaming\.minecraft\crash-reports\fml-crash-2021-10-28_15:22:50.txt (The filename, directory name, or volume label syntax is incorrect)     at java.io.FileOutputStream.open0(Native Method) ~[?:1.8.0_51]     at java.io.FileOutputStream.open(FileOutputStream.java:270) ~[?:1.8.0_51]     at java.io.FileOutputStream.<init>(FileOutputStream.java:213) ~[?:1.8.0_51]     at java.io.FileOutputStream.<init>(FileOutputStream.java:162) ~[?:1.8.0_51]     at java.io.FileWriter.<init>(FileWriter.java:90) ~[?:1.8.0_51]     at b.a(SourceFile:227) [b.class:?]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_51]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_51]     at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_51]     at net.minecraftforge.fml.relauncher.CoreModManager.discoverCoreMods(CoreModManager.java:305) [forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.relauncher.CoreModManager.handleLaunch(CoreModManager.java:246) [forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.relauncher.FMLLaunchHandler.setupHome(FMLLaunchHandler.java:95) [forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.relauncher.FMLLaunchHandler.setupClient(FMLLaunchHandler.java:72) [forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.relauncher.FMLLaunchHandler.configureForClientLaunch(FMLLaunchHandler.java:34) [forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.common.launcher.FMLTweaker.injectIntoClassLoader(FMLTweaker.java:119) [forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraft.launchwrapper.Launch.launch(Launch.java:115) [launchwrapper-1.12.jar:?]     at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] [15:22:50] [main/INFO] [STDOUT]: [net.minecraftforge.fml.relauncher.CoreModManager:discoverCoreMods:306]: #@!@# FML has crashed the game deliberately. Crash report saved to: #@!@# C:\Users\silic\AppData\Roaming\.minecraft\crash-reports\fml-crash-2021-10-28_15:22:50.txt [15:22:50] [main/INFO] [STDERR]: [net.minecraftforge.fml.relauncher.FMLLaunchHandler:setupHome:99]: java.lang.RuntimeException: Extracted mod jars found, loading will NOT continue [15:22:50] [main/INFO] [STDERR]: [net.minecraftforge.fml.relauncher.FMLLaunchHandler:setupHome:99]:     at net.minecraftforge.fml.relauncher.CoreModManager.discoverCoreMods(CoreModManager.java:298) [15:22:50] [main/INFO] [STDERR]: [net.minecraftforge.fml.relauncher.FMLLaunchHandler:setupHome:99]:     at net.minecraftforge.fml.relauncher.CoreModManager.handleLaunch(CoreModManager.java:246) [15:22:50] [main/INFO] [STDERR]: [net.minecraftforge.fml.relauncher.FMLLaunchHandler:setupHome:99]:     at net.minecraftforge.fml.relauncher.FMLLaunchHandler.setupHome(FMLLaunchHandler.java:95) [15:22:50] [main/INFO] [STDERR]: [net.minecraftforge.fml.relauncher.FMLLaunchHandler:setupHome:99]:     at net.minecraftforge.fml.relauncher.FMLLaunchHandler.setupClient(FMLLaunchHandler.java:72) [15:22:50] [main/INFO] [STDERR]: [net.minecraftforge.fml.relauncher.FMLLaunchHandler:setupHome:99]:     at net.minecraftforge.fml.relauncher.FMLLaunchHandler.configureForClientLaunch(FMLLaunchHandler.java:34) [15:22:50] [main/INFO] [STDERR]: [net.minecraftforge.fml.relauncher.FMLLaunchHandler:setupHome:99]:     at net.minecraftforge.fml.common.launcher.FMLTweaker.injectIntoClassLoader(FMLTweaker.java:119) [15:22:50] [main/INFO] [STDERR]: [net.minecraftforge.fml.relauncher.FMLLaunchHandler:setupHome:99]:     at net.minecraft.launchwrapper.Launch.launch(Launch.java:115) [15:22:50] [main/INFO] [STDERR]: [net.minecraftforge.fml.relauncher.FMLLaunchHandler:setupHome:99]:     at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [15:22:50] [main/ERROR] [FML]: An error occurred trying to configure the minecraft home at C:\Users\silic\AppData\Roaming\.minecraft for Forge Mod Loader java.lang.RuntimeException: Extracted mod jars found, loading will NOT continue     at net.minecraftforge.fml.relauncher.CoreModManager.discoverCoreMods(CoreModManager.java:298) ~[forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.relauncher.CoreModManager.handleLaunch(CoreModManager.java:246) ~[forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.relauncher.FMLLaunchHandler.setupHome(FMLLaunchHandler.java:95) [forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.relauncher.FMLLaunchHandler.setupClient(FMLLaunchHandler.java:72) [forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.relauncher.FMLLaunchHandler.configureForClientLaunch(FMLLaunchHandler.java:34) [forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.common.launcher.FMLTweaker.injectIntoClassLoader(FMLTweaker.java:119) [forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraft.launchwrapper.Launch.launch(Launch.java:115) [launchwrapper-1.12.jar:?]     at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] [15:22:50] [main/ERROR] [LaunchWrapper]: Unable to launch java.lang.RuntimeException: Extracted mod jars found, loading will NOT continue     at net.minecraftforge.fml.relauncher.CoreModManager.discoverCoreMods(CoreModManager.java:298) ~[forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.relauncher.CoreModManager.handleLaunch(CoreModManager.java:246) ~[forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.relauncher.FMLLaunchHandler.setupHome(FMLLaunchHandler.java:95) ~[forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.relauncher.FMLLaunchHandler.setupClient(FMLLaunchHandler.java:72) ~[forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.relauncher.FMLLaunchHandler.configureForClientLaunch(FMLLaunchHandler.java:34) ~[forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraftforge.fml.common.launcher.FMLTweaker.injectIntoClassLoader(FMLTweaker.java:119) ~[forge-1.8.9-11.15.1.2318-1.8.9.jar:?]     at net.minecraft.launchwrapper.Launch.launch(Launch.java:115) [launchwrapper-1.12.jar:?]     at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] Exception in thread "main" [15:22:50] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: net.minecraftforge.fml.relauncher.FMLSecurityManager$ExitTrappedException [15:22:50] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]:     at net.minecraftforge.fml.relauncher.FMLSecurityManager.checkPermission(FMLSecurityManager.java:30) [15:22:50] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]:     at java.lang.SecurityManager.checkExit(SecurityManager.java:761) [15:22:50] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]:     at java.lang.Runtime.exit(Runtime.java:107) [15:22:50] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]:     at java.lang.System.exit(System.java:971) [15:22:50] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]:     at net.minecraft.launchwrapper.Launch.launch(Launch.java:138) [15:22:50] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]:     at net.minecraft.launchwrapper.Launch.main(Launch.java:28)  
    • fdjshfmiysdfhpuiosd
    • These libraries failed to download. try again.   commons-io:commons-io:2.4  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.