Jump to content

Start value for Extended Properties


Bedrock_Miner

Recommended Posts

Hey Guys!

I've created some extended properties for the player's mana.

I want the player to have 200 Mana on the first spawn. How can I do this?

 

This is my code:

 

package com.bedrockminer.magicum.entity;

 

import java.util.HashMap;

import java.util.Map.Entry;

 

import com.bedrockminer.magicum.Main;

import com.bedrockminer.magicum.network.ExtendedPropertiesEditPacket;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.world.World;

import net.minecraftforge.common.IExtendedEntityProperties;

 

public class ExtendedProperties implements IExtendedEntityProperties {

 

private EntityPlayer player;

private boolean serverSide;

 

public static final String IDENTIFIER = "magicumPlayer";

 

public ExtendedProperties(EntityPlayer player) {

this.player = player;

this.serverSide = player instanceof EntityPlayerMP;

 

this.maxValues.put("mana", 200);

}

 

///////////////////////////////////////////////////////////////////////////////////////////////

 

public HashMap<String, Integer> values = new HashMap<String, Integer>();

public HashMap<String, Integer> maxValues = new HashMap<String, Integer>();

 

@Override

public void saveNBTData(NBTTagCompound compound) {

for (Entry<String, Integer> entry : this.maxValues.entrySet()) {

compound.setInteger(entry.getKey(), this.values.get(entry.getKey()));

}

}

 

@Override

public void loadNBTData(NBTTagCompound compound) {

for (Entry<String, Integer> entry : this.maxValues.entrySet()) {

this.values.put(entry.getKey(), compound.getInteger(entry.getKey()));

}

}

 

@Override

public void init(Entity entity, World world) {

 

}

}

 

 

PS: init doesn't work, its only called on client side.

Link to comment
Share on other sites

Couldn't you just set "values.put("mana", 200)" in the constructor?

 

I'm a bit confused with your code, to be honest; you seem to be making it much more complicated than you need to - do you really need hashmaps, rather than simply a couple integer fields? Why don't you save the max value as well, does it not ever change?

Link to comment
Share on other sites

Why not just check in load from nbt , is there alredy mana value or no? If there is no that value , then make it 200.I think there is even function for that in NBT....get stuff , but if its dont exists it will return "first value".

Link to comment
Share on other sites

Why would you check during loading from NBT? If you want a default value, set it in the constructor - that's what constructors are for. If you want the maximum value to change, you can do so just fine without a HashMap, and if you only have a few pre-defined values (such as 'mana', 'xp', etc.), you aren't gaining anything by using a HashMap versus several local fields or even an array or List.

Link to comment
Share on other sites

Why would you check during loading from NBT? If you want a default value, set it in the constructor - that's what constructors are for. If you want the maximum value to change, you can do so just fine without a HashMap, and if you only have a few pre-defined values (such as 'mana', 'xp', etc.), you aren't gaining anything by using a HashMap versus several local fields or even an array or List.

beacos if player just reconects - what will be? It will load that default values..Or actually it will be worse - it will load from NBT value 0.Beacos getInteger returns 0 , if its cant find that tag.

 

Or why dont do both of that? 1.If there is no that tag , what we a searching in NBT , dont modify HashMap. 2. If there is that value in NBT , load it from NBT.

 

So if you do default values , it will load them , beacos player dont have that tag.

Link to comment
Share on other sites

Why would you check during loading from NBT? If you want a default value, set it in the constructor - that's what constructors are for. If you want the maximum value to change, you can do so just fine without a HashMap, and if you only have a few pre-defined values (such as 'mana', 'xp', etc.), you aren't gaining anything by using a HashMap versus several local fields or even an array or List.

beacos if player just reconects - what will be? It will load that default values..Or actually it will be worse - it will load from NBT value 0.Beacos getInteger returns 0 , if its cant find that tag.

 

Or why dont do both of that? 1.If there is no that tag , what we a searching in NBT , dont modify HashMap. 2. If there is that value in NBT , load it from NBT.

 

So if you do default values , it will load them , beacos player dont have that tag.

If you are saving and loading NBT properly, the value you load will be correct; loading from NBT is not the place to set a default value. When the player first starts a world, the constructor is called without reading from NBT afterward, so the default value you set there will then be saved and loaded just fine.

Link to comment
Share on other sites

Why would you check during loading from NBT? If you want a default value, set it in the constructor - that's what constructors are for. If you want the maximum value to change, you can do so just fine without a HashMap, and if you only have a few pre-defined values (such as 'mana', 'xp', etc.), you aren't gaining anything by using a HashMap versus several local fields or even an array or List.

beacos if player just reconects - what will be? It will load that default values..Or actually it will be worse - it will load from NBT value 0.Beacos getInteger returns 0 , if its cant find that tag.

 

Or why dont do both of that? 1.If there is no that tag , what we a searching in NBT , dont modify HashMap. 2. If there is that value in NBT , load it from NBT.

 

So if you do default values , it will load them , beacos player dont have that tag.

If you are saving and loading NBT properly, the value you load will be correct; loading from NBT is not the place to set a default value. When the player first starts a world, the constructor is called without reading from NBT afterward, so the default value you set there will then be saved and loaded just fine.

 

hmm , didnt know that *lafing at bad documented wiki*. What about if player was alredy playing on server?

Link to comment
Share on other sites

Well, I did it now in the constructor and it worked.

The HashMaps have the advantage of easier packet handling: one packet for all values without a switch statement to get the correct one.

Sure (you could send all the data in one packet without a HashMap, too), but the disadvantage is you then have to send all of the data every time any value needs updating, so you are wasting a lot of bandwidth and processing time handling your packets this way, depending of course on how many different values you plan on storing in your maps. You are trading performance for convenience, which of course is your decision to make, but it's something to consider, at least.

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

    • LINK DAFTAR : KLIK DISINI LINK DAFTAR : KLIK DISINI   Slot SHOPEEPAY adalah situs slot deposit SHOPEEPAY Ribu paling gacor di indonesia pada tahun 2023. Situs slot SHOPEEPAY kini menyediakan layanan deposit pakai aplikasi shopee yang amat gacor sampai detik ini. MAXWINBET77 Situs slot SHOPEEPAY saat ini menggunakan layanan deposit dari e-wallet shopee adalah alat pembayaran dempet digital lewat SHOPEEPAY. Slot SHOPEEPAY saat ini menjadi situs slot ternama dengan banyak nya keunggulan di dalam situs slot SHOPEEPAY ini. Slot deposit SHOPEEPAY hadir untuk menyedia kan sarana deposit paling termurah di indonesia. Deposit slot SHOPEEPAY hanya dengan modal 5000 Ribu saja kamu sudah bisa mainkan semua jenis game yang ada di dalam situs slot SHOPEEPAY Ribu seperti gates of olympus, mahjong ways 2, Legacy of Kong Maxways dan Koi Gate yang saat ini banyak sekali di cari orang karna tingkatan kemenangan nya paling besar dan mudah jackpot. TRIK DAN TRIK BERMAIN PALING JITU / SLOT DEPOSIT SHOPEEPAY Pilih Game Slot Gacor Yang Sesuai Dengan Preferensi Dan Anggaran Anda Ada banyak tipe game slot gacor yang bisa Anda pilih, mulai dari yang bertema klasik, petualangan, mitologi, sampai film. Pilihlah game slot gacor yang menarik bagi anda dan cocok dengan volatilitas dan RTP yang anda inginkan. Volatilitas yakni tingkat risiko dan varians dalam permainan, sedangkan RTP yakni prosentase pengembalian kepada pemain. Pilihlah game slot gacor dengan volatilitas dan RTP yang pantas dengan anggaran dan tujuan anda. Manajemen Bankroll Yang Baik Bankroll ialah jumlah uang yang Anda siapkan untuk bermain slot gacor. Penting bagi anda untuk mengelola bankroll anda dengan bagus supaya tidak kehabisan uang atau terjebak dalam kecanduan judi. Tentukan jumlah maksimal yang mau anda pertaruhkan per sesi, per hari, atau per minggu, dan jangan melebihi batas tersebut. Juga, tentukan jumlah kemenangan yang mau anda capai atau jumlah kerugian yang bisa anda terima, dan stop bermain dikala mencapai salah satu dari keduanya. Manfaatkan Bonus Dan Promosi Situs slot gacor Neobank menawarkan bonus dan promosi menarik kepada para pemainnya, seperti bonus new member, bonus deposit, bonus cashback, bonus referral, bonus turnover, jackpot progresif, turnamen, freebet, dan lainnya. Manfaatkan bonus dan promosi ini untuk meningkatkan modal dan peluang kemenangan anda. Tetapi, pastikan juga untuk membaca syarat dan ketentuan yang berlaku agar tidak terjebak dalam prasyarat taruhan atau batasan penarikan yang tidak menguntungkan. Pelajari Paytable Dan Fitur Game Sebelum bermain slot gacor Neobank, pastikan Anda mempelajari paytable dan fitur game. Paytable yaitu tabel yang menonjolkan skor masing masing simbol dan kombinasi kemenangan dalam game. Fitur game yaitu fitur tambahan yang bisa meningkatkan kesempatan kemenangan Anda, seperti wild, scatter, cuma cuma spins, bonus games, multiplier, dsb. Dengan mempelajari paytable dan fitur game, Anda bisa mengenal simbol mana yang semestinya Anda targetkan ketika bermain.
    • Link Daftar : KLIK DISINI  Link Login : KLIK DISINI  Link RTP   : KLIK DISINI  Link Gacor Slot Dana   : KLIK DISINI slot deposit dana 5000 ribu via dana adalah permainan slot dana gacor dengan menyediakan slot server thailand deposit dana. dan slot deposit dana adalah slot terbesar di thailand. anda cukup daftar disini dan mainkan disini slot deposit 5000 ribu via dana sudah dipastikan dengan deposit dana akan membuat akun anda menjadi akun special. situs deposit dana adalah situs yang terpercaya dan terakurat. Slot dana merupakan situs slot deposit dana yang sangat trending dan sangat dikenal luas di masyarakat. dengan adanya MAXWINBET77 anda bisa mendapatkan keuntungan besar setiap hari tanpa adanya potongan  yang pastinya menguntungkan bagi anda. situs slot dana  maxwinbet77 adalah situs slot dana terbaik 2024 dan dijamin mudah maxwin. PERMAINAN YANG ADA DI SLOT DANA MAXWINBET77: - TOGEL 4D - SLOT ONLINE - LIVE CASINO - SPORTSBOOK - ARCADE TEMBAK IKAN - SABUNG AYAM Saat Ini Slot Dana Maxwinbet77 Menyediakan Bonus Berupa : - Bonus New Member - Bonus Deposit Harian - Bonus Cashback - Bonus 2D TERBALIK - Bonus Prize 2 & Prize 3 - Bonus Refferal DAFATR DISINI
    • LINK DAFTAR : KLIK DISINI LINK DAFTAR : KLIK DISINI   Slot seabank meruapakan salah satu situs slot paling gacor deposit seabank 100% mudah maxwin, hari ini situs slot seabank meghadirkan permainan slot dengan kemudahan bergabung hanya dengan menggunakan aplikasi Seabank langsung bisa join dengan bandar slot Seabank terbaik dan terpercaya no.1 di indonesia. Slot Seabank resmi di daftar situs slot deposit pakai Seabank 5000 Gampang Maxwin dimana aplikasi Seabank tersebut telah sanggat membantu para bosku untuk bermain slot online deposit via Seabank saat ini slot Seabank ini membantu dalam mempermudah transaksi disaat bosku ingin deposit melakukan pembayaran. kini orang orang ingin bermian judi online khusus nya games slot tidak perlu khawatir lagi apabila tidak memilikui saldo di ATM, sebab dengan adanya aplikasi Seabank sudah memberikan dampak signifikan buat perjudian di indonesia. Selain slot pakai Seabank, terdapat beberapa aplikasi e-wallet yang dapat di gunakan untuk bertansaksi antara lain, slot deposit 5000 Seabank, slot dana, slot ovo, slot pulsa tanpa potongan, dan slot shopeepay mudah menang bisa bosku pakai untuk setoran Seabank resmi terbaru. intinya slot online deposit Seabank memberikan jamianan kemudahan saat main games slot gacor uang asli terbaik di indonesia bos.
    • LINK DAFTAR : KLIK DISINI LINK DAFTAR : KLIK DISINI   Slot deposit bank bsi merupakan salah satu situs slot gacor deposit bank bsi 24 jam mudah maxwin tanpa batas. hari ini slot deposit bank bsi menawarkan bonus terbesar untuk player yang sudah bergabung di situs slot bank bsi ini, dengan ada nya slot bank bsi sanget mempermudah player untuk melakukan transaksi deposit dengan bank bsi. Sebagai Situs Slot Deposit Bank Bsi meyediakan banyak permainan seperti slot online, live casino, sabung ayam, tembak ikan, sportbook semua game tersebuat sangat aman dan terpercaya. Beramin slot bank bsi sangat mudah hanya dengan niminal deposit 5000 ribu saja anda sudah bisa bermain di semua game yang sudah di sediakan oleh situs slot bank bsi. Slot bank bsi adalah saranan untuk Pemain yang mencari pengalaman bermain slot gacor sekarang dapat menemukan metode pembayaran beragam di berbagai situs slot gacor yang tersebar luas di seluruh negeri. Munculnya situs Slot Bank BSI, kini para pemain dapat menikmati kemudahan dan kenyamanan dalam melakukan transaksi pembayaran. Bahkan memungkinkan pemain untuk fokus sepenuhnya pada permainan yang mereka nikmati sepanjang waktu. Ini adalah langkah penting dalam memperluas aksesibilitas judi slot online di Indonesia dan memberikan pengalaman bermain yang lebih baik kepada para pecinta slot gacor.    
    • Sometimes love could be the worst experience. you get to love and trust your partner only to feel regret over it. i have been married for 7 years now and i found some sudden change in my partner attitude, i tried talking about it but he complains i'm nagging a lot . i tried to ignore his attitude but it became unbearable so i was advised to hire a hacker to help me gain access to his phone so i had know if he is cheating or not so i was introduced to [ Remote spy hacker @ g m ail . c o m ] and this expert helped me gain access to his phone without his notice. i got to see his messages, photos, call recordings and many more . Now i can see his cheating and that's the reason for the attitude all along.
  • Topics

×
×
  • Create New...

Important Information

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