Jump to content

[1.8] Random unexpected result when removing block from World


Blackout

Recommended Posts

Hello everyone,

ย 

In my mod, I remove block from world using

world.setBlockState(myBlockPos, Blocks.air.getDefaultState(), 2);

when an explosion occurs to prevent any drops.

There is a problem when I try to remove block like redstone dusts or torches, sometimes there still are drops.

I use '2' as flags so normaly game engine doesn't care about order, right ?

ย 

In fact, when I have 4 redstone dusts above dirt blocks and I remove this 8 blocks, all is fine, all is removed, I have no drops.

But when I have 5 redstone dusts and I remove this 10 blocks (5 redstone dusts + 5 dirts blocks), sometimes 1 or 2 redstone dusts are dropped, sometimes no drops. It is random, I don't know what happens. I really don't think it come from my side :/ And I can't release my mod with this bug :/ Do you have any ideas ?

Link to comment
Share on other sites

Probably what's happening is you are removing the supporting block before the redstone dust and torches. Then it drops as an item before you removed the actual block. I'm not sure what all the flags represent, but I'm sure one of the flags must allow you to remove the block without updating the surrounding blocks.ย  If not, perhaps you should try removing all the blocks that require a support, then those that don't.

With all due respect, sir: I do, what I do, the way I do it. ~ MacGyver

Link to comment
Share on other sites

perhaps you should try removing all the blocks that require a support

When I do it, that's work but no way lol xD This is for this mod https://www.youtube.com/watch?v=A3_ibDsezwo, and I can't reverse iterate throught the dependency tree to know which I have to remove first xD That's why I must remove blocks without taking care about orders. Why it's work for 4 blocks with dependency and more it doesn't ? :/

ย 

ย 

Link to comment
Share on other sites

Sometimes it works, sometimes it doesn't? Could it be that you are trying to remove some of these blocks client side? I've run into that problem before, myself....

ย 

Also, reverse iteration is hardly needed: just work from the highest y to the lowest. That already eliminates anything on floors - only things on walls could then still be an issue...

ย 

Is there any way you could maybe remove non-opaque blocks first? Because all the things you mention need to be attached to opaque blocks...

If anyone has a comprehensive, visual guide to GUIs - don't hesitate to message me. They make my head spin.

Link to comment
Share on other sites

I'm not sure what all the flags represent

ย 

Is in the Javadoc.

1 causes a block update.

2 sends the change to the client.

4 prevents it from being rerendered.

Flags can be added together.

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

Sometimes it works, sometimes it doesn't? Could it be that you are trying to remove some of these blocks client side? I've run into that problem before, myself....

ย 

Also, reverse iteration is hardly needed: just work from the highest y to the lowest. That already eliminates anything on floors - only things on walls could then still be an issue...

ย 

Is there any way you could maybe remove non-opaque blocks first? Because all the things you mention need to be attached to opaque blocks...

ย 

I do this operation serverside only.

It's not a simple reverse iteration :/ Because wall hanging object, bed, and other custom blocks could be afftected :/

My mod must be compatible with other mods ... Imagine a mods which add a diamond non-opaque block which need support from above, it will be droped and replaced, so duplicate.

I can't release my mod with this potential bug :/

Link to comment
Share on other sites

Here's an idea:

1. Scan for and store all ItemEntities in the area.

2. Destroy blocks.

3. Destroy all ItemEntities in the area.

4. Do whatever you do to restore blocks in that really cool video ya got.

5. Restore the stored ItemEntities.

If anyone has a comprehensive, visual guide to GUIs - don't hesitate to message me. They make my head spin.

Link to comment
Share on other sites

Now I'm curious. How exactly did you do that in the video? I'm assuming you get affected block positions from explosion event, but how did you get them to slowly regenerate,ย  instead of all at once? Did you start a new thread for that?

With all due respect, sir: I do, what I do, the way I do it. ~ MacGyver

Link to comment
Share on other sites

Now I'm curious. How exactly did you do that in the video? I'm assuming you get affected block positions from explosion event, but how did you get them to slowly regenerate,ย  instead of all at once? Did you start a new thread for that?

ย 

https://github.com/EyZox/ForgeCreeperHeal/tree/1.2.0

Open source ;)

Handler : https://github.com/EyZox/ForgeCreeperHeal/blob/1.2.0/main/java/fr/eyzox/forgecreeperheal/handler/ExplosionEventHandler.java

Handler Processing Class : https://github.com/EyZox/ForgeCreeperHeal/blob/1.2.0/main/java/fr/eyzox/forgecreeperheal/worldhealer/WorldHealer.java

Data Structure : https://github.com/EyZox/ForgeCreeperHeal/blob/1.2.0/main/java/fr/eyzox/timeline/AbstractTimeline.java

ย 

I use the tick loop, because Minecraft isn't thread safe ;)

Link to comment
Share on other sites

So, I was working on a solution and I came up with this something like this. I'm not sure how you are storing blocks to be removed, but I used a Map<BlockPos, IBlockState>, and an additional map for tile entities.

ย 

