Jump to content

Recommended Posts

Posted

Hey everyone!

 

I'm trying to make a vehicle. I've got it moving and the controls work, but it keeps jolting up and down. Sometimes it will stop, before promptly teleporting back to it's original position and starting again.

 

Does anyone have any ideas? This is the first time I've made a vehicle, so i'm not an expert, but i can't find anything causing it. I've tried adding code to stop it, but still nothing. I used code from EntityBoat, and removed some parts I didn't need.

 

package assets.battlefield.common.entity.vechicle;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class EntityTank extends Entity {

private double speedMultiplier = 4d;

public EntityTank(World p_i1582_1_) {

	super(p_i1582_1_);
	this.setSize(1.5F, 0.6F);
	this.yOffset = this.height / 2.0F;
	this.preventEntitySpawning = true;

}

public AxisAlignedBB getCollisionBox(Entity p_70114_1_)
{
	return p_70114_1_.boundingBox;
}

public AxisAlignedBB getBoundingBox()
{
	return this.boundingBox;
}

@Override
public boolean canBeCollidedWith() {

	return true;

}

public void onUpdate()
{
	super.onUpdate();

	this.prevPosX = this.posX;
	this.prevPosY = this.posY;
	this.prevPosZ = this.posZ;
	byte b0 = 5;
	double d0 = 1d / b0;

	double d10 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
	double d2;
	double d4;
	int j;

	if(!this.onGround) {

		this.motionX *= 0.1d;
		this.motionZ *= 0.1d;

		if(this.motionY > -9d) {

			this.motionY -= 0.9d;

		}

	}

	if (d10 > 0.26249999999999996D)
	{
		d2 = Math.cos((double)this.rotationYaw * Math.PI / 180.0D);
		d4 = Math.sin((double)this.rotationYaw * Math.PI / 180.0D);

		for (j = 0; (double)j < 1.0D + d10 * 60.0D; ++j)
		{
			double d5 = (double)(this.rand.nextFloat() * 2.0F - 1.0F);
			double d6 = (double)(this.rand.nextInt(2) * 2 - 1) * 0.7D;
			double d8;
			double d9;

			int id = Block.getIdFromBlock(worldObj.getBlock((int)posX, (int)posY - 1, (int)posZ));
			int meta = worldObj.getBlockMetadata((int)posX, (int)posY - 1, (int)posZ);

			if (this.rand.nextBoolean())
			{
				d8 = this.posX - d2 * d5 * 0.8D + d4 * d6;
				d9 = this.posZ - d4 * d5 * 0.8D - d2 * d6;
				this.worldObj.spawnParticle("blockcrack_" + id + "_" + meta, d8, this.posY - 0.125D, d9, this.motionX, this.motionY, this.motionZ);
			}
			else
			{
				d8 = this.posX + d2 + d4 * d5 * 0.7D;
				d9 = this.posZ + d4 - d2 * d5 * 0.7D;
				this.worldObj.spawnParticle("blockcrack_" + id + "_" + meta, d8, this.posY - 0.125D, d9, this.motionX, this.motionY, this.motionZ);
			}
		}
	}

	double d11;
	double d12;

	if (this.motionY < 0.0D)
	{
		this.motionY /= 2.0D;
	}

	if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityLivingBase)
	{
		EntityLivingBase entitylivingbase = (EntityLivingBase)this.riddenByEntity;
		float f = this.riddenByEntity.rotationYaw + -entitylivingbase.moveStrafing * 90.0F;
		this.motionX += -Math.sin((double)(f * (float)Math.PI / 180.0F)) * this.speedMultiplier * (double)entitylivingbase.moveForward * 0.05000000074505806D;
		this.motionZ += Math.cos((double)(f * (float)Math.PI / 180.0F)) * this.speedMultiplier * (double)entitylivingbase.moveForward * 0.05000000074505806D;
	}

	d2 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);

	if (d2 > 0.35D)
	{
		d4 = 0.35D / d2;
		this.motionX *= d4;
		this.motionZ *= d4;
		d2 = 0.35D;
	}

	int l;

	for (l = 0; l < 4; ++l)
	{
		int i1 = MathHelper.floor_double(this.posX + ((double)(l % 2) - 0.5D) * 0.8D);
		j = MathHelper.floor_double(this.posZ + ((double)(l / 2) - 0.5D) * 0.8D);

		for (int j1 = 0; j1 < 2; ++j1)
		{
			int k = MathHelper.floor_double(this.posY) + j1;
			Block block = this.worldObj.getBlock(i1, k, j);

			if (block == Blocks.snow_layer)
			{
				this.worldObj.setBlockToAir(i1, k, j);
				this.isCollidedHorizontally = false;
			}
			else if (block == Blocks.waterlily)
			{
				this.worldObj.func_147480_a(i1, k, j, true);
				this.isCollidedHorizontally = false;
			}
		}
	}

	if (this.onGround) {

		this.motionX *= 0.5D;
		this.motionY *= 0.5D;
		this.motionZ *= 0.5D;

	}

	this.moveEntity(this.motionX, this.motionY, this.motionZ);
	this.motionX *= 0.9900000095367432D;
	this.motionY *= 0.949999988079071D;
	this.motionZ *= 0.9900000095367432D;

	this.rotationPitch = 0.0F;
	d4 = (double)this.rotationYaw;
	d11 = this.prevPosX - this.posX;
	d12 = this.prevPosZ - this.posZ;

	if (d11 * d11 + d12 * d12 > 0.001D)
	{
		d4 = (double)((float)(Math.atan2(d12, d11) * 180.0D / Math.PI));
	}

	double d7 = MathHelper.wrapAngleTo180_double(d4 - (double)this.rotationYaw);

	if (d7 > 20.0D)
	{
		d7 = 20.0D;
	}

	if (d7 < -20.0D)
	{
		d7 = -20.0D;
	}

	this.rotationYaw = (float)((double)this.rotationYaw + d7);
	this.setRotation(this.rotationYaw, this.rotationPitch);

	if (!this.worldObj.isRemote)
	{
		List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D));

		if (list != null && !list.isEmpty())
		{
			for (int k1 = 0; k1 < list.size(); ++k1)
			{
				Entity entity = (Entity)list.get(k1);

				if (entity != this.riddenByEntity && entity.canBePushed() && entity instanceof EntityBoat)
				{
					entity.applyEntityCollision(this);
				}
			}
		}

		if (this.riddenByEntity != null && this.riddenByEntity.isDead)
		{
			this.riddenByEntity = null;
		}
	}

	if(this.onGround) {

		this.motionY = 0d;

	}

}

