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

Has anybody seen a weird effect where a spawned throwable, regardless of the velocity set, appears to drop straight down... yet the coordinates seen in onImpact appear to reflect the velocity given?

 

This is my first attempt to spawn a throwable entity, and for the moment I haven't even defined a proper model for it, so it appears as a white cube.  The white cube appears in front of me where I expected, but then it appears to drop straight down and disappear.  Some short time later, onImpact fires with coordinates that are not straight down.  Here's the code for my Throwable subclass:

 

package net.strout.wizarding;

import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;

public class EntitySpell extends EntityThrowable {

    public EntitySpell(World worldIn) {
    		super(worldIn);
    }

	public static String GetRegistryName() {
		return ModMain.MODID + ":" + "spell";
	}
	
	@Override
	protected void onImpact(RayTraceResult result) {
		System.out.println("Spell hit something at " + result.hitVec + " side " + result.sideHit);
		this.setDead();
	}

}

 

Here's where I register it in my main class:

	@SubscribeEvent
	public static void registerEntities(RegistryEvent.Register<EntityEntry> event) {
		ModelResourceLocation res = new ModelResourceLocation(EntitySpell.GetRegistryName(), "entity");
		EntityEntry entry = EntityEntryBuilder.create()
			    .entity(EntitySpell.class)
			    .id(res, 1234)   // ?!?
			    .name("wizarding_spell")
			    .tracker(64, 20, false)
			    .build();
			event.getRegistry().register(entry);	
		System.out.println("Registered entity: " + entry.getRegistryName());
	}

 

And finally, here's where I spawn it, for now in response to a chat message on the server:

	@SubscribeEvent
	public static void onChat(ServerChatEvent event) {
		String msg = event.getMessage().toLowerCase();
		// ...
		if (msg.startsWith("spawn")) {
			double speed = Double.parseDouble(msg.substring(6));
			if (speed == 0) speed = 1;
			WorldServer world = event.getPlayer().getServerWorld();
			EntitySpell entity = new EntitySpell(world);
			Vec3d pos = PointAhead(1F);
			Vec3d dir = event.getPlayer().getLookVec();
			entity.setPosition(pos.x, pos.y, pos.z);
			entity.shoot(dir.x, dir.y, dir.z, (float)speed, 0.1F);
			world.spawnEntity(entity);
			SendStatus("Spawned spell at " + entity.getPosition() + " with velocity " + entity.motionX + ", " + entity.motionY + ", " + entity.motionZ);
		}
	}

 

When I run this, I see the cube appear and drop straight down, regardless of which way I'm facing or what velocity I specify.  But the console shows stuff like:

[21:17:23] [Server thread/INFO]: [CHAT] Spawned spell at BlockPos{x=-132, y=102, z=275} with velocity 1.3810391495309446, 1.4458082115081663, 0.03919115940359643
[21:17:23] [Server thread/INFO]: <Player416> spawn 2
  ...
[21:17:23] [main/INFO]: [CHAT] <Player416> spawn 2
[21:17:28] [Server thread/INFO] [STDOUT]: [net.strout.wizarding.EntitySpell:onImpact:20]: Spell hit something at (-47.548026190592275, 92.0, 277.67980515187014) side up

 

So you can see here that I was facing mostly in the +X direction, and also pitched up (+Y).  And when the thing landed, it had a major change in X and Y, but not Z.

 

Any idea what I'm missing here?

Edited by JoeStrout

  • Author

Thanks for those tips, that's really helpful — I couldn't find any docs on what all those parameters mean.

(PointAhead just gets a point directly ahead of where the player is looking.)

 

...It looks like that sendVelocityUpdates=false was causing my problem; changing it to true makes everything work.  Hey cool, I have successfully spawned a particle!  :)

 

Thanks again for your help.

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.