Jump to content

'Faceted' Aiming when velocity is high


drok0920
 Share

Recommended Posts

I have made an item which shoots my custom projectile all is good until i bring the velocity of the projectile to around 15 or higher.  At this point it begins to prefer aiming at 45 degree angles.  rather than where i am actually aiming.  I assume it has to do with how im calculating the motion of the projectile.  Does anyone know how i can fix this problem.

 

Spoiler

package com.drok.progressiveg.common.item;

import com.drok.progressiveg.GunMod;
import com.drok.progressiveg.entity.projectile.EntityLeadBullet;

import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityEnderPearl;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;

public class ItemLeadGun extends Item {
	
	public Item ammo;
	public int damage;
	public int velocity;
	
	public ItemLeadGun(String name, Item ammo, int damage, int velocity) {
		this();
		this.ammo = ammo;
		this.damage = damage;
		this.velocity = velocity;
		
		this.setRegistryName(name);
		this.setUnlocalizedName(name);
		
	}
	
	public ItemLeadGun() {
		this.setCreativeTab(GunMod.TABGUNS);
		this.setMaxStackSize(1);
		
	}
	
	public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
    {
		ItemStack item = findAmmo(playerIn);
		
		if(!item.isEmpty()) {
			EntityLeadBullet bullet = new EntityLeadBullet(worldIn, playerIn, damage);
			bullet.setAim(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 20, 0);
			bullet.posX = playerIn.posX;
			bullet.posY = playerIn.posY + 1;
			bullet.posZ = playerIn.posZ;
			
			
			worldIn.spawnEntity(bullet);

			return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, playerIn.getHeldItemMainhand());
		} else {
			return new ActionResult<ItemStack>(EnumActionResult.FAIL, playerIn.getHeldItemMainhand());
		}
    }
	
	 private ItemStack findAmmo(EntityPlayer player)
	 {
	        for(int i = 0; i < player.inventory.getSizeInventory(); i++) {
	        	ItemStack item = player.inventory.getStackInSlot(i);
	        	
	        	
	        	if(item != null) {
	        		if(item.getItem().getUnlocalizedName().equalsIgnoreCase(ammo.getUnlocalizedName())) {
	        			return item;
	        		}
	        	}
	        }
	        return ItemStack.EMPTY;
	 }
}

 

 


package com.drok.progressiveg.entity.projectile;

import com.drok.progressiveg.GunMod;

import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.IThrowableEntity;

public class EntityLeadBullet extends Entity implements IProjectile {

	public Entity owner;
	public int damage;
	
	public float speed() {
		float a = (float) Math.abs(this.motionX);
		float b = (float) Math.abs(this.motionY);;
		float c = (float) Math.abs(this.motionZ);;
		
		return (a + b + c) / 3;
	};
	
	public EntityLeadBullet(World worldIn) {
		this(worldIn, null, 0);
	}
	
	public EntityLeadBullet(World worldIn, Entity own, int dmg) {
		super(worldIn);
		
		owner = own;
		damage = dmg;
		
		this.setSize(0.5F, 0.5F);
		this.setNoGravity(false);
		this.setVelocity(0, 0, 50);
	}
	
	public void setAim(Entity entityThrower, float rotationPitchIn, float rotationYawIn, float pitchOffset, float velocity, float inaccuracy)
    {
        double f = -MathHelper.sin(rotationYawIn * 0.017453292F) * MathHelper.cos(rotationPitchIn * 0.017453292F);
        double f1 = -MathHelper.sin((rotationPitchIn + pitchOffset) * 0.017453292F);
        double f2 = MathHelper.cos(rotationYawIn * 0.017453292F) * MathHelper.cos(rotationPitchIn * 0.017453292F);
        this.setThrowableHeading((double)f, (double)f1, (double)f2, velocity, inaccuracy);
        this.motionX += entityThrower.motionX;
        this.motionZ += entityThrower.motionZ;

        if (!entityThrower.onGround)
        {
            this.motionY += entityThrower.motionY;
        }
    }
	
	@Override
	public void setVelocity(double x, double y, double z) {
		this.motionX = x;
        this.motionY = y;
        this.motionZ = z;
		
	}
	
	@Override
	public void onUpdate() {
		super.onUpdate();
		
		this.posX += this.motionX;
		this.posY += this.motionY;
   		this.posZ += this.motionZ;
   		Vec3d from = new Vec3d(this.posX, this.posY, this.posZ);
   		Vec3d to = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
   		RayTraceResult raytraceresult = this.world.rayTraceBlocks(from, to, false, true, false);
   		
   		if(raytraceresult != null) {
   			this.onHit(raytraceresult);
   		}
   		
   		this.motionX *= 0.99;
   		this.motionY *= 0.99;
   		this.motionZ *= 0.99;
   		
   		this.motionY -= 0.05000000074505806D;
   		
		this.setPosition(this.posX, this.posY, this.posZ);
		this.doBlockCollisions();
	}
	
