Jump to content

[1.10.2]Prevent other mods interacting with some blocks


Recommended Posts

Posted

Hi everyone,

 

is there any way to prevent other mods from interacting with some of my blocks? In my situation i need to prevent the right clicking mods because they cause a abuse of a modfeature.

I suscribed at already at the event to cancel it, with highest priority, but the right clicking mod do this too...And then my suscribed event only works when my event is fired befor the other mods.

Is there any better way doing this?

 

thanks for every answer,

 

Kaneka

Posted

Try checking if the Entity (Living?) is an instanceof FakePlayer or if that doesn't work try to apply the effects within a Event instead of the onBlockAcivatedMethod(...) that may work.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

 

I am talking about a block.

here is a example of the mods interactiong with my mod, how do I prevent them doing this?

Source: https://github.com/sblectric/OpenHarvest/blob/master/src/main/java/sblectric/openharvest/events/HarvestEvents.java

public class HarvestEvents {

/** Harvest crops on this event */
@SubscribeEvent
public void onHarvestCrops(PlayerInteractEvent.RightClickBlock event) {
	World world = event.getWorld();
	if(world.isRemote) return; // do nothing on client thread

	BlockPos pos = event.getPos();
	IBlockState state = world.getBlockState(pos);
	Block block = state.getBlock();
	EntityPlayerMP ply = (EntityPlayerMP)event.getEntityPlayer();

	// make sure the off-hand is active and right-clicking a crop block
	if(event.getHand() == EnumHand.OFF_HAND && block instanceof BlockCrops) {

		// make sure the block isn't blacklisted
		ResourceLocation name = block.getRegistryName();
		String modid = name.getResourceDomain();
		if(!HarvestConfig.modBlacklist.contains(modid) && !HarvestConfig.blockBlacklist.contains(name.toString())) {

			// get the age type
			PropertyInteger age = null;
			int maxAge = -1;
			for(IProperty prop : state.getPropertyNames()) {
				if(prop instanceof PropertyInteger && prop.getName().equals("age")) {
					age = (PropertyInteger)prop;
					maxAge = HarvestUtils.max(age.getAllowedValues());
					break;
				}
			}

			// make sure the age property is valid
			if(age != null && maxAge > -1) {
				if(state.getValue(age) == maxAge) {
					for(ItemStack s : block.getDrops(world, pos, state, 0)) {
						ply.inventory.addItemStackToInventory(s);
					}
					world.setBlockState(pos, block.getDefaultState());
				}
			}

		}
	}
}
}

Posted

 

I am talking about a block.

here is a example of the mods interactiong with my mod, how do I prevent them doing this?

Source: https://github.com/sblectric/OpenHarvest/blob/master/src/main/java/sblectric/openharvest/events/HarvestEvents.java

public class HarvestEvents {

/** Harvest crops on this event */
@SubscribeEvent
public void onHarvestCrops(PlayerInteractEvent.RightClickBlock event) {
	World world = event.getWorld();
	if(world.isRemote) return; // do nothing on client thread

	BlockPos pos = event.getPos();
	IBlockState state = world.getBlockState(pos);
	Block block = state.getBlock();
	EntityPlayerMP ply = (EntityPlayerMP)event.getEntityPlayer();

	// make sure the off-hand is active and right-clicking a crop block
	if(event.getHand() == EnumHand.OFF_HAND && block instanceof BlockCrops) {

		// make sure the block isn't blacklisted
		ResourceLocation name = block.getRegistryName();
		String modid = name.getResourceDomain();
		if(!HarvestConfig.modBlacklist.contains(modid) && !HarvestConfig.blockBlacklist.contains(name.toString())) {

			// get the age type
			PropertyInteger age = null;
			int maxAge = -1;
			for(IProperty prop : state.getPropertyNames()) {
				if(prop instanceof PropertyInteger && prop.getName().equals("age")) {
					age = (PropertyInteger)prop;
					maxAge = HarvestUtils.max(age.getAllowedValues());
					break;
				}
			}

			// make sure the age property is valid
			if(age != null && maxAge > -1) {
				if(state.getValue(age) == maxAge) {
					for(ItemStack s : block.getDrops(world, pos, state, 0)) {
						ply.inventory.addItemStackToInventory(s);
					}
					world.setBlockState(pos, block.getDefaultState());
				}
			}

		}
	}
}
}

What you are saying is you do not want it to be right click and you do not have to deal with planting? Have you tried registering your event in preInit and then canceling it (most events are registered during init normally but I believe they can be registered in any of those events) I am not sure how events get fired to well.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Try checking if the Entity (Living?) is an instanceof FakePlayer or if that doesn't work try to apply the effects within a Event instead of the onBlockAcivatedMethod(...) that may work.

 

He's already trying the event, and his problem is that he can't be entirely certain that his mod handles the event first or that it prevents other mods from handling the event. Same with any of the block methods, those can be intercepted by other mods handling the event.

 

Back to the original posters question. Regarding mod load order and intercepting them I'm not sure you can fully solve that, but you can probably make it a lot less likely to be a problem. First of all, I believe that the default load order is alphabetical (someone can confirm) by mod id so maybe giving your mod an id with "aa" in the front might help move it forward.

 

In the @Mod annotation, you can add dependencies where you specify whether your mod must load before or after. I'm not sure you want to make a dependency on the other mods (since you don't want to make them required) but there might be a clever way to use this anyway, like make the dependency but handle the error, or maybe look at how the mod load order works and somehow force your mod early.

 

