Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2] Smooth Velocity for Client-Side Entity


Solitary_Knight
 Share

Recommended Posts

I'm trying to add a feature to a mod (1.12.2 currently, and ideally 1.8.9 as well) which will allow me to spawn an entity (armor stand) and control its movement. For testing, I'm having the entity copy my movements, offset by x = 2. I need to do everything client-side because I want it to run on a server to which I don't have access. Here is a thread which I am running via a command. "player" is the command sender, "world" is Minecraft.getInstance().world, and "mil" is just the milliseconds between updates.

class EntityThread extends Thread {
	Entity player;
	int mil;
	World world;
	EntityThread(EntityPlayer player, World world, int mil) {
		this.player = player;
		this.mil = mil;
		this.world = world;
	}

	public void run() {
		if (this.world.isRemote == true) {
			TKRS.message("Not server side.");
		}
		double x = player.posX + 2;
		double y = player.posY;
		double z = player.posZ;
		double vx = player.motionX;
		double vy = player.motionY;
		double vz = player.motionZ;
		float yaw = player.rotationYaw;
		float pitch = player.rotationPitch;
		Entity entity = new net.minecraft.entity.item.EntityArmorStand(world, x, y, z);
		world.spawnEntity(entity);
		for (int i = 0; i < (int)(10000/mil); i++) {
			try {
				Thread.sleep(this.mil);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
			x = player.posX + 2;
			y = player.posY;
			z = player.posZ;
			vx = player.motionX;
			vy = player.motionY;
			vz = player.motionZ;
			yaw = player.rotationYaw;
			pitch = player.rotationPitch;
			
			entity.setLocationAndAngles(x, y, z, yaw, pitch);
			entity.setVelocity(vx, vy, vz);
			entity.velocityChanged = true;
			world.updateEntity(entity);
		}
		world.removeEntity(entity);
	}
}

This works OK both in single-player and on a server, except that it is very jittery because the position is only updating 20 times per second, and the velocity does not update at all. If I provide a server world to the EntityThread (only possible in singleplayer), it is smooth with velocity updates, but lags behind my movements for some reason (client-side world doesn't lag, just jittery).

 

So my question is, how can I update the velocity for an entity spawned on client-side, without significant lag? I've tried looking up how to simulate clientbound packets from a non-existent server to update the velocity, but no luck so far.

Edited by Solitary_Knight
Link to comment
Share on other sites

  • Solitary_Knight changed the title to [1.12.2] Smooth Velocity for Client-Side Entity
  • Maybe using a different thread is iffy, but it's working perfectly fine for me so far.
  • I am spawning the entity client-side, so that statement isn't true. I can't interact with it, and that's fine, I just want to be able to control its visual movement, which I can do, just not smoothly.

I did get it able to be a little smoother by using .setLocationAndAngles() every tick, and .move() 5 times per tick, but a better solution would be appreciated.

Link to comment
Share on other sites

14 minutes ago, Solitary_Knight said:

Maybe using a different thread is iffy, but it's working perfectly fine for me so far.

It's not iffy, it is broken. It will break. And in unpredictable and seemingly inexplicable and strange ways.

 

15 minutes ago, Solitary_Knight said:

I am spawning the entity client-side, so that statement isn't true. I can't interact with it, and that's fine, I just want to be able to control its visual movement, which I can do, just not smoothly.

The entity will behave strangely and this is in general not an intended use. If you want something to be client-side only use something other than entities, such as particles.

  • Haha 1
Link to comment
Share on other sites

1 hour ago, diesieben07 said:

It's not iffy, it is broken. It will break. And in unpredictable and seemingly inexplicable and strange ways.

 

The entity will behave strangely and this is in general not an intended use. If you want something to be client-side only use something other than entities, such as particles.

If a thread is going to break, do you have a recommendation for an alternative way to get/set player/entity position ~100 times per second?

I need the object which I am moving to be an armor stand (so that I can put a block on its head). I assume there is no such thing as a particle armor stand?

Link to comment
Share on other sites

9 hours ago, Solitary_Knight said:

so that I can put a block on its head

Perhaps you just want to render a block there instead? I'm not sure exactly what your intent here is, but that might be what you're looking for.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

9 hours ago, Solitary_Knight said:

I need the object which I am moving to be an armor stand (so that I can put a block on its head)

You realize that this entity you've created on the client side basically is a ghost, right? Nothing you do will ever show up on any other client's view of what you're doing. Placing a block "on" the armor stand won't take that block out of your inventory, etc.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

What are you trying to achieve, from a player’s perspective?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

I think OP wants to create a visual effect of an armor stand. There is no need for interaction or synchronizing to other clients.

 

Entities are not meant to be used as client-side rendering techniques. Instead of spawning the entity in the client world, you should subscribe to RenderWorldLastEvent and manually render the armor stand there. One approach would be to create a static list of all the visual armor stand's data, and render ArmorStandEntity in RenderWorldLastEvent according to the list.

 

Then, instead of creating another thread to handle the updating, simply subscribe to ClientTickEvent and make a timer to determine when movements should be applied to the rendered armor stand.

  • Like 1

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

45 minutes ago, DavidM said:

I think OP wants to create a visual effect of an armor stand. There is no need for interaction or synchronizing to other clients.

 

Entities are not meant to be used as client-side rendering techniques. Instead of spawning the entity in the client world, you should subscribe to RenderWorldLastEvent and manually render the armor stand there. One approach would be to create a static list of all the visual armor stand's data, and render ArmorStandEntity in RenderWorldLastEvent according to the list.

 

Then, instead of creating another thread to handle the updating, simply subscribe to ClientTickEvent and make a timer to determine when movements should be applied to the rendered armor stand.

Yes, you are correct about what I am trying to do. Although I don't understand it completely yet, what you are suggesting sounds useful, and I'll try it. Thanks

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Although that too has issues. The forge defined configuration files are loaded after registration
    • Unless I have misunderstood your requirements, I don't think what you are trying to do is going to work.   The closest things in minecraft are banner patterns or paintings. But these are registered in code (not what you want) on both the client and the server. Then when it loads resource packs on the client it looks up the texture for each one.   It does it this way because the game defines what should exist, then lets the user/modpack developer give them textures (with you providing a default texture).   You seem to want to populate a registry from what textures exist in a resource pack? So kind of the reverse. This isn't going to work for at least 2 reasons: * By the time resource packs are loaded, the registries are frozen - It is too late. * Servers don't even load resource packs, so there is no way it can use this mechanism    You need some other mechanism to populate your registry. e.g. a configuration file holding the names of what should exist, but it doesn't sound like what you want?
    • For the most part, this worked, somehow more mods were outdated and i need to fix them
    • You have a version of oculus from the beta (1.2.5) The latest version is mc1.19-1.2.5a, if that doesn't work contact the mod author https://www.curseforge.com/minecraft/mc-mods/oculus/files  
    • ---- Minecraft Crash Report ---- // Hi. I'm Minecraft, and I'm a crashaholic. Time: 8/10/22 7:20 PM Description: Mod loading error has occurred java.lang.Exception: Mod Loading has failed     at net.minecraftforge.fml.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:85) [?:?] {re:classloading}     at net.minecraftforge.fml.client.ClientModLoader.completeModLoading(ClientModLoader.java:188) [?:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.lambda$null$1(Minecraft.java:508) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft$$Lambda$3569/1174919051.run(Unknown Source) [?:?] {}     at net.minecraft.util.Util.func_215077_a(Util.java:320) [?:?] {re:classloading}     at net.minecraft.client.Minecraft.lambda$new$2(Minecraft.java:504) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft$$Lambda$3352/424832797.accept(Unknown Source) [?:?] {}     at net.minecraft.client.gui.ResourceLoadProgressGui.func_230430_a_(ResourceLoadProgressGui.java:113) [?:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.func_195458_a(GameRenderer.java:481) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.func_195542_b(Minecraft.java:977) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:607) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:184) [?:?] {re:classloading,pl:runtimedistcleaner:A}     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] {}     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_51] {}     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_51] {}     at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_51] {}     at net.minecraftforge.fml.loading.FMLClientLaunchProvider.lambda$launchService$0(FMLClientLaunchProvider.java:51) [forge-1.16.5-36.2.34.jar:36.2] {}     at net.minecraftforge.fml.loading.FMLClientLaunchProvider$$Lambda$420/566698125.call(Unknown Source) [forge-1.16.5-36.2.34.jar:36.2] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.1.3.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.1.3.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.1.3.jar:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.1.3.jar:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.1.3.jar:?] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at net.minecraftforge.fml.CrashReportExtender.lambda$dumpModLoadingCrashReport$7(CrashReportExtender.java:88) ~[?:?] {re:classloading} -- MOD jei -- Details:     Mod File: jei-1.16.5-7.7.1.152.jar     Failure message: fml.modloading.dupedmod     Mod Version: 7.7.1.152     Mod Issue URL: https://github.com/mezz/JustEnoughItems/issues?q=is%3Aissue     Exception message: MISSING EXCEPTION MESSAGE Stacktrace:     at net.minecraftforge.fml.CrashReportExtender.lambda$dumpModLoadingCrashReport$7(CrashReportExtender.java:88) ~[?:?] {re:classloading}     at net.minecraftforge.fml.CrashReportExtender$$Lambda$3599/485371408.accept(Unknown Source) ~[?:?] {}     at java.util.ArrayList.forEach(ArrayList.java:1249) ~[?:1.8.0_51] {}     at net.minecraftforge.fml.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:86) [?:?] {re:classloading}     at net.minecraftforge.fml.client.ClientModLoader.completeModLoading(ClientModLoader.java:188) [?:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.lambda$null$1(Minecraft.java:508) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft$$Lambda$3569/1174919051.run(Unknown Source) [?:?] {}     at net.minecraft.util.Util.func_215077_a(Util.java:320) [?:?] {re:classloading}     at net.minecraft.client.Minecraft.lambda$new$2(Minecraft.java:504) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft$$Lambda$3352/424832797.accept(Unknown Source) [?:?] {}     at net.minecraft.client.gui.ResourceLoadProgressGui.func_230430_a_(ResourceLoadProgressGui.java:113) [?:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.func_195458_a(GameRenderer.java:481) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.func_195542_b(Minecraft.java:977) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:607) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:184) [?:?] {re:classloading,pl:runtimedistcleaner:A}     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] {}     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_51] {}     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_51] {}     at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_51] {}     at net.minecraftforge.fml.loading.FMLClientLaunchProvider.lambda$launchService$0(FMLClientLaunchProvider.java:51) [forge-1.16.5-36.2.34.jar:36.2] {}     at net.minecraftforge.fml.loading.FMLClientLaunchProvider$$Lambda$420/566698125.call(Unknown Source) [forge-1.16.5-36.2.34.jar:36.2] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.1.3.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.1.3.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.1.3.jar:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.1.3.jar:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.1.3.jar:?] {} -- System Details -- Details:     Minecraft Version: 1.16.5     Minecraft Version ID: 1.16.5     Operating System: Windows 10 (amd64) version 10.0     Java Version: 1.8.0_51, Oracle Corporation     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation     Memory: 507993864 bytes (484 MB) / 1791492096 bytes (1708 MB) up to 3817865216 bytes (3641 MB)     CPUs: 4     JVM Flags: 4 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xss1M -Xmx4096m -Xms256m     ModLauncher: 8.1.3+8.1.3+main-8.1.x.c94d18ec     ModLauncher launch target: fmlclient     ModLauncher naming: srg     ModLauncher services:          /mixin-0.8.4.jar mixin PLUGINSERVICE          /eventbus-4.0.0.jar eventbus PLUGINSERVICE          /forge-1.16.5-36.2.34.jar object_holder_definalize PLUGINSERVICE          /forge-1.16.5-36.2.34.jar runtime_enum_extender PLUGINSERVICE          /accesstransformers-3.0.1.jar accesstransformer PLUGINSERVICE          /forge-1.16.5-36.2.34.jar capability_inject_definalize PLUGINSERVICE          /forge-1.16.5-36.2.34.jar runtimedistcleaner PLUGINSERVICE          /mixin-0.8.4.jar mixin TRANSFORMATIONSERVICE          /forge-1.16.5-36.2.34.jar fml TRANSFORMATIONSERVICE      FML: 36.2     Forge: net.minecraftforge:36.2.34     FML Language Providers:          javafml@36.2         minecraft@1         kotori_scala@2.13.8-build-3     Mod List:          forge-1.16.5-36.2.34-client.jar                   |Minecraft                     |minecraft                     |1.16.5              |NONE      |Manifest: NOSIGNATURE         forge-1.16.5-36.2.34-universal.jar                |Forge                         |forge                         |36.2.34             |NONE      |Manifest: 22:af:21:d8:19:82:7f:93:94:fe:2b:ac:b7:e4:41:57:68:39:87:b1:a7:5c:c6:44:f9:25:74:21:14:f5:0d:90
  • Topics

×
×
  • Create New...

Important Information

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