Jump to content

[1.12.2] Client Side Entity variable not changing with Packet


FuzzyAcornIndustries

Recommended Posts

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.

Link to comment
Share on other sites

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.

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • we tried both versions and both cant run on her laptop for some reason idk what to do  
    • Okay so we tried both versions and both cant run on her pc for some reason!  
    • Well. Make sure you installed a correct jdk for your forge mdk version. Make sure your JAVA_HOME and %PATH% environment-variables are setup correctly. (If you're on windows)   I downloaded an example forge mdk for my version and extracted the contents to a folder I'm working in Using Eclipse, I opened Eclipse and imported an existing gradle Project (with its root directory in the folder directory which I previously extracted my contents to). Waited for Eclipse to do its thing After it having finished, I ran genEclipseRuns, setupDecompWorkspace and setupDevWorkspace (Gradle Tasks > your mod name here > forgegradle)    If it still didn't work (and you're using Eclipse) run cleanEclipse and, in a command prompt  Also If I recall correctly, someone, somewhere said that the way you setup your workspace changes depending on your Minecraft Version. I did this in 1.8.9.
    • https://mclo.gs/ZlRMU4G Still crash, help 
    • Hi, im having problem with error: Could not resolve dependency: net.minecraftforge:forge:1.20.1:userdev   im new in modding, but i tried everything, and it is still not working. all versions are correct etc.   build gradle: plugins {     id 'eclipse'     id 'idea'     id 'maven-publish'     id 'net.minecraftforge.gradle' version '[6.0,6.2)'     id 'org.parchmentmc.librarian.forgegradle' version '1.+' } version = mod_version group = mod_group_id base {     archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft {     // See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md     // Additional setup is needed to use their mappings: https://parchmentmc.org/docs/getting-started     mappings channel: mapping_channel, version: mapping_version          copyIdeResources = true          runs {         // applies to all the run configs below         configureEach {             workingDirectory project.file('run')             property 'forge.logging.markers', 'REGISTRIES'             // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels             property 'forge.logging.console.level', 'debug'             mods {                 "${mod_id}" {                     source sourceSets.main                 }             }         }         client {             // Comma-separated list of namespaces to load gametests from. Empty = all namespaces.             property 'forge.enabledGameTestNamespaces', mod_id         }         server {             property 'forge.enabledGameTestNamespaces', mod_id             args '--nogui'         }                  gameTestServer {             property 'forge.enabledGameTestNamespaces', mod_id         }         data {             workingDirectory project.file('run-data')                          args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')         }     } } // Include resources generated by data generators. sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { } dependencies {     minecraft "net.minecraftforge:forge:1.20.1" } tasks.named('processResources', ProcessResources).configure {     var replaceProperties = [             minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range,             forge_version: forge_version, forge_version_range: forge_version_range,             loader_version_range: loader_version_range,             mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,             mod_authors: mod_authors, mod_description: mod_description,     ]     inputs.properties replaceProperties     filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {         expand replaceProperties + [project: project]     } } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure {     manifest {         attributes([                 'Specification-Title'     : mod_id,                 'Specification-Vendor'    : mod_authors,                 'Specification-Version'   : '1', // We are version 1 of ourselves                 'Implementation-Title'    : project.name,                 'Implementation-Version'  : project.jar.archiveVersion,                 'Implementation-Vendor'   : mod_authors,                 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")         ])     }     // This is the preferred method to reobfuscate your jar file     finalizedBy 'reobfJar' } publishing {     publications {         register('mavenJava', MavenPublication) {             artifact jar         }     }     repositories {         maven {             url "file://${project.projectDir}/mcmodsrepo"         }     } } tasks.withType(JavaCompile).configureEach {     options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation }       please help me out
  • Topics

×
×
  • Create New...

Important Information

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