Jump to content

[SOLVED] Help with soft dependencies in 1.18 referencing other mod classes


Rawket Sushi

Recommended Posts

So I'm attempting to make a mod that's pretty much just an aesthetics mod. I'm trying to make a variety of items place-able. When it comes to vanilla I have that figured out. The problem is when it comes to doing the same for some other mods. Of course you need minecraft to run a minecraft mod so I don't have to worry about what happens if minecraft isn't present. But the same cannot be said for other mods, and in my situation, I want to make an item class that has the potential to function like a normal BlockItem when crouching, and place a new custom block, but can still act like it's original item when not crouching.

Right now I have set up a custom class, effectively a BlockItem, that extends a custom item class from the mod I want to reference. It all works fine if the mod is installed, but I don't know how to make it independent so that it works, and adds all the stuff specific to that mod, if the other mod is present but it doesn't need the other mod to be present to run and just have the vanilla based stuff.

I know I can't keep that custom BlockItem class as it is, but I don't know how to add the place-able functionality to it and also have it keep it's normal functionality without extending it's class.

Edited by Rawket Sushi
Link to comment
Share on other sites

Er well now I'm just having trouble figuring out how to register it.
I keep running into the same issues. I think I must have made the "create" method incorrectly. And I'm not sure I'm registering the item correctly for this either. Basically I keep running into the create method not being allowed to be referenced from a static context, which I don't really understand cuz the method in which I call it is not static, nor is the create method itself. Unless the "itemImpl" or "coinItem" in my case can't be static, but if that isn't static then I can't use it to register the way it's set up because in order to register the IDE tells me to make it static.

When I say I think I might have made the create method wrong, I mean the as it stands, it's really just

public Item create() {
	return this;
}

cuz I didn't know what else to have it do. I have so far not seen that it causes any issues(other than the back and forth between one side of the issue wanting it to be static and the other not static) because ultimately it does come back to an item, albeit through several "extends" but it has had no issue taking it as a return. Unless this will also cause the same crash you were talking about which I can also see being a possibility but I haven't been able to get that far to find out for myself yet. I can't make the method static because when I do it gives me an error that "this" cannot be referenced from a static context. but then often I also end up seeing "create" cannot be referenced from a static context which again not sure what it means when the method containing the "create" call isn't static, nor is the "create" method itself.

With the "if" statement, I have it setting the item to be either the mod item or just a normal item because if the other mod isn't loaded I don't need this item to do anything because it will be inaccessible. 

if (ModList.get().isLoaded("thermal")) {
	coinItem = PlonkCoinItem.create();
} else {
	coinItem = new Item(new Item.Properties());
}

"coinItem" in this case is initialized in the class and then set here.

and then finally there's the registry object

public static final RegistryObject<Item> LEAD_COIN = THERMAL_ITEMS.register("lead_coin",
            () -> new coinItem(PlonkBlocks.LEAD_COIN.get(), new Item.Properties()));

I can't put any of the properties in the if statement because I need to make several of these, but also the "new Item" has to have that part about Item.Properties or else I get an error and so I'm not even sure at this point if I'm registering it correctly either.

Link to comment
Share on other sites

4 hours ago, Rawket Sushi said:

Unless the "itemImpl" or "coinItem" in my case can't be static, but if that isn't static then I can't use it to register the way it's set up because in order to register the IDE tells me to make it static.

your IDE has the solution for your, you also need to return a new instance inside the create method

4 hours ago, Rawket Sushi said:

With the "if" statement, I have it setting the item to be either the mod item or just a normal item because if the other mod isn't loaded I don't need this item to do anything because it will be inaccessible.

where did you use the if statement, since it should be inside the Supplier of the RegistryObject

4 hours ago, Rawket Sushi said:

I can't put any of the properties in the if statement because I need to make several of these, but also the "new Item" has to have that part about Item.Properties or else I get an error and so I'm not even sure at this point if I'm registering it correctly either.

