Jump to content

MC 1.12.2 setters in constructor


winnetrie

Recommended Posts

So this is how my constructor looks like for my slabs class:

    public static final PropertyEnum<BlockBaseSlabColoredA.EnumType> COLOR = PropertyEnum.<BlockBaseSlabColoredA.EnumType>create("color", BlockBaseSlabColoredA.EnumType.class);
    
    private final Block modelBlock;
    private final IBlockState modelState;
    

    public BlockBaseSlabColoredA(String name, IBlockState state)
    {
        super(state.getMaterial());
        this.modelBlock = state.getBlock();
        this.modelState = state;
        IBlockState iblockstate = this.blockState.getBaseState().withProperty(COLOR, BlockBaseSlabColoredA.EnumType.WHITE);   
        if(!this.isDouble()){

        	iblockstate = iblockstate.withProperty(HALF, EnumBlockHalf.BOTTOM).withProperty(COLOR, BlockBaseSlabColoredA.EnumType.WHITE);
		}

        this.setDefaultState(iblockstate);
        setUnlocalizedName(name);
        setRegistryName(name);
        setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
        setHardness(this.modelState.getBlockHardness(null, null));
        setResistance(this.modelBlock.getExplosionResistance(null, null, null, null));
        setSoundType(this.modelBlock.getSoundType(null, null, null, null));
        setHarvestLevel(this.modelBlock.getHarvestTool(state), this.modelBlock.getHarvestLevel(state));
        setLightLevel(0.0F);
        this.useNeighborBrightness = true;
		
		BlockInit.BLOCKS.add(this);

    }

As you can see i have alot of "null" here. I guess i should not do this, but how do i get all these arguments?

Link to comment
Share on other sites

Alright i have added this in my class now:

@Override
    public float getExplosionResistance(World world, BlockPos pos, @Nullable Entity exploder, Explosion explosion)
    {
    	return this.modelBlock.getExplosionResistance(world, pos, exploder, explosion);
    }
    
    @Override
    public float getBlockHardness(IBlockState blockState, World worldIn, BlockPos pos)
    {
        return this.modelState.getBlockHardness(worldIn, pos);
    }
    
    @Override
    public SoundType getSoundType(IBlockState state, World world, BlockPos pos, @Nullable Entity entity)
    {
        return this.modelBlock.getSoundType(state, world, pos, entity);
    }

It all works and no errors. I also deleted those setters in the constructor ofcourse.

I hope this is how it should be done.

Link to comment
Share on other sites

I did this for a tile entity of mine.

It's a massive headache.

The way I went around doing it was to register a dimension, use that dimension as the place to "store" the block/TE information that I wanted. I mapped the six slots in my TE to six locations in the extra dimension (while possible to have two TEs use the same locations, it's not a concern, as the TE checks the BlockPos and if it isn't correct, changes it--there would be GC overhead involved, but the likelyhood that a player does this is small). The chunks in that dimension are chunkloaded while my TE has need of them (any given TE will chunkload at most 1 chunk). And of course, in order to get the world reference, I had to pass things through my Proxy class because the client and server worlds are different.

 

This was less of a hassle than creating a World object that wasn't connected to anything at all (also possible).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

15 minutes ago, Draco18s said:

I'm sorry, but i fail to see or understand how this is usefull to me and how i even should use this.

Link to comment
Share on other sites

The Fake World code is sprawling and in several files. If you're interested in knowing what I did, peruse my repository. Everything you need is there.

I recommend starting here:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/industry/entities/TileEntityFilter.java#L169

Follow the references.

If you have specific questions, ask.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

A fake world is the proper way to do it, but you could probably be sneaky and place the block somewhere very, very unlikely to cause trouble, like a bedrock location, temporarily and then put it back to bedrock.

 

So basically, set hardness and stuff to some default fixed value in the constructor. Then during world generation run a loop once that takes a bedrock location, cycles through the list of blocks you want to create slabs for, place the block, grab the properties, replace with next block, grab the properties, and so on then put back the bedrock when done.

 

Also, if you only want to handle vanilla blocks you could probably just hardcode the values. A bit of a pain, but you figure out the values (maybe even algorithmically with a simple mod/program) and then read them in.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.