I figured this would be the best place to post this question, though I'm not sure if this counts as mod development,
What I'd like to accomplish, through whatever means would make the most sense, is this:
Modify the properties of both vanilla and existing mod blocks (like ores from CoFH's Thermal Foundation, and Thaumcraft's crystals) to only be mineable by vanilla or mod tools of a certain material or list of materials (like vanilla obsidian and diamond, just extended to more tool materials and blocks).
I don't really know what the best approach to making that change would be, or if it's even possible, as I've never even dabbled in modifying the game on this level myself. The most I've done is configure and bugfix a large modpack I'm making for personal use. In case it makes a difference, I'm wanting to do this for a 1.12.2 install of Minecraft.
Any suggestions would be very much appreciated.
Edit: And please, if there's a more appropriate place for me to post this question, let me know.
The Meaning of Life, the Universe, and Everything.
Location:
Colorado
Join Date:
3/27/2016
Posts:
208
Location:
Colorado
Minecraft:
ProfessorOro
Discord:
gargatheoro
PMC:
GargatheOro
Member Details
You have to make an addon which will override onMine events to certain blocks. Make an if statement that checks if the player is using the correct tool, and let it proceed if so. If not, cancel the onMine event.
I very much appreciate your answer. This little project is really my first foray into modding (I was just making a modpack to begin with lol), so I'm still very much learning, but I've found some very good resources to learn from, and now with your answer, I know exactly what I'm aiming for.
I'd like to keep this thread open for now, because I will surely have follow-up questions in the near future.
Would it be asking too much to ask if you would possibly be able to give me an example of what that IF function would look like? Even just for a single tool and a single block type, like cancelling an onMine event of a vanilla stone block using a vanilla wooden pickaxe. I can extrapolate from there how to use it for my whole progression.
I'm trying my best to learn the fundamentals of this stuff, and I'll keep doing that, but I think just a basic example of the code I'm looking for would help me along greatly. If I'm being naive about what I'm asking, and it's not that simple, just let me know.
The Meaning of Life, the Universe, and Everything.
Location:
Colorado
Join Date:
3/27/2016
Posts:
208
Location:
Colorado
Minecraft:
ProfessorOro
Discord:
gargatheoro
PMC:
GargatheOro
Member Details
Alright, please try and figure it out yourself and watch the video, but I wrote and attached code. I annotated the heck out of it so if you use it, and it works and you can copy-paste, then read the comments so you know how it works.
Alright, so first off, thank you very very much <3.
Now, after some figuring out and watching that video (plus a few more from his series), I think I have a couple of specific questions:
1) When I replace the "ItemInit.SILVER_INGOT" with "ItemInit.STONE_PICKAXE", and create the ItemInit class with the constructor:
"public static final Item STONE_PICKAXE = new ItemPickaxe(ToolMaterial.STONE);"
It gives me an error of "The constructor ItemPickaxe(ToolMaterial.STONE) is not visible." Is this something to do with Minecraft's handling of it's own classes, or just a mistake I've made?
2) In that tutorial video, he sets up his custom event class like this (with my event in place of his examples):
CustomEvent class:
package com.vulpixusedember.tutorialmod2.events;
import com.vulpixusedember.tutorialmod2.init.ItemInit;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
public class CustomEvent
{
public void onMineEvent(BreakEvent event)
{
EntityPlayer miner = event.getPlayer();
if(miner.getHeldItemMainhand().getItem() != ItemInit.STONE_PICKAXE);
}
}
which I notice doesn't include the @SubscribeEvent annotation. I'm just wondering if these event registry methods he set up replace the need for that annotation in the CustomEvent class itself (forgive any misused jargon):
EventHandler class:
package com.vulpixusedember.tutorialmod2.util.handlers;
import com.vulpixusedember.tutorialmod2.events.CustomEvent;
import net.minecraftforge.common.MinecraftForge;
public class EventHandler
{
public static void registerEvents()
{
CustomEvent eventCustom = new CustomEvent();
MinecraftForge.EVENT_BUS.register(eventCustom);
}
}
RegistryHandler class:
package com.vulpixusedember.tutorialmod2.util.handlers;
import com.vulpixusedember.tutorialmod2.init.ItemInit;
import com.vulpixusedember.tutorialmod2.util.interfaces.IHasModel;
import net.minecraft.item.Item;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@EventBusSubscriber
public class RegistryHandler
{
@SubscribeEvent
public static void onItemRegister(RegistryEvent.Register<Item> event)
{
event.getRegistry().registerAll(ItemInit.ITEMS.toArray(new Item[0]));
}
@SubscribeEvent
public static void onModelRegister(ModelRegistryEvent event)
{
for(Item item : ItemInit.ITEMS)
{
if(item instanceof IHasModel)
{
((IHasModel)item).registerModels();
}
}
}
public static void preInitRegistries()
{
EventHandler.registerEvents();
}
public static void initRegistries()
{
}
public static void postInitRegistries()
{
}
public static void serverRegistries(FMLServerStartingEvent event)
{
}
}
(Ignore the "IHasModel" part, it was just part of his tutorial, and I'm not trying to add any items)
I do have one other question as well, which is to ask if the original method you provided would be checking the block type as well, since I want to set a custom event for each of a specific list of ores and other blocks (as in "IF HELD_PICKAXE != PROPER_PICKAXE (when mining x block)").
You've been more than helpful already, and if you don't feel like holding my hand beyond this point, I understand.
Just add another if statement checking if the mined block is the block you want. Also, vanilla items are not in ItemInit, they are in Items. Blocks are in Blocks, which I reflected in the changed code to give you context. As far as the registry stuff, I found it overcomplicated so I put these two lines in my preInit method in the main class:
CustomEvent eventCustom = new CustomEvent();
MinecraftForge.EVENT_BUS.register(eventCustom);
The reason it doesn't use @SubscribeEvent is because the event is being registered under something else which has @SubscribeEvent.
I wish I could like all of your responses a hundred times, and I owe you so much.
I could just be overconfident, but I think I fully understand what to do from the code and the explanations you've given me. I'm going to get to work on it right now, I'm hoping I won't have any more questions, just positive feedback. I could've probably waited 'till after doing the work to respond so I could give the feedback now, but I just wanted to express my appreciation immediately.
I might as well run this by you now while I'm here as well. When it comes to using this method for mod items from other mods, I found a forum thread where it was recommended to deobfuscate the mod in question and loading it into Eclipse as a library. Is that sound advice? You can just give a yes or no lol, I've asked enough already. I think building the method itself was the hard part for me, and you've helped me immeasurably with that.
I'll post another reply after dinner and coding to let you know how it went and wrap up.
Edit: I meant to add, the main point of this is to thank you again and also not leave the thread hanging.
Don't worry about a late reply with me - as you can see, I'm not one to complain
I've had other things come up that've taken my attention away from this a little, but I still intend on finishing it, and owe you a huge debt of gratitude for your help, because I think you basically carried me most of the way
I'll add this, since I'm here anyways, if you feel like taking a look at any point. It seems like an issue that should be simple to address compared to actually writing the methods you wrote for me. The code all looks fine in Eclipse, no errors, and loads fine into the forge test Minecraft environment, but the actual behaviour doesn't seem to occur. I just set up everything like the basic setup in most tutorials, that Main class PreInit part, and your code with my changes (just set up to cancel a stone pickaxe mining an iron ore block).
I don't have a github setup, but here's a dropbox of my source folder:
I'm gonna try and just figure it out myself, and if not I'll create a new forum post, but I figured I'd put it here anyways. I wonder if it's something to do with the ClientProxy, since it's being invoked I guess in the Main class with "@SidedProxy", but was intended I think for adding an item in the tutorial, and in it's class file there's only a "ModelLoader" function, presumably to do with adding the tutorial item.
LAST UPDATE: After having gotten busy with other things since last posting and forgetting about this whole effort, and now coming back to my modpack, I've since found an existing solution to everything I was trying to do with making this plugin.
I figured this would be the best place to post this question, though I'm not sure if this counts as mod development,
What I'd like to accomplish, through whatever means would make the most sense, is this:
Modify the properties of both vanilla and existing mod blocks (like ores from CoFH's Thermal Foundation, and Thaumcraft's crystals) to only be mineable by vanilla or mod tools of a certain material or list of materials (like vanilla obsidian and diamond, just extended to more tool materials and blocks).
I don't really know what the best approach to making that change would be, or if it's even possible, as I've never even dabbled in modifying the game on this level myself. The most I've done is configure and bugfix a large modpack I'm making for personal use. In case it makes a difference, I'm wanting to do this for a 1.12.2 install of Minecraft.
Any suggestions would be very much appreciated.
Edit: And please, if there's a more appropriate place for me to post this question, let me know.
You have to make an addon which will override onMine events to certain blocks. Make an if statement that checks if the player is using the correct tool, and let it proceed if so. If not, cancel the onMine event.
An SF Towny server! Join our Discord: Click here
I very much appreciate your answer. This little project is really my first foray into modding (I was just making a modpack to begin with lol), so I'm still very much learning, but I've found some very good resources to learn from, and now with your answer, I know exactly what I'm aiming for.
I'd like to keep this thread open for now, because I will surely have follow-up questions in the near future.
Edited: Removed a dumb question.
Would it be asking too much to ask if you would possibly be able to give me an example of what that IF function would look like? Even just for a single tool and a single block type, like cancelling an onMine event of a vanilla stone block using a vanilla wooden pickaxe. I can extrapolate from there how to use it for my whole progression.
I'm trying my best to learn the fundamentals of this stuff, and I'll keep doing that, but I think just a basic example of the code I'm looking for would help me along greatly. If I'm being naive about what I'm asking, and it's not that simple, just let me know.
Thanks again, anyways.
So let's look at some code:
(THIS CODE WILL NOT COMPILE, IT IS JUST AN EXAMPLE TO SEE THE GENERAL STRUCTURE)
@SubscribeEvent
public void onMineEvent(MineEvent event){
if(HELD PICKAXE != PROPER PICKAXE){
// CANCELS THE MINING PROCESS
event.setCanceled(true);
return;
}
}
So I didn't watch it, but this seems helpful and relevant:
An SF Towny server! Join our Discord: Click here
Alright, please try and figure it out yourself and watch the video, but I wrote and attached code. I annotated the heck out of it so if you use it, and it works and you can copy-paste, then read the comments so you know how it works.
https://github.com/GargatheOro/GargatheOro/blob/master/TESTEVENT.java
An SF Towny server! Join our Discord: Click here
Alright, so first off, thank you very very much <3.
Now, after some figuring out and watching that video (plus a few more from his series), I think I have a couple of specific questions:
1) When I replace the "ItemInit.SILVER_INGOT" with "ItemInit.STONE_PICKAXE", and create the ItemInit class with the constructor:
"public static final Item STONE_PICKAXE = new ItemPickaxe(ToolMaterial.STONE);"
It gives me an error of "The constructor ItemPickaxe(ToolMaterial.STONE) is not visible." Is this something to do with Minecraft's handling of it's own classes, or just a mistake I've made?
2) In that tutorial video, he sets up his custom event class like this (with my event in place of his examples):
CustomEvent class:
which I notice doesn't include the @SubscribeEvent annotation. I'm just wondering if these event registry methods he set up replace the need for that annotation in the CustomEvent class itself (forgive any misused jargon):
EventHandler class:
RegistryHandler class:
(Ignore the "IHasModel" part, it was just part of his tutorial, and I'm not trying to add any items)
I do have one other question as well, which is to ask if the original method you provided would be checking the block type as well, since I want to set a custom event for each of a specific list of ores and other blocks (as in "IF HELD_PICKAXE != PROPER_PICKAXE (when mining x block)").
You've been more than helpful already, and if you don't feel like holding my hand beyond this point, I understand.
I got it to work doing this: https://github.com/GargatheOro/GargatheOro/blob/master/TESTEVENT.java
Just add another if statement checking if the mined block is the block you want. Also, vanilla items are not in ItemInit, they are in Items. Blocks are in Blocks, which I reflected in the changed code to give you context. As far as the registry stuff, I found it overcomplicated so I put these two lines in my preInit method in the main class:
CustomEvent eventCustom = new CustomEvent();
MinecraftForge.EVENT_BUS.register(eventCustom);
The reason it doesn't use @SubscribeEvent is because the event is being registered under something else which has @SubscribeEvent.
An SF Towny server! Join our Discord: Click here
I wish I could like all of your responses a hundred times, and I owe you so much.
I could just be overconfident, but I think I fully understand what to do from the code and the explanations you've given me. I'm going to get to work on it right now, I'm hoping I won't have any more questions, just positive feedback. I could've probably waited 'till after doing the work to respond so I could give the feedback now, but I just wanted to express my appreciation immediately.
I might as well run this by you now while I'm here as well. When it comes to using this method for mod items from other mods, I found a forum thread where it was recommended to deobfuscate the mod in question and loading it into Eclipse as a library. Is that sound advice? You can just give a yes or no lol, I've asked enough already. I think building the method itself was the hard part for me, and you've helped me immeasurably with that.
I'll post another reply after dinner and coding to let you know how it went and wrap up.
Sorry for the late reply, but yes that is sound advice. Then you will be able to directly import and call it through your IDE.
An SF Towny server! Join our Discord: Click here
Edit: I meant to add, the main point of this is to thank you again and also not leave the thread hanging.
Don't worry about a late reply with me - as you can see, I'm not one to complain
I've had other things come up that've taken my attention away from this a little, but I still intend on finishing it, and owe you a huge debt of gratitude for your help, because I think you basically carried me most of the way
I'll add this, since I'm here anyways, if you feel like taking a look at any point. It seems like an issue that should be simple to address compared to actually writing the methods you wrote for me. The code all looks fine in Eclipse, no errors, and loads fine into the forge test Minecraft environment, but the actual behaviour doesn't seem to occur. I just set up everything like the basic setup in most tutorials, that Main class PreInit part, and your code with my changes (just set up to cancel a stone pickaxe mining an iron ore block).
I don't have a github setup, but here's a dropbox of my source folder:
https://www.dropbox.com/sh/cf27iilvnsw608r/AACKHBRZ_qvf7bbcPOxYueR2a?dl=0
(Edit) Or, better yet, a link to a github:
https://github.com/VulpixUsedEmber/ECMining/tree/master/ECMining
I'm gonna try and just figure it out myself, and if not I'll create a new forum post, but I figured I'd put it here anyways. I wonder if it's something to do with the ClientProxy, since it's being invoked I guess in the Main class with "@SidedProxy", but was intended I think for adding an item in the tutorial, and in it's class file there's only a "ModelLoader" function, presumably to do with adding the tutorial item.
LAST UPDATE: After having gotten busy with other things since last posting and forgetting about this whole effort, and now coming back to my modpack, I've since found an existing solution to everything I was trying to do with making this plugin.
If anyone coming back to this now happened to be curious, the mod "FxControl" (https://www.curseforge.com/minecraft/mc-mods/fx-control) includes a setting specifically to cancel breakEvents per tool.
Thank you to arisalanna (don't know how to tag) for all of your help regardless, problem solved!