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

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!

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.

  • Author

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

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.