Posted August 27, 201510 yr [shadow=red,left][font=arial][glow=red,4,400]Ok, so I am wondering how I can make a truck. So, I made code for it and it works, but it doesnt move. It rotates and everything, but it stays stationary. Why does it do that? How do I fix it? Please help. [/glow] Here is my code for the Entity: package com.camp.entity; [/font][/shadow] import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; public class EntityTruck extends EntityMob // this to make mob hostile { public boolean stationary; public EntityTruck(World par1World) { super(par1World); isImmuneToFire = false; } protected void applEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20000.0d); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.4f); this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(1.0f); this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(100f); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(10.0f); } protected boolean canDespawn() { return false; } public boolean interact(EntityPlayer entityplayer) { if (riddenByEntity == null || riddenByEntity == entityplayer) { entityplayer.mountEntity(this); return true; } else { return false; } } protected boolean isMovementCeased() { return stationary; } public void moveEntity(double d, double d1, double d2) { if (riddenByEntity != null) { this.prevRotationYaw = this.rotationYaw = this.riddenByEntity.rotationYaw; this.rotationPitch = this.riddenByEntity.rotationPitch * 0.5F; this.setRotation(this.rotationYaw, this.rotationPitch); this.rotationYawHead = this.renderYawOffset = this.rotationYaw; stationary = true; motionX += riddenByEntity.motionX * 2F; // * 0.20000000000000001D; motionZ += riddenByEntity.motionZ * 2F; // * 0.20000000000000001D; if (isCollidedHorizontally) { isJumping = true; } else { isJumping = false; } super.moveEntity(motionX, motionY, motionZ); } else { stationary = false; super.moveEntity(d, d1, d2); } } public void onUpdate() { super.onUpdate(); if (riddenByEntity != null) //check if there is a rider { //currentTarget = this; this.randomYawVelocity = 0; //try not to let the horse control where to look. this.rotationYaw = riddenByEntity.rotationYaw; } } protected boolean isAIEnabled() //Allow your AI task to work? { return true; } } [shadow=red,left][/shadow] I AM SUS
August 27, 201510 yr Author [glow=red,20,200] Anyone out there that can help me? Please? [/glow] I AM SUS
August 28, 201510 yr Only one hint - how should the players motionX move the truck if the player sits ON the truck?
August 29, 201510 yr Author [glow=red,20,200]Oh... Well I dont know any other way of making it move, I have never made one before. If I put a solid number there, it will move, but only in one direction and non-controllable. I was thinking that I could use keybindings, but I have no idea how to do that.[/glow] I AM SUS
August 29, 201510 yr Watch Pahimar's video tutorial on YouTube about Keybindings, that should help. Who are you? Why have you brought me here? And why are there so many PewDiePie fanboys surrounding meeeeeeeee....... *falls into pit and dies*. Also this. Check it out. http://i.imgur.com/J4rrGt6.png[/img]
August 29, 201510 yr [glow=red,20,200]Oh... Well I dont know any other way of making it move, I have never made one before. If I put a solid number there, it will move, but only in one direction and non-controllable. I was thinking that I could use keybindings, but I have no idea how to do that.[/glow] First of all why do you write in red and second - think of what you need. Youll need a speed and the propper calculations hint - have a look at minecrafts entity boat class
August 30, 201510 yr Author [glow=red,20,200] I tried the keybinding, and it doesnt work. Also, I couldnt find it in the EntityBoat class. I have no idea what I am doing. If anyone knows how to help me, please tell me! [/glow] I AM SUS
August 30, 201510 yr Nobody is going to program the whole mod for you. So please try to search for the answer in the classes full of working examples forge is providing you. (E.g. EntityBoat, EntityPig, EntityHorse - names may be slightly different though with a bit of effort easy to find). A few tips are already given for a possible solution. You need some way of keybinding. And the Entity that needs to recieve the motion is the Entity the player is riding, not the Player itself. Projects: Discontinued: - N2ConfigAPI - Meachanical Crafting Table Latest: - CollectionUtils Coöperations: - InGameConfigManager
August 31, 201510 yr Another tip - write your code on paper, then in code so youll find buggs easier. Planning is most of the work done
September 1, 201510 yr No need for keybindings... Just set the entity's [b]moveStrafing[/b] and [b]moveForward[/b] fields to the same value as the riding entity's moveStrafing and moveForward . Do that in the onLivingUpdate method of your entity (after the super call), check if it's ridden by anything of course ( [b]riddenByEntity[/b] is not null ). To steer it, you'd need to set the [b]rotationYaw[/b] and [b]rotationYawHead[/b] fields of your entity to the ones of the riding one. Do it right before setting the move* fields. Also override [b]canBeSteered()[/b] and return true. 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.
September 1, 201510 yr No need for keybindings... Just set the entity's [b]moveStrafing[/b] and [b]moveForward[/b] fields to the same value as the riding entity's moveStrafing and moveForward . Do that in the onLivingUpdate method of your entity (after the super call), check if it's ridden by anything of course ( [b]riddenByEntity[/b] is not null ). To steer it, you'd need to set the [b]rotationYaw[/b] and [b]rotationYawHead[/b] fields of your entity to the ones of the riding one. Do it right before setting the move* fields. Also override [b]canBeSteered()[/b] and return true. Wow, I have to say you've got some of the best explanations. Very thorough, tells you where to look, and at the same time isn't spoonfeeding. Not sure you can get any better than that. I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!
September 6, 201510 yr Author Ok, but there is no moveForward field in the riding entity. Or a moveStrafing. I AM SUS
September 6, 201510 yr Author No need for keybindings... Just set the entity's [b]moveStrafing[/b] and [b]moveForward[/b] fields to the same value as the riding entity's moveStrafing and moveForward . Do that in the onLivingUpdate method of your entity (after the super call), check if it's ridden by anything of course ( [b]riddenByEntity[/b] is not null ). To steer it, you'd need to set the [b]rotationYaw[/b] and [b]rotationYawHead[/b] fields of your entity to the ones of the riding one. Do it right before setting the move* fields. Also override [b]canBeSteered()[/b] and return true. Wow, I have to say you've got some of the best explanations. Very thorough, tells you where to look, and at the same time isn't spoonfeeding. Not sure you can get any better than that. Dude, this isnt a praise area. I AM SUS
September 6, 201510 yr Ok, but there is no moveForward field in the riding entity. Or a moveStrafing. I say this only one more time - before you start messing up your code - PLAN THE WHOLE THING ON PAPER! And the move straffing field is not in the entitity itself, it is in the ridingEntity. We will not write your mod for you, try figuring it out. We will help you if you run in some problems, but youll have to do the main part of it on your own.
September 7, 201510 yr Ok, but there is no moveForward field in the riding entity. Or a moveStrafing. And the move straffing field is not in the entitity itself, it is in the ridingEntity. I'd say it is... https://github.com/SanAndreasP/EnderStuffPlus/blob/master/java/de/sanandrew/mods/enderstuffp/entity/living/EntityEnderMiss.java#L591-L592 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.
September 27, 201510 yr Author Sorry it took me so long to respond, here is my most recent updated code. Also, I am not asking you to code my entire mod, this is only MY FIRST MOD!!! Please, just tell me how to do it and then I will know. Here it is... package com.camp.entity; import net.minecraft.entity.Entity; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; public class EntityTruck extends EntityMob // this to make mob hostile { public boolean stationary; public EntityTruck(World par1World) { super(par1World); isImmuneToFire = false; } protected boolean canDespawn() { return false; } public boolean interact(EntityPlayer entityplayer) { if (riddenByEntity == null || riddenByEntity == entityplayer) { entityplayer.mountEntity(this); return true; } else { return false; } } protected boolean isMovementCeased() { return stationary; } public void moveEntity(double d, double d1, double d2) { if (riddenByEntity != null) { EntityPlayer player = (EntityPlayer) this.riddenByEntity; this.prevRotationYaw = this.rotationYaw = this.riddenByEntity.rotationYaw; this.rotationPitch = this.riddenByEntity.rotationPitch * 0.5F; this.setRotation(this.rotationYaw, this.rotationPitch); this.rotationYawHead = player.rotationYawHead; stationary = false; motionX += riddenByEntity.motionX * 10; // * 0.20000000000000001D; motionZ += riddenByEntity.motionZ * 10; // * 0.20000000000000001D; //this.moveStrafing = player.moveStrafing; //this.moveForward = player.moveForward; if (isCollidedHorizontally) { isJumping = true; } else { isJumping = false; } super.moveEntity(motionX, motionY, motionZ); } else { stationary = false; super.moveEntity(d, d1, d2); } } public void onUpdate() { super.onUpdate(); if (riddenByEntity != null) //check if there is a rider { //currentTarget = this; this.randomYawVelocity = 0; //try not to let the horse control where to look. this.rotationYaw = riddenByEntity.rotationYaw; } } protected boolean isAIEnabled() //Allow your AI task to work? { return true; } } I AM SUS
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.