Jump to content

[1.11.X] Compass to point to your personal spawn point


gibraltar

Recommended Posts

I've written a compass that I believe should point to your personal spawn point, if it's been set. It looks a lot like the regular compass code, but instead of pointing to world spawn it gets the bed location for the current user and points to that. The issue I'm seeing is that when I sleep in a new place, the compass doesn't start pointing to the new location. But I've checked that the player's spawn is changing, and the same method, getBedLocation returns a different value when called within other events, so I'm not sure what the problem is. Any help would be appreciated.

 

public class ItemPersonalCompass extends Item {
    public ItemPersonalCompass() {
        addPropertyOverride(new ResourceLocation("angle"), new IItemPropertyGetter() {
            @SideOnly(Side.CLIENT)
            double rotation;
            @SideOnly(Side.CLIENT)
            double rota;
            @SideOnly(Side.CLIENT)
            long lastUpdateTick;

            @SideOnly(Side.CLIENT)
            public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) {
                if (entityIn == null && !stack.isOnItemFrame()) {
                    return 0.0F;
                }
                else {
                    boolean flag = entityIn != null;
                    Entity entity = flag ? entityIn : stack.getItemFrame();

                    if (worldIn == null) {
                        worldIn = entity.worldObj;
                    }

                    BlockPos destinationPos = new BlockPos(0, 0, 0);
                    if (entity instanceof EntityPlayer) {
                        destinationPos = ((EntityPlayer) entity).getBedLocation(0);
                        if (destinationPos == null) {
                            return 0;
                        }
                    }
                    else {
                        return 0F;
                    }

                    double d0;

                    if (destinationPos != null) {
                        double d1 = flag ? (double) entity.rotationYaw : getFrameRotation((EntityItemFrame) entity);
                        d1 = d1 % 360.0D;
                        double d2 = getPosToAngle(worldIn, entity, destinationPos);
                        d0 = Math.PI - ((d1 - 90.0D) * 0.01745329238474369D - d2);
                    } else {
                        d0 = Math.random() * (Math.PI * 2D);
                    }

                    if (flag) {
                        d0 = wobble(worldIn, d0);
                    }

                    float f = (float) (d0 / (Math.PI * 2D));
                    return MathHelper.positiveModulo(f, 1.0F);
                }
            }

            @SideOnly(Side.CLIENT)
            private double wobble(World p_185093_1_, double p_185093_2_) {
                if (p_185093_1_.getTotalWorldTime() != lastUpdateTick) {
                    lastUpdateTick = p_185093_1_.getTotalWorldTime();
                    double d0 = p_185093_2_ - rotation;
                    d0 = d0 % (Math.PI * 2D);
                    d0 = MathHelper.clamp_double(d0, -1.0D, 1.0D);
                    rota += d0 * 0.1D;
                    rota *= 0.8D;
                    rotation += rota;
                }

                return rotation;
            }

            @SideOnly(Side.CLIENT)
            private double getFrameRotation(EntityItemFrame itemFrame) {
                return (double) MathHelper.clampAngle(180 + itemFrame.facingDirection.getHorizontalIndex() * 90);
            }

            @SideOnly(Side.CLIENT)
            private double getPosToAngle(World world, Entity entity, BlockPos blockpos) {
                return Math.atan2((double) blockpos.getZ() - entity.posZ, (double) blockpos.getX() - entity.posX);
            }
        });

        setUnlocalizedName("compass_personal");
        setCreativeTab(CreativeTabs.TOOLS);
        setRegistryName(Reference.MOD_PREFIX + "compass_personal");

        GameRegistry.register(this);
        GameRegistry.addRecipe(new ItemStack(this), " I ", "IRI", " I ", 'I', Items.IRON_INGOT, 'R', Items.REDSTONE);
        ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation("iberia:compass_personal", "inventory"));
    }
}

Link to comment
Share on other sites

It is because you are using the IItemPropertyGetter inside your constructor, so the players spawn point wont change, because the constructor is only called once.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

It is because you are using the IItemPropertyGetter inside your constructor, so the players spawn point wont change, because the constructor is only called once.

 

This is literally gibberish. The IItemPropertyGetter interface sets up a callback method which is invoked when the item is rendered, all the time, every time.

 

Unless you somehow think that during preInit (before! The title screen) there is a player object and a world to look at...

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

Right, I'm setting up the IItemPropertyGetter the same way it is set up in the vanilla compass class, so I feel good about that. But I think there must be some difference between the EntityPlayer being passed into the apply method and the EntityPlayer being passed to the PlayerSetSpawn event

Link to comment
Share on other sites