public boolean interactFirst(EntityPlayer player) {

	if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != player)
	{
		return true;
	}
	else
	{
		if (!this.worldObj.isRemote)
		{
			player.mountEntity(this);
		}

		return true;
	}

}

public void updateRiderPosition()
{
	if (this.riddenByEntity != null)
	{
		double d0 = Math.cos((double)this.rotationYaw * Math.PI / 180.0D) * 0.4D;
		double d1 = Math.sin((double)this.rotationYaw * Math.PI / 180.0D) * 0.4D;
		this.riddenByEntity.setPosition(this.posX + d0, this.posY + this.getMountedYOffset() + this.riddenByEntity.getYOffset(), this.posZ + d1);
	}
}

@Override
protected void entityInit() {}

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

}

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

}

}

 

Thanks, Romejanic.

Romejanic

 

Creator of Witch Hats, Explosive Chickens and Battlefield!

Posted

I'll just start from what I learned over years with MC code: Minecraft is not designed to work smoothly. It has no easing functions, no movement predictions, really nothing to fix visual bugs.

This means that anything that could be lagging between server and client will be visible (quite well).

 

Where can we spot those?

 

Press 'B' + 'F3' to see all Entities bounding box (ingame). Any bounding box that is in touch with ground might be glitching (just a little).

 

Now back to your vehicle - I don't really see anything wrong inside this code. Yet again - normal boat can glitch like that too, so this might be: http://www.forbbodiesonly.com/moparforum/attachment.php?attachmentid=111454&d=1365473434

<clap if you get the reference>

 

Anyway - making your entity a LivingEntityBase (which would also make it a living thing with health etc.) might just fix your problems. I rly don't know why but never seen mobs lagging like rest of "dead" entities, despite fact they are both extending Entity.class

 

