Jump to content

[Solved]elementClicked not being called


FredTargaryen
 Share

Recommended Posts

Since I started porting to 1.8 the GuiSlot I created doesn't seem to react to mouse input. What do I need to change for this to start working again?

 

Code if needed:

 

 

    @SideOnly(Side.CLIENT)
    class PlaceList extends GuiSlot
    {
        private final java.util.List l = Lists.newArrayList();
        private static final String __OBFID = "CL_00000699";

        public PlaceList()
        {
            super(GuiTeleport.this.mc, GuiTeleport.this.width, GuiTeleport.this.height, 32, GuiTeleport.this.height - 65 + 4, 18);
            this.setShowSelectionBox(true);
        }

        protected int getSize()
        {
            return GuiTeleport.this.placenamelist.size();
        }

        /**
         * The element in the slot that was clicked, boolean for whether it was double clicked or not
         */
        protected void elementClicked(int id, boolean p_148144_2_, int p_148144_3_, int p_148144_4_)
        {
            GuiTeleport.this.idSelected = id;
            GuiTeleport.this.goBtn.enabled = GuiTeleport.this.enabledlist.get(GuiTeleport.this.idSelected);
        }

        /**
         * Returns true if the element passed in is currently selected
         */
        protected boolean isSelected(int p_148131_1_)
        {
            return p_148131_1_ == GuiTeleport.this.idSelected && GuiTeleport.this.enabledlist.get(idSelected);
        }

        /**
         * Return the height of the content being scrolled
         */
        @Override
        protected int getContentHeight()
        {
            return this.getSize() * 18;
        }

        @Override
        protected void drawBackground(){}

        @Override
        protected void drawSlot(int id, int p_148126_2_, int p_148126_3_, int p_148126_4_, int p_148126_6_, int p_148126_7_)
        {
            GuiTeleport.this.drawCenteredString(GuiTeleport.this.fontRendererObj, GuiTeleport.this.placenamelist.get(id), this.width / 2, p_148126_3_ + 1, GuiTeleport.this.enabledlist.get(id) ? 65280 : 16711680);
        }

        @Override
        public void drawScreen(int i, int j, float f)
        {
            super.drawScreen(i, j, f);
            this.flooverlayBackground(0, this.top, 255, 255);
            this.flooverlayBackground(this.bottom, this.height, 255, 255);
        }
        /**
         * Overlays the background to hide scrolled items
         */
        private void flooverlayBackground(int p_148136_1_, int p_148136_2_, int p_148136_3_, int p_148136_4_)
        {
            WorldRenderer wr = Tessellator.getInstance().getWorldRenderer();
            GuiTeleport.this.mc.getTextureManager().bindTexture(DataReference.TP_BACKGROUND);
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            float f = 32.0F;
            wr.startDrawingQuads();
            wr.addVertexWithUV((double)this.left, (double)p_148136_2_, 0.0D, 0.0D, (double)((float)p_148136_2_ / f));
            wr.addVertexWithUV((double)(this.left + this.width), (double)p_148136_2_, 0.0D, (double)((float)this.width / f), (double)((float)p_148136_2_ / f));
            wr.addVertexWithUV((double)(this.left + this.width), (double)p_148136_1_, 0.0D, (double)((float)this.width / f), (double)((float)p_148136_1_ / f));
            wr.addVertexWithUV((double)this.left, (double)p_148136_1_, 0.0D, 0.0D, (double)((float)p_148136_1_ / f));
            Tessellator.getInstance().draw();
        }

        @Override
        protected void drawContainerBackground(Tessellator tessellator)
        {
        }
    }

 

 

 

Thank you for reading.

Link to comment
Share on other sites

Show the Gui code containing the PlaceList.

Sure.

 

 

@SideOnly(Side.CLIENT)
public class GuiTeleport extends GuiScreen
{
    /** The title string that is displayed in the top-centre of the screen. */
    protected String screenTitle = "===Choose a destination===";
    private String status;

    //"Go!".
    private GuiButton goBtn;
    //"Cancel"
    private GuiButton cancelBtn;
    
