Jump to content

[1.8.9][TileEntity] createNewTileEntity returning null slows the game


Major Squirrel

Recommended Posts

Hey boyz (and girls),

 

I'm playing with TileEntity for now, and something is happening when creating a new TileEntity.

 

I'm creating a barrel block that extends BlockContainer : I have to implement createNewTileEntity(World worldIn, int meta). I want to keep the TE logic for the server mod, so I implement all the TE code in the server mod, and in the client mod I'm returning null.

 

When I return null for this method, when the block is placed, the chunk updates increase from 0 to 40 chunk updates constantly ! FPS decrease too (when I destroy the block it will return normal). But when I return an empty TileEntity (just the class + an empty constructor) it works without any problem, why is that ?

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

Don't return null.

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

Here is my attempt

 

I suppose that in client mod I override hasTileEntity to return false and in server mod I override to return true and createTileEntity to return a new TE ?

 

Also, why should I not extend BlockContainer ? I followed GreyGhost and BedrockMiner tutorials but according to you it seems not ok for me.

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

This is why you

Don't return null.

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

Yup, I just made the changes you indicate me and it works very well, thank you guys.

 

However, I still have some questions about server updating clients. What is the difference between this :

 

    private void        sendUpdateBarrelTexture() {
        IBlockState     blockState;

        blockState = this.worldObj.getBlockState(this.pos).getBlock().getStateFromMeta(this.currentCycle);
        this.worldObj.setBlockState(this.pos, blockState, 2);
    }

 

and this

 

    private void        sendUpdateBarrelTexture() {
        IBlockState     blockState;

        blockState = this.worldObj.getBlockState(this.pos).getBlock().getStateFromMeta(this.currentCycle);
        this.worldObj.setBlockState(this.pos, blockState);
        this.worldObj.markBlockForUpdate(this.pos);
        this.markDirty();
    }

 

For the first code, especially the setBlockState method, the javadoc says : "sets the block state at a given location. Flag 1 will cause a block update. Flag 2 will send the change to clients (you almost always want this). Flag 4 prevents the block from being re-rendered, if this is a client world. Flags can be added together."

 

In my case, I just want to tell clients that the state of the block has changed (other texture). Currently I'm using the first code, am I wrong doing this ?

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

First of all, you should never be calling getMetaFromState (or getStateFromMeta) yourself.

To the question, both of what you showed is kinda weird.

 

markBlockForUpdate re-sends the chunk data to the client.

markDirty updates comparators and tells minecraft that your TE's data has changed, so it will need to be saved to disk.

 

Okay, so it seems that I'm doing something wrong here. I just want to tell players that the block has changed : the this.currentCycle has been incremented and the texture is properly set according to the currentCycle. (that is probably why I should save to disk, isn't it ?) I do not really see how can I change the block state if I don't have to access to getStateFromMeta myself.  :-\

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

Use

Block#getDefaultState

to get the default state of a block, then chain

IBlockState#withProperty

calls to get an

IBlockState

with the specified property values.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I don't see the point not to use my getStateFromMeta method if it is already doing it :

 

    @Override
    public IBlockState                  getStateFromMeta(int meta) {
        return (this.getDefaultState().withProperty(TYPE, EnumType.byMetadata(meta)));
    }

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

The point is you should not ever deal with metadata in your code, except in getStateFromMeta and getMetaFromState.

Magic numbers are bad.

 

Compare:

 

setBlockState(myBlock.getStateFromMeta(12)) // what does this do?!
setBlockState(myBlock.getDefaultState().withProperty(MyBlock.TYPE, MyBlock.Type.FOOBAR)) // very clear

 

The byMetadata method inside the enum handles the meta by returning the correct enum :

 

        public static EnumType          byMetadata(int meta) {
            if (meta < 0 || meta >= META_LOOKUP.length) meta = 0;
            return (META_LOOKUP[meta]);
        }

 