	protected void onHit(RayTraceResult result)
    {
		GunMod.log(result.getBlockPos().toString());
		
		Entity entity = result.entityHit;
		
		if(entity != null) {
			DamageSource damagesource = null;

            if (this.owner == null && this.owner instanceof EntityPlayer)
            {
                damagesource = DamageSource.causePlayerDamage((EntityPlayer) this.owner);
            }
            else if (this.owner == null && this.owner instanceof EntityLivingBase)
            {
                damagesource = DamageSource.causeMobDamage((EntityLivingBase) this.owner);
            } else {
            	GunMod.log("No Valid Bullet Owner!  Please contact the mod developer.");
            	return;
            }
            
            entity.attackEntityFrom(damagesource, this.damage);
			
		} else {
			BlockPos blkpos = result.getBlockPos();
			IBlockState blkst = this.world.getBlockState(blkpos);
			if(blkst.getMaterial() == Material.GLASS && speed() > 7) {
				world.setBlockToAir(blkpos);
				for(int x = -1; x < 2; x++) {
					for(int y = -1; y < 2; y++) {
						for(int z = -1; z < 2; z++) {
							BlockPos blkpos2 = blkpos;
							blkpos2 = blkpos2.add(x, y, z);
							IBlockState blkst2 = this.world.getBlockState(blkpos2);
							GunMod.log("1: " + blkpos + ", 2: " + blkpos2);
							if(blkst2.getMaterial() == Material.GLASS && GunMod.rand.nextBoolean()) {
								world.setBlockToAir(blkpos2);
								this.motionX *= 0.5f;
								this.motionY *= 0.5f;
								this.motionZ *= 0.5f;
							}
						}	
					}	
				}
			} else {
				this.setDead();
			}
			
		}
    }