    private List<String> placenamelist = new ArrayList<String>();
private List<Integer> xcoordlist = new ArrayList<Integer>();
private List<Integer> ycoordlist = new ArrayList<Integer>();
private List<Integer> zcoordlist = new ArrayList<Integer>();
private List<Boolean> enabledlist = new ArrayList<Boolean>();

private boolean receivedLists;

    private PlaceList scrollWindow;
    
private int initX, initY, initZ, idSelected;

    public GuiTeleport(int x, int y, int z)
    {
    	this.initX = x;
    	this.initY = y;
    	this.initZ = z;
        this.idSelected = 0;
        this.refresh();
    }
    
    /**
     * Adds the buttons (and other controls) to the screen in question.
     */
    public void initGui()
    {
        this.buttonList.clear();
        Keyboard.enableRepeatEvents(true);
        GuiButton refreshButton = new GuiButton(-2, this.width - 100, 0, 98, 20, "Refresh");
        refreshButton.enabled = false;
        this.buttonList.add(this.goBtn = new GuiButton(-3, this.width / 2 - 100, this.height / 4 + 144, 98, 20, "Go!"));
        this.goBtn.enabled = false;
        this.buttonList.add(this.cancelBtn = new GuiButton(-1, this.width / 2 + 2, this.height / 4 + 144, 98, 20, "Cancel"));
        if (receivedLists)
        {
            refreshButton.enabled = true;
            this.scrollWindow = new PlaceList();
            this.scrollWindow.setEnabled(true);
        }
        this.buttonList.add(refreshButton);
    }

    /**
     * Called when the screen is unloaded. Used to disable keyboard repeat events
     */
    public void onGuiClosed()
    {
        ClientProxy proxy = (ClientProxy) FloocraftBase.proxy;
        Keyboard.enableRepeatEvents(false);
        proxy.overrideTicker.start();
    }

    /**
     * Called from the main game loop to update the screen.
     */
    public void updateScreen()
    {
        super.updateScreen();
        if (!this.receivedLists)
        {
            this.status = "Loading...";
        }
        else //if the lists were received...
        {
            //if they are empty...
            if (this.placenamelist.size() == 0) {
                this.status = "No places found";
            } else {
                this.status = "";
            }
        }
    }