The purpose to use metadata here is to get the correct enum according to the currentCycle/metadata, incremented in the TileEntity.

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

Again, don't deal with the metadata.

Use the Enum inside the TileEntity. Not some arbitrary number. Why do you have the enum if you then don't use it?

 

I use it, to get the correct texture block according to the currentCycle : the currentCycle corresponds to the metadata. It is then converted to the specific enum which gets the correct texture of the block.

 

BlockBarrel.java

TileEntityBlockbarrel.java (server)

 

If I don't have to deal with metadata, could you explain me how can I change my texture block according to an incrementing variable (dynamically) ?

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

That is because I wanted to associate an integer to a string so that the texture could be set according to the variants, for example :

 

{
    "variants": {
        "mode=normal": { "model": "questsystem:block_barrel" },
        "mode=fermented": { "model": "questsystem:block_barrel_fermented"}
    }
}

 

The mode is the enum, normal and fermented are strings of the enum associated with the int (the currentCycle/metadata)

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

Actually, it looks like he should be using PropertyBoolean FERMENTED, which could be true or false (default false). Is there any need for an enum that has only two values?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Sorry, I'm updating my code anytime, I'm just discovering the Property concept. I'll lock this topic as it is solved now and, my bad, it derived to new questions.

 

The purpose of all of this is to change dynamically a block texture according to a fermentation cycle in the TileEntity : on block placed, the barrel starts its fermentation at cycle 0, then every X ticks the fermentation "levels up" and the cycle increments.

 

At first, I was using an EnumType called "type", associating a string (cycle0, cycle1, etc) to a value (0, 1, 2...). The purpose of using an enum was to correctly set the blockstates according to the enum properties :

 

(old code)

{
    "variants": {
	"type=cycle0": { "model": "questsystem:block_barrel_cycle_zero" },
	"type=cycle1": { "model": "questsystem:block_barrel_cycle_one" },
	"type=cycle2": { "model": "questsystem:block_barrel_cycle_two" },
	"type=cycle3": { "model": "questsystem:block_barrel_cycle_three" }
    }
}

 

According to the current type of the TileEntity, it set the correct texture associated to the correct model. I was passing the cycle value through blockstates changes, that is why I was talking about metadata.

 

Lately, I wanted to set the block according to the direction the player is facing (like the furnace). It is a that moment that I understood I had to handle the EnumDirection "facing" for each "type" cycle :

 

(current code)

{
    "variants": {
	"fermented=false,facing=north": { "model": "questsystem:block_barrel" },
	"fermented=false,facing=south": { "model": "questsystem:block_barrel", "y": 180 },
	"fermented=false,facing=west": { "model": "questsystem:block_barrel", "y": 270 },
	"fermented=false,facing=east": { "model": "questsystem:block_barrel", "y": 90 },
	"fermented=true,facing=north": { "model": "questsystem:block_barrel_fermented" },
	"fermented=true,facing=south": { "model": "questsystem:block_barrel_fermented", "y": 180 },
	"fermented=true,facing=west": { "model": "questsystem:block_barrel_fermented", "y": 270 },
	"fermented=true,facing=east": { "model": "questsystem:block_barrel_fermented", "y": 90 }
    }
}

 

There, I switched my EnumType to an PropertyBoolean for only two cycles (0 and 1) because the number of cycles is now limited to 10 (because directions use 6 bits on metadata). I suppose that I can go on a PropertyInteger to reach these 10 cycles, but I won't do it for now.

 

