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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://pastebin.com/VwpAW6PX My game crashes upon launch when trying to implement the Oculus mod to this mod compilation, above is the crash report, I do not know where to begin to attempt to fix this issue and require assistance.
    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. 📈 Skills: RPG-style skill system that enhances your gaming experience! 🎮 Leaderboards: Compete and shine! Top players are rewarded weekly! 🏆 Random Teleporter: Travel instantly across different worlds with a click! 🌐 Custom World Generation: Beautifully generated world. 🌍 Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. 🏰 Kits: Unlock ranks and gain access to various kits. 🛠️ Fishing Tournament: Compete in a friendly fishing tournament! 🎣 Chat Games: Enjoy games right within the chat! 🎲 Minions: Get some help from your loyal minions. 👥 Piñata Party: Enjoy a festive party with Piñatas! 🎉 Quests: Over 1000 quests that you can complete! 📜 Bounty Hunter: Set a bounty on a player's head. 💰 Tags: Displayed on nametags, in the tab list, and in chat. 🏷️ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! 🟢 Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. 🔲✨[ Player Warp: Set your own warp points for other players to teleport to. 🌟 Display Shop: Create your own shop and sell to other players! 🛒 Item Skins: Customize your items with unique skins. 🎨 Pets: Your cute loyal companion to follow you wherever you go! 🐾 Cosmetics: Enhance the look of your character with beautiful cosmetics! 💄 XP-Bottle: Store your exp safely in a bottle for later use! 🍶 Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! 📦 Glowing: Stand out from other players with a colorful glow! ✨ Player Particles: Over 100 unique particle effects to show off. 🎇 Portable Inventories: Over virtual inventories with ease. 🧳 And a lot more! Become part of our growing community today! Discord: https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working   I am not familiar with Linux - check for similar/related issues  
  • Topics

×
×
  • Create New...

Important Information

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