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

Playerdata how?


Slastic
 Share

Recommended Posts

How can I store a list of coordinates (BlockPos) and String name, for each individual player globally.

What would be a simple way of doing this?

 

Does this require The Capability System, if so -- how would you use it for this?

https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/

 

I'm newbie,

Help is appreciated 

Edited by Slastic
Link to comment
Share on other sites

18 hours ago, Slastic said:

globally

Just make either a static list or a HashMap. What's your use case, knowing it will help.

 

18 hours ago, Slastic said:

String name

DO NOT do this, vanilla did this with Ender pearls up to 1.13 and it lead to major exploits, what if a player changes their name?

Instead use the player's UUID (PlayerEntitygetUniqueId).

 

Edit: Use a HashMap, just used one for my own mod, here's a link to the class where I use it, in my case I'm storing a PlayerEntity as the key and a DimensionType as the value, then I'm using the values to teleport each player to their corresponding dimension.

Edited by Novârch

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

Thanks much I will try this out, may need help though

One question is how would you put data into the list, for example (onBlockActivated) data like pos.

 

Then how would you be able to select a specific item (using the index value, from it)

I have a UI that has 10 buttons, click the first button it will select the first index from the hashmap

 

Hope that made some sense, and that I'm not mistaken

Edited by Slastic
Link to comment
Share on other sites

22 hours ago, Slastic said:

for each individual player

To get a value from a HashMap you need a key, in my case a PlayerEntity, if you want to store a BlockPos for each individual player then you will make a HashMap with PlayerEntity as the key and BlockPos as the value (HashMap<PlayerEntity, BlockPos>), then you will get the BlockPos by calling HashMap#get with your player as the parameter.

Edited by Novârch

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

TotemPos.get(playerIn).add(pos.getX(), pos.getY(), pos.getZ());

So I would add to it like this, right?

The list HashMap is registered as told

public static HashMap<PlayerEntity, BlockPos> TotemPos = new HashMap<>();

Edited by Slastic
Link to comment
Share on other sites

10 minutes ago, Slastic said:

TotemPos.get(playerIn).add(pos.getX(), pos.getY(), pos.getZ());

So I would add to it like this, right?

The list HashMap is registered as told

public static HashMap<PlayerEntity, BlockPos> TotemPos = new HashMap<>();

No, use HashMap#put, please read up on HashMaps, they're really useful. Think of the PlayerEntity as the index of the BlockPos, HashMaps don't have normal indexes, try printing out a HashMaps's values and you'll get an order different then the order you added them in.

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

What is it that you are trying to do?
Describe it as what the player sees, not your attempt to code it.

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.

Link to comment
Share on other sites

 

 

There is a totem block, when you right click it - onBlockActivated() - it will show a gui with a button that says bind totem.

If they bind it, it will show another gui, this gui will show a list of all bound totems

Lastly when you press totem 1 for example it will tp you to the first one you bounded.

 

Hopefully that made sense

 

Here is what adds buttons to teleport to totems

 

Spoiler

    @Override
    public void init() {
        super.init();
        this.buttons.clear();

        int heightOffset = 75;
        int index = 0;
        
        for (int i = 0; i <  7 /* List Length*/ ; i++) {
            Button(index = index + 1,  heightOffset = heightOffset - 25);
        }
    }
    
    // Button
    void Button(int index, int heightOffset) {
      // Teleport
        this.addButton(new Button(this.width / 2 - 85, this.height - (this.height / 2) - 10 - heightOffset, 150, 20, "Totem - " + index, (button) -> {
            System.out.println("Telelport - " + index);
        }));
      // Unbind Button - next to the first button
        this.addButton(new Button(this.width / 2 + 65, this.height - (this.height / 2) - 10 - heightOffset, 20, 20, "\u2715", (button) -> {
            System.out.println("unBounded - " + index);
        }));
    }

 

 

 

And onBlockActivated

Spoiler

    @Override
    public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand handIn, BlockRayTraceResult hit) {
        if (!worldIn.isRemote) {
            ItemStack itemIn = playerIn.getHeldItem(handIn);
            if (itemIn.getItem() == RegistryHandler.DREAD_MIRROR.get()) {
                DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().displayGuiScreen(new AddTotemScreen(new StringTextComponent("hi"))));
            }
        }
        return super.onBlockActivated(state, worldIn, pos, playerIn, handIn, hit);
    }

 

 

I'm aware my code properly has issues keep in mind that I'm new to this so don't expect this to be perfect

 

Thanks you have been great help

Link to comment
Share on other sites

So what you need is a list of bound totems stored (in a capability) on each player.

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.

Link to comment
Share on other sites

