Vswe's Summer Courses | You're not logged in. Sign up or log in | Server time: | Donate
One can now see other persons' badge hunts. Simply head over to their profiles to access them.

Go back to course page

Climbing the interface ladder

From basic graphical interfaces to very advanced ones

removing a slot

  • 2013-08-15 12:49:47
    in my mod i have 3 different gui textures, under different events i wanne change gui, but with changing gui i also need to change slots, is it possable to not render a slot so a second slot can be rendered on the same space but 2 pixels off?
  • 2013-08-15 21:58:34
    You will have to do two things to make dynamic slots. Modify the slot itself and modify the textures. For the textures to work you can't have static textures, you'll have to have dynamically rendered slots (i.e. you render the slot's box on top of the interface).

    The way I do it (in Steve's Carts 2) is to create my own type of slot, a dynamic one. It is of course extending the normal one. Then the interface renders all of these slots by simply drawing the the texture at their current location. Modifying their current location will therefore do both things: move the slot itself as well as its texture.

    Removing slots is quite tricky, maybe even impossible. I know I've tried to do it in the past but I can't remember exactly why I dropped the idea, something didn't work properly. However, in your scenario I would simply move the existing slot, no need to remove it. Just set it up so you can modify its position properly, it's not that tricky (and with the texture thingy I mentioned earlier you don't have to bother about the textures themselves).

    However, if you really want to remove a slot or rather remove it for the user I am using a trick that simulates that the slot is being removed. Like I said, when I tried it in the past I didn't manage to actually remove the slots properly. The trick however is to do three things.

    1. Don't render the texture.
    2. Move the slot very far away, outside the screen.
    3. Disable all interaction with it.

    Maybe not the best way and maybe not even the best possible way. But this is how I do it and it works. Setting up a dynamic slot class that has setVisibility method that does this for you of course allows you to write it once and then you'll never have to bother about it. This is the reason why I can't say for sure that there's no better way of removing a slot: I wrote a solution in the past, and now I can just rely on that solution without actually knowing what it does.

    But like I said, moving a slot should be good enough for your purpose.
  • 2013-08-16 10:31:03
    With rendering slot i meant not showing the glowing squire and not showing the items but your answer still aplies, thank you for your big, very precise answer :D
  • 2013-08-19 17:22:44
    i did that now, but it seems it doesnt update (i think) is there a way to let it update?
  • 2013-08-19 17:41:32
    Container:
    http://pastebin.com/WVzesP7F

    Gui:
    http://pastebin.com/atWVgxey
  • 2013-08-19 23:49:26
    In the code you've posted there's nothing using the type whatsoever.
  • 2013-08-20 07:09:20
    Its about moving the slot right, im confused now
  • 2013-08-20 09:08:18
    There's nothing in your code doing anything to move the slot.
  • 2013-08-20 09:11:12
    Oh derp, i moved that to the packethandler
  • 2013-08-20 09:51:45
    shouldn't slots and textures be created and drawn in Container and Gui?
  • 2013-08-20 10:05:12
    im only moving it there,it is already created
  • 2013-08-20 10:07:52
    eh what, now i am confused, i did only send 1/4 container, new one:

    http://pastebin.com/dqAY4egX
  • 2013-08-20 10:25:35
    1. Why are the update method and the arrays static?

    2. You're not synchronizing the update to the client.
  • 2013-08-20 10:33:29
    array is static because it gets called in update method (otherwise i get an error (ive a little lack of static (sometimes it is needed sometime not))) and update because it gets called from the packethandler

    packethandler:

    http://pastebin.com/PMRYnUFC
  • 2013-08-20 10:50:46
    I don't need to see that file.

    1. The arrays and the update method shouldn't be static.

    2. The data should be synchronized to the client.
  • 2013-08-20 11:12:18
    im lost, this is how it should be right?:

    the client player press a button, that should be send to the server, the server should handle the slots move and then send it back to all the player that are currently in the GUi?
  • 2013-08-20 11:28:52
    is this more like it?

    container:
    http://pastebin.com/uVu6su3n

    gui:
    http://pastebin.com/P5Rqstjq
  • 2013-08-20 12:05:08
    you don't have to let the server handle slot movement.
  • 2013-08-20 12:26:19
    ok, ignore my previous post. what i mean is you should send a packet to the server when a player clicked the button and update the information in your tile entity. then you update your slot in your container.
  • 2013-08-20 12:32:36
    *update your slot in your container from the information from tile entity with addCraftingToCrafters(ICrafting player), updateProgressBar(int id, int value) and detectAndSendChanges()

    synchronizing data between client and server can be very confusing for interfaces. i took like 4 hours per exercise for this course but i learned a lot. i recommend you try the exercises before doing more advance stuff if you haven't :P
  • 2013-08-20 12:54:51
    im doing this right? the only difference is that i dont do it trought the tileentity, where is that needed for?
  • Log in or sign up to reply to this thread