Jump to content

[Solved for igniting custom TNT] [1.14.4] add Dispense Behavior to vanilla item


Recommended Posts

Posted (edited)

Solved for my specific issue! My TNT just needed to override IForgeBlock#catchFire.

 

Hi there,

My mod adds new types of TNT and I would like Dispensers to be able to prime them with vanilla Flint and Steel.

My problem is that DispenserBlock#registerDispenseBehavior(item, behavior) puts the specified behavior in a map with item as the key so if I register a new Behavior for Items.FLINT_AND_STEEL, the old vanilla behavior and/or behavior that another mod might have added gets overridden. Is there another way of doing it? I haven't found any sort of Dispenser event or Redstone event (although a Redstone event probably wouldn't work because I also need the exact slot of the dispenser that is being used).

Cheers,

TheOnlyTrueEnte

Edited by TheOnlyTrueEnte
solution for my specific issue
Posted (edited)

Have you made your custom TNTs class(es) extend net.minecraft.block.TNTBlock?

Edited by Xander402
  • Thanks 1

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Posted (edited)
5 hours ago, Xander402 said:

Have you made your custom TNTs class(es) extend net.minecraft.block.TNTBlock?

No. If my TNT extends TNTBlock, dispensing Flint and Steel onto it will just spawn a vanilla TNTEntity. Here's an excerpt from IDispenseItemBehavior#init, of the OptionalDispenseBehavior for FLINT_AND_STEEL:

if (blockstate.getBlock() instanceof TNTBlock) {
	TNTBlock.explode(world, blockpos);
    world.removeBlock(blockpos, false);
}

TNTBlock#explode is obviously a static method here so I can't do anything to sort of override it.

 

EDIT: as of 1.14.4-28.1.92, this calls blockstate.catchFire which my TNT block can override.

Edited by TheOnlyTrueEnte
I had the wrong version
Posted (edited)
21 minutes ago, TheOnlyTrueEnte said:

No. If my TNT extends TNTBlock, dispensing Flint and Steel onto it will just spawn a vanilla TNTEntity. Here's an excerpt from IDispenseItemBehavior#init, of the OptionalDispenseBehavior for FLINT_AND_STEEL:


if (blockstate.getBlock() instanceof TNTBlock) {
	TNTBlock.explode(world, blockpos);
    world.removeBlock(blockpos, false);
}

TNTBlock#explode is obviously a static method here so I can't do anything to sort of override it.

 

This should have been fixed by this PR (merged in Forge 1.14.4-28.1.92). The dispense behaviour now checks for any flammable block and calls Block#catchFire instead of calling the static method.

Edited by Choonster
  • Thanks 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
3 minutes ago, Choonster said:

 

This should have been fixed by this PR (merged in Forge 1.14.4-28.1.92).

You're right, I should have checked the new version first. Thank you.

Just out of curiosity though and since I might add more Dispense behaviors in the future, is there a way to actually add Dispense functionality to an already registered block?

Posted
2 hours ago, TheOnlyTrueEnte said:

Just out of curiosity though and since I might add more Dispense behaviors in the future, is there a way to actually add Dispense functionality to an already registered block?

 

It should be possible to overwrite the existing behaviour simply by calling DispenserBlock.registerDispenseBehavior with your IDispenseItemBehavior. If you want to delegate to the existing behaviour, you'll need to use reflection to access DispenserBlock.DISPENSE_BEHAVIOR_REGISTRY and fetch the existing behaviour before overwriting it.

  • Thanks 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.