So do that then.

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.

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.
Note: Your post will require moderator approval before it will be visible.

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

    • Whoops! Sorry about that. I've updated the code and removed the reference. The errant line (DivineFavourTabGui.java:31) is currently commented out as well.
    • Take a look at the github https://github.com/lordofwizard/mcserver and the video in it if you want to try it out You can host your very own Java/Bedrock Minecraft Server using Google Cloud Shell. This works under Ubuntu/Debian based Linux operation system. This project requires NO CREDIT CARD and the whole project is entirely FREE! You can make a server without costing you anything. The following features are added into this project are:   Supports different type of Bedrock Servers Clean & Friendly Interface Supports Additional type of Java Server (eg. Sponge, Paper, Fabric etc) Added Server Management Easier functional scripts (eg. ./uninstall allows you to delete your server easily) Instant EULA script setup (Completly skipping this part which makes other people's life much easier to manage) Faster Server Installation (It would probably take you like approx 30 seconds to setup a server) Server Specs: OS: Debian GNU/Linux 10 (buster) x86_64 RAM: 8GB to 16GB Location: Based on your physical location. Storage: Approx 5GB CPU: AMD EPYC (2) 7B12 @ 2.249GHz or Intel Xeon (4) @ 2.199GHz You can view your exact specs by doing ./specinfo Keeping the Server Alive 24/7 There's only ONE way to keep your server online longer than 20 minutes: You must Keep your browser open to keep your server online. This so the shell doesn't get terminated when it's unused or the browser is closed. You can also use google cloud sdk if you don't want to keep you browser open (Don't worry, your device that is being used to host your server isn't affected from the intensity of your server.) If you have any method the would possibly keep the server alive 24/7, feel free to Fork this project and request a Pull to this project. Any help will be greatly appreciated. Limitation of this project Google Cloud Shell Quota While I was editing this project, I notice that Google has added a quota for each Cloud Shell uses and you can only host your server for the max of 50 hours per Week. Once you used all of the hours, you can't use it again until next week. No Dedicated IP Sadly you can't use the host IP into your dedicated IP as it won't let you join that server, you can only join your server by the generated dedicated IP provided by playit.gg. If you know how to reverse proxy the tunnel system, you can actually use the host IP to make a dedicated IP for your server but I highly doubt that would ever happen. Mixed Server Specs Each Cloud Shell session will have different specs of your server based on your physical location so you won't always get the best performance of your server but good news being that it's always the range between 8GB to 16GB so you won't have to worry about lag when playing in the server with high processing in your server. Even take a look at this:https://cloud.google.com/shell/docs/limitations Conclusion Now you can host your very own Minecraft Server for both Java & Bedrock fast and easy and it won't cost you a single penny to make a fast and strong server. Best of all, IT'S FOREVER! Feel free to leave any requests you would like me to add into the project. If you have any issues, go to the Issues tab and submit a issue there.
    • Take a look at the github https://github.com/lordofwizard/mcserver and the video in it if you want to try it out You can host your very own Java/Bedrock Minecraft Server using Google Cloud Shell. This works under Ubuntu/Debian based Linux operation system. This project requires NO CREDIT CARD and the whole project is entirely FREE! You can make a server without costing you anything. The following features are added into this project are:   Supports different type of Bedrock Servers Clean & Friendly Interface Supports Additional type of Java Server (eg. Sponge, Paper, Fabric etc) Added Server Management Easier functional scripts (eg. ./uninstall allows you to delete your server easily) Instant EULA script setup (Completly skipping this part which makes other people's life much easier to manage) Faster Server Installation (It would probably take you like approx 30 seconds to setup a server) Server Specs: OS: Debian GNU/Linux 10 (buster) x86_64 RAM: 8GB to 16GB Location: Based on your physical location. Storage: Approx 5GB CPU: AMD EPYC (2) 7B12 @ 2.249GHz or Intel Xeon (4) @ 2.199GHz You can view your exact specs by doing ./specinfo Keeping the Server Alive 24/7 There's only ONE way to keep your server online longer than 20 minutes: You must Keep your browser open to keep your server online. This so the shell doesn't get terminated when it's unused or the browser is closed. You can also use google cloud sdk if you don't want to keep you browser open (Don't worry, your device that is being used to host your server isn't affected from the intensity of your server.) If you have any method the would possibly keep the server alive 24/7, feel free to Fork this project and request a Pull to this project. Any help will be greatly appreciated. Limitation of this project Google Cloud Shell Quota While I was editing this project, I notice that Google has added a quota for each Cloud Shell uses and you can only host your server for the max of 50 hours per Week. Once you used all of the hours, you can't use it again until next week. No Dedicated IP Sadly you can't use the host IP into your dedicated IP as it won't let you join that server, you can only join your server by the generated dedicated IP provided by playit.gg. If you know how to reverse proxy the tunnel system, you can actually use the host IP to make a dedicated IP for your server but I highly doubt that would ever happen. Mixed Server Specs Each Cloud Shell session will have different specs of your server based on your physical location so you won't always get the best performance of your server but good news being that it's always the range between 8GB to 16GB so you won't have to worry about lag when playing in the server with high processing in your server. Even take a look at this:https://cloud.google.com/shell/docs/limitations Conclusion Now you can host your very own Minecraft Server for both Java & Bedrock fast and easy and it won't cost you a single penny to make a fast and strong server. Best of all, IT'S FOREVER! Feel free to leave any requests you would like me to add into the project. If you have any issues, go to the Issues tab and submit a issue there.
    • Hey guys, I'm trying to run the dev env with two mods (Alexs Mobs and Citadel), therefore I copied their build.gradle because there's a lot of mixin stuff: build.gradle: https://pastebin.com/PUef70eP The server boots up normally when I use the old mappings, but when I change to Mojang's mappings, I get this error on startup: java.lang.BootstrapMethodError: java.lang.ClassFormatError: Duplicate method name "isFood" with signature "(Lnet.minecraft.item.ItemStack;)Z" in class file com/github/alexthe666/alexsmobs/entity/EntityRaccoon I already use fg.deof to match the mappings of the mods to my mappings, what else could be the reason for this error?  
    • Your code does not compile for me, because you are using the Vec3f class from javafx. This means your code will also not work for many people that aren't using Oracle Java. You should use Vector3f from Minecraft instead.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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