i'm not 100% sure what's the problem, but every Item needs a Item.Properties, so why did you not create a new instance each time?

Link to comment
Share on other sites

Oh wait the if statement goes inside the registry object? So every registry object should have the if statement? If yes then that should solve everything I haven't been trying to give specific properties and stuff cuz I had the if statement not in the registry object and I was trying to make it useful to each but if I have to do it for each individually then I guess that aught to solve the whole issue.

Also I wasn't creating a new instance of the custom item because the custom item extends a class from thermal foundation and does even stated that doing "new custom item" would crash cuz it's still going reference that unloaded class hence the .create however I think from what you're saying, I should return "new coinitem" and like just pass in the specific properties?

 

 

 

 

Edited by Rawket Sushi
Link to comment
Share on other sites

2 hours ago, Rawket Sushi said:

Oh wait the if statement goes inside the registry object? So every registry object should have the if statement?

yes

3 hours ago, Rawket Sushi said:

Also I wasn't creating a new instance of the custom item because the custom item extends a class from thermal foundation and does even stated that doing "new custom item" would crash cuz it's still going reference that unloaded class hence the .create however I think from what you're saying, I should return "new coinitem" and like just pass in the specific properties?

as D7 already told you the create method schuld return a new instance of the Item from the Dependency, but the return type of the method should be a vanilla super class (in your case Item),

inside the create method you can do every thing you want, and yeah you can (need) to pass in the specific properties

Link to comment
Share on other sites

I know he said it needs to return an item, I didn't see that it needed to return a new vanilla class. I just saw that it needed to return an item. But that does make sense, I kinda thought that was a possibility, is why I mentioned that that at one point. Like I didn't just miss that possibility, I knew I might have to try it that way but I was just gonna cross that bridge when I got to it cuz that hadn't caused me issues yet so I wanted to just deal with what was giving me issues.

But just to make sure, if I have it return a vanilla blockitem is it still going to have the other functionality that the original mod item has?

 

Edited by Rawket Sushi
Link to comment
Share on other sites

14 minutes ago, Rawket Sushi said:

But just to make sure, if I have it return a vanilla blockitem is it still going to have the other functionality that the original mod item has?

what did you mean by functionality? place a Block on right click?

Link to comment
Share on other sites

Well this item for example is a coin. In thermal foundation, when you right click it, it puts heads or tails in chat. That's pretty minor of a function but I want to know how to retain that while also making it so you can place it as a block that I'm creating to add to it, that way I know how to do it moving forward for more complex items as well. Right now my custom item containing three create method extends that coin item from thermal, but if the create method returns just a vanilla item idk if it'll retain the functionally it has with the thermal mod.

I mean I'll prolly try it anyway just to see what happens but that's what I'm trying to do

Edited by Rawket Sushi
Link to comment
Share on other sites

if the Thermal Mod is installed, the retunred Item by the create method is your PlonkCoinItem, then you be able to cast it back
so yeah the Item keeps it functionality and btw this is basic OOP programming
if the Thermal Mod is not installed, it's your fallback Item so it does not have the functionality of Thermal Mod Item your are extending

Link to comment
Share on other sites

2 hours ago, Luis_ST said:

the retunred Item by the create method is your PlonkCoinItem

Alright so that's what I was thinking then, sorry I just misread something, ADHD makes reading retention hard. When you said the return type needs to be vanilla I thought you said that the thing that is returned needs to be vanilla. 
 

2 hours ago, Luis_ST said:

and btw this is basic OOP programming

And I'm a beginner. I'm just trying to learn. We all gotta suck at something before we can be good at it. I did put effort in to learning the basics, now I'm just trying to get the experience so that I like actually know it know it, like so I can retain it long term so that I don't have to keep asking on forums and stuff, I only do so as a last resort cuz I don't wanna like rely on it. And I'm asking all these follow ups in an attempt to better understand this stuff. 

Link to comment
Share on other sites

Ok so I can't compile without the mods loaded because the PlonkCoinItem extends an item from that mod. It just tells me package does not exist.