To remove blocks, something like this worked for me:

ย 

ย 


ย  ย  
ย  ย  public static List<BlockPos> orderBlocks(List<BlockPos> affectedBlockPositions, World worldObj) {

ย  ย  	final List<BlockPos> airBlocks = Lists.newArrayList();
ย  ย  	final List<BlockPos> fallingBlocks = Lists.newArrayList();
ย  ย  	final List<BlockPos> fullBlocks = Lists.newArrayList();
ย  ย  	final List<BlockPos> nonFullBlocks = Lists.newArrayList();
ย  ย  	
ย  ย  	Iterator<BlockPos> iterator = affectedBlockPositions.iterator();
ย  ย  	while (iterator.hasNext()) {
ย  ย  		BlockPos pos = iterator.next();
ย  ย  		Block block = worldObj.getBlockState(pos).getBlock();
ย  ย  		
ย  ย  		if (block == Blocks.air) airBlocks.add(pos);
ย  ย  		else if (block instanceof BlockFalling) fallingBlocks.add(pos);
ย  ย  		else if (block.isFullBlock()) fullBlocks.add(pos);
ย  ย  		else nonFullBlocks.add(pos);
ย  ย  	}

ย  ย  	airBlocks.addAll(fullBlocks);
ย  ย  	airBlocks.addAll(fallingBlocks);
ย  ย  	airBlocks.addAll(nonFullBlocks);
ย  ย  	
ย  ย  	return airBlocks;
ย  ย  }

ย 

ย 

Might not be the most efficient way, but it seems to work.

ย 

For replacing the blocks, it was similar, but just a bit more complicated. Assuming the blocks are stored in a map like above, replacing them like this should work.

ย 




			Comparator<BlockPos> posComparator = new Comparator<BlockPos>() {

				@Override
				public int compare(BlockPos o1, BlockPos o2) {
					return o1.compareTo(o2);
				}

			};


			List<Map<BlockPos, IBlockState>> ordered = Lists.newArrayList();
			Map<BlockPos, IBlockState> fullBlocks = Maps.newHashMap();
			Map<BlockPos, IBlockState> fallingBlocks = Maps.newTreeMap(posComparator);
			Map<BlockPos, IBlockState> nonFullBlocks = Maps.newHashMap();
			ordered.add(fullBlocks);
			ordered.add(fallingBlocks);
			ordered.add(nonFullBlocks);

			for (Map.Entry<BlockPos, IBlockState> entry : blocks.entrySet()) {

				Block block = entry.getValue().getBlock();

				if (block == Blocks.air) continue;
				else if (block instanceof BlockFalling) fallingBlocks.put(entry.getKey(), entry.getValue());
	ย  ย  		else if (block.isFullBlock()) fullBlocks.put(entry.getKey(), entry.getValue());
	ย  ย  		else nonFullBlocks.put(entry.getKey(), entry.getValue());

			}

ย 

ย 

If you iterate over the list 'ordered', and then iterate over each map and replace accordingly, you shouldn't have too many problems. Only thing is that doing it like so seems to screw over doors and beds, but it seems you already have a workaround for that. Again, this probably is terribly inefficient, and ugly, but it seemed to work.

With all due respect, sir: I do, what I do, the way I do it. ~ MacGyver

Link to comment
Share on other sites

This is not efficient, not scalable and not custom block compatible.

Watch my code, I use a Factory to build each "healable block". Its allow someone who have create a custom block to create its own factory to make it compatable with my mod.

I can't use falling, non-opaque etc ... because this is not constant rules.

ย 

Then, with you method, you sort all block in one time when an explosion occurs. This could create a lag spike for massive explosions.

Link to comment
Share on other sites

This is not efficient, not scalable and not custom block compatible.

Watch my code, I use a Factory to build each "healable block". Its allow someone who have create a custom block to create its own factory to make it compatable with my mod.

I can't use falling, non-opaque etc ... because this is not constant rules.

ย 

Then, with you method, you sort all block in one time when an explosion occurs. This could create a lag spike for massive explosions.

Yeah that's just something I threw together quickly as a proof of concept. I didn't bother making it scalable or compatible with custom blocks since you already had. It got me thinking,ย  though.ย  Perhaps for each IHealable, you can require a priority. Then, use that priority to determine removal and replace order. Just a thought, though.

With all due respect, sir: I do, what I do, the way I do it. ~ MacGyver

Link to comment
Share on other sites

I ran in debug mod with breakpoint on each EntityItem constructors.

Except these f*ck**g chickens who spawn eggs entity items each 5 min, I could see where is the problem by studying the stack trace.

ย 

World.setBlockState call Chunk.setSate call Block.breakBlock call sometimes Block.updateNeightboor ><

So the call to Block.breakBlock in Chunk.setState is the source of this issue.

ย 

I think I have to create a copy of Chunk.setState method, use reflection to access private Chunk field and then I hope this will be fixed.

ย 

However, I have an other question if I use reflection.

What is the most performant ? Create a wrapper wich contains private chunk field initialized in constructor with reflection and store it in cache while explosion event processing. Or each time use reflection to get field ?

