Jump to content

Recommended Posts

Posted (edited)

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
Posted

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

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

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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