Jump to content

Overriding Entity's setInWeb method


ravand

Recommended Posts

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

 

 

 

 

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

ლ(́◉◞౪◟◉‵ლ

Link to comment
Share on other sites

@ 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

 

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

    • Hi, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Here's the link: https://mclo.gs/7L5FibL Here's the link: https://mclo.gs/7L5FibL
    • Also the mod "Connector Extras" modifies Reach-entity-attributes and can cause fatal errors when combined with ValkrienSkies mod. Disable this mod and continue to use Syntra without it.
    • Hi everyone. I was trying modify the vanilla loot of the "short_grass" block, I would like it drops seeds and vegetal fiber (new item of my mod), but I don't found any guide or tutorial on internet. Somebody can help me?
    • On 1.20.1 use ValkrienSkies mod version 2.3.0 Beta 1. I had the same issues as you and it turns out the newer beta versions have tons of unresolved incompatibilities. If you change the version you will not be required to change the versions of eureka or any other additions unless prompted at startup. This will resolve Reach-entity-attributes error sound related error and cowardly errors.
  • Topics

×
×
  • Create New...

Important Information

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