Jump to content

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


Kriptikz

Recommended Posts

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



×
×
  • Create New...

Important Information

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