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.

Featured Replies

Posted

I am working with Packets to assign a value to an Entity's Client Side version to pass animation information to its Model class. This particular value tells the client side entity that the mob has a current target (aggro). Most all of the code I have checked seems to run/fire correctly but the key value I need assigned/changed doesn't change on the client side entity.

 

With this set up, when I run print statements I see the Server side Entity will say true for isAggroed but false for Client side.

 

Here is what I have right now:

Entity Class (EntityImmortalArcanine):

	public boolean isAggroed = false;

.......

	@Override
	public void onUpdate()
	{
		super.onUpdate();

		.....

  		if(!this.world.isRemote)
		{
			System.out.println( "Server isAggroed " + isAggroed );
			
			checkAggro();
		}
		else
		{
			System.out.println( "Client isAggroed " + isAggroed );
			
			calculateAggroValue();
		}
		....
	}

	public void checkAggro()
	{
		if(this.getAttackTarget() != null)
		{
			if(!this.isAggroed)
			{
				this.isAggroed = true;
				KindredLegacyMain.sendMobAggroPacket(this, true);
			}
		}
		else
		{
			if(this.isAggroed)
			{
				this.isAggroed = false;
				KindredLegacyMain.sendMobAggroPacket(this, false);
			}
		}
	}

	@Override
	public void setAggro(boolean isAggroed)
	{
		this.isAggroed = isAggroed;
	}

 

Main Mod Class (KindredLegacyMain):

	@EventHandler
	public void init(FMLInitializationEvent event)
	{
		network = NetworkRegistry.INSTANCE.newSimpleChannel(ModInfo.CHANNEL);
		
		int packetID = 0;
		network.registerMessage(PacketAnimation.Handler.class, PacketAnimation.class, packetID, Side.CLIENT);
		packetID++;
		network.registerMessage(PacketMobTargeting.Handler.class, PacketMobTargeting.class, packetID, Side.CLIENT);

		.....
	}

.......

	public static boolean isEffectiveClient() 
	{
		return FMLCommonHandler.instance().getEffectiveSide().isClient();
	}

	public static void sendMobAggroPacket(IAdvAnimatedEntity entity, boolean isAggroed) 
	{
		if(isEffectiveClient()) 
			return;

		entity.setAggro(isAggroed);
		network.sendToAll(new PacketMobTargeting((boolean)isAggroed, ((Entity)entity).getEntityId()));
	}

 

Packet Class (PacketMobTargeting):

public class PacketMobTargeting implements IMessage 
{
	private boolean isTargeting;
	private int entityID;

	public PacketMobTargeting() {}

	public PacketMobTargeting(boolean isTargetingBoolean, int entity) 
	{
		isTargeting = isTargetingBoolean;
		entityID = entity;
	}

	@Override
	public void toBytes(ByteBuf buffer) 
	{
		buffer.writeBoolean(isTargeting);
		buffer.writeInt(entityID);
	}

	@Override
	public void fromBytes(ByteBuf buffer) 
	{
		isTargeting = buffer.readBoolean();
		entityID = buffer.readInt();
	}

	public static class Handler implements IMessageHandler<PacketMobTargeting, IMessage> 
	{
		@Override
		public IMessage onMessage(PacketMobTargeting packet, MessageContext ctx) 
		{
			World world = KindredLegacyMain.proxy.getWorldClient();
			IAdvAnimatedEntity entity = (IAdvAnimatedEntity)world.getEntityByID(packet.entityID);

			if(entity != null) 
			{
				entity.setAggro(packet.isTargeting);
			}

			return null;
		}
	}
}

 

Associated Interface (IAdvAnimatedEntity):

public interface IAdvAnimatedEntity 
{
	void setAggro(boolean isAggro);
	float getAggroValue();
}

 

This set up is almost identical to an action animation set up I have and that does work correctly.

  • Author

Ah, I did not know EntityDataManager applied to both Client and Server. It works beautifully now, thanks!

 

I may look to see if that can affect my action animation code as that logic was originally written before EntityDataManager was an established thing.

 

Thank you for that little bit about Packets as that helped me better realize what those various functions on SimpleNetworkWrapper are intended to do.

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.