Jump to content

Custom lamp problem 1.12.2


MrPablo2000

Recommended Posts

Hi, it me   - again...

 

 

I want to make my neon letter as a redstone lamp. I use the code from RedstoneLight.class. 

When I power my block, its working. It place block NeonLetterENeonActive...but with another rotation as NeonLetterEIdle...

 

My default direction is West, but i make a method that the block rotates to player on placing. 

 

For example: Idle block is north, but when i power it, the powered block are placed with default, west rotation..

 

 

What i must change in code, to get this: when i power the block, powered block has the same ratation as unpowered?

 

I use this code - it's coppied from vanilla RedstoneLight:

Spoiler

   public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
    {
        if (!worldIn.isRemote)
        {
            if (this.isOn && !worldIn.isBlockPowered(pos))
            {
                worldIn.setBlockState(pos, ModBlocks.neonletterENeonIdle.getDefaultState(), 2);
            }
            else if (!this.isOn && worldIn.isBlockPowered(pos))
            {
                worldIn.setBlockState(pos, ModBlocks.neonletterENeonActive.getDefaultState(), 2);
            }
        }
    }

    /**
     * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
     * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
     * block, etc.
     */
    public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
    {
        if (!worldIn.isRemote)
        {
            if (this.isOn && !worldIn.isBlockPowered(pos))
            {
                worldIn.scheduleUpdate(pos, this, 4);
            }
            else if (!this.isOn && worldIn.isBlockPowered(pos))
            {
                worldIn.setBlockState(pos, ModBlocks.neonletterENeonActive.getDefaultState(), 2);
            }
        }
    }

    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        if (!worldIn.isRemote)
        {
            if (this.isOn && !worldIn.isBlockPowered(pos))
            {
                worldIn.setBlockState(pos, ModBlocks.neonletterENeonIdle.getDefaultState(), 2);
            }
        }
    }

 

Edited by MrPablo2000
language errors - sorry for my bad English..
Link to comment
Share on other sites

As I told you via PM, @deprecated means "do not INVOKE," not "do not override." If you look at the block class literally every method is marked @deprecated.

Edited by Draco18s

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

I still don't know how to do it..  :(

 

I try this way, to use only 1 block:

public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!worldIn.isRemote)
    {
        if (!worldIn.isBlockPowered(pos))
        {
            isActive=false;
        }
    }
}

 

In constructor:

	if(this.isActive=true)
		{
			setLightLevel(1F);
		}

 

 

and boolean:

private boolean isActive = false;	

 

 

But it stil doesn't work... :/ 

Link to comment
Share on other sites

2 hours ago, MrPablo2000 said:

I still don't know how to do it..  :(

 

I try this way, to use only 1 block:


public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!worldIn.isRemote)
    {
        if (!worldIn.isBlockPowered(pos))
        {
            isActive=false;
        }
    }
}

 

In constructor:


	if(this.isActive=true)
		{
			setLightLevel(1F);
		}

 

 

and boolean:


private boolean isActive = false;	

 

 

But it stil doesn't work... :/ 

Post your entire code, and preferably a GitHub 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

2 hours ago, MrPablo2000 said:

public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)

This doesn't work the way you think it does. It's not the same as the update method of TileEntities that gets called once per tick. This method gets called once per tick... on one random block in all loaded chunks.

 

2 hours ago, MrPablo2000 said:

if(this.isActive=true)

This is always true since this sets the isActive field to true.

 

2 hours ago, MrPablo2000 said:

private boolean isActive = false;	

 

Blocks are singletons. You can't use fields to store per-block data. Use block properties.

Link to comment
Share on other sites

1 hour ago, V0idWa1k3r said:

This method gets called once per tick... on one random block in all loaded chunks.

Well, I think its actually on 16 blocks per chunk, but otherwise more or less.

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

7 hours ago, V0idWa1k3r said:

This doesn't work the way you think it does. It's not the same as the update method of TileEntities that gets called once per tick. This method gets called once per tick... on one random block in all loaded chunks.

 

This is always true since this sets the isActive field to true.

 

Blocks are singletons. You can't use fields to store per-block data. Use block properties.

Block Properties? You mean .setHardness, .setLightLevel etc?

Link to comment
Share on other sites

3 hours ago, MrPablo2000 said:

I try to do it with crops code, but i never works with Properties...Have you any toturial about it ?

Check out the forge docs on BlockStates.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Quote

 "facing=north": 

That is not how you define states in forge blockstates. If you want to use vanilla syntax use vanilla format.

 

On 8/21/2018 at 3:46 PM, V0idWa1k3r said:
On 8/21/2018 at 12:51 PM, MrPablo2000 said:

public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)

This doesn't work the way you think it does. It's not the same as the update method of TileEntities that gets called once per tick. This method gets called once per tick... on one random block in all loaded chunks.

 

public boolean isMaxState(IBlockState state)
{
    return ((Integer)state.getValue(this.getStateProperty())).intValue() >= this.getMaxState();
}

This will never be true as your state property is within a [0-1] range and getMaxState returns 7 for whatever reason.

Also you don't need half of these methods, they just make your block class bloated. Never copy vanilla code and simply change the names of methods and variables without understanding of what's going on.

 

@Override
    public int getMetaFromState(IBlockState state) {
        return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
}
 
    @Override
    public IBlockState getStateFromMeta(int meta) {
        return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
    }

You must include your state property in metadata serialization/deserialization.

 

@Override
    public BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, FACING);
    }

You must include your state property in the BlockStateContainer created.

 

    public static final PropertyInteger STATE = PropertyInteger.create("state", 0, 1);

If your integer is only within a [0-1] range then you don't need an integer, you need a boolean. 

 

Here are the docs on the blockstates. 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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