create method within the custom Item class looks like this

public static Item create(Block pBlock, Item.Properties pProperties) {
        return new PlonkCoinItem(pBlock, pProperties);
    }

if statement looks like this

public static Item getCoinItem(Block pBlock, Item.Properties pProperties) {
        Item coinItem;
        if (ModList.get().isLoaded("thermal")) {
			coinItem = PlonkCoinItem.create(pBlock, pProperties);
        } else {
            coinItem = new Item(new Item.Properties());
        }
        return coinItem;
    }

registryobject looks like this

public static final RegistryObject<Item> LEAD_COIN = THERMAL_ITEMS.register("lead_coin",
            () -> InitModItems.getCoinItem(PlonkBlocks.LEAD_COIN.get(), new Item.Properties()));

I made "InitModItems" to hold the if statement just to test if that would help, I didn't expect it to but I still wanted to just give it a shot . But clearly I've done something wrong and idk what because I have no errors other than the mod package not existing.

Link to comment
Share on other sites

I did and it works fine when they're there. But I was trying to run it without that to see if it still worked cuz the whole point here is to make it so that the other mod doesn't need to be loaded for mine to still work, just in that case without the stuff relating to that other mod. Is there another way to test or do I just have to like fully compile/export the project to test that.

Link to comment
Share on other sites

I think I figured it out. Am I supposed to like fully remove it? Cuz I instead changed it to compileOnly and it works as intended. But does that properly simulate that mod just not being present? Like if I were to export this as is and load it into a proper game it would work the same?

