Jump to content

1.18.1 - Double checking on 'block overrides'


DePhoegon

Recommended Posts

I'm just wanting to make sure that I have The 'Override' done correctly, and I've not missed anything that will cause unforeseen problems. 
- Why -> I have wood-based blocks that burn & get replaced with 'ash' versions.  I want to make sure that [logs, wood, planks, slabs, & stairs] of default Minecraft gets included in that.
- If possible, I would rather not override if I could somehow include these blocks into my use of the 'isFlamable' call that I have as an option for my blocks in the lowest levels of my block types (rotatedpillar, stair, slab, block, wall).

I am not changing anything about them value wise.  The "","",""  are tooltips (left blank as to not add to them), and the true is the boolean flag meant to allow the call of a RNG fallcall. (that will destroy, & place the ash correct ash block in the exact same way it was [slabtype/stairtype/etc....])

package com.dephoegon.delbase.block.blockOverride;

import com.dephoegon.delbase.aid.block.stock.axisBlock;
import com.dephoegon.delbase.aid.block.stock.genBlock;
import com.dephoegon.delbase.aid.block.stock.slabBlock;
import com.dephoegon.delbase.aid.block.stock.stairBlock;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import java.util.function.Supplier;

import static net.minecraft.world.level.block.Blocks.*;