I think I will ask this on stackoverflow but if someone have the answers, I take it :P

ย 

ย 

Link to comment
Share on other sites

I would think that doing it once per explosion then storing it would be faster, since you're only doing it once. You could try both ways, test performance, and if there is no noticeable difference, you could do what you are most comfortable with. For me though, unless the speed benefits contrast in a large manner, I tend to go for whatever I come up with first that works.

With all due respect, sir: I do, what I do, the way I do it. ~ MacGyver

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

    • SV388: Temukan situs taruhan sabung ayam resmi yang terjamin aman di Winning303! Bergabunglah dengan SV388 untuk pengalaman taruhan sabung ayam yang mengasyikkan dan aman. Nikmati berbagai pertandingan sabung ayam terbaik sambil memanfaatkan layanan terpercaya dari Winning303. Daftar sekarang dan rasakan sensasi taruhan yang tak terlupakan dengan SV388 di Winning303! โฑโฑโฑโฑโฑ DAFTAR DI SINI โฐโฐโฐโฐโฐ โฑโฑโฑโฑโฑ DAFTAR DI SINI โฐโฐโฐโฐโฐ
    • MPO1121: Temukan daftar situs judi slot dengan layanan pembayaran melalui Bank Danamon. Bergabunglah dengan MPO1121 untuk pengalaman taruhan slot online yang menarik dan aman. Nikmati berbagai permainan slot terbaik sambil memanfaatkan kemudahan pembayaran melalui Bank Danamon. Daftar sekarang dan rasakan sensasi taruhan yang tak terlupakan dengan MPO1121!" โฑโฑโฑโฑโฑ DAFTAR DI SINI โฐโฐโฐโฐโฐ โฑโฑโฑโฑโฑ DAFTAR DI SINI โฐโฐโฐโฐโฐ
    • Salah satu jenis permainan yang populer adalah slot 0nline. Dalam dunia slot online, terdapat beberapa server yang dikenal memiliki tingkat kemenangan yang tinggi, salah satunya adalah server Kamboja. Di server ini, terdapat seorang pemain yang dikenal dengan sebutan "Abang Gac0r", yang memiliki reputasi sebagai pemain yang sering menang besar. >> DAFTAR LANGSUNG DISINI << Slot Server THAILAND - Abang Gacor dikenal sebagai pemain slot online yang sangat berpengalaman dan memiliki keberuntungan yang luar biasa. Dia sering kali berhasil memenangkan jackpot dan hadiah besar dalam permainan slot online. Banyak pemain lain yang mengagumi kemampuannya dalam bermain slot online di server Kamboja ini. Slot Gacor Maxwln - Salah satu alasan mengapa Abang Gacor sering menang adalah karena dia memiliki strategi bermain yang baik. Dia tidak hanya mengandalkan keberuntungan semata, tetapi juga memperhatikan faktor-faktor lain seperti memilih mesin slot yang tepat, mengatur taruhan dengan bijak, dan mengetahui kapan harus berhenti bermain. Slot Gac0r Resmi - Selain itu, Abang Gacor juga sering memanfaatkan promo dan bonus yang ditawarkan oleh situs slot online. Dengan memanfaatkan promo dan bonus ini, dia dapat meningkatkan peluangnya untuk menang tanpa harus mengeluarkan banyak modal.
    • RAJA328 ๐Ÿ’ฏ Daftar Link Slot Gacor Hari Ini Bisa Judi Slot Online KLIK DISINI >>>ย ย ย DAFTAR AKUN GACOR KLIK DISINI >>>ย DAFTAR AKUN VVIP KLIK DISINI >>>ย ย LINK ALTERNATIF KLIK DISINI >>>ย AKUN GACOR SCATTER HITAM RAJA328 adalah slot gacor winrate 100% dengan server thailand dan akun pro. Dapatkan akses menuju kemenangan ke puluhan sampai ratusan juta rupiah hanya dalam hitungan menit. 3 web yang kami hadirkan ini adalah yang terbaik dengan histori kemenangan tertinggi di satu Asia Tenggara. Member-member dari web ini selalu kembali karena tim admin dan CS yang profesional serta kemenangan berapapun pasti akan dibayar. RTP slot gacor juga sudah disiapkan agar kalian tidak bingung lagi mau main apa dan di jam berapa. Semua fasilitas seperti deposit dana dan pulsa sudah disiapkan juga untuk kemudahan para slotters. Jadi tunggu apalagi? Raih kemenangan kalian disini sekarang juga!
    • Dengan bonus 100% untuk pemain baru, pilihan permainan yang luas, keamanan dan keandalan yang tak tertandingi, layanan pelanggan yang ramah dan responsif, serta kemudahan akses dan kompatibilitas, tidak ada alasan untuk tidak memilih Pasarbaris sebagai tempat Anda bermain slot online. Bergabunglah sekarang dan rasakan sensasi keseruan dan kegembiraan yang ditawarkan oleh Pasarbaris! ย  ย 
  • Topics

×
×
  • Create New...

Important Information

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