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.

Announcements



×
×
  • Create New...

Important Information

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