Jump to content

Hooking into event for *all* blocks without modifying base classes


porl

Recommended Posts

Hi all

 

Is there an easy way to allow my mod to modify the behaviour of blocks in general without modifying the base class? I want to be able to adjust speed depending on block type an entity is on (like soul sand). I saw the event onEntityCollidedWithBlock is used for soul sand, but can I hook that in the general case for all blocks?

 

Also, if I can do this can I stop the soul sand's version of the event from triggering? I don't want to be having to modify soul sand as a special case if possible.

 

Thanks for the help.

Link to comment
Share on other sites

Any advice is always welcome! I'm trying to learn how to mod and I thought I'd do something that I wanted a while back.

 

Basically I want to be able to make the "base speed" of different blocks variable - eg. stone is faster to move across than sand and so on. Would it be better to just replace the base classes since in theory I'd like it to be able to work with any block (from mods etc)?

Link to comment
Share on other sites

Would that work if I want it configurable for every type of block though? Say for instance someone has a mod that adds hundreds of different blocks. I'd like to be able to have in a config file a list of block ids (or some way to reference them) and a speed multiplier that gets assigned to each block. Obviously the default would be one for all blocks but I imagine it would get quite messy if I was overriding many blocks (most of which I may not know about since they are from other mods).

 

Am I missing some "easy" way that this would work with replacing them with the custom block? My understanding is that I am needing to override the onEntityCollidedWithBlock for all blocks. Is there another way to do this?

Link to comment
Share on other sites

actually, all you would need to do is give it a normal collision box. it's slightly lower than a normal block, hence why you sink into it.

 

Just FYI:

There's two different functions going on here that result in Soul Sand's behavior.

1) Soul Sand's collision box is smaller than a full cube.  This is required (minimum 1% smaller) for soul sand's effect to work

2) Soul Sand's on-collision function, which actually slows the player (cactus does damage, etc*).

 

*Web actually works differently

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.

Link to comment
Share on other sites

You could use something close to event handler - i mean, do the tick and when block below you == something, then set player speed to something. I am sure I can find those methods, because I've been making a road block (sadly mine was full ModBlock so i used just call for EntityWalking or something like this, yours are vanilia ones, thats why you would need to use ticks). And other way is to of course make Reflection and stuff proposed before.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

If I did it by tick would it be overridden by, say, the default soul sand behaviour?

 

If I was to use reflection is there a way that I could keep it flexible enough that someone could put in a config something like

 

MARBLE 1.2

 

where MARBLE is some block from a mod (that my mod has no knowledge of) and 1.2 is a speed? Obviously there may need to be another way to represent it but that's the basic idea I'm after.

 

Thanks for all the advice guys, I really appreciate it.

Link to comment
Share on other sites

That would be perfect but could that work (with other mods) using reflection? I can see how to do it easily (in theory anyway) if I can modify the block class (and the soul sand class to remove it's special case) but as that is a no-no I'd like to know how to do it properly but still keep the flexibility of someone being able to put in a block id of any block from any mod and the speed adjustment work.

Link to comment
Share on other sites

I think I'm confusing myself now. Using reflection, can I do this without actually changing the block for a custom block class? If I changed the block to a custom one I wouldn't be able to know what special functions/events etc the block I'm replacing would need (due to being possibly from another mod) so I don't think that would work. That's not a definitive statement by the way, I'm happy to be proven wrong.

Link to comment
Share on other sites

I think I'm confusing myself now. Using reflection, can I do this without actually changing the block for a custom block class? If I changed the block to a custom one I wouldn't be able to know what special functions/events etc the block I'm replacing would need (due to being possibly from another mod) so I don't think that would work. That's not a definitive statement by the way, I'm happy to be proven wrong.

>_>

 

<_<

 

Yes, but you shouldn't.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

Is there any "correct" way to do what I am wanting then? If the other methods are "dodgy" anyway then I think I'd prefer to go dodgy all the way and just modify the base classes but I'd like to do the right thing if possible.

Link to comment
Share on other sites

The funny thing is, it seems like "block placed" and "block destroyed" are two of the most common and most wanted events, but I can't seem to find any sort of associated event. Which makes me think that it's some other, stupidly obvious method, which is why I'm afraid to post it on the hook suggestions, either for fear of "There's already a method stop bugging me lockban!" or "I'm going to implement one stop bugging me lockban!"

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

I thought "lockban" was someone's name for a second there haha

 

What are the actual problems with modifying a base class (other than it being incompatible if I were to change things too much)? In essence I am just adding one event method to all blocks so I assume that isn't the problem itself. Assuming no change I make has any issue with other mods that don't also modify the class itself (obviously if two mods both change the same file there would be issues) are there any other issues to watch for?

Link to comment
Share on other sites

I'm still not understanding how the event could override the soul-sand case without modifying base classes though.

 

If there was a way to "unregister" the soul-sand "onEntityCollidedWithBlock" and register a hook for all blocks for "onEntityWalking" (and possibly "onEntityCollidedWithBlock" if necessary) then this would be ideal. Is this what you are suggesting I request the ability to do? Without the ability to remove the soul-sand's event I don't think it would work.

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.