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

After two weeks of helping other people (but it seems like longer), I finally need some help myself. With an entity that is glitching horribly when I try to drive it.

 

I know it's just something stupid, some packet-related thing I forgot... but could someone point out to me what I did?

 

Here's my Entity code:

 

package sbfp.secret;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

import org.lwjgl.input.Keyboard;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class EntitySecret extends Entity{

public static final double speed = 0.25;

public EntitySecret(World w){
	super(w);
	this.preventEntitySpawning = true;
	this.entityCollisionReduction = 1;
	this.yOffset = this.height/2.0F;
}

@Override
protected boolean canTriggerWalking(){
	return true;
}

@Override
protected void entityInit(){
}

@Override
public AxisAlignedBB getCollisionBox(Entity e){
	return e.boundingBox;
}

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

@Override
public void setPosition(double x, double y, double z){
	this.posX = x;
	this.posY = y;
	this.posZ = z;
	this.boundingBox.setBounds(x-0.375,y,z-0.75,x+0.375,y+1.125,z+0.75);
}

public EntitySecret(World w, double x, double y, double z){
	this(w);
	this.setPosition(x,y+this.yOffset,z);
	this.motionX = 0;
	this.motionY = 0;
	this.motionZ = 0;
	this.prevPosX = x;
	this.prevPosY = y;
	this.prevPosZ = z;
}

@Override
public double getMountedYOffset(){
	return 0.3;
}

@Override
public boolean attackEntityFrom(DamageSource ds, int damage){
	if(ds.damageType=="lava"||ds.damageType=="outOfWorld"||ds.damageType=="generic"){
		this.setDead();
		return true;
	}
	return false;
}

@Override
public boolean canBeCollidedWith(){
	return !this.isDead;
}

@Override
public void onUpdate(){
	super.onUpdate();
	if(this.riddenByEntity!=null){
		float dyaw = 0;
		if(Keyboard.isKeyDown(Keyboard.KEY_W)){
			this.motionX = Math.cos(this.rotationYaw*speed);
			this.motionZ = Math.sin(this.rotationYaw*speed);
		}else{
			this.motionX = 0;
			this.motionZ = 0;
		}
		if(Keyboard.isKeyDown(Keyboard.KEY_A)){
			dyaw = 5;
		}
		if(Keyboard.isKeyDown(Keyboard.KEY_D)){
			dyaw = -5;
		}
		this.setRotation(this.rotationPitch, this.rotationYaw+dyaw);
	}
	if(!this.onGround){
		this.motionY -= 0.098;
	}else{
		this.motionY = 0;
	}
	this.moveEntity(this.motionX,this.motionY,this.motionZ);
	if(!this.worldObj.isRemote){
		List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this,this.boundingBox.expand(0.2,0,0.2));
		if(list!=null&&!list.isEmpty()){
			for(int i = 0; i<list.size(); ++i){
				Entity entity = (Entity) list.get(i);
				if(entity!=this.riddenByEntity&&entity.canBePushed()&&!(entity instanceof EntitySecret)){
					entity.applyEntityCollision(this);
				}
			}
		}
		for(int i = 0; i<4; ++i){
			int blockX = MathHelper.floor_double(this.posX+(i%2-0.5D)*0.8D);
			int blockZ = MathHelper.floor_double(this.posZ+(i/2-0.5D)*0.8D);
			for(int j = 0; j<2; ++j){
				int blockY = MathHelper.floor_double(this.posY)+j;
				int id = this.worldObj.getBlockId(blockX,blockY,blockZ);
				if(id==Block.snow.blockID){
					this.worldObj.setBlockToAir(blockX,blockY,blockZ);
				}else if(id==Block.waterlily.blockID){
					this.worldObj.destroyBlock(blockX,blockY,blockZ,true);
				}
			}
		}
		if(this.riddenByEntity!=null&&this.riddenByEntity.isDead){
			this.riddenByEntity = null;
		}
	}
}

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

/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
@Override
protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound){}

/**
 * (abstract) Protected helper method to read subclass entity data from NBT.
 */
@Override
protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound){}

@Override
@SideOnly(Side.CLIENT)
public float getShadowSize(){
	return 0.0F;
}

/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
@Override
public boolean interact(EntityPlayer par1EntityPlayer){
	if(this.riddenByEntity!=null&&this.riddenByEntity instanceof EntityPlayer&&this.riddenByEntity!=par1EntityPlayer){
		return true;
	}else{
		if(!this.worldObj.isRemote){
			par1EntityPlayer.mountEntity(this);
		}
		return true;
	}
}
}

 

My git repo, in case you need other files, is at https://github.com/Pentachoron-Labs/SBFP-Tech/tree/secretfeature—make sure you're on the "secretfeature" branch. Oh, and if the constant use of "secret" bothers you, just mentally replace it with "tractor".

Thanks!

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

  • Author

Bump (TRIPLE POST!)

 

Am I really the only modder here courageous enough to brave vehicles? Nobody else has an example? Any entity would work. Especially given that the tractor glitches even when I'm not standing on it.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

You can look at my code for the turrets. You can ride them, although you can't move with them:

https://github.com/SanAndreasP/TurretModv3/blob/master/sanandreasp/mods/TurretMod3/entity/turret/EntityTurret_Base.java

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

  • Author

I'm honestly not sure how I found the solution, but I added tractorX/Y/Z/Yaw/Pitch and velocityX/Y/Z variables akin to the way they're used in EntityBoat and EntityMinecart, and it worked. Then I started fixing the bounding box and ran into... well, this.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

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.