    /**
     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
     */
    protected void actionPerformed(GuiButton par1GuiButton)
    {
        if (par1GuiButton.enabled)
        {
            //Cancel
            if (par1GuiButton.id == -1)
            {
                ((ClientProxy) FloocraftBase.proxy).overrideTicker.start();
                this.mc.displayGuiScreen(null);
            }
            //Refresh
            else if(par1GuiButton.id == -2)
            {
            	this.refresh();
            }
            //Go!
            else if(par1GuiButton.id == -3)
            {
                int initX = this.initX;
                int initY = this.initY;
                int initZ = this.initZ;
                int destX = xcoordlist.get(this.idSelected);
                int destY = ycoordlist.get(this.idSelected);
                int destZ = zcoordlist.get(this.idSelected);
                try
                {
                    if(!(initX == destX && initY == destY && initZ == destZ))
                    {
                        MessageTeleportEntity m = new MessageTeleportEntity();
                        m.initX = initX;
                        m.initY = initY;
                        m.initZ = initZ;
                        m.destX = destX;
                        m.destY = destY;
                        m.destZ = destZ;
                        PacketHandler.INSTANCE.sendToServer(m);
                    }
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
                this.actionPerformed(GuiTeleport.this.cancelBtn);
            }
        }
    }

    /**
     * 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.actionPerformed(this.cancelBtn);
        }
    }

    /**
     * Draws the screen and all the components in it.
     */
    @Override
    @SideOnly(Side.CLIENT)
    public void drawScreen(int par1, int par2, float par3)
    {
        this.drawCenteredString(this.fontRendererObj,
                this.status,
                this.width / 2,
                this.height / 4 + 48,
                13158600);
        GL11.glPushMatrix();
        GL11.glTranslatef((float) (this.width / 2), 0.0F, 50.0F);
        float f1 = 93.75F;
        GL11.glScalef(-f1, -f1, -f1);
        GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
        GL11.glPopMatrix();
        if (this.scrollWindow != null) {
            this.scrollWindow.drawScreen(par1, par2, par3);
        }
        this.drawCenteredString(this.fontRendererObj,
                this.screenTitle,
                this.width / 2,
                15,
                16777215);
        super.drawScreen(par1, par2, par3);
    }
    
    private void refresh()
    {
    	this.placenamelist.clear();
    	this.xcoordlist.clear();
    	this.ycoordlist.clear();
    	this.zcoordlist.clear();
    	this.enabledlist.clear();
    	this.receivedLists = false;
    	this.initGui();
        PacketHandler.INSTANCE.sendToServer(new MessageFireplaceListRequest());
    }
    
    public void onMessageReceived(MessageFireplaceList m)
    {
        try
	{
        	this.placenamelist = m.placenamelist;
        	this.xcoordlist = m.xcoordlist;
        	this.ycoordlist = m.ycoordlist;
        	this.zcoordlist = m.zcoordlist;
        	this.enabledlist = m.enabledlist;
		this.receivedLists = true;
	}
	catch(Exception ex)
	{
		ex.printStackTrace();
	}
        this.initGui();
    }
    
    /**
     * Returns true if this GUI should pause the game when it is displayed in single-player
     */
    @Override
    public boolean doesGuiPauseGame()
    {
        return false;
    }

 

 

Link to comment
Share on other sites

Solved!

I needed this:

@Override
    public void handleMouseInput()
    {
        try
        {
            this.scrollWindow.handleMouseInput();
            super.handleMouseInput();
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • It works on mi local world but not in the server.  C:\Users\Giuliano\Desktop\Server>REM Forge requires a configured set of both JVM and program arguments. C:\Users\Giuliano\Desktop\Server>REM Add custom JVM arguments to the user_jvm_args.txt C:\Users\Giuliano\Desktop\Server>REM Add custom program arguments {such as nogui} to this file in the next line before the  or C:\Users\Giuliano\Desktop\Server>REM  pass them to this script directly C:\Users\Giuliano\Desktop\Server>java @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.18.2-40.2.0/win_args.txt 2023-02-02 12:34:29,948 main WARN Advanced terminal features are not available in this environment [12:34:30] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--launchTarget, forgeserver, --fml.forgeVersion, 40.2.0, --fml.mcVersion, 1.18.2, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20220404.173914] [12:34:30] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 9.1.3+9.1.3+main.9b69c82a starting: java version 19.0.2 by Oracle Corporation [12:34:30] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/Giuliano/Desktop/Server/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%2314!/ Service=ModLauncher Env=SERVER [12:34:30] [main/WARN] [ne.mi.fm.lo.mo.ModFileParser/LOADING]: Mod file C:\Users\Giuliano\Desktop\Server\libraries\net\minecraftforge\fmlcore\1.18.2-40.2.0\fmlcore-1.18.2-40.2.0.jar is missing mods.toml file [12:34:30] [main/WARN] [ne.mi.fm.lo.mo.ModFileParser/LOADING]: Mod file C:\Users\Giuliano\Desktop\Server\libraries\net\minecraftforge\javafmllanguage\1.18.2-40.2.0\javafmllanguage-1.18.2-40.2.0.jar is missing mods.toml file [12:34:30] [main/WARN] [ne.mi.fm.lo.mo.ModFileParser/LOADING]: Mod file C:\Users\Giuliano\Desktop\Server\libraries\net\minecraftforge\lowcodelanguage\1.18.2-40.2.0\lowcodelanguage-1.18.2-40.2.0.jar is missing mods.toml file [12:34:30] [main/WARN] [ne.mi.fm.lo.mo.ModFileParser/LOADING]: Mod file C:\Users\Giuliano\Desktop\Server\libraries\net\minecraftforge\mclanguage\1.18.2-40.2.0\mclanguage-1.18.2-40.2.0.jar is missing mods.toml file [12:34:30] [main/INFO] [ne.mi.fm.lo.mo.JarInJarDependencyLocator/]: No dependencies to load found. Skipping! [12:34:31] [main/INFO] [mixin/]: Compatibility level set to JAVA_17 [12:34:31] [main/INFO] [cp.mo.mo.LaunchServiceHandler/MODLAUNCHER]: Launching target 'forgeserver' with arguments [] [12:34:32] [main/WARN] [mixin/]: Error loading class: java/lang/Boolean (java.lang.IllegalArgumentException: Unsupported class file major version 63) Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:39)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.Launcher.run(Launcher.java:106)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.Launcher.main(Launcher.java:77)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23)         at cpw.mods.bootstraplauncher@1.0.0/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) Caused by: java.lang.reflect.InvocationTargetException         at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)         at java.base/java.lang.reflect.Method.invoke(Method.java:578)         at MC-BOOTSTRAP/fmlloader@1.18.2-40.2.0/net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:32)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)         ... 7 more Caused by: org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError: An unexpected critical error was encountered         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:392)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClass(MixinTransformer.java:250)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.service.modlauncher.MixinTransformationHandler.processClass(MixinTransformationHandler.java:131)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.launch.MixinLaunchPluginLegacy.processClass(MixinLaunchPluginLegacy.java:131)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.serviceapi.ILaunchPluginService.processClassWithFlags(ILaunchPluginService.java:156)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.LaunchPluginHandler.offerClassNodeToPlugins(LaunchPluginHandler.java:88)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.ClassTransformer.transform(ClassTransformer.java:120)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.TransformingClassLoader.maybeTransformClassBytes(TransformingClassLoader.java:50)         at cpw.mods.securejarhandler@1.0.3/cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:110)         at cpw.mods.securejarhandler@1.0.3/cpw.mods.cl.ModuleClassLoader.lambda$findClass$16(ModuleClassLoader.java:216)         at cpw.mods.securejarhandler@1.0.3/cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:226)         at cpw.mods.securejarhandler@1.0.3/cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:216)         at cpw.mods.securejarhandler@1.0.3/cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:132)         at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)         at TRANSFORMER/forge@40.2.0/net.minecraftforge.registries.GameData.init(GameData.java:123)         at TRANSFORMER/forge@40.2.0/net.minecraftforge.registries.GameData.<clinit>(GameData.java:108)         at TRANSFORMER/minecraft@1.18.2/net.minecraft.core.Registry.forge(Registry.java:407)         at TRANSFORMER/minecraft@1.18.2/net.minecraft.core.Registry.forge(Registry.java:391)         at TRANSFORMER/minecraft@1.18.2/net.minecraft.core.Registry.<clinit>(Registry.java:170)         at TRANSFORMER/minecraft@1.18.2/net.minecraft.server.Bootstrap.m_135870_(Bootstrap.java:44)         at TRANSFORMER/minecraft@1.18.2/net.minecraft.server.Main.main(Main.java:109)         at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)         ... 10 more Caused by: org.spongepowered.asm.mixin.throwables.ClassMetadataNotFoundException: java.lang.Boolean         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.transformMethod(MixinPreProcessorStandard.java:754)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.transform(MixinPreProcessorStandard.java:739)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.attach(MixinPreProcessorStandard.java:310)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.createContextFor(MixinPreProcessorStandard.java:280)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinInfo.createContextFor(MixinInfo.java:1288)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.apply(MixinApplicatorStandard.java:292)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.TargetClassContext.apply(TargetClassContext.java:383)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.TargetClassContext.applyMixins(TargetClassContext.java:365)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:363)         ... 31 more C:\Users\Giuliano\Desktop\Server>pause Press any key to continue . . .
    • That most likely means that the data on the server is not being synced to the client properly. You'll probably need to override #getShareTag to send the capability data. Additionally, you probably should make sure the stack doesn't have the items stored in two different locations.
    • Generally, this would be the responsibility of the world carver, but there are ways to get around it. You could do something where you check if the entire placement area is within blocks and the opening to the cave is touching some other air block. In general though, you would need to program most of your logic from scratch since I don't believe Minecraft does anything like this itself. The closest I can recommend as an example would probably be the GeodeFeature, though I don't think that's gonna get you anywhere to close to what you would need.
    • If you haven't been testing with a new world each time, I would recommend doing so. Otherwise, it seems like there is a bunch of mod compatibility issues (e.g. waila, etc.) with some classes in certain mods not being found or located. You should also make sure there are no client-only mods on the server as well.
    • There seems to be a crash with flywheel and something else; could be mod or with your graphics drivers since I'm pretty sure there are some newer versions of the AMD drivers that do not work properly with Forge and mods.
  • Topics

×
×
  • Create New...

Important Information

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