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

    • Hi, I'm one of the user who's using Custom NPCs 1.7.10. But I have one problem. I see some items are equipped to NPC rotated, not in the right position. How can I rotate the arm of NPC?
    • Hello. I decided to try to make a mod, but for some reason I stumbled at the very beginning. How do I register a block for it to appear in the inventory? It seems that I'm trying to do it according to the manual, but only the procedure for registering new blocks is described there. So I made a mod class. I registered the registration, but when I install it into the game, I do not see my block in the intent. And I will also be grateful if you give a link to some kind of detailed manual. So that step by step it was described how what can be created. Thanks.   @Mod("examplemod") public class ExampleMod { // Directly reference a log4j logger. private static final Logger LOGGER = LogManager.getLogger(); private static final String MODID = "0.1"; private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID); public static final RegistryObject<Block> MyBlock = BLOCKS.register("mysuperblockreg", () -> new SuperBlock(BlockBehaviour.Properties.of(Material.WOOD).lightLevel((s) -> { return 1; }).sound(SoundType.WOOD))); public ExampleMod() { // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); // Register the enqueueIMC method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC); // Register the processIMC method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC); BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus()); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { // some preinit code LOGGER.info("HELLO FROM PREINIT"); LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName()); } private void enqueueIMC(final InterModEnqueueEvent event) { // some example code to dispatch IMC to another mod InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world"; }); } private void processIMC(final InterModProcessEvent event) { // some example code to receive and process InterModComms from other mods LOGGER.info("Got IMC {}", event.getIMCStream().map(m -> m.messageSupplier().get()).collect(Collectors.toList())); } // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { // do something when the server starts LOGGER.info("HELLO from server starting"); } // You can use EventBusSubscriber to automatically subscribe events on the // contained class (this is subscribing to the MOD // Event bus for receiving Registry Events) @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents { @SubscribeEvent public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) { // register a new block here LOGGER.info("HELLO from Register Block"); } } }  
    • I'm probably really stupid but how do I fix this error. It happens whenever I try to startup Minecraft forge 1.8.9 recommended [19:13:10 ERROR]: Gave up trying to download https://maven.minecraftforge.net/jline/jline/2.13/jline-2.13.jar for job 'Version & Libraries' [19:13:10 ERROR]: Job 'Version & Libraries' finished with 1 failure(s)! (took 0:00:13.982)   How do I fix this?
    • Override attackEntityFrom and do checks there, for example DamageSource#isProjectile. Or check how Enderman does it.
    • Hey, I just started modding, and especially texturing, so I'm still new to all of this. I thought a fun thing to do would be to turn the world to glass (turn blocks such as grass and stone and ores etc..) to have the grass texture, so the world would be glass. Seemed kinda fun. So I just copy-pasted the glass texture into my pack, renamed it to stone, and ran into a problem. It is rendering the glass texture, but is not transparent. Its just grey on the inside, with the glass textures on the side. I am completely lost as of what to do. Does anyone have a solution ? thank you
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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