Jump to content

Using forge interact hook to control vanilla cow


microjunk

Recommended Posts

For about more than a week now I have been trying to figure out how to make it possible to ride the vanilla cow with forge hooks. So far the only one that seems to get me close is the interact event. However there have been some complications roadblocking me every step of the way. This is my event set up for this particular event.

 

 

@ForgeSubscribe
    public void entityInteractEvent(EntityInteractEvent event)
    {
	final EntityAIControlledByPlayer aiControlledByPlayer;
	boolean canBeSteered;
	this.speedMultiplier = 0.07D;
    	if(event.target.interact(event.entityPlayer))
    	{
    		return;
    	}
    	if (event.target instanceof EntityCow && !event.entity.worldObj.isRemote && (this.riddenByEntity == null || this.riddenByEntity == event.entityPlayer))
        {
    		EntityCow cow = (EntityCow)event.target;
    		EntityPlayer player = (EntityPlayer)event.entityPlayer;
    		player.mountEntity(cow);
    		player.tasks.taskEntries.add(0, new EntityAIControlledByPlayer(cow, 0.34F));
        }
    	if(event.target instanceof EntityCow && event.target.riddenByEntity != null && event.entityPlayer.isRiding())
    	{
    		double par1 = 0.0D;
		double par3 = 0.0D;
		double par5 = 0.0D;
		CowHelper.moveEntity(par1, par3, par5);

    	}	
    }

 

 

 

Ignore the AI addition of controlledbyPlayer....it doesnt work anyway. At the moment I have an error on COwHelper.moveEntity...its suggestion I change the method modifier to static, when I do that and make for necessary changes it crashes.

 

CowHelper

 

 

public class CowHelper extends EntityCow
{
public static boolean isInWeb;
public static World worldObj;
static double prevMotionX;
    static double prevMotionZ;
    private static String togglekey;
    private static int itogglekey;

public CowHelper()
{
	super(worldObj);
}

public void moveEntity(double par1, double par3, double par5) 
{
	if (this.riddenByEntity != null)
        {
            boolean var7 = true;
            boolean var8 = false;

            if (this.onGround && !var7 && !this.isSprinting() && !this.isInWeb)
            {
            	this.setSprinting(true);
            }

            int var9 = CowHelper.worldObj.getBlockId(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.boundingBox.minY) - 1, MathHelper.floor_double(this.posZ));
            float var10 = 1.0F;

            if (Keyboard.getEventKeyState() && Keyboard.getEventKey() == itogglekey)
            {
            	this.motionY = 0.1D;
            	this.motionX = this.prevMotionX * 1.5D;
            	this.motionZ = this.prevMotionZ * 1.5D;
            	this.moveEntity(this.motionX, this.motionY, this.motionZ);
            	this.jump();
            }

            if (var9 == Block.ice.blockID)
            {
                var10 = Block.blocksList[var9].slipperiness * 0.3F;
            }
            else if (!this.onGround && !this.isInWeb)
            {
            	this.motionX += this.riddenByEntity.motionX;
            	this.motionZ += this.riddenByEntity.motionZ;
            }
            else
            {
            	this.isInWeb = false;
                this.motionX += this.riddenByEntity.motionX * 7.0D * (double)var10;
                this.motionZ += this.riddenByEntity.motionZ * 7.0D * (double)var10;
            }

            EntityPlayer var11 = (EntityPlayer)this.riddenByEntity;
            this.rotationYaw = this.prevRotationYaw = var11.rotationYaw;
            this.prevMotionX = this.motionX * 0.6000000000000001D;
            this.prevMotionZ = this.motionZ * 0.6000000000000001D;
            this.moveEntity(this.motionX, this.motionY, this.motionZ);
            this.motionX = this.prevMotionX * 1.5D;
            this.motionZ = this.prevMotionZ * 1.5D;
            this.moveEntity(this.motionX, this.motionY, this.motionZ);
        }
        else
        {
        	this.moveEntity(par1, par3, par5);
        }
}
public static void assignToggleButton(String var0)
    {
        togglekey = var0;
        itogglekey = Keyboard.getKeyIndex(togglekey);
    }
public void jump()
    {
	this.motionY = 0.41999998688697815D;

        if (this.isPotionActive(Potion.jump))
        {
        	this.motionY += (double)((float)(this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F);
        }

        if (this.isSprinting())
        {
            float f = this.rotationYaw * 0.017453292F;
            this.motionX -= (double)(MathHelper.sin(f) * 0.2F);
            this.motionZ += (double)(MathHelper.cos(f) * 0.2F);
        }

        this.isAirBorne = true;
        ForgeHooks.onLivingJump(this);
    }
}

 

 

 

Any help, thoughts, suggestions, or even some other way to do this, I am all open...I also have the crash report from when I change the modifier in the cowhelper class...

Link to comment
Share on other sites

Whoa, I'm not sure where to begin mate.

I think you should look at your code line by line and try to understand what it really means. (Did you look into those videos?)

 

The problems I'd guess to be many, and they seem to all be tied to a misunderstanding of java basics.

For example:

  final EntityAIControlledByPlayer aiControlledByPlayer;

Doesn't this redline/error in eclipse as a compiler error?

I would at least assume so.

 

And what is the purpose of the first if statement?

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Well yes, I did check out the videos, and while they were informative, didnt really get me any closer to a solution. I have probably tried 40 different ways to get to the preferred out come, but nothing is even close, I can mount the cow, but not control. I have added a new task entry and all, I have tried to load new methods in my event class for move entity and onupdate....but alas I get nowhere with it. I know it can be done, maybe not the way I am attempting to do so, but iChun did it with his trail mix mod. I think he may have used a world tick handler or similar. Unfortunately I do not know where to begin doing so with a tick handler to accomplish the task. After about 30 attempts is when I posted this seeking help. I would like someone to point me in a direction of best way of doing this, if anyone knows how. I want to make vanilla mobs rideable without editing base files....again I know this can be done...

Link to comment
Share on other sites

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.