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
  On 9/11/2016 at 5:59 PM, Kaneka said:

 

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
  On 9/11/2016 at 5:27 PM, Animefan8888 said:

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
  On 9/11/2016 at 5:59 PM, Kaneka said:

 

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
  On 9/11/2016 at 6:25 PM, Kaneka said:

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).

  Quote

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

Posted
  On 9/11/2016 at 6:42 PM, Ernio said:

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • my game keeps crashing right before launching the game before full screen and keeps poping up this error message "error code 1 " The game crashed: rendering overlay Error: java.lang.IllegalAccessError: failed to access class com.mojang.blaze3d.platform.GlStateManager$TextureState from class net.coderbot.iris.gl.IrisRenderSystem$DSAARB (com.mojang.blaze3d.platform.GlStateManager$TextureState is in module minecraft@1.18.2 of loader 'TRANSFORMER' @d919544; net.coderbot.iris.gl.IrisRenderSystem$DSAARB is in module oculus@1.6.4 of loader 'TRANSFORMER' @d919544)
    • removing oculus or any of ETF or EMF or even embeddium doesn't change anything it just crashes again with error -1  https://gist.github.com/Tikalian-coconut/d49e8fb83bf57d5e04eb042522046786 this time i removed all 4 at same time and that gave it something is wrong with the game seriously..
    • crash report -> https://gist.github.com/Tikalian-coconut/18c41f97bdacef54725e5141f57697d7 from what i see it seems like Entity Texture Features doesn't like Oculus doing something or invert.. not sure it's why everything is all black textured but that causes a -1 error
    • well that's bad, cuz there's no crash report at all (the last crash report is from previous replies) it's probably another issue that doesn't fit in this bug report, the game works fine except that everything is black, no texture except the sky and skin, everything else is just black i've tried reloading the textures in game, see for drivers updates but it did nothing, seems like an issue with Embeddium or Oculus i think, but i know nothing compared to you i can still send the latest debug and latest.log files.. edit: it seems that when i re-add rechiseled (1.1.6-1.20.1) it crashes as error 1 (i can't remove it off from the modpack cuz that'll break all my builds on some maps) lemme start the game and get it to crash to get a crash report done)
    • If you've fallen victim to a crypto scam, you're not alone and thankfully, you're not without options. I highly recommend iBolt Cyber Hacker Company for anyone seeking professional and effective assistance in recovering scammed cryptocurrency. After extensive research and hearing from multiple satisfied clients, it's clear that iBolt stands out in a crowded and often unreliable market. Their team of experienced cyber experts and blockchain analysts uses advanced tracking techniques to follow stolen funds across the blockchain and engage with crypto exchanges when possible. They’re not just tech-savvy—they’re strategic and persistent. WHY CHOOSE iBOLT CYBER HACKER COMPANY? (1) Proven success in crypto asset recovery (2) Fast, professional, and discreet service (3) Skilled in blockchain forensics and cyber investigation (4) Committed to fighting online fraud and supporting victims Don’t give up. I strongly recommend reaching out to iBolt Cyber Hacker Company. ENQUIRIES: info @ iboltcyberhack . org/ www . iboltcyberhack. org/ +39. 351. 105. 3619.
  • Topics

×
×
  • Create New...

Important Information

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