Ok, here's my current theory, after further investigation. The EntityPlayer that gets passed to the IItemPropertyGetter.apply is an AbstractClientPlayer and thus on the client side. I believe that EntityPlayer never has it's spawnChunk field updated when the player's spawn is set (that happens on the server), and the EntityPlayer object on the server side that does have it's spawnChunk set is never communicating that information to the client side.

 

So it appears I need some way, given an AbstractClientPlayer, to ask the server for that player's bed location / spawnChunk. Once that's in place, I'll need a way of caching that info on the client side associated with the AbstractClientPlayer so I'm not asking for it every time we render a compass. I'll be investigating how to do that next, but any tips/pointers to get me started would be awesome.

Link to comment
Share on other sites

Packets, basically.  The client asks the server "hey, were's my bed?" when it logs in.

When asked, or when the bed is set, the server sends that client the information.

 

You don't need to do anything with the AbstractClientPlayer because when the client asks the server, the server already knows which non-abstract player is asking (due to the message context).

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
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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • If you’ve ever experienced the sinking feeling of losing funds online, you’re not alone. Enter recovery services like ADWARE RECOVERY SPECIALIST, the heroes of the digital age who help individuals track down and retrieve lost funds. These services act as modern-day sheriffs in the Wild West of the internet, bringing justice to those who have fallen victim to online scams and fraud. In a world where online transactions are as common as selfies, the need for recovery services is more pressing than ever. Individuals worldwide are vulnerable to various online schemes, from investment fraud to phishing scams. Recovery services provide a glimmer of hope for those who have lost money, offering a chance to recover what's rightfully theirs and restore faith in the digital realm. The beauty of recovery services like ADWARE RECOVERY SPECIALIST lies in their global reach. Email: Adwarerecoveryspecialist@auctioneer. net  Regardless of where individuals are located worldwide, these services extend their virtual arms to help victims of online fraud. From bustling metropolises to remote villages, no corner of the world is beyond the grasp of these modern-day Robin Hoods. Thanks to the wonders of globalization, recovery services have transcended geographical boundaries to serve individuals worldwide. The interconnected nature of the digital world means that help is just a click away, bridging gaps between nations and bringing relief to those in need. In a world where borders are becoming increasingly blurred, recovery services stand as beacons of accessibility and assistance. When a broker stole from me and withheld access from me for five months, I had no idea that I would be able to recover my trading money back. I'm relieved that I was able to get my money returned without any issues. The impact of recovery services like ADWARE RECOVERY SPECIALIST extends far beyond individual wallets. Communities worldwide have experienced a renewed sense of trust and security, knowing that there are dedicated professionals working tirelessly to recover their lost assets. These services not only bring financial relief but also restore faith in the integrity of the digital world. Trust is the cornerstone of any successful recovery service, and building credibility in a global market can pose unique challenges. ADWARE RECOVERY SPECIALIST strives to maintain transparency and reliability in all its interactions, earning the trust of clients worldwide. ADWARE RECOVERY SPECIALIST can be talked to through:  Website: www.adwarerecoveryspecialist.expert  Telegram: @ADWARE_RECOVERY_SPECIALIST
    • The game wont start and keeps crashing everytime I hit play "The game crashed whilst rendering overlay Error: java.lang.IllegalAccessError: failed to access class com.mojang.blaze3d.platform.GlStateManager$TextureState from class net.coderbot.iris.gl.IrisRenderSystem$DSAARB (com.mojang.blaze3d.platform.GlStateManager$TextureState is in module minecraft@1.18.2 of loader 'TRANSFORMER' @724b939e; net.coderbot.iris.gl.IrisRenderSystem$DSAARB is in module oculus@1.6.4 of loader 'TRANSFORMER' @724b939e)" How do I get it to stop? Log error here: https://pastebin.com/byv1dR54
    • In case anyone happens on this with the same issue, I was able to overcome it. After re-reading @Paint_Ninja's last post numerous time, it finally dawned on me that he was referring wholly to the forge installer, which has nothing to do with the packaged modpack installer. As such, I downloaded the new copy of the forge installer and copied it to my linux host, then opened a second ssh session and prepared a cp command to move the new (correct) installer over to the install directory where I was installing the modpack. After the modpack installer had just about finished retrieving files, I overwrote the installer.jar file with the correct one in a seperate ssh session. The modpack (packaged) installer then used that jar to install forge with the included files, and the install finished as I would have expected. Thanks all!
    • Just tried it again removed directory entirely, downloaded a brand new, fresh copy and did a fresh install, even going as far as running as root for the install to make sure I didn't hose something up permissions wise (I know its a terrible idea.), but same thing, failed install. This is making me feel mighty dumb, I must say... any help anyone could provide would be greatly appreciated.
  • Topics

×
×
  • Create New...

Important Information

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