Jump to content

Recommended Posts

Posted

I'm learning how to code for Minecraft so I'm following tutorials and trying to understand every method. The code below is from http://modwiki.temporal-reality.com/mw/index.php/Main_Page

 

I noticed that the container is created twice in the methods, once server side and once client side. Is it supposed to be created twice or is it preferable to create it only once?  Line 19 creates a new TestContainer server side. Then line 30 creates another new TestContainer client side.

 

The author says you need both containers - one client and one server.  Why?  It is possible for me to pass the TestContainer created from the server method down to the client method and then only create one container.  Then the client gets the GUI and the server gets the container.

 

Both approaches (one or two containers) don't appear to cause any errors. Which is preferable? Is there a reason why you would want to create only one or to specifically create two containers?  I'm just trying to understand how the code works.

 

12 public class GuiProxy implements IGuiHandler { 
13 
14     @Override 
15     public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { 
16         BlockPos pos = new BlockPos(x, y, z); 
17         TileEntity te = world.getTileEntity(pos); 
18         if (te instanceof TestContainerTileEntity) { 
19             return new TestContainer(player.inventory, (TestContainerTileEntity) te); 
20         } 
21         return null; 
22     } 
23 
24     @Override 
25     public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { 
26         BlockPos pos = new BlockPos(x, y, z); 
27         TileEntity te = world.getTileEntity(pos); 
28         if (te instanceof TestContainerTileEntity) { 
29             TestContainerTileEntity containerTileEntity = (TestContainerTileEntity) te; 
30             return new TestContainerGui(containerTileEntity, new TestContainer(player.inventory, containerTileEntity)); 
31         } 
32         return null; 
33     }

 

Posted

The method's do not create the "same" thing.

 

First and formost:

The server only handles the Container. The container, is in essence, simply a list of boxes, and what they contain.

The client handles the GUI. This is where the boxes from the Container are drawn.  The client never touches the container directly. Anything you do inside a GUI, is sent to the server through packets. Think of it as a computer & screen. You interact with the screen, to change something in the computer. You don't manually open the harddrive and somehow magically set the correct state in the harddrive.

 

In the code you showed:

Line 19:

return new [b]TestContainer[/b](player.inventory, (TestContainerTileEntity) te); 

Line 30:

return new [b]TestContainerGui[/b](containerTileEntity, new TestContainer(player.inventory, containerTileEntity)); 

They return different things, if quite badly named, for the appropriate side.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted

Thanks, that's kind of my understanding as well - which is kind of why I ask the question.

 

Maybe I totally misunderstand the concepts but the TestContainerGui creates a "new" TestContainer as an argument.  So even though it only needs to return a GUI, it still goes through all the code to create an additional container.

 

The server code creates and returns a new TestContainer.  Then the Client code creates another new TestContainer as an argument that then gets passed to the TestContainerGui.  So all the code to create a TestContainer gets called twice by both methods.

 

Would it be better to output the TestContainer created by the server code and use it as the argument for the TestContainerGui rather than create a new container inside the TestContainerGui?  Or does it just not even matter?

 

I only noticed this because I put some tracers in the methods and I can see that all the TestContainer code gets called twice every time a new container is created - once by the server and then again by the client.

Posted

Here is what I mean.  I create a field to hold the TestContainer created by the server and pass it to the client to create the GUI.  This results in the TestContainer code only being called once.

 

Again this may not matter but I just want to make sure I understand what is happening and why.

 

public static TestContainer serverContainer;

 

    @Override

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

        BlockPos pos = new BlockPos(x, y, z);

        TileEntity te = world.getTileEntity(pos);

        if (te instanceof TestContainerTileEntity) {

        serverContainer = new TestContainer(player.inventory, (TestContainerTileEntity) te, world);

            return serverContainer;

        }

        return null;

    }

   

    @Override

    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

    BlockPos pos = new BlockPos(x, y, z);

        TileEntity te = world.getTileEntity(pos);

        if (te instanceof TestContainerTileEntity) {

            TestContainerTileEntity containerTileEntity = (TestContainerTileEntity) te;

            return new TestContainerGui((TestContainerTileEntity)te, serverContainer);

        }

        return null;

    }

Posted

Yes, because the GUI portion still needs to know what the slots are which is defined in the Container (the "server" half).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

You must remember that clients and servers can be on totally different physical places, you can't just let the server send an instance of the container to the client, they would only communicate through the network.

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

    • My parents made a big decision a few years ago they sold our longtime family home in Manhattan New York with the dream of starting a new chapter After decades in the city they wanted a quieter lifestyle with more space and the chance to build their dream home from the ground up They had their eyes on the neighboring state of Pennsylvania which offered more affordable land and a slower pace of life After selling the Manhattan home and an adjacent plot of land they were financially ready to make the move After some searching they found what looked like the perfect opportunity a piece of land listed for sale in the Poconos region of Pennsylvania The area was known for its scenic beauty peaceful environment and growing development potential The seller painted a convincing picture of rising property values and urged them to act quickly to secure a prime spot The deal seemed urgent but my parents were excited and eager to get started The seller requested a $30,000 USD down payment to reserve the plot with the catch being that the payment needed to be made in cryptocurrency Bitcoin specifically While it raised a few red flags the seller provided what looked like valid documents including supposed title information and a property map Trusting the process my parents sent the payment Almost immediately after that communication started to break down The phone numbers were suddenly unreachable emails bounced and the website they had been using disappeared Worse still when they tried to verify the land records with the local county office they learned there was no such property under the seller’s name It was a total scam The emotional and financial hit was crushing They had put down a large part of their life savings and it felt like everything had come crashing down Thankfully hope returned when my dad happened to run into an old college friend while visiting a mutual acquaintance in New Jersey During their catch-up my dad shared what had happened and that friend immediately recommended Byte phantom cyber services a cyber-forensics and scam recovery team that specialized in crypto fraud At first my parents were skeptical after all it felt like they had already been fooled once But they decided to reach out The team at Byte phantom cyber services was prompt professional and surprisingly knowledgeable They launched an investigation tracked the blockchain transactions and followed the digital trail using specialized tools Over the following weeks they kept my parents updated and eventually succeeded in recovering the entire $30,000 that had been scammed It was an incredible relief Not only did they recover the lost funds but they also learned valuable lessons about digital security and the importance of verifying everything especially when it comes to unconventional payment methods With their money back they resumed their search this time more carefully and eventually found a legitimate piece of land in the Lehigh Valley area of Pennsylvania where they are now happily building their new home  
    • I didn’t even notice that side of the report, as I expected it was a bunch of client mods, thanks for the advice
    • Yea it looks like it. Looks like I have to wait for a fix for that. Just don't level up fishermen ahaha.
    • Also make a test without all mods related to worldgeneration and the xaero mods - like betterdungeons, integrated-api etc
    • Make a test without all Create addons: - create_buffers__beams_overhauled 1.0.0 - create_central_kitchen 1.4.1 - create_confectionery 1.1.0 - create_copper_and_zinc 1.6.0 - create_crush_everything 1.0.2 - create_dd 0.1b.Release-Early-Dev - create_easy_structures 0.2 - create_enchantment_industry 1.3.2-for-create-6.0.4 - create_questing 1.0.0 - create_sa 2.1.0 - createbb 3.1.1 - createcasing 1.7.1-fix2 - createdeco 2.0.3-1.20.1-forge One or more of these may not compatible with Create 6
  • Topics

×
×
  • Create New...

Important Information

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