However, none of that will fully work because you can actually make an event handler receive canceled events (so canceling doesn't even ensure that all mods will not see the event).

 

I think maybe an alternative is to actually be the last loaded and then check if any of the right-click mods are loaded and then undo whatever it is that they're doing.

 

In the end though what you're talking about is a mod conflict -- the user has installed the other mod for a reason and you are trying to prevent that mod from working. So basically your mods are probably incompatible and you should advise users and mod-pack makers to not use both. Or if there is some functionality of the other mod you want to leave alone, then what you should do is contact the other mods' author and work with them to create compatibility (maybe the mods can have a configuration that allows one or the other be active on right-click).

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

Posted

my problem is that my mod add a doubling ore way by creating ore plants, these plants dont drop any seed, because then you have endless ingots and thats not what i want to. The right click mods(simple harvest, gentle harvest and so on) bypassed this and direktly replant them without checking if there is a seed or not.

I have contacted some right click mod authors and they add the seedcheck. But these simple harvest mods are "easy" and because of that so many authors copy that idea and try to make their own. Now there are so much right click mod I can´t contact every author....

So dependency wont work because I cant take any mod in my code

Posted

 

I am talking about a block.

here is a example of the mods interactiong with my mod, how do I prevent them doing this?

Source: https://github.com/sblectric/OpenHarvest/blob/master/src/main/java/sblectric/openharvest/events/HarvestEvents.java

public class HarvestEvents {

/** Harvest crops on this event */
@SubscribeEvent
public void onHarvestCrops(PlayerInteractEvent.RightClickBlock event) {
	World world = event.getWorld();
	if(world.isRemote) return; // do nothing on client thread

	BlockPos pos = event.getPos();
	IBlockState state = world.getBlockState(pos);
	Block block = state.getBlock();
	EntityPlayerMP ply = (EntityPlayerMP)event.getEntityPlayer();

	// make sure the off-hand is active and right-clicking a crop block
	if(event.getHand() == EnumHand.OFF_HAND && block instanceof BlockCrops) {

		// make sure the block isn't blacklisted
		ResourceLocation name = block.getRegistryName();
		String modid = name.getResourceDomain();
		if(!HarvestConfig.modBlacklist.contains(modid) && !HarvestConfig.blockBlacklist.contains(name.toString())) {

			// get the age type
			PropertyInteger age = null;
			int maxAge = -1;
			for(IProperty prop : state.getPropertyNames()) {
				if(prop instanceof PropertyInteger && prop.getName().equals("age")) {
					age = (PropertyInteger)prop;
					maxAge = HarvestUtils.max(age.getAllowedValues());
					break;
				}
			}

			// make sure the age property is valid
			if(age != null && maxAge > -1) {
				if(state.getValue(age) == maxAge) {
					for(ItemStack s : block.getDrops(world, pos, state, 0)) {
						ply.inventory.addItemStackToInventory(s);
					}
					world.setBlockState(pos, block.getDefaultState());
				}
			}

		}
	}
}
}

Couldn't you just bypass this whole thing by not extending BlockCrops and instead making your own class the is BlockCrops. You can just override onBlockActivated(...) assuming they do not cancel  the event and just destroy the block there as it would be placed before onBlockActivate(...) is called after the event.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

my problem is that my mod add a doubling ore way by creating ore plants, these plants dont drop any seed, because then you have endless ingots and thats not what i want to. The right click mods(simple harvest, gentle harvest and so on) bypassed this and direktly replant them without checking if there is a seed or not.

I have contacted some right click mod authors and they add the seedcheck. But these simple harvest mods are "easy" and because of that so many authors copy that idea and try to make their own. Now there are so much right click mod I can´t contact every author....

So dependency wont work because I cant take any mod in my code

 

Sorry but your problem is really mod incompatibility. There is always the possibility in modding that there are mods that can't be used with yours. For example, imagine you have a mod that creates a special sword and another mod replaces all swords for some reason. Those two mods simply can't be used together. You have to tell users that you're incompatible with mods you know don't work, and tell users you might be incompatible with other righ-click mods. Hopefully your mod is more interesting to them than the other mod and they'll choose yours.

 

If there is a popular mod that you think people want to use with yours and the author won't or can't make it compatible you might consider adding those other right-click features so users don't feel the need to run both mods.

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

Posted

Well, you could force your mod to be loaded 1st, thus making your event priority be highest of HIGHEST.

use "before" in @Mod. There is probably even wildcard (if not, you can simply put there mods that make things bad, like one you mentioned).

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

Posted

Well, you could force your mod to be loaded 1st, thus making your event priority be highest of HIGHEST.

use "before" in @Mod. There is probably even wildcard (if not, you can simply put there mods that make things bad, like one you mentioned).

 

I already mentioned that. It would help, but wouldn't be foolproof because other mods could also do that (in which case I think it would still load in alphabetical order).

 

More importantly, canceling events is not a foolproof way of preventing other mods from intercepting your mod's functionality. For example, even if your mod gets to handle the mod first and then cancels it (so no other mod gets the event) other mods can actually set receiveCanceled=true and still get the event. Furthermore, canceling events can really screw up other mods and even vanilla functionality. A lot of times with events you want to do something additional to vanilla but not prevent all the vanilla stuff from also happening.

 

Anyway, I'm just saying that there is not really a foolproof way of preventing other mods from interfering with yours. You can try to increase the priority of your handler and get your mod to the front of the load order, but there are still ways the other mods can affect you.

 

Best bet is to make users aware of incompatibility and contact as many mod authors as you can to help improve compatibility.

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

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.