TheOnlyTrueEnte Posted November 29, 2019 Posted November 29, 2019 (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 November 29, 2019 by TheOnlyTrueEnte solution for my specific issue Quote
Xander402 Posted November 29, 2019 Posted November 29, 2019 (edited) Have you made your custom TNTs class(es) extend net.minecraft.block.TNTBlock? Edited November 29, 2019 by Xander402 1 Quote 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++; }); } }
TheOnlyTrueEnte Posted November 29, 2019 Author Posted November 29, 2019 (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 November 29, 2019 by TheOnlyTrueEnte I had the wrong version Quote
Choonster Posted November 29, 2019 Posted November 29, 2019 (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 November 29, 2019 by Choonster 1 Quote 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.
TheOnlyTrueEnte Posted November 29, 2019 Author Posted November 29, 2019 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? Quote
Choonster Posted November 29, 2019 Posted November 29, 2019 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. 1 Quote 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.
Recommended Posts
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.