Jump to content

(SOLVED) [1.12] How to get the server-side instance of the player in a client-side method?


xyz

Recommended Posts

Hello, I am trying to make a custom compass that points towards the player's bed, however, IItemPropertyGetter only passes the client-side player in the apply method. The problem is that getBedLocation always returns the world spawn on a client-side player object, the question is: how do I get a server-side instance of the player from nothing?

 

This is the IItemPropertyGetter

Spoiler

this.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 = (Entity)(flag ? entityIn : stack.getItemFrame());
	                if (worldIn == null) {
	                        worldIn = entity.world;
	                }
	                double d0;
	                if (worldIn.provider.isSurfaceWorld()) {
	                	double d1 = flag ? (double)entity.rotationYaw : this.getFrameRotation((EntityItemFrame)entity);
	                	d1 = MathHelper.positiveModulo(d1 / 360.0D, 1.0D);
	                    double d2 = this.getSpawnToAngle(worldIn, entity) / (Math.PI * 2D);
	                    d0 = 0.5D - (d1 - 0.25D - d2);
	                } else {
	                	d0 = Math.random();
	                }
	                if (flag) {
	                        d0 = this.wobble(worldIn, d0);
	                }
	                return MathHelper.positiveModulo((float)d0, 1.0F);
	            }
	        }
	        
	        @SideOnly(Side.CLIENT)
	        private double wobble(World worldIn, double p_185093_2_) {
	        	if (worldIn.getTotalWorldTime() != this.lastUpdateTick) {
	            	this.lastUpdateTick = worldIn.getTotalWorldTime();
	                double d0 = p_185093_2_ - this.rotation;
	            	d0 = MathHelper.positiveModulo(d0 + 0.5D, 1.0D) - 0.5D;
	                this.rota += d0 * 0.1D;
	                this.rota *= 0.8D;
	                this.rotation = MathHelper.positiveModulo(this.rotation + this.rota, 1.0D);
	            }
	                return this.rotation;
	        }
	        
	        @SideOnly(Side.CLIENT)
	        private double getFrameRotation(EntityItemFrame itemFrame) {
	        	return (double)MathHelper.clampAngle(180 + itemFrame.facingDirection.getHorizontalIndex() * 90);
	        }
	        
	        @SideOnly(Side.CLIENT)
	        private double getSpawnToAngle(World world, Entity player) {
				// ???
	        	return 0;
	        }
	        
	    });

 

 

Edited by xyz
Link to comment
Share on other sites

TLDR:

You can't.  And when you could you shouldn't.

  • Like 2

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

Why can't you use the client side player? The vanilla compass uses the client player as well.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

2 minutes ago, larsgerrits said:

Why can't you use the client side player? The vanilla compass uses the client player as well.

As I explained in the OP, using getBedLocation() on a client-side player always returns the world spawn while I need the player's bed location.

Edited by xyz
Link to comment
Share on other sites

Ok.

Let me put it this way:

 

The logical client is not always on the same physical machine as the logical server.

 

Ergo you have no access to the server-side player entity.  If you want to reach across logical sides, then by all means, go ahead and do so, but your mod will be SSP only.

  • Like 1

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

If you were to look at the code the vanilla compass uses to determine the user's bed location (AKA the spawnpoint of the user), you could see you can use World#getSpawnPoint to get the client player's spawnpoint.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

8 minutes ago, larsgerrits said:

If you were to look at the code the vanilla compass uses to determine the user's bed location (AKA the spawnpoint of the user), you could see you can use World#getSpawnPoint to get the client player's spawnpoint.

While you are technically correct that still doesn't change that I'm looking for the player's bed location and not the world spawn (the vanilla compass points towards the world spawn).

 

9 minutes ago, Draco18s said:

Ok.

Let me put it this way:

 

The logical client is not always on the same physical machine as the logical server.

 

Ergo you have no access to the server-side player entity.  If you want to reach across logical sides, then by all means, go ahead and do so, but your mod will be SSP only.

Thanks a lot for your explanation.

Edited by xyz
Link to comment
Share on other sites

2 minutes ago, xyz said:

(the vanilla compass points towards the world spawn)

After all this time, how could I forget... My bad.

 

 

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

17 minutes ago, xyz said:

While you are technically correct that still doesn't change that I'm looking for the player's bed location and not the world spawn (the vanilla compass points towards the world spawn).

 

Thanks a lot for your explanation.

You are gonna want to save the Players Bed spawnpoint to a capability and then update it with packets so the client side also has the data.

  • Like 1

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

1 hour ago, Animefan8888 said:

You are gonna want to save the Players Bed spawnpoint to a capability and then update it with packets so the client side also has the data.

How exactly would I go about using packets? There doesn't really seem to be any up-to-date tutorial on it.

Link to comment
Share on other sites

Just now, xyz said:

How exactly would I go about using packets? There doesn't really seem to be any up-to-date tutorial on it.

Packets have not really changed much since 1.7 unless something happened in 1.12 that i don't know about. So here is a tutorial  from Diesieben.

  • Like 1

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

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

    • Slot Bank BRI atau Daftar slot Bank BRI bisa anda lakukan pada situs Museumbola kapanpun dan dimanapun, Bermodalkan Hp saja anda bisa mengakses chat ke agen kami selama 24 jam full. keuntungan bergabung bersama kami di Museumbola adalah anda akan mendapatkan bonus 50% khusus member baru yang bergabung dan deposit. Tidak perlu banyak, 10 ribu rupiah saja anda sudah bisa bermain bersama kami di Museumbola. Tunggu apa lagi ? Segera Klik DAFTAR dan anda akan jadi Jutawan dalam semalam.
    • Museumbola adalah situs judi slot BANK BCA tergacor 2024 dengan minimal deposit  10 ribu rupiah saja anda sudah bisa spin slot gacor di Museumbola. Mulai dari Pragmatic, Pg Soft, Habanero, Playstar, Spadegaming, dan masih banyak lagi. Pilihan slot yang begitu banyak tidak akan membuat anda bosan. Segera daftarkan BANK BCA anda dan jadi member aktif Museumbola. anda akan diberi kesempatan mendapatkan bonus deposit harian setiap hari. Segera Klik DAFTAR sekarang juga sebelum terlambat.  
    • Slot BANK BCA adalah pilihan tergacor untuk memulai bermain slot judi Online dimuka bumi saat ini. Jika anda mempunyai BANK BCA, Anda berkesempatan mendapatkan Akun Pro atau ID pro untuk bermain slot. Tunggu apa lagi? Segera daftarkan diri anda sekarang dan dapatkan kemewahan menang maxwin di Museumbola.
    • SLOT SCATTER HITAM : SLOT MAHJONG SCATTER HITAM - MAHJONG WAYS SCATTER HITAM - SLOT PRAGMATIC SCATTER HITAM KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • SLOT 1000 : SLOT1000 DEPOSIT 1000 VIA DANA - SLOT 1000 VIA QRIS - SLOT DEPOSIT QRIS 1000 - SLOT DEPO 1K - SLOT 1000 BET KECIL KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
  • Topics

×
×
  • Create New...

Important Information

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