Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Solved] [1.11.2] Entity not spawning client side and opinions on my design.

Featured Replies

Posted

When spawning an entity from an items onPlayerStoppedUsing method, the entity works server side but it seems it's not getting spawned client side.

Here is my item class:

https://github.com/Kriptikz/Archmage/blob/1.11.2/src/main/java/kriptikz/archmage/item/ItemWand.java#L55

From what I understand, an entity should only be spawned server side and the server will tell the client to spawn the entity, but it's not spawning it on the client.

This worked for me previously before I changed my spell class hierarchy to something I thought would work better for me. Basically I have it set up so my ItemWand class will be cleaner,

previously I had this:

Spoiler

	@Override
	public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeleft)
	{
		if (timeleft <= 975)
		{		
			if (!worldIn.isRemote)
			{
				EntitySpellProjectile spell = null;
				IPlayerData playerData = PlayerDataProvider.getPlayerCapability(entityLiving);
				
				switch(playerData.getSelectedSpell())
				{
					case 0:
						spell = new EntitySpellProjectile(worldIn, entityLiving, SpellProjectileHandler.FIREBALL);
						break;
					case 1:
						spell = new EntitySpellProjectile(worldIn, entityLiving, SpellProjectileHandler.STUN);
						break;
					case 2:
						SpellSelfHeal.healPlayer((EntityPlayer) entityLiving,
								((SpellDataHelper.getHealAmount(playerData.getSelectedSpell(),
										playerData.getSpellLevel(playerData.getSelectedSpell())))));

						float manaCost = SpellDataHelper.getManaCost(playerData.getSelectedSpell(),
								playerData.getSpellLevel(playerData.getSelectedSpell()));
						
						if ((playerData.getMana() - manaCost) >= 0)
						{
							playerData.setMana(playerData.getMana() - manaCost);
						}
						else
						{
							entityLiving.sendMessage(new TextComponentString("Not enough mana!!!"));
						}

						break;
					case 3:
						spell = new EntitySpellProjectile(worldIn, entityLiving, SpellProjectileHandler.HEALPROJECTILE);
						break;
					case 4:
						spell = new EntitySpellProjectile(worldIn, entityLiving, SpellProjectileHandler.DIZZIFY);
						break;
					case 5:
						spell = new EntitySpellProjectile(worldIn, entityLiving, SpellProjectileHandler.SLOW);
						break;
					case 6: 
						// SpellDummyClone
						if ((playerData.getMana() - 25) >= 0)
						{
							playerData.setMana(playerData.getMana() - 25);
							
							RayTraceResult result = this.rayTrace(worldIn, (EntityPlayer)entityLiving, false);
							BlockPos blockPos = result.getBlockPos();
							
							worldIn.spawnEntity(new EntityDummyTarget(worldIn, blockPos, entityLiving.getPosition(), 100, (EntityPlayer)entityLiving));
						}
						else
						{
							entityLiving.sendMessage(new TextComponentString("Not enough mana!!!"));
						}
						
						break;
					case 7:
						if (entityLiving instanceof EntityPlayer)
						{
							SpellLevitate.levitate((EntityPlayer) entityLiving);
						}
						break;
					case 8:
						spell = new EntitySpellProjectile(worldIn, entityLiving, SpellProjectileHandler.WARP);
						break;
					case 9:
						TeleportDestination teleportDestination = playerData.getTeleportDestination();
						BlockPos teleportPos = teleportDestination.getTeleportPos();
						int dimId = teleportDestination.getTeleportDimId();
						int oldId = entityLiving.getEntityWorld().provider.getDimension();
						
				        if (oldId != dimId)
				        {
				            TeleportDestination.teleportToDimension((EntityPlayer) entityLiving, dimId, teleportPos.getX() + 0.5, teleportPos.getY() + 1.5, teleportPos.getZ() + 0.5);
				        } 
				        else
				        {
				            ((EntityPlayer) entityLiving).setPositionAndUpdate(teleportPos.getX()+0.5, teleportPos.getY() + 0.5, teleportPos.getZ()+0.5);
				        }
						
						break;
					
				}
				if (spell != null)
				{
					float manaCost = SpellDataHelper.getManaCost(playerData.getSelectedSpell(), playerData.getSpellLevel(playerData.getSelectedSpell()));
					
					if ((playerData.getMana() - manaCost) >= 0)
					{
						playerData.setMana(playerData.getMana() - manaCost);
						worldIn.spawnEntity(spell);						
					}
					else
					{
						entityLiving.sendMessage(new TextComponentString("Not enough mana!!!"));
					}
				
				}

			}
		}
	}

 

Some spells are projectiles and some are not. So in the new version I have ISpellBase interface which has only two methods, isProjectile() and doSpell(). From here I have another base class called EntitySpellBase. If the spell is a projectile I extend EntitySpellBase, if not it just implements ISpellBase. I use isProjectile() to determine if the spell is a projectile, if it is I spawn it, if its not I just doSpell(). My goal with the change was to make the code cleaner and make it easier to implement different models for different spell projectiles as well as allow handling a spell easily whether it is suppose to be a projectile or not.

So in the switch statement any spell could be initialized like this, whether it is suppose to be an entity or not:

Spoiler

spell = new SpellFireball(worldIn, entityLiving);

 

Where SpellFireball is replaced by the corresponding spell.

This seemed like it could work nicely, but maybe it's a bad design. I'm pretty new to programming in general so any criticism is welcome. I do have other designs in mind but I liked this one the most. 

Edited by Kriptikz
Solved

  • Author
5 minutes ago, diesieben07 said:

Cloned your repo and the entity definitely spawns on the client.

Do you see the particles as well?

  • Author
16 minutes ago, diesieben07 said:

Yes, I did see fire particles.

Sorry I should have been more specific, I meant the travel and impact particles.

Edited by Kriptikz

  • Author

Ok, It is spawning on the client, I just wasn't writing maxTicksExisted with writeSpawnData(), so it was defaulting to 0 on the client lol, woops. Now to figure out why the particles aren't spawning.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.