	@Override
	public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy)
    {
        float f = MathHelper.sqrt(x * x + y * y + z * z);
        x = x / (double)f;
        y = y / (double)f;
        z = z / (double)f;
        x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
        y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
        z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
        x = x * (double)velocity;
        y = y * (double)velocity;
        z = z * (double)velocity;
        this.motionX = x;
        this.motionY = y;
        this.motionZ = z;
        float f1 = MathHelper.sqrt(x * x + z * z);
        this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
        this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI));
        this.prevRotationYaw = this.rotationYaw;
        this.prevRotationPitch = this.rotationPitch;
        //this.ticksInGround = 0;
    }

	@Override
	protected void entityInit() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void readEntityFromNBT(NBTTagCompound compound) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void writeEntityToNBT(NBTTagCompound compound) {
		// TODO Auto-generated method stub
		
	}

}

 

 

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

    • Hello! I downloaded the MrCrayfishs Furniture mod for 1.19.3. I also have 1.19.3 for forge and optifine. It's the only mod in my mods folder. It would be nice if anyone could help me. xx This is the crash report: ---- Minecraft Crash Report ---- // My bad. Time: 2023-01-30 13:17:38 Description: Mod loading error has occurred java.lang.Exception: Mod Loading has failed     at net.minecraftforge.logging.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:55) ~[forge-1.19.3-44.1.0-universal.jar%23155!/:?] {re:classloading}     at net.minecraftforge.client.loading.ClientModLoader.completeModLoading(ClientModLoader.java:167) ~[forge-1.19.3-44.1.0-universal.jar%23155!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.lambda$new$2(Minecraft.java:588) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.Util.m_137521_(Util.java:432) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading}     at net.minecraft.client.Minecraft.lambda$new$3(Minecraft.java:582) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.gui.screens.LoadingOverlay.m_86412_(LoadingOverlay.java:137) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:920) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1135) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:713) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.m_239872_(Main.java:212) ~[1.19.3-forge-44.1.0.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:51) ~[1.19.3-forge-44.1.0.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:27) ~[fmlloader-1.19.3-44.1.0.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:141) ~[securejarhandler-2.1.4.jar:?] {} -- MOD cfm -- Details:     Caused by 0: java.lang.NoClassDefFoundError: net/minecraft/data/tags/BlockTagsProvider         at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:?] {}         at java.lang.Class.privateGetDeclaredConstructors(Class.java:3373) ~[?:?] {}         at java.lang.Class.getConstructor0(Class.java:3578) ~[?:?] {}         at java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[?:?] {}         at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:68) ~[javafmllanguage-1.19.3-44.1.0.jar%23152!/:?] {}         at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:121) ~[fmlcore-1.19.3-44.1.0.jar%23151!/:?] {}         at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}         at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}         at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}         at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}         at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}         at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}         at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}     Mod File: /C:/Users/User/AppData/Roaming/.minecraft/mods/MrCrayfishs-Furniture-Mod-Forge-1.19.3.jar     Failure message: MrCrayfish's Furniture Mod (cfm) has failed to load correctly         java.lang.NoClassDefFoundError: net/minecraft/data/tags/BlockTagsProvider     Mod Version: 7.0.0-pre34     Mod Issue URL: https://github.com/MrCrayfish/MrCrayfishFurnitureMod/issues     Exception message: java.lang.ClassNotFoundException: net.minecraft.data.tags.BlockTagsProvider Stacktrace:     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:141) ~[securejarhandler-2.1.4.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:?] {}     at java.lang.Class.privateGetDeclaredConstructors(Class.java:3373) ~[?:?] {}     at java.lang.Class.getConstructor0(Class.java:3578) ~[?:?] {}     at java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[?:?] {}     at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:68) ~[javafmllanguage-1.19.3-44.1.0.jar%23152!/:?] {}     at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:121) ~[fmlcore-1.19.3-44.1.0.jar%23151!/:?] {}     at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}     at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}     at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}     at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}     at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}     at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}     at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {} -- System Details -- Details:     Minecraft Version: 1.19.3     Minecraft Version ID: 1.19.3     Operating System: Windows 10 (amd64) version 10.0     Java Version: 17.0.3, Microsoft     Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Microsoft     Memory: 241410776 bytes (230 MiB) / 503316480 bytes (480 MiB) up to 2147483648 bytes (2048 MiB)     CPUs: 4     Processor Vendor: AuthenticAMD     Processor Name: AMD FX-8800P Radeon R7, 12 Compute Cores 4C+8G      Identifier: AuthenticAMD Family 21 Model 96 Stepping 1     Microarchitecture: unknown     Frequency (GHz): 2.10     Number of physical packages: 1     Number of physical CPUs: 4     Number of logical CPUs: 4     Graphics card #0 name: AMD Radeon R7 Graphics     Graphics card #0 vendor: Advanced Micro Devices, Inc. (0x1002)     Graphics card #0 VRAM (MB): 256.00     Graphics card #0 deviceId: 0x9874     Graphics card #0 versionInfo: DriverVersion=27.20.1034.6     Memory slot #0 capacity (MB): 8192.00     Memory slot #0 clockSpeed (GHz): 2.13     Memory slot #0 type: DDR4     Memory slot #1 capacity (MB): 8192.00     Memory slot #1 clockSpeed (GHz): 2.13     Memory slot #1 type: DDR4     Virtual memory max (MB): 18519.90     Virtual memory used (MB): 7647.12     Swap memory total (MB): 2432.00     Swap memory used (MB): 35.46     JVM Flags: 9 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xss1M -Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M     ModLauncher: 10.0.8+10.0.8+main.0ef7e830     ModLauncher launch target: forgeclient     ModLauncher naming: srg     ModLauncher services:          mixin-0.8.5.jar mixin PLUGINSERVICE          eventbus-6.0.3.jar eventbus PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar slf4jfixer PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar object_holder_definalize PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar runtime_enum_extender PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar capability_token_subclass PLUGINSERVICE          accesstransformers-8.0.4.jar accesstransformer PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar runtimedistcleaner PLUGINSERVICE          modlauncher-10.0.8.jar mixin TRANSFORMATIONSERVICE          modlauncher-10.0.8.jar fml TRANSFORMATIONSERVICE      FML Language Providers:          minecraft@1.0         lowcodefml@null         javafml@null     Mod List:          client-1.19.3-20221207.122022-srg.jar             |Minecraft                     |minecraft                     |1.19.3              |COMMON_SET|Manifest: a1:d4:5e:04:4f:d3:d6:e0:7b:37:97:cf:77:b0:de:ad:4a:47:ce:8c:96:49:5f:0a:cf:8c:ae:b2:6d:4b:8a:3f         forge-1.19.3-44.1.0-universal.jar                 |Forge                         |forge                         |44.1.0              |COMMON_SET|Manifest: 84:ce:76:e8:45:35:e4:0e:63:86:df:47:59:80:0f:67:6c:c1:5f:6e:5f:4d:b3:54:47:1a:9f:7f:ed:5e:f2:90         MrCrayfishs-Furniture-Mod-Forge-1.19.3.jar        |MrCrayfish's Furniture Mod    |cfm                           |7.0.0-pre34         |ERROR     |Manifest: NOSIGNATURE     Crash Report UUID: d668c79d-366a-4acb-9754-f4cd52ab88cb     FML: 44.1     Forge: net.minecraftforge:44.1.0
    • thanks for your help. I found that issue: https://github.com/MinecraftForge/MinecraftForge/issues/8498
    • i'm trying to have my friend join my modded server. I gave them all the mods i have installed and the 'mixmatched mod list' keeps poping up.
  • Topics

×
×
  • Create New...

Important Information

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