Jump to content

Recommended Posts

Posted

It's great that you're trying so many things, but it is important to go through a few steps before asking for help.

 

For example don't just say "it doesn't work". What exactly doesn't work? Did you trace the code execution to see where it is failing? Does the code for the entity being ridden show that it "knows" that it is being ridden? Do you see the code related to movement properly switching to the ridden entity.

 

Without knowing this we will just say "copy the code for riding a pig"...

 

Basically, always trace your code to figure out where exactly it is failing, then if you can't figure out what is wrong, post the specific description along with the code.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

I've attached the entity code. How do I make my code work so that the player can control it.

public float scale = 1.0f;
		private EntityPlayer pilot;
		
		public int armamentLeftHand = -1;
		public int armamentRightHand = -1;
		
		private boolean leftInputDown = false;
		private boolean rightInputDown = false;
		private boolean forwardInputDown = false;
		private boolean backInputDown = false;
		
		public MSMob(World worldIn) {
			super(worldIn);
			this.heal(Float.MAX_VALUE);
		}
		
		@SideOnly(Side.CLIENT)
	    public void updateInputs(boolean p_184442_1_,boolean p_184442_2_,boolean p_184442_3_,boolean p_184442_4_) {
	        this.leftInputDown = p_184442_1_;
	        this.rightInputDown = p_184442_2_;
	        this.forwardInputDown = p_184442_3_;
	        this.backInputDown = p_184442_4_;
	        System.out.println(this.backInputDown);
	    }
		
		private void control() {
	        if(this.isBeingRidden()) {
	            float f = 0.0F;

	            if(this.rightInputDown != this.leftInputDown && !this.forwardInputDown && !this.backInputDown) f += 0.005F;
	            if(this.forwardInputDown) f += 0.04F;
	            if(this.backInputDown) f -= 0.005F;

	            this.motionX += (double)f;
	            this.motionZ += (double)f;
	        }
	    }
		
		@Override
		public boolean canPassengerSteer() {
			return true;
		}
		
		@Override
		public boolean canBreatheUnderwater() {
			return true;
		}
		
		@Override
		public NBTTagCompound writeToNBT(NBTTagCompound root) {
			root = super.writeToNBT(root);
			NBTTagCompound ms = new NBTTagCompound();
			ms.setInteger("armamentLeftHand",this.armamentLeftHand);
			ms.setInteger("armamentRightHand",this.armamentRightHand);
			NBTTagList armaments = new NBTTagList();
			for(int i = 0;i < this.getMSRegistryEntry().getArmamentCount();i++) {
				MobileSuitArmament armament = this.getMSRegistryEntry().getArmament(i);
				armaments.appendTag(armament.saveNBT());
			}
			ms.setTag("armaments",armaments);
			root.setTag("mobileSuit",ms);
			return root;
		}
		
		@Override
		public void readFromNBT(NBTTagCompound root) {
			super.readFromNBT(root);
			if(root.hasKey("mobileSuit")) {
				NBTTagCompound ms = root.getCompoundTag("mobileSuit");
				this.armamentLeftHand = ms.getInteger("armamentLeftHand");
				this.armamentRightHand = ms.getInteger("armamentRightHand");
				if(ms.hasKey("armaments")) {
					NBTTagList armaments = ms.getTagList("armaments",10);
					for(int i = 0;i < armaments.tagCount();i++) {
						MobileSuitArmament armament = this.getMSRegistryEntry().getArmament(i);
						armament.loadNBT(armaments.getCompoundTagAt(i));
					}
				}
			}
		}
		
		@Override
		public boolean processInteract(EntityPlayer player,EnumHand hand) {
			if(player.inventory.getStackInSlot(player.inventory.currentItem).getItem().getUnlocalizedName().equals("item."+GundamMod.MODID+".wrench")) {
				// TODO: show customization interface
			} else {
				if(this.pilot != null) return false;
				this.pilot = player;
				this.pilot.startRiding(this);
				IHumanCapability human = Human.getHuman(this.pilot);
				human.setMS(this);
				if(this.pilot.world.isRemote) Minecraft.getMinecraft().setRenderViewEntity(this);
			}
			return true;
		}
		
		@Override
		public void onUpdate() {
			super.onUpdate();
			this.control();
			this.move(MoverType.SELF,this.motionX,this.motionY,this.motionZ);
		}
		
		public EntityPlayer getPilot() {
			return this.pilot;
		}
		
		public MobileSuit getMSRegistryEntry() {
			return MSRegistry.getMobileSuit(this.getName());
		}
		
		@Override
		public boolean canRiderInteract() {
			return true;
		}
		
		@Override
		public boolean canBeSteered() {
			return true;
		}
		
		private void updateRiderPosition(Entity entity) {
			if(entity != null) {
				entity.setPosition(this.posX,this.posY+(getMountedYOffset()+entity.getYOffset())/2,this.posZ);
			}
		}
		
		@Override
		public void updatePassenger(Entity passenger) {
			this.updateRiderPosition(passenger);
			passenger.setInvisible(true);
			this.rotationPitch = passenger.rotationPitch;
			this.rotationYaw = passenger.rotationYaw;
			this.motionX = passenger.motionX;
			this.motionY = passenger.motionY;
			this.motionZ = passenger.motionZ;
		}
		
		@Override
		public void removePassenger(Entity passenger) {
			if(passenger != null) passenger.setPosition(this.posX,this.posY,this.posZ);
			super.removePassenger(passenger);
			passenger.setInvisible(false);
			if(passenger instanceof EntityPlayer) {
				IHumanCapability human = Human.getHuman((EntityPlayer)passenger);
				human.setMS(null);
				this.pilot = null;
				human.syncToServer();
				Minecraft.getMinecraft().setRenderViewEntity(passenger);
			}
		}

 

