Jump to content

Recommended Posts

Posted

Hello Forge Community,

 

I am pretty new to modding in minecraft and starting to get a bit into the forge API so bare with me:

 

What i want to do is removing the Entity slow property when a player is inside a cobweb by overriding the setInWeb() method from the Entity class. My problem is, that i haven't figured out a way to actually make use over the overriden method of the super class and at this point im not even sure if it is possible without using ASM.

 

What i've got so far:

 

public class WebSlow extends Entity{

public WebSlow(World p_i1582_1_) {
	super(p_i1582_1_);
}
@Override
    public void setInWeb()
    {
        this.isInWeb = false;
    }
@Override
protected void entityInit() {		
}
@Override
protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {	
}
@Override
protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {		
}

 

I will probably need a way to constantly set field "isInWeb" to false (which the setInWeb() method does) but i haven't found any onPlayerMove events or anything similiar, i have tried it with the "EntityJoinWorld" event but that didn't work out.

 

Is what im trying to do the right approach, is there any other way to prevent the web slow or is the use of ASM inevitable?

 

 

I would appreciate any suggestions to solve my little mod problem.

Thans in advance

 

 

 

 

Posted

First of all, what kind of entity are you making? Or are you trying to do this to all entities?

 

You're extending entity, but if you really wanted to do this for a mob or living entity you need to extend the proper subclass, like EntityMob or whatever. But extending is for making your own entity -- is that what you want to do, or do you want behavior of vanilla entities to change?

 

Basically I'm saying that extending a class is used for making something new, in this case a new entity.

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

Posted

I am trying to completely remove the effect of cobwebs slowing down the player or any other entity. I had already looked into the Blocks class but none of the methods or fields helped there (i think). Maybe there is an easier mor straight forward way to prevent this, like canceling a certain event maybe?

 

So im not really trying to make a new entity, no. The entity class has this MoveEntity method (don't know exact name atm, not at home sry) that checks if the entity has the "isInWeb" property set, which is handled by the "setInWeb()" method, which is why i want to override that method.

 

So question still remains, is this override even possible so it effects every Entity without coremods?

Posted

No, the way you are doing it is not possible. You can't just make a new Entity class and override stuff expecting it to affect other entity classes - that's not how inheritance works.

 

If you change the actual Entity class itself, however, then yes, but that would require modifying the vanilla class.

 

Another option would be to replace all web blocks with a custom web block that simply overrides #onEntityCollidedWithBlock to do nothing, as opposed to calling #setInWeb.

 

Either of those 2 options will completely remove the effect from the game, however, for every entity.

 

You could also try subscribing to LivingUpdateEvent and setting the entity's #isInWeb field to false, either via Reflection or a 'dirty' accessor class, but whether that works or not depends on the order in which the methods are called. If the Block method is called first, then the living update, and then, finally, current motion is modified, it will work, otherwise it won't. This option would allow you to control which entities can move freely in webs, if you wanted.

Posted

@coolAlias

 

Thanks for your post!

I was aware , when i extended the Entity class, that i was creating a new Entity class, however i thought i could replace an entities behaviour by assigning the new Entity class when the Entity was spawned for example. I do something similiar when the MainMenu load event is called  to add custom buttons.

 

I will look further into the onEntityCollidedWithBlock event a bit later when i have some time. Would you be so kind and provide an example?

 

Also i have tried using the LivingUpdateEvent however there is 1 problem, the isInWeb field is protected :/ I will try modifying them with a Reflection class.

 

Thanks in advance!

Posted

I was aware , when i extended the Entity class, that i was creating a new Entity class, however i thought i could replace an entities behaviour by assigning the new Entity class when the Entity was spawned for example.

Not unless you recreated every single Entity class there is, including for mods, which is obviously impossible. Otherwise, you will replace, say, EntityCow with your new entity class, and suddenly it is no longer a cow.

 

You either have to modify the base Entity class that every other entity class extends from, or find a different way. Creating a new Entity class only works for new entities, not any that already have a class inheriting from the original Entity.

Posted

Heres what youve got to do m8. In the moveEntity method, the game calls a couple Block.onEntityCollidedWithBlock() methods. There you have the entity.setInWeb() being called by BlockWeb. You'll need to use asm to override either the moveEntity method or the BlockWeb class.

 

Asm is the only way to make it work

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Posted

@ thebest108

Yes you are right, i realized that too late after trying numerous things(also the ones suggested above) but none of them really worked.

The ASM method is dirty and tideous to work with but at least it is working now, guess i have to get used to it.

 

I emptied the onEntityCollidedWithBLock() method inside the BlockWeb class,  for anyone who is interested in doing this.

 

Thanks for your help

 

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.