Link to comment
Share on other sites

  • Rawket Sushi changed the title to [SOLVED] Help with soft dependencies in 1.18 referencing other mod classes

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

    • java.lang.RuntimeException:null at net.minecraftforge.registries.GameData.postRegisterEvents(GameData.java:315) ~[forge-1.20.1-47.3.10-universal.jar%23329!/:?] {re:mixin,re:classloading,pl:mixin:APP:supermartijn642corelib.mixins.json:GameDataMixin,pl:mixin:A}at net.minecraftforge.common.ForgeStatesProvider.lambda$new$4(ForgeStatesProvider.java:25) ~[forge-1.20.1-47.3.10-universal.jar%23329!/:?] {re:classloading}at net.minecraftforge.fml.ModLoader.handleInlineTransition(ModLoader.java:217) ~[fmlcore-1.20.1-47.3.10.jar%23325!/:?] {}at net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$19(ModLoader.java:209) ~[fmlcore-1.20.1-47.3.10.jar%23325!/:?] {}at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] {re:mixin}at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:209) ~[fmlcore-1.20.1-47.3.10.jar%23325!/:?] {}at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$13(ModLoader.java:183) ~[fmlcore-1.20.1-47.3.10.jar%23325!/:?] {}at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {re:mixin}at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:183) ~[fmlcore-1.20.1-47.3.10.jar%23325!/:?] {}at net.minecraftforge.client.loading.ClientModLoader.lambda$begin$1(ClientModLoader.java:69) ~[forge-1.20.1-47.3.10-universal.jar%23329!/:?] {re:classloading,pl:runtimedistcleaner:A}at net.minecraftforge.client.loading.ClientModLoader.lambda$createRunnableWithCatch$4(ClientModLoader.java:89) ~[forge-1.20.1-47.3.10-universal.jar%23329!/:?] {re:classloading,pl:runtimedistcleaner:A}at net.minecraftforge.client.loading.ClientModLoader.begin(ClientModLoader.java:69) ~[forge-1.20.1-47.3.10-universal.jar%23329!/:?] {re:classloading,pl:runtimedistcleaner:A}at net.minecraft.client.Minecraft.                Size    Insert image from URL
    • My Bitcoin Recovery Experience With  The Hack Angels.     I highly recommend the service of The Hack Angels to everyone who wishes to recover lost money either bitcoin or other cryptocurrencies from these online scammers, wallet hackers, or if you ever sent bitcoins to the wrong wallet address. I was able to recover my lost bitcoins from online swindlers in less than two days after contacting them. They are the best professional hackers out there and I’m truly thankful for their help in recovering all I lost. If you need their service too, here is their contact information.   Mail Box; support@thehackangels. com    (Web: https://thehackangels.com) Whats Ap; +1 520) - 200, 23  20
    • Temu Coupon Code $50 off [taa85211] or [tad85211] for New and Existing Users To get Temu $50 off Coupon Code [taa85211] or [tad85211] as a new user enter the Coupon during checkout when making your first purchase at Temu You will receive the benefit once the Coupon applied. TEMU App is a shopping platform that provides us with the best-branded items at Cheap prices. You will also notice that TEMU offers users to save extra by applying the TEMU Coupon Code during checkout. You can get $50 off Temu by using the Coupon Code “taa85211} or {tad85211} ”. Existing customers can use this code. Temu existing user Coupon Code: [taa85211} or {tad85211} Using Temu’s Coupon Code [taa85211} or {tad85211] will get you $50 off, access to exclusive deals, and benefits for additional savings. Save $50 off with Temu Coupon Codes. New and existing customer offers. What is Temu $50 Coupon Bundle? New Temu $50 Coupon bundle includes $50 worth of Temu Coupon Codes. The Temu $50 Coupon Code [taa85211} or {tad85211] can be used by new and existing Temu users to get a Coupon on their purchases. Temu $50 Coupon Bundle Code [taa85211} or {tad85211] Temu Coupon $50 off for existing customers There are a number of Coupons and deals shoppers can take advantage of with the Teemu Coupon Bundle [taa85211} or {tad85211]. Temu Coupon $50 off for existing customers"taa85211} or {tad85211" will save you $100 on your order. To get a Coupon, click on the item to purchase and enter the code. You can think of it as a supercharged savings pack for all your shopping needs Temu Coupon Code $50 off free shipping You will save $50 when you use Temu’s $50 OFF Coupon Code [taa85211} or {tad85211]. Enter the Coupon Code when purchasing an item How Does Temu $50 Coupon Work Temu’s $50 Coupon Code isn’t just one big Coupon you use all at once. Instead, think of it as a welcome package filled with different Coupons and offers worth $50. New customers are welcome. Temu Coupon Code $50 off Temu $40 OFF Coupon Code “taa85211} or {tad85211” will save you $50 on your order. To get a Coupon, click on the item to purchase and enter the code. Yes, Temu offers $50 off Coupon Code “taa85211} or {tad85211” for first time users. You can get a $50 bonus plus 30% off any purchase at Temu with the $40 Coupon Bundle at Temu if you sign up with the Coupon Code [taa85211} or {tad85211] and make a first purchase of $50 or more. How Do Apply Temu Coupon Code [taa85211} or {tad85211]? 1.Download the TEMU app and create a new account. 2.Fill in basic details to complete account verification. 3. Select the item you want to purchase and add it to your cart Minimum of $100. 4.Click on the Coupon Code option and enter the TEMU Coupon Code. 5.Once the Coupon has been applied, you will see the final Coupon. 6.P rice Select your payment method and complete your purchase. Temu Coupon Code $50 off first time user yes, If you’re a first-time user, Temu offers $50 off with Coupon Code “taa85211} or {tad85211” Temu offers first-time users a $50 Coupon. Here are some Temu Coupons! The fact that new users can benefit from such generous Coupons is great. How do you redeem Temu $50 Coupon Code? Yes, To redeem the Temu $50 Coupon Code, follow these steps: 1.Sign Up: If you haven’t already, sign up for a Temu account on their website or app. 2.Add Items to Cart: Browse through the products you’d like to purchase. Add items worth $50 or more to your cart. 3.Apply Coupon Code: During checkout, enter the Coupon Code “taa85211} or {tad85211” in the designated field. This will unlock the $50 Coupon bundle. You can also use the Coupon Code “taa85211} or {tad85211” when signing up to receive the same benefit. 4.Enjoy Savings: The Coupon will be applied, and you’ll enjoy additional savings on your purchase. Plus, you can combine this with other available Coupons, such as the 50% off code for fashion, home, and beauty categories.
    • Temu Coupon Code $50 off [taa85211] or [tad85211] for New and Existing Users To get Temu $50 off Coupon Code [taa85211] or [tad85211] as a new user enter the Coupon during checkout when making your first purchase at Temu You will receive the benefit once the Coupon applied. TEMU App is a shopping platform that provides us with the best-branded items at Cheap prices. You will also notice that TEMU offers users to save extra by applying the TEMU Coupon Code during checkout. You can get $50 off Temu by using the Coupon Code “taa85211} or {tad85211} ”. Existing customers can use this code. Temu existing user Coupon Code: [taa85211} or {tad85211} Using Temu’s Coupon Code [taa85211} or {tad85211] will get you $50 off, access to exclusive deals, and benefits for additional savings. Save $50 off with Temu Coupon Codes. New and existing customer offers. What is Temu $50 Coupon Bundle? New Temu $50 Coupon bundle includes $50 worth of Temu Coupon Codes. The Temu $50 Coupon Code [taa85211} or {tad85211] can be used by new and existing Temu users to get a Coupon on their purchases. Temu $50 Coupon Bundle Code [taa85211} or {tad85211] Temu Coupon $50 off for existing customers There are a number of Coupons and deals shoppers can take advantage of with the Teemu Coupon Bundle [taa85211} or {tad85211]. Temu Coupon $50 off for existing customers"taa85211} or {tad85211" will save you $100 on your order. To get a Coupon, click on the item to purchase and enter the code. You can think of it as a supercharged savings pack for all your shopping needs Temu Coupon Code $50 off free shipping You will save $50 when you use Temu’s $50 OFF Coupon Code [taa85211} or {tad85211]. Enter the Coupon Code when purchasing an item How Does Temu $50 Coupon Work Temu’s $50 Coupon Code isn’t just one big Coupon you use all at once. Instead, think of it as a welcome package filled with different Coupons and offers worth $50. New customers are welcome. Temu Coupon Code $50 off Temu $40 OFF Coupon Code “taa85211} or {tad85211” will save you $50 on your order. To get a Coupon, click on the item to purchase and enter the code. Yes, Temu offers $50 off Coupon Code “taa85211} or {tad85211” for first time users. You can get a $50 bonus plus 30% off any purchase at Temu with the $40 Coupon Bundle at Temu if you sign up with the Coupon Code [taa85211} or {tad85211] and make a first purchase of $50 or more. How Do Apply Temu Coupon Code [taa85211} or {tad85211]? 1.Download the TEMU app and create a new account. 2.Fill in basic details to complete account verification. 3. Select the item you want to purchase and add it to your cart Minimum of $100. 4.Click on the Coupon Code option and enter the TEMU Coupon Code. 5.Once the Coupon has been applied, you will see the final Coupon. 6.P rice Select your payment method and complete your purchase. Temu Coupon Code $50 off first time user yes, If you’re a first-time user, Temu offers $50 off with Coupon Code “taa85211} or {tad85211” Temu offers first-time users a $50 Coupon. Here are some Temu Coupons! The fact that new users can benefit from such generous Coupons is great. How do you redeem Temu $50 Coupon Code? Yes, To redeem the Temu $50 Coupon Code, follow these steps: 1.Sign Up: If you haven’t already, sign up for a Temu account on their website or app. 2.Add Items to Cart: Browse through the products you’d like to purchase. Add items worth $50 or more to your cart. 3.Apply Coupon Code: During checkout, enter the Coupon Code “taa85211} or {tad85211” in the designated field. This will unlock the $50 Coupon bundle. You can also use the Coupon Code “taa85211} or {tad85211” when signing up to receive the same benefit. 4.Enjoy Savings: The Coupon will be applied, and you’ll enjoy additional savings on your purchase. Plus, you can combine this with other available Coupons, such as the 50% off code for fashion, home, and beauty categories.
    • Temu Coupon Code $50 off [taa85211] or [tad85211] for New and Existing Users To get Temu $50 off Coupon Code [taa85211] or [tad85211] as a new user enter the Coupon during checkout when making your first purchase at Temu You will receive the benefit once the Coupon applied. TEMU App is a shopping platform that provides us with the best-branded items at Cheap prices. You will also notice that TEMU offers users to save extra by applying the TEMU Coupon Code during checkout. You can get $50 off Temu by using the Coupon Code “taa85211} or {tad85211} ”. Existing customers can use this code. Temu existing user Coupon Code: [taa85211} or {tad85211} Using Temu’s Coupon Code [taa85211} or {tad85211] will get you $50 off, access to exclusive deals, and benefits for additional savings. Save $50 off with Temu Coupon Codes. New and existing customer offers. What is Temu $50 Coupon Bundle? New Temu $50 Coupon bundle includes $50 worth of Temu Coupon Codes. The Temu $50 Coupon Code [taa85211} or {tad85211] can be used by new and existing Temu users to get a Coupon on their purchases. Temu $50 Coupon Bundle Code [taa85211} or {tad85211] Temu Coupon $50 off for existing customers There are a number of Coupons and deals shoppers can take advantage of with the Teemu Coupon Bundle [taa85211} or {tad85211]. Temu Coupon $50 off for existing customers"taa85211} or {tad85211" will save you $100 on your order. To get a Coupon, click on the item to purchase and enter the code. You can think of it as a supercharged savings pack for all your shopping needs Temu Coupon Code $50 off free shipping You will save $50 when you use Temu’s $50 OFF Coupon Code [taa85211} or {tad85211]. Enter the Coupon Code when purchasing an item How Does Temu $50 Coupon Work Temu’s $50 Coupon Code isn’t just one big Coupon you use all at once. Instead, think of it as a welcome package filled with different Coupons and offers worth $50. New customers are welcome. Temu Coupon Code $50 off Temu $40 OFF Coupon Code “taa85211} or {tad85211” will save you $50 on your order. To get a Coupon, click on the item to purchase and enter the code. Yes, Temu offers $50 off Coupon Code “taa85211} or {tad85211” for first time users. You can get a $50 bonus plus 30% off any purchase at Temu with the $40 Coupon Bundle at Temu if you sign up with the Coupon Code [taa85211} or {tad85211] and make a first purchase of $50 or more. How Do Apply Temu Coupon Code [taa85211} or {tad85211]? 1.Download the TEMU app and create a new account. 2.Fill in basic details to complete account verification. 3. Select the item you want to purchase and add it to your cart Minimum of $100. 4.Click on the Coupon Code option and enter the TEMU Coupon Code. 5.Once the Coupon has been applied, you will see the final Coupon. 6.P rice Select your payment method and complete your purchase. Temu Coupon Code $50 off first time user yes, If you’re a first-time user, Temu offers $50 off with Coupon Code “taa85211} or {tad85211” Temu offers first-time users a $50 Coupon. Here are some Temu Coupons! The fact that new users can benefit from such generous Coupons is great. How do you redeem Temu $50 Coupon Code? Yes, To redeem the Temu $50 Coupon Code, follow these steps: 1.Sign Up: If you haven’t already, sign up for a Temu account on their website or app. 2.Add Items to Cart: Browse through the products you’d like to purchase. Add items worth $50 or more to your cart. 3.Apply Coupon Code: During checkout, enter the Coupon Code “taa85211} or {tad85211” in the designated field. This will unlock the $50 Coupon bundle. You can also use the Coupon Code “taa85211} or {tad85211” when signing up to receive the same benefit. 4.Enjoy Savings: The Coupon will be applied, and you’ll enjoy additional savings on your purchase. Plus, you can combine this with other available Coupons, such as the 50% off code for fashion, home, and beauty categories.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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