The official YouTuber Spaceboy Ross

Posted

Before talking about this specific problem, your code has another problem. You're calling the Minecraft class (where you set the view entity) from a common class. This will cause crashes on a dedicated server. Checking for isRemote isn't sufficient because the Minecraft class will not even be loaded so the code statement will not be understandable to the JVM. Instead, you should make a method in your proxy system called something like setViewEntity() and in the common code do nothing but in the client proxy version call your Minecraft code.

 

Okay, now regarding your issue with steering. To debug problems people don't just read code, rather they *trace* (i.e. follow along with) the actual execution to observe what is actually happening. There is no need to guess. I personally do this by simply adding console statements (System.out.println()) throughout my code then watching the console to confirm how things are operating. 

 

For example, in your onInteract() method you should add console statements to confirm that the code path that sets the pilot is executing as expected. And in your control() method you should add statements that firstly confirm the method is being called at all and also confirm that the isRidden code path is the one being followed.

 

And so on. If you do this, you'll quickly find out what is wrong. Either the methods aren't being called at all, or when they are some fields are not the values you expect and so the code doesn't follow the path you expect.

 

So add statements, see if you can notice anything specific going wrong. If you can't figure it out, post the revised code along with the actual console output so we can help.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
5 hours ago, Spaceboy Ross said:

