Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Minecraft Forge
  • Suggestions
  • Add TrampleEvent
Sign in to follow this  
Followers 1
zennyrpg

Add TrampleEvent

By zennyrpg, September 15, 2018 in Suggestions

  • Reply to this topic
  • Start new topic

Recommended Posts

zennyrpg    0

zennyrpg

zennyrpg    0

  • Tree Puncher
  • zennyrpg
  • Members
  • 0
  • 9 posts
Posted September 15, 2018

I want to disable crop trampling.  The two relevant pieces of code are:

 

BlockFarmland.class

    /**
     * Block's chance to react to a living entity falling on it.
     */
    public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance)
    {
        if (!worldIn.isRemote && entityIn.canTrample(worldIn, this, pos, fallDistance)) // Forge: Move logic to Entity#canTrample
        {
            this.turnToDirt(worldIn, pos);
        }

        super.onFallenUpon(worldIn, pos, entityIn, fallDistance);
    }

 

Entity.class

    public boolean canTrample(World world, Block block, BlockPos pos, float fallDistance)
    {
        return world.rand.nextFloat() < fallDistance - 0.5F
            && this instanceof EntityLivingBase
            && (this instanceof EntityPlayer || world.getGameRules().getBoolean("mobGriefing"))
            && this.width * this.width * this.height > 0.512F;
    }

 

The only way I can think of to turn off trampling globally is to create a new subclass Entity for every Entity in the game, override the canTrample method, and then replace all the default spawns with my new subclass.  This... seems like a bad idea.  (Maybe there is an easier way, but I don't see any place here for a global override)

 

I suggest adding an event to onFallenUpon.  First fire the TrampledEvent where it could be set to Result.Deny.  If left on Result.Default, it would call the Entity.canTrample method to produce the default behavior.  This would allow for not only global overrides, but also more detailed behavior like allowing/denying based off what's growing.

  • Quote

Share this post


Link to post
Share on other sites

DaemonUmbra    358

DaemonUmbra

DaemonUmbra    358

  • Reality Controller
  • DaemonUmbra
  • Forum Team
  • 358
  • 6447 posts
Posted September 15, 2018

What version are you using?

This was added 3 months ago.

  • Quote

Share this post


Link to post
Share on other sites

zennyrpg    0

zennyrpg

zennyrpg    0

  • Tree Puncher
  • zennyrpg
  • Members
  • 0
  • 9 posts
Posted September 16, 2018

Welp.  Just checked and I'm on 14.21.1.2406, that's over a year old.  Wow, guess its time to upgrade!

 

Thank you for the reply and link :)

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • DragonITA
      [1.14.4] How to get Minecraft Horse model/texture to make a custom unicorn?

      By DragonITA · Posted 17 minutes ago

      package net.batonfack.fantasymod.client.renders; import net.batonfack.fantasymod.FantasyMod; import net.batonfack.fantasymod.client.models.ModelUnicornWithAbstracHorse; import net.batonfack.fantasymod.client.models.ModelUnicornWitoutAbstracHorse; import net.batonfack.fantasymod.entities.UnicornEntity; import net.minecraft.client.renderer.entity.AbstractHorseRenderer; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.client.renderer.entity.MobRenderer; import net.minecraft.entity.passive.horse.AbstractHorseEntity; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.client.registry.IRenderFactory; @OnlyIn(Dist.CLIENT) public class UnicornEntityRender extends AbstractHorseRenderer<UnicornEntity, ModelUnicornWithAbstracHorse<AbstractHorseEntity>> // <<---The Line with the error { //public UnicornEntityRender(EntityRendererManager manager) { // super(manager, new UnicornEntityModel(0), 0f); //} //private static ModelUnicornWitoutAbstracHorse<UnicornEntity> UnicornModel; public static final ResourceLocation unicorn = new ResourceLocation("fantasymod:" + "textures/entity/unicorn_entity.png"); private static float shadowOpaque = 0.0f; public UnicornEntityRender(EntityRendererManager manager, ModelUnicornWithAbstracHorse<AbstractHorseEntity> UnicornModel, float p_i50961_3_) { super(manager, new ModelUnicornWithAbstracHorse<>(0.0f), p_i50961_3_); } @Override protected ResourceLocation getEntityTexture(UnicornEntity entity) { return unicorn; } public static class RenderFactory implements IRenderFactory<UnicornEntity> { @Override public EntityRenderer<? super UnicornEntity> createRenderFor(EntityRendererManager manager) { return new UnicornEntityRender(manager, new ModelUnicornWithAbstracHorse<>(0.0f), shadowOpaque); } } }  
    • DragonITA
      [1.14.4] How to get Minecraft Horse model/texture to make a custom unicorn?

      By DragonITA · Posted 18 minutes ago

    • The_Unkown675
      Can't connect to own server; No syncable config

      By The_Unkown675 · Posted 29 minutes ago

      Server debug file - https://paste.gg/p/anonymous/0671148362b5476fbce55b8922262dad Latest log file -https://paste.gg/p/anonymous/bab7c2b3ca0947df9b10bce9c2632c22 Hope this helps! If you need anything else please let me know, I'll be happy to help, thank you for your help!
    • diesieben07
      Forge 1.12.2 crashes and wont load world!

      By diesieben07 · Posted 30 minutes ago

      In the future please always post the debug.log. From the excerpt you posted it looks like your world got corrupted. Restore from backup.
    • diesieben07
      Clean forge installer

      By diesieben07 · Posted 32 minutes ago

      Only ever download Forge from https://files.minecraftforge.net/. Any other site offering Forge downloads is illegitimate.   There is no Forge version for 1.15 at this time. Be patient.
  • Topics

    • DragonITA
      46
      [1.14.4] How to get Minecraft Horse model/texture to make a custom unicorn?

      By DragonITA
      Started Monday at 10:06 AM

    • The_Unkown675
      2
      Can't connect to own server; No syncable config

      By The_Unkown675
      Started 18 hours ago

    • PolarBr0
      1
      Forge 1.12.2 crashes and wont load world!

      By PolarBr0
      Started 50 minutes ago

    • Rick57
      1
      Clean forge installer

      By Rick57
      Started 3 hours ago

    • CrashDbo
      3
      [1.12.2] Water Crafting with dropped items like AE2

      By CrashDbo
      Started 17 hours ago

  • Who's Online (See full list)

    • MoeBoy76
    • nojomo123
    • plugsmustard
    • DragonITA
    • hohserg
  • All Activity
  • Home
  • Minecraft Forge
  • Suggestions
  • Add TrampleEvent
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community