Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED]Delay TileEntity removal when block broken in creative mode.
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 2
TheMCJavaFre4k

[SOLVED]Delay TileEntity removal when block broken in creative mode.

By TheMCJavaFre4k, February 27 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

TheMCJavaFre4k    1

TheMCJavaFre4k

TheMCJavaFre4k    1

  • Stone Miner
  • TheMCJavaFre4k
  • Members
  • 1
  • 84 posts
Posted February 27 (edited)

Hi There

Im wanting to prevent the tile entity of a block from being removed until after Ive executed some code within the tile entity via a custom packet.

 

Im able to get this working in survival mode by sending the packet within the getDrops method and delaying removal until the harvestBlock method(Similar to blockFlowerPot) as so:

Spoiler

@Override
	public void getDrops(net.minecraft.util.NonNullList<ItemStack> drops, IBlockAccess worldIn, BlockPos pos, IBlockState state, int fortune)
	{
		super.getDrops(drops, worldIn, pos, state, fortune);
		World world = (World)worldIn;

		TileEntityDJDeck te = world.getTileEntity(pos) instanceof TileEntityDJDeck ? (TileEntityDJDeck)world.getTileEntity(pos) : null;

		System.out.println("Called Get Drops");

		if (te != null) {

			System.out.println("Sending Stop To Server");

			MCDJMod.network.sendToAllAround(new PacketPlaySoundOnClient(pos, 0, 3), new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 20)); 

		}

	}

	@Override
	public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack tool)
	{
		super.harvestBlock(world, player, pos, state, te, tool);

		System.out.println("Harvesting");

		world.setBlockToAir(pos);
		world.removeTileEntity(pos);
	}

	@Override
	public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
		return true; 
	}

 

 Currently when broken in creative, nothing happens(Only breaking particles). I was initially using breakBlock but that didn't provide enough time for the packet to be read and when it was, the tile entity at the BlockPos was already removed.

Im just not sure what methods would provide the necessary time or how i would modify the above setup to work for creative mode.

Edited February 27 by TheMCJavaFre4k
Solved
  • Quote

Share this post


Link to post
Share on other sites

Cadiboo    275

Cadiboo

Cadiboo    275

  • Reality Controller
  • Cadiboo
  • Members
  • 275
  • 3303 posts
Posted February 27

Why are you trying to do this? You can probably send whatever data you need in the packet

  • Quote

Share this post


Link to post
Share on other sites

TheMCJavaFre4k    1

TheMCJavaFre4k

TheMCJavaFre4k    1

  • Stone Miner
  • TheMCJavaFre4k
  • Members
  • 1
  • 84 posts
Posted February 27
1 minute ago, Cadiboo said:

Why are you trying to do this? You can probably send whatever data you need in the packet

My tile entity has a few methods responsible for stopping sound playback. The packet is used to update all nearby clients to stop any sound the TileEntity is making before it is removed. So in the packet handler I'm getting the TileEntity from the position sent over the packet and calling my methods on the client from there.

  • Quote

Share this post


Link to post
Share on other sites

Cadiboo    275

Cadiboo

Cadiboo    275

  • Reality Controller
  • Cadiboo
  • Members
  • 275
  • 3303 posts
Posted February 27

Couldn’t you subscribe to the sound play event and cancel it?

  • Quote

Share this post


Link to post
Share on other sites

TheMCJavaFre4k    1

TheMCJavaFre4k

TheMCJavaFre4k    1

  • Stone Miner
  • TheMCJavaFre4k
  • Members
  • 1
  • 84 posts
Posted February 27
6 minutes ago, Cadiboo said:

Couldn’t you subscribe to the sound play event and cancel it?

I haven't dealt with any Events thus far other than the standard registration ones so I wouldn't know where to begin. They current way I'm dealing with sounds is by using a custom MovingSound class(So to update positioning) being played by Minecraft.getMinecraft().getSoundHandler().playSound(). I can then stop it by passing in the exact same sound. This allows me to differentiate the exact same sound being played from 2 TileEntities and stop them independent of one another. Is this same functionality obtainable using a @SubscribeEvent and subscribing to the PlaySoundEvent class?

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2089

Draco18s

Draco18s    2089

  • Reality Controller
  • Draco18s
  • Members
  • 2089
  • 13986 posts
Posted February 27

Option (a) include all of the relevant parameters in the packet so you don't need the TE.

 

Option (b) use an ITickableSound in order for it to terminate itself when its source block is removed.

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/ores/client/SoundWindmill.java#L37

  • Quote

Share this post


Link to post
Share on other sites

TheMCJavaFre4k    1

TheMCJavaFre4k

TheMCJavaFre4k    1

  • Stone Miner
  • TheMCJavaFre4k
  • Members
  • 1
  • 84 posts
Posted February 27
7 hours ago, Draco18s said:

Option (b) use an ITickableSound in order for it to terminate itself when its source block is removed.

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/ores/client/SoundWindmill.java#L37

I totally forgot to check if I could use the sound to stop itself. I guess I just had tunnel vision when looking at the problem. Considering my custom sound is a tickable sound, this works flawlessly. Thanks heaps!

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 2
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • jgfarrell
      I'm having trouble with Java on !MAC!

      By jgfarrell · Posted 8 minutes ago

      Sorry Junior.   I thought I was going to be a hero!   Good luck.
    • diesieben07
      [1.14.4] [Solved] Trouble With Packets

      By diesieben07 · Posted 50 minutes ago

      If you do this, then there is no point having the capability. Just store it in the stack's NBT tag directly at that point...
    • Cerandior
      [1.14.4] [Solved] Trouble With Packets

      By Cerandior · Posted 57 minutes ago

      Yeah, I registered the entity and everything is fine now.
    • Cerandior
      [1.14.4] [Solved] Trouble With Packets

      By Cerandior · Posted 1 hour ago

      I have no idea man. I tried setting the breakpoints at different parts of the class because intelliJ displays a tree of all the methods called at that point and I never found any of the shareTags methods where I expected them to be. And I know, what I did doesn't really make too much sense because the stack should call the readShareTag and getShareTag automatically (I did look into a lot of methods related to itemstacks), but for some reason nothing was working as expected for me. I just tried that and everything works fine now, if I get rid of that line of code nothing works again.   As for the entity, that is probably caused by the "unique" type of zombie that my staff spawns. I forgot to register that in my registry events. I am surprised the entity was spawning considering I haven't registered them actually. I will register them right now, and check if the error will persist. Thank you for your help.
    • diesieben07
      on/off button for custom furnace

      By diesieben07 · Posted 1 hour ago

      Any GUI that has a button on it. MainMenuScreen for example.
  • Topics

    • Junior240
      4
      I'm having trouble with Java on !MAC!

      By Junior240
      Started November 9

    • Cerandior
      10
      [1.14.4] [Solved] Trouble With Packets

      By Cerandior
      Started 23 hours ago

    • plugsmustard
      18
      on/off button for custom furnace

      By plugsmustard
      Started 23 hours ago

    • AkosM
      3
      Increase target's damage via usable item

      By AkosM
      Started 17 hours ago

    • leesj
      3
      How to Give potion effect to entity

      By leesj
      Started 23 hours ago

  • Who's Online (See full list)

    • Choco
    • diesieben07
    • desht
    • plugsmustard
    • Maraea21
    • Eonasdan
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED]Delay TileEntity removal when block broken in creative mode.
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community