Last thing - bigger model, more you see. (I bet that until seeing it on B+F3, you didn't see EntityItem glitching - just throw it on the ground).

 

EDIT: Question - how big is this glitch compared to e.g EntityItem?

 

 

 

1.7.10 is no longer supported by forge, you are on your own.

Posted

I'll just start from what I learned over years with MC code: Minecraft is not designed to work smoothly. It has no easing functions, no movement predictions, really nothing to fix visual bugs.

This means that anything that could be lagging between server and client will be visible (quite well).

 

Where can we spot those?

 

Press 'B' + 'F3' to see all Entities bounding box (ingame). Any bounding box that is in touch with ground might be glitching (just a little).

 

Now back to your vehicle - I don't really see anything wrong inside this code. Yet again - normal boat can glitch like that too, so this might be: http://www.forbbodiesonly.com/moparforum/attachment.php?attachmentid=111454&d=1365473434

<clap if you get the reference>

 

Anyway - making your entity a LivingEntityBase (which would also make it a living thing with health etc.) might just fix your problems. I rly don't know why but never seen mobs lagging like rest of "dead" entities, despite fact they are both extending Entity.class

 

Last thing - bigger model, more you see. (I bet that until seeing it on B+F3, you didn't see EntityItem glitching - just throw it on the ground).

 

EDIT: Question - how big is this glitch compared to e.g EntityItem?

 

Basically me and my friend copied the code back over from the boat and we were very picky about what code to add and remove. It seems pretty stable now. Thanks anyway, just need help getting it move up blocks. Any ideas?

Romejanic

 

Creator of Witch Hats, Explosive Chickens and Battlefield!

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

    • Hello! I have been having a problem with Forgematica, Embeddium, Oculus, and create. I wanted to download litematica so I could see which blocks are in my creative mode build, so that I could collect them all in survival. However, litematica is a fabric mod. I found a port called forgematica, which I added (along with it's dependency) to my mods folder. I loaded into a new world, and built a structure. Then, I added a part from the create mod, and the game crashed instantly, with exit code -1. Thanks for any help! Crash Report and mods list: https://pastebin.com/rtzh6LAi
    • To say that losing 40,000 BTC was a devastating blow would be an understatement. It was an emotional and financial crisis that left me feeling hopeless and utterly lost. For weeks, I was trapped in a whirlwind of regret, second-guessing every decision that led me to that point. The fear that I would never be able to recover such a significant sum of cryptocurrency consumed me, and with each passing day, my despair deepened. I had all but given up on ever regaining my wealth. Then I happened to stumble onto Tech Cyber Force Recovery. In the beginning, I was hesitant. It looked too good to be true: could someone get back so much of their lost Bitcoin? After trying several different approaches and programs without success, I was hesitant to put my trust in another recovery agency. However, I changed my mind after reading Tech Cyber Force Recovery's stellar reviews and reputation. Reaching out to their team was a risk I made. They were courteous and professional from the first time I got in touch with them. I felt like I wasn't just another case to be solved by the staff at Tech Cyber Force Recovery; they truly cared about getting me my lost Bitcoin back. They listened carefully to my circumstances and guided me through each stage, giving me succinct and understandable explanations as I went. Their passion gave me new hope, and their openness instantly made me feel better. As the recovery process began, I still had my doubts, but I knew I had placed my trust in the right hands. The Tech Cyber Force Recovery team kept me informed and updated on their progress, ensuring I never felt in the dark. Despite the complexity of my case, they worked tirelessly, and their expertise became evident at every turn. The level of professionalism and attention to detail they demonstrated throughout the process was beyond impressive. And then, after what felt like an eternity of anticipation, the moment I had been waiting for arrived. I received the news that my 40,000 BTC had been successfully recovered. It was hard to believe at first—it felt like a dream. The weight that had been dragging me down for so long was suddenly lifted, and I could breathe again. The financial loss I had feared would define my future was no longer a reality. I can’t fully express the emotions I felt during that moment. It was a mix of relief, joy, and an overwhelming sense of gratitude. I had gone from a place of utter despair to a complete resurgence of wealth, both emotionally and financially. The Tech Cyber Force Recovery team didn’t just restore my Bitcoin—they restored my faith in the possibility of recovery and gave me back something far more valuable: peace of mind. I will urge anyone in this same predicament to.  
    • Have you found a modder for this vehicle project? Because it will be really hard and I want to know that hero who can create all this
    • and what?????????
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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