public class overrideHook {
    private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "minecraft");
    private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "minecraft");

    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_SPRUCE_LOG = register("spruce_log",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(SPRUCE_LOG).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_SPRUCE_WOOD = register("spruce_wood",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(SPRUCE_WOOD).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_OAK_LOG = register("oak_log",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(OAK_LOG).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_OAK_WOOD = register("oak_wood",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(OAK_WOOD).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_DARK_OAK_LOG = register("dark_oak_log",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(DARK_OAK_LOG).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_DARK_OAK_WOOD = register("dark_oak_wood",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(DARK_OAK_WOOD).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_ACACIA_LOG = register("acacia_log",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(ACACIA_LOG).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_ACACIA_WOOD = register("acacia_wood",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(ACACIA_WOOD).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_JUNGLE_LOG = register("jungle_log",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(JUNGLE_LOG).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_JUNGLE_WOOD = register("jungle_wood",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(JUNGLE_WOOD).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_BIRCH_LOG = register("birch_log",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(BIRCH_LOG).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_BIRCH_WOOD = register("birch_wood",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(BIRCH_WOOD).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_STRIPPED_SPRUCE_LOG = register("stripped_spruce_log",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(STRIPPED_SPRUCE_LOG).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_STRIPPED_SPRUCE_WOOD = register("stripped_spruce_wood",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(STRIPPED_SPRUCE_WOOD).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_STRIPPED_OAK_LOG = register("stripped_oak_log",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(STRIPPED_OAK_LOG).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_STRIPPED_OAK_WOOD = register("stripped_oak_wood",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(STRIPPED_OAK_WOOD).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_STRIPPED_DARK_OAK_LOG = register("stripped_dark_oak_log",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(STRIPPED_DARK_OAK_LOG).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_STRIPPED_DARK_OAK_WOOD = register("stripped_dark_oak_wood",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(STRIPPED_DARK_OAK_WOOD).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_STRIPPED_ACACIA_LOG = register("stripped_acacia_log",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(STRIPPED_ACACIA_LOG).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_STRIPPED_ACACIA_WOOD = register("stripped_acacia_wood",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(STRIPPED_ACACIA_WOOD).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_STRIPPED_JUNGLE_LOG = register("stripped_jungle_log",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(STRIPPED_JUNGLE_LOG).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_STRIPPED_JUNGLE_WOOD = register("stripped_jungle_wood",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(STRIPPED_JUNGLE_WOOD).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_STRIPPED_BIRCH_LOG = register("stripped_birch_log",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(STRIPPED_BIRCH_LOG).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<RotatedPillarBlock> OVERRIDE_STRIPPED_BIRCH_WOOD = register("stripped_birch_wood",
            ()-> new axisBlock(BlockBehaviour.Properties.copy(STRIPPED_BIRCH_WOOD).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<Block> OVERRIDE_SPRUCE_PLANKS = register("spruce_planks",
            ()-> new genBlock(BlockBehaviour.Properties.copy(SPRUCE_PLANKS).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<Block> OVERRIDE_OAK_PLANKS = register("oak_planks",
            ()-> new genBlock(BlockBehaviour.Properties.copy(OAK_PLANKS).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<Block> OVERRIDE_DARK_OAK_PLANKS = register("dark_oak_planks",
            ()-> new genBlock(BlockBehaviour.Properties.copy(DARK_OAK_PLANKS).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<Block> OVERRIDE_ACACIA_PLANKS = register("acacia_planks",
            ()-> new genBlock(BlockBehaviour.Properties.copy(ACACIA_PLANKS).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<Block> OVERRIDE_JUNGLE_PLANKS = register("jungle_planks",
            ()-> new genBlock(BlockBehaviour.Properties.copy(JUNGLE_PLANKS).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<Block> OVERRIDE_BIRCH_PLANKS = register("birch_planks",
            ()-> new genBlock(BlockBehaviour.Properties.copy(BIRCH_PLANKS).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<SlabBlock> OVERRIDE_SPRUCE_SLAB = register("spruce_slab",
            ()-> new slabBlock(BlockBehaviour.Properties.copy(SPRUCE_SLAB).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<SlabBlock> OVERRIDE_OAK_SLAB = register("oak_slab",
            ()-> new slabBlock(BlockBehaviour.Properties.copy(OAK_SLAB).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<SlabBlock> OVERRIDE_DARK_OAK_SLAB = register("dark_oak_slab",
            ()-> new slabBlock(BlockBehaviour.Properties.copy(DARK_OAK_SLAB).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<SlabBlock> OVERRIDE_ACACIA_SLAB = register("acacia_slab",
            ()-> new slabBlock(BlockBehaviour.Properties.copy(ACACIA_SLAB).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<SlabBlock> OVERRIDE_JUNGLE_SLAB = register("jungle_slab",
            ()-> new slabBlock(BlockBehaviour.Properties.copy(JUNGLE_SLAB).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<SlabBlock> OVERRIDE_BIRCH_SLAB = register("birch_slab",
            ()-> new slabBlock(BlockBehaviour.Properties.copy(BIRCH_SLAB).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<StairBlock> OVERRIDE_SPRUCE_STAIRS = register("spruce_stairs",
            ()-> new stairBlock(SPRUCE_STAIRS::defaultBlockState, BlockBehaviour.Properties.copy(SPRUCE_STAIRS).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<StairBlock> OVERRIDE_OAK_STAIRS = register("oak_stairs",
            ()-> new stairBlock(OAK_STAIRS::defaultBlockState, BlockBehaviour.Properties.copy(OAK_STAIRS).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<StairBlock> OVERRIDE_DARK_OAK_STAIRS = register("dark_oak_stairs",
            ()-> new stairBlock(DARK_OAK_STAIRS::defaultBlockState, BlockBehaviour.Properties.copy(DARK_OAK_STAIRS).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<StairBlock> OVERRIDE_ACACIA_STAIRS = register("acacia_stairs",
            ()-> new stairBlock(ACACIA_STAIRS::defaultBlockState, BlockBehaviour.Properties.copy(ACACIA_STAIRS).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<StairBlock> OVERRIDE_JUNGLE_STAIRS = register("jungle_stairs",
            ()-> new stairBlock(JUNGLE_STAIRS::defaultBlockState, BlockBehaviour.Properties.copy(JUNGLE_STAIRS).sound(SoundType.WOOD),"","","", true));
    public static final RegistryObject<StairBlock> OVERRIDE_BIRCH_STAIRS = register("birch_stairs",
            ()-> new stairBlock(BIRCH_STAIRS::defaultBlockState, BlockBehaviour.Properties.copy(BIRCH_STAIRS).sound(SoundType.WOOD),"","","", true));

    public static void register() {
        IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
        BLOCKS.register(eventBus);
        ITEMS.register(eventBus);
    }
    private static <T extends Block> RegistryObject<T> register(String name, Supplier<T> block) {
        RegistryObject<T> exit = BLOCKS.register(name, block);
        ITEMS.register(name, () -> new BlockItem(exit.get(),
                new Item.Properties().stacksTo(64).tab(CreativeModeTab.TAB_BUILDING_BLOCKS)));
        return exit;
    }
}

 

Edited by diesieben07
syntax highlight
Link to comment
Share on other sites

17 minutes ago, diesieben07 said:

Please show the block classes you are using to override, then we can help you with a possible alternative to overriding.

I am not 'entirely' sure what you mean, but I'll create a github to share.  The phrasing isn't clicking with me.

overrideHook java file (where the override blocks are registered)

The block registrations used for the overrideHooks is here.

Link to comment
Share on other sites

Just now, diesieben07 said:
  • Destroying blocks in the world when isFlammable is called is terrible. That is not what this method is for. This method must not modify the world, it should only return whether the block is flammable or not.
  • I don't see a good alternative to registry-replacing the blocks here.

I do agree, but a few things

The 'destroy block' before place is intended to prevent client desync (I can't figure the placing doesn't do it properly)

I understand 'IsFlamable' is in fact called only when flame tick 'would hit' the block and is used to trigger flames.
- I could not get a grasp on the 'flaming sides' methods used by default.
- I also, didn't want things like 'walls/fences/slab/bottom_stairs' to catch on fire on the 'top' of them, as it looks janky as all getup.
-- It literally will spawn floating fireblocks (either pixels above the wall/fence, and on stairs), but also in mid-air... 

I would alter the call and put it in another spot, but as it stands I've not a real idea on how to do that, as 'onCaughtFire' is called when something catches fire, which stairs, walls, fences, do not catch fire like that.

My goal is to literally have it 'burnt' and 'replaced', I'm open to suggestions.  Though I will need it on the following.
- RotatedPillarBlock
- Block
- StairBlock
- SlabBlock
- WallBlock
- FenceBlock (not inuse yet, but planned for expanding)

I would be willing to override the correct function, but I did not understand it enough to attempt.  I also would need to solve the whole fire bit of spawning in midair & ontop of other fireblocks) 
-- I see the limiting of generating fireblocks, on walls, bottom slabs, bottom stairs, fences (future), as a positive, and there is little more then I could do to fix the silliness spawned fireblocks in mid air.  (though I have to leave it set to true for rotatedpillarblocks to allow a firespread to hit forests & replace the logs&wood with ash versions in place.

I also, don't view this as a problem, as the replacement blocks will 'not' burn in the open world (no point to it).

I understand this isn't optimal, but in honesty... I fail to see the problem; all it does is spread up & in truth will overall cause fires to die out with only spots of ash variant blocks replaced around the fire source. 

I am open to being shown the flaw in it.  Though I do wish you well & thank you for letting me know that I didn't entirely fubar my setup for the overrides.  I rather not cause more issues than I have to.  (I understand doing that will cause some complications with other mods, if they need to touch the blocks in the same way their selves. [in which case, I should produce a compatible mod for things if I want to add it to other packs, and deal with the inconsistency])

Link to comment
Share on other sites

i strongly recommend against replacing blocks fully when all you want is to add functionality to it.

yes it would work, but only one block can replace oak log. if two mods try that, user will need to pick which one to cut.

here is what i would do - of the top of my head / not a thorough plan:
1) detect that a supported (replaceable with ash) block is burning (actually that it is adjacent to a fire)
1b) check in a list of burning block whether it's already there; it it is, skip 1c
1c) store it in a list as a structure {block state, position, ticks (zero) }
2) every X world ticks (20 maybe) loop through the list...
2a) check what's in the world at current position...
2a1) if it's air or fire, make an ash block; use stored blockstate to ensure proper orientation; delete from list.
2a2) if it's not air/fire, but also not stored block (i'd ignore blockstate), delete from list.
2b) increase tick count. if it's there for more than Y seconds, give up and delete from list (maybe check if there is still fire around?)

far from a finished mod, but should work.

minor note: you shouldn't destroy existing blocks because you don't want drops. just do a setBlock.

Link to comment
Share on other sites

23 minutes ago, diesieben07 said:

The issue is that you are misusing this method and breaking its contract. By doing this, you will cause potentially undefined behavior, specifically when mods are involved.

I fail to see why you cannot use onCaughtFire, which exists specifically for this purpose (it. e.g. makes TNT light when burning).

That method is usable (though the practical side effects will end up causing fireblocks in weird places right next to said blocks. [not bad, but just looks really bad]
-this doesn't address floating fire above bottom slab/stairs, & above wall models. 

Is there a way to allow it to catch fire while preventing ...  what amounts to derpy ass behavior from a blank true on a wallblock. 
--  I can show you what I mean, by the derp behavior.

I was also under the impression that disabling firetick/firespread would also disable the isflamable.  [this is an assumption by myself, untested]

Clarification question, is this method always called even if no fire is spawned, or does fire have to spawn (I'm really trying to avoid ultra derp looks when it comes to fireblocks

17 minutes ago, MFMods said:

i strongly recommend against replacing blocks fully when all you want is to add functionality to it.

yes it would work, but only one block can replace oak log. if two mods try that, user will need to pick which one to cut.

here is what i would do - of the top of my head / not a thorough plan:
1) detect that a supported (replaceable with ash) block is burning (actually that it is adjacent to a fire)
1b) check in a list of burning block whether it's already there; it it is, skip 1c
1c) store it in a list as a structure {block state, position, ticks (zero) }
2) every X world ticks (20 maybe) loop through the list...
2a) check what's in the world at current position...
2a1) if it's air or fire, make an ash block; use stored blockstate to ensure proper orientation; delete from list.
2a2) if it's not air/fire, but also not stored block (i'd ignore blockstate), delete from list.
2b) increase tick count. if it's there for more than Y seconds, give up and delete from list (maybe check if there is still fire around?)

far from a finished mod, but should work.

minor note: you shouldn't destroy existing blocks because you don't want drops. just do a setBlock.

First to the minor note
- I did that first, and it produced a client/server desync (even on a SP world). 

I just want to be clear, I would need to do this for 42+ different blocks types (and some with multiple states) every tick, on that note...  I start to wonder if that's worth the impact hit.
-I've not yet put the fences, as I haven't used them yet for even my own blocks.

I'm willing to look at it, but I might need some help forming it as I can't seem to see it that way as you are describing.  

 

Link to comment
Share on other sites

2 minutes ago, MFMods said:

setBlockAndUpdate

>.> Thank you, I must have been far too exhausted to triple check methods in Level.  I actually prefer this one. 

I will need to take the time to examine what i use, and if there are better methods/calls/whatnot to use.  I've just been feeling overrun with typing and typos & have not taken the time it needs to do it.

Link to comment
Share on other sites

24 minutes ago, diesieben07 said:

I have zero idea what the hell you are talking about.

of course.....  

Ok, explain how to fix this & use 'onCaughtFire' without the exceptional derpness of the fire doing things that shouldn't really happen Fire Being Derpy (OneDrive Link)
-random tick speed is set at 500 {just to accelerate the process & not have to 'wait' to see if something works }
-walls were set to return true as flamable

 

Also, It's unclear.. does the fire spawn before or after 'onCaughtFire' is called? 
-I will totally use it if it is called before, but I've not a clue how to properly spawn the fireblocks from it as normal, if I override it for use.

Link to comment
Share on other sites

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • rp.crazyheal.xyz mods  
    • I'm developing a dimension, but it's kinda resource intensive so some times during player teleporting it lags behind making the player phase down into the void, so im trying to implement some kind of pregeneration to force the game loading a small set of chunks in the are the player will teleport to. Some of the things i've tried like using ServerLevel and ServerChunkCache methods like getChunk() dont actually trigger chunk generation if the chunk isn't already on persistent storage (already generated) or placing tickets, but that doesn't work either. Ideally i should be able to check when the task has ended too. I've peeked around some pregen engines, but they're too complex for my current understanding of the system of which I have just a basic understanding (how ServerLevel ,ServerChunkCache  and ChunkMap work) of. Any tips or other classes I should be looking into to understand how to do this correctly?
    • https://mclo.gs/4UC49Ao
    • Way back in the Forge 1.17 days, work started for adding JPMS (Java Platform Module Support) to ModLauncher and ForgeModLoader. This has been used internally by Forge and some libraries for a while now, but mods (those with mods.toml specifically) have not been able to take advantage of it. As of Forge 1.21.1 and 1.21.3, this is now possible!   What is JPMS and what does it mean for modders? JPMS is the Java Platform Module System, introduced in Java 9. It allows you to define modules, which are collections of packages and resources that can be exported or hidden from other modules. This allows for much more fine-tuned control over visibility, cleaner syntax for service declarations and support for sealed types across packages. For example, you might have a mod with a module called `com.example.mod` that exports `com.example.mod.api` and `com.example.mod.impl` to other mods, but hides `com.example.mod.internal` from them. This would allow you to have a clean API for other mods to use, while keeping your internal implementation details hidden from IDE hints, helping prevent accidental usage of internals that might break without prior notice. This is particularly useful if you'd like to use public records with module-private constructors or partially module-private record components, as you can create a sealed interface that only your record implements, having the interface be exported and the record hidden. It's also nice for declaring and using services, as you'll get compile-time errors from the Java compiler for typos and the like, rather than deferring to runtime errors. In more advanced cases, you can also have public methods that are only accessible to specific other modules -- handy if you want internal interactions between multiple of your own mods.   How do I bypass it? We understand there may be drama in implementing a system that prevents mods from accessing each other's internals when necessary (like when a mod is abandoned or you need to fix a compat issue) -- after all, we are already modding a game that doesn't have explicit support for Java mods yet. We have already thought of this and are offering APIs from day one to selectively bypass module restrictions. Let me be clear: Forge mods are not required to use JPMS. If you don't want to use it, you don't have to. The default behaviour is to have fully open, fully exported automatic modules. In Java, you can use the `Add-Opens` and `Add-Exports` manifest attributes to selectively bypass module restrictions of other mods at launch time, and we've added explicit support for these when loading your Forge mods. At compile-time, you can use existing solutions such as the extra-java-module-info Gradle plugin to deal with non-modular dependencies and add extra opens and exports to other modules. Here's an example on how to make the internal package `com.example.examplemod.internal` open to your mod in your build.gradle: tasks.named('jar', Jar) { manifest { attributes([ 'Add-Opens' : 'com.example.examplemod/com.example.examplemod.internal' 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors // (...) ]) } } With the above in your mod's jar manifest, you can now reflectively access the classes inside that internal package. Multiple entries are separated with a space, as per Java's official spec. You can also use Add-Exports to directly call without reflection, however you'd need to use the Gradle plugin mentioned earlier to be able to compile. The syntax for Add-Exports is the same as Add-Opens, and instructions for the compile-time step with the Gradle plugin are detailed later in this post. Remember to prefer the opens and exports keywords inside module-info.java for sources you control. The Add-Opens/Add-Exports attributes are only intended for forcing open other mods.   What else is new with module support? Previously, the runtime module name was always forced to the first mod ID in your `mods.toml` file and all packages were forced fully open and exported. Module names are now distinguished from mod IDs, meaning the module name in your module-info.java can be different from the mod ID in your `mods.toml`. This allows you to have a more descriptive module name that doesn't have to be the same as your mod ID, however we strongly recommend including your mod ID as part of your module name to aid troubleshooting. The `Automatic-Module-Name` manifest attribute is now also honoured, allowing you to specify a module name for your mod without needing to create a `module-info.java` file. This is particularly useful for mods that don't care about JPMS features but want to have a more descriptive module name and easier integration with other mods that do use JPMS.   How do I use it? The first step is to create a `module-info.java` file in your mod's source directory. This file should be in the same package as your main mod class, and should look something like this: open module com.example.examplemod { requires net.minecraftforge.eventbus; requires net.minecraftforge.fmlcore; requires net.minecraftforge.forge; requires net.minecraftforge.javafmlmod; requires net.minecraftforge.mergetool.api; requires org.slf4j; requires logging; } For now, we're leaving the whole module open to reflection, which is a good starting point. When we know we want to close something off, we can remove the open modifier from the module and open or export individual packages instead. Remember that you need to be open to Forge (module name net.minecraftforge.forge), otherwise it can't call your mod's constructor. Next is fixing modules in Gradle. While Forge and Java support modules properly, Gradle does not put automatic modules on the module path by default, meaning that the logging module (from com.mojang:logging) is not found. To fix this, add the Gradle plugin and add a compile-time module definition for that Mojang library: plugins { // (...) id 'org.gradlex.extra-java-module-info' version "1.9" } // (...) extraJavaModuleInfo { failOnMissingModuleInfo = false automaticModule("com.mojang:logging", "logging") } The automatic module override specified in your build.gradle should match the runtime one to avoid errors. You can do the same for any library or mod dependency that is missing either a module-info or explicit Automatic-Module-Name, however be aware that you may need to update your mod once said library adds one. That's all you need to get started with module support in your mods. You can learn more about modules and how to use them at dev.java.
    • Faire la mise à jour grâce à ce lien m'a aider personnellement, merci à @Paint_Ninja. https://www.amd.com/en/support 
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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