if(player.inventory.getStackInSlot(player.inventory.currentItem).getItem().getUnlocalizedName().equals("item."+GundamMod.MODID+".wrench")) { 

Why are you comparing the unlocalized names of your Items and not the Items themselves?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
7 minutes ago, Spaceboy Ross said:

It's easier that way for my code.

That's ridiculous, that means you are not storing your Items in variables anywhere(I assume).

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
24 minutes ago, Spaceboy Ross said:

Then why not

 

player.inventory.getStackInSlot(player.inventory.currentItem).getItem() == GundamItems.item

Or even better

player.getActiveItemStack().getItem() == GundamItems.item

 

Edited by Animefan8888

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Look at the horse class (the abstract one should have the code you want), neither the pig or boat really move - the pig follows the carrot on a stick and the boat appears to literally use the paddles for control (+1 for realism Mojang) which makes it a little useless for your task (if I didn’t read the code wrong and they really are using the paddles). You could also take a look at the minecart class, but there’s lots and lots of track logic.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
9 hours ago, Spaceboy Ross said:

Because I didn't really think I could do that, plus I was writing that code at like 2 AM so I was like subconsciously writing that code. In the next commit, I'll fix that.

Good, don't stringly type your code.

http://wiki.c2.com/?StringlyTyped

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

I've got some of the movement code from the AbstractHorse class but it's still not moving.

		@Override
		public void travel(float p_191986_1_,float p_191986_2_,float p_191986_3_) {
			if(this.isBeingRidden() && this.canBeSteered()) {
				EntityLivingBase driver = (EntityLivingBase)this.getControllingPassenger();
				this.rotationYaw = driver.rotationYaw;
				this.rotationPitch = driver.rotationPitch;
				this.setRotation(this.rotationYaw,this.rotationPitch);
				this.renderYawOffset = this.rotationYaw;
	            this.rotationYawHead = this.renderYawOffset;
	            p_191986_1_ = driver.moveStrafing;
	            p_191986_3_ = driver.moveForward;
	            
	            if(p_191986_3_ <= 0.0F) p_191986_3_ *= 0.25F;
	            
	            if(this.canPassengerSteer()) {
	            	this.setAIMoveSpeed(1.0f);
                	super.travel(p_191986_1_,p_191986_2_,p_191986_3_);
	            } else if(driver instanceof EntityPlayer) {
	            	this.motionX = 0.0d;
	            	this.motionY = 0.0d;
	            	this.motionZ = 0.0d;
	            }
			} else super.travel(p_191986_1_,p_191986_2_,p_191986_3_);
		}

 

Edited by Spaceboy Ross

The official YouTuber Spaceboy Ross

Posted (edited)
2 minutes ago, Spaceboy Ross said:

I've got the movement code from the AbstractHorse class but it's still not moving.


		@Override
		public void travel(float p_191986_1_,float p_191986_2_,float p_191986_3_) {
			if(this.isBeingRidden() && this.canBeSteered()) {
				EntityLivingBase driver = (EntityLivingBase)this.getControllingPassenger();
				this.rotationYaw = driver.rotationYaw;
				this.rotationPitch = driver.rotationPitch;
				this.setRotation(this.rotationYaw,this.rotationPitch);
				this.renderYawOffset = this.rotationYaw;
	            this.rotationYawHead = this.renderYawOffset;
	            p_191986_1_ = driver.moveStrafing;
	            p_191986_3_ = driver.moveForward;
	            
	            if(p_191986_3_ <= 0.0F) p_191986_3_ *= 0.25F;
	            
	            if(this.canPassengerSteer()) {
	            	this.setAIMoveSpeed(1.0f);
                	super.travel(p_191986_1_,p_191986_2_,p_191986_3_);
	            } else if(driver instanceof EntityPlayer) {
	            	this.motionX = 0.0d;
	            	this.motionY = 0.0d;
	            	this.motionZ = 0.0d;
	            }
			} else super.travel(p_191986_1_,p_191986_2_,p_191986_3_);
		}

 

You obviously just cut & pasted that, you need to understand the code. Step through the code with the debugger.

You literally copy & pasted it verbatim it still has SRG arguments & the code still has stuff to do with AI! Make sure that canPassengerSteer can return true. Also please post your entire code not just a snippet

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
1 minute ago, Cadiboo said:

You obviously just cut & pasted that, you need to understand the code.

Why are there SRG Named arguments in your code and why is there AI stuff in your code.

2 minutes ago, Cadiboo said:

Step through the code with the debugger.

2 minutes ago, Cadiboo said:

please post your entire code

 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

so what do they do? what is p_191986_1_ and what does it do?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Sorry. Its 2 am here.

Go through the code. Refactor the code i.e.

rename the variables to have names that make sense. Remove stuff that you don't need (if your SURE you don't need it) (HINT: AI stuff)

Please post your entire code.

What do you mean eclipse froze? do you mean Minecraft froze or that Eclipse crashed? Programs are meant to freeze when they hit a breakpoint. Where did you place your breakpoint? did you put it on a variable (breaks on read/write access) or on a line of code (breaks right before the program executes that line)

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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




×
×
  • Create New...

Important Information

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