Jump to content

Recommended Posts

Posted

Hello. I'm trying to make a block where on random ticks it will grow upwards(for now), like reeds. Also it is supposed to grow upwards on player activation. I have somewhat of a clue how to to this and the current code I have isn't working. The block is registering in game and the name, texture, and creative tab are all working.

package TestMod.tutorial.block;

import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class GooBlock extends BlockBase{
    
    public GooBlock(String name){
        super(Material.ROCK, name);
        setTickRandomly(true);
        setHardness(0f);
        setResistance(1f);
    } 
    
    @Override
    public GooBlock setCreativeTab(CreativeTabs tab){
        super.setCreativeTab(tab);
        return this;
    }
    
    public void updateTick(World worldIn, BlockPos pos){
        BlockPos pos0 = new BlockPos(pos.getX(), (pos.getY()+1) , pos.getZ());

        
        worldIn.setBlockState(pos0, ModBlocks.gooblock.getDefaultState());
    }
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ){
        BlockPos pos0 = new BlockPos(pos.getX(), (pos.getY()+1) , pos.getZ());
        worldIn.setBlockState(pos0, ModBlocks.gooblock.getDefaultState());
    return false;}
}

 

Thanks for the help.

I don't optimize my code before it works.

Posted

You can simplify this:

BlockPos pos0 = new BlockPos(pos.getX(), (pos.getY()+1) , pos.getZ());

BlockPos pos0 = pos.up();

 

That said, what isn't working correctly?

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.

Posted

In game nothing happens. The code should be working right?

 

For random ticks, you didn't specify that your block should receive random ticks).

For right-clicking, you have the wrong method signature (@Override would tell you this). You want

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)

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.

Posted

public GooBlock(String name){
        super(Material.ROCK, name);
        setTickRandomly(true);
        setHardness(0f);
        setResistance(1f);
    } 

 

It was in there. I tried adding the

this.

but it still didn't work.

I don't optimize my code before it works.

Posted

I believe they need to be scheduled.

world.scheduleBlockUpdate(pos, blockIn, delay, priority);

I would do it in onBlockPlaced and then in the update method itself when the first one happens.

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.

Posted

I believe they need to be scheduled.

world.scheduleBlockUpdate(pos, blockIn, delay, priority);

I would do it in onBlockPlaced and then in the update method itself when the first one happens.

 

There are random update ticks. Look at BlockCrops.

Line 28, specifically.

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.

Posted

I believe they need to be scheduled.

world.scheduleBlockUpdate(pos, blockIn, delay, priority);

I would do it in onBlockPlaced and then in the update method itself when the first one happens.

 

There are random update ticks. Look at BlockCrops.

Line 28, specifically.

I thought they were the same thing, like you would schedule a random tick by scheduling it using Random#nextInt(...). Bu his other problem is a wrong method signature with updateTick it is Block#updateTick(World world, BlockPos pos, IBlockState state, Random rand)

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.

Posted

Any ideas of what's wrong? None of the block changes are happening.

 

Current Code:

package TestMod.tutorial.block;

import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class GooBlock extends BlockBase{
    
    public GooBlock(String name){
        super(Material.ROCK, name);
        setTickRandomly(true);
        setHardness(0f);
        setResistance(1f);
    } 
    
    @Override
    public GooBlock setCreativeTab(CreativeTabs tab){
        super.setCreativeTab(tab);
        return this;
    }
    
    public void updateTick(World worldIn, BlockPos pos){
        BlockPos pos0 = new BlockPos(pos.getX(), (pos.getY()+1) , pos.getZ());
        worldIn.setBlockState(pos0, ModBlocks.gooblock.getDefaultState());
    }

    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ){
        BlockPos pos0 = new BlockPos(pos.getX(), (pos.getY()+1) , pos.getZ());
        worldIn.setBlockState(pos0, ModBlocks.gooblock.getDefaultState());
    return false;}
}

I don't optimize my code before it works.

Posted

I thought they were the same thing, like you would schedule a random tick by scheduling it using Random#nextInt(...).

 

scheduled ticks are, by definition, not random.  You can use a random interval, but they are distinct from random update ticks, which are given to a fixed number of blocks in each chunk at random.

 

Any ideas of what's wrong? None of the block changes are happening.

 

Yes:

wrong method signature with updateTick it is Block#updateTick(World world, BlockPos pos, IBlockState state, Random rand)

 

Use @Override on every method that you are overriding. If Eclipse says "not valid, suggest remove" then you should fix the signature.  Eclipse can't suggest an alternate signature, its too complex of an operation.

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.

Posted

So what does the @Override tell you? The random tick is working (Thank you) but the player activation still isn't.

@Override
    boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ){
        BlockPos pos0 = new BlockPos(pos.getX(), (pos.getY()+1) , pos.getZ());
        worldIn.setBlockState(pos0, ModBlocks.gooblock.getDefaultState());
    return false;}

It is okay with the code without the @Override but it doesn't like it with the override. (I'm using NetBeans 8.2)

I don't optimize my code before it works.

Posted

If it 'doesn't like it with the override', that means your IDE is telling you that you're not overriding correctly. Go to the superclass and find the method you want to override and copy the exact method signature to make sure it is correct.

Posted
It is okay with the code without the @Override but it doesn't like it with the override.

 

Stop for a moment and think about what that means... It is quiet without the assertion, but you hear about an error when you assert the truth about the method.

 

As the designer, you KNOW that a method is (supposed to) override an inherited method. Therefore, when your IDE suggests that you remove the annotation, you KNOW that it's bad advice (like "curing" a fever by removing that pesky thermometer -- all you accomplish is that you turn off the alert; you wouldn't be fixing the problem).

 

Now there are some methods that you are not allowed to override. If you are modding in unexplored territory, you might run into static and/or private (and maybe final?) methods. Then you need to get creative. However, onBlockActivated shouldn't be one of those.

 

Follow the advice above: Copy-paste the exact method header. You can then change parameter names if you like, but don't mess with the return type, qualifiers or parameter types.

 

And yes, every Java programmer should attach the @Override annotation to each and every method that's supposed be overriding an inherited method -- NO EXCEPTIONS. The first time you go through an upgrade exercise to a new MC release, you will thank your past self for pasting all those annotations where they assert the truth of your design (because they'll flag subtle inconsistencies created by vanilla code changes).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.