Currently, I'm looking for another way to change texture dynamically but it seems that I have to use blockstates to do this ... This will go on another topic I suppose. Anyway, thank you guys to enrich my knowledge.

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Detik4D adalah situs slot 4D resmi yang menawarkan pengalaman bermain yang mengasyikkan dan peluang menang besar. Dengan koleksi permainan slot yang beragam dan fitur-fitur menarik, Detik4D menjadi pilihan utama bagi para pecinta slot online. Peluang Menang Besar dengan Jackpot Resmi Salah satu keunggulan utama Detik4D adalah peluang menang besar yang ditawarkan. Dengan sistem jackpot resmi, para pemain memiliki kesempatan untuk memenangkan hadiah besar yang dapat mengubah hidup mereka. Jackpot-jackpot ini tidak hanya menghadirkan keseruan tambahan dalam bermain, tetapi juga memberikan peluang nyata untuk meraih keuntungan yang signifikan. Detik4D juga memiliki berbagai macam permainan slot dengan tingkat pembayaran yang tinggi. Dengan demikian, peluang untuk meraih kemenangan dalam jumlah besar semakin terbuka lebar. Para pemain dapat memilih dari berbagai jenis permainan slot yang menarik, termasuk slot klasik, video slot, dan slot progresif. Setiap jenis permainan memiliki fitur-fitur unik dan tema yang berbeda, sehingga para pemain tidak akan pernah merasa bosan. Pengalaman Bermain yang Mengasyikkan Selain peluang menang besar, Detik4D juga menawarkan pengalaman bermain yang mengasyikkan. Dengan tampilan grafis yang menarik dan suara yang menghibur, para pemain akan merasa seperti berada di kasino sungguhan. Fitur-fitur interaktif seperti putaran bonus, putaran gratis, dan fitur-fitur lainnya juga akan menambah keseruan dalam bermain. Detik4D juga memiliki antarmuka yang user-friendly, sehingga para pemain dapat dengan mudah mengakses permainan dan fitur-fitur lainnya. Proses pendaftaran dan deposit juga sangat mudah dan cepat, sehingga para pemain dapat segera memulai petualangan mereka di dunia slot online. Detik4D juga menyediakan layanan pelanggan yang responsif dan profesional. Tim dukungan pelanggan yang ramah akan siap membantu para pemain dengan segala pertanyaan atau masalah yang mereka hadapi. Dengan demikian, para pemain dapat bermain dengan tenang dan yakin bahwa mereka akan mendapatkan bantuan yang mereka butuhkan. Keamanan dan Kepercayaan Detik4D sangat memprioritaskan keamanan dan kepercayaan para pemain. Situs ini menggunakan teknologi enkripsi terkini untuk melindungi data pribadi dan transaksi keuangan para pemain. Selain itu, Detik4D juga bekerja sama dengan penyedia permainan terkemuka yang telah teruji dan terpercaya, sehingga para pemain dapat bermain dengan aman dan adil. Detik4D juga memiliki lisensi resmi dan diatur oleh otoritas perjudian yang terkemuka. Hal ini menjamin bahwa semua permainan yang ditawarkan adalah fair dan tidak ada kecurangan yang terjadi. Para pemain dapat bermain dengan tenang, mengetahui bahwa mereka berada di situs yang terpercaya dan terjamin. Jadi, jika Anda mencari situs slot 4D resmi dengan peluang menang besar dan pengalaman bermain yang mengasyikkan, Detik4D adalah pilihan yang tepat. Bergabunglah sekarang dan rasakan sendiri keseruan dan keuntungan yang ditawarkan oleh Detik4D.
    • Perjudian online telah menjadi tren yang populer di kalangan penggemar permainan kasino. Salah satu permainan yang paling diminati adalah mesin slot online. Mesin slot online menawarkan kesenangan dan kegembiraan yang tak tertandingi, serta peluang untuk memenangkan hadiah besar. Salah satu situs slot online resmi yang menarik perhatian banyak pemain adalah Tuyul Slot. Kenapa Memilih Tuyul Slot? Tuyul Slot adalah situs slot online resmi yang menawarkan berbagai keuntungan bagi para pemainnya. Berikut adalah beberapa alasan mengapa Anda harus memilih Tuyul Slot: 1. Keamanan dan Kepercayaan Tuyul Slot adalah situs slot online resmi yang terpercaya dan memiliki reputasi yang baik di kalangan pemain judi online. Situs ini menggunakan teknologi keamanan terkini untuk melindungi data pribadi dan transaksi keuangan pemain. Anda dapat bermain dengan tenang dan yakin bahwa informasi Anda aman. 2. Pilihan Permainan yang Beragam Tuyul Slot menawarkan berbagai macam permainan slot online yang menarik. Anda dapat memilih dari ratusan judul permainan yang berbeda, dengan tema dan fitur yang beragam. Setiap permainan memiliki tampilan grafis yang menarik dan suara yang menghibur, memberikan pengalaman bermain yang tak terlupakan. 3. Kemudahan Menang Salah satu keunggulan utama dari Tuyul Slot adalah kemudahan untuk memenangkan hadiah. Situs ini menyediakan mesin slot online dengan tingkat pengembalian yang tinggi, sehingga peluang Anda untuk memenangkan hadiah besar lebih tinggi. Selain itu, Tuyul Slot juga menawarkan berbagai bonus dan promosi menarik yang dapat meningkatkan peluang Anda untuk menang. Cara Memulai Bermain di Tuyul Slot Untuk memulai bermain di Tuyul Slot, Anda perlu mengikuti langkah-langkah berikut: 1. Daftar Akun Kunjungi situs Tuyul Slot dan klik tombol "Daftar" untuk membuat akun baru. Isi formulir pendaftaran dengan informasi pribadi yang valid dan lengkap. Pastikan untuk memberikan data yang akurat dan jaga kerahasiaan informasi Anda. 2. Deposit Dana Setelah mendaftar, Anda perlu melakukan deposit dana ke akun Anda. Tuyul Slot menyediakan berbagai metode pembayaran yang aman dan terpercaya. Pilih metode yang paling nyaman untuk Anda dan ikuti petunjuk untuk melakukan deposit. 3. Pilih Permainan Setelah memiliki dana di akun Anda, Anda dapat memilih permainan slot online yang ingin Anda mainkan. Telusuri koleksi permainan yang tersedia dan pilih yang paling menarik bagi Anda. Anda juga dapat mencoba permainan secara gratis sebelum memasang taruhan uang sungguhan. 4. Mulai Bermain Saat Anda sudah memilih permainan, klik tombol "Main" untuk memulai permainan. Anda dapat mengatur jumlah taruhan dan jumlah garis pembayaran sesuai dengan preferensi Anda. Setelah itu, tekan tombol "Putar" dan lihat apakah Anda beruntung untuk memenangkan hadiah. Promosi dan Bonus Tuyul Slot menawarkan berbagai promosi dan bonus menarik kepada para pemainnya. Beberapa jenis promosi yang tersedia termasuk bonus deposit, cashback, dan turnamen slot. Pastikan untuk memanfaatkan promosi ini untuk meningkatkan peluang Anda memenangkan hadiah besar. Kesimpulan Tuyul Slot adalah situs slot online resmi yang menawarkan pengalaman bermain yang seru dan peluang menang yang tinggi. Dengan keamanan dan kepercayaan yang terjamin, berbagai pilihan permainan yang menarik, serta bonus dan promosi yang menguntungkan, Tuyul Slot menjadi pilihan yang tepat bagi para penggemar mesin slot online. Segera daftar akun dan mulai bermain di Tuyul Slot untuk kesempatan memenangkan hadiah besar!
    • I have been having a problem with minecraft forge. Any version. Everytime I try to launch it it always comes back with error code 1. I have tried launching from curseforge, from the minecraft launcher. I have also tried resetting my computer to see if that would help. It works on my other computer but that one is too old to run it properly. I have tried with and without mods aswell. Fabric works, optifine works, and MultiMC works aswell but i want to use forge. If you can help with this issue please DM on discord my # is Haole_Dawg#6676
    • Add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I have no idea how a UI mod crashed a whole world but HUGE props to you man, just saved me +2 months of progress!  
  • Topics

×
×
  • Create New...

Important Information

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