Jump to content

Help with setBlockState


Durtle02

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Slot deposit 3000 adalah situs slot deposit 3000 via dana yang super gacor dimana para pemain dijamin garansi wd hari ini juga hanya dengan modal receh berupa deposit sebesar 3000 baik via dana, ovo, gopay maupun linkaja untuk para pemain pengguna e-wallet di seluruh Indonesia.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT 3000 ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • OLXTOTO: Menikmati Sensasi Bermain Togel dan Slot dengan Aman dan Mengasyikkan Dunia perjudian daring terus berkembang dengan cepat, dan salah satu situs yang telah menonjol dalam pasar adalah OLXTOTO. Sebagai platform resmi untuk permainan togel dan slot, OLXTOTO telah memenangkan kepercayaan banyak pemain dengan menyediakan pengalaman bermain yang aman, adil, dan mengasyikkan. DAFTAR OLXTOTO DISINI <a href="https://imgbb.com/"><img src="https://i.ibb.co/GnjSVpx/daftar1-480x480.webp" alt="daftar1-480x480" border="0" /></a> Keamanan Sebagai Prioritas Utama Salah satu aspek utama yang membuat OLXTOTO begitu menonjol adalah komitmennya terhadap keamanan pemain. Dengan menggunakan teknologi enkripsi terkini, situs ini memastikan bahwa semua informasi pribadi dan keuangan para pemain tetap aman dan terlindungi dari akses yang tidak sah. Beragam Permainan yang Menarik Di OLXTOTO, pemain dapat menemukan beragam permainan yang menarik untuk dinikmati. Mulai dari permainan klasik seperti togel hingga slot modern dengan fitur-fitur inovatif, ada sesuatu untuk setiap selera dan preferensi. Grafik yang memukau dan efek suara yang mengagumkan menambah keseruan setiap putaran. Peluang Menang yang Tinggi Salah satu hal yang paling menarik bagi para pemain adalah peluang menang yang tinggi yang ditawarkan oleh OLXTOTO. Dengan pembayaran yang adil dan peluang yang setara bagi semua pemain, setiap taruhan memberikan kesempatan nyata untuk memenangkan hadiah besar. Layanan Pelanggan yang Responsif Tim layanan pelanggan OLXTOTO siap membantu para pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Dengan layanan yang ramah dan responsif, pemain dapat yakin bahwa mereka akan mendapatkan bantuan yang mereka butuhkan dengan cepat dan efisien. Kesimpulan OLXTOTO telah membuktikan dirinya sebagai salah satu situs terbaik untuk penggemar togel dan slot online. Dengan fokus pada keamanan, beragam permainan yang menarik, peluang menang yang tinggi, dan layanan pelanggan yang luar biasa, tidak mengherankan bahwa situs ini telah menjadi pilihan utama bagi banyak pemain. Jadi, jika Anda mencari pengalaman bermain yang aman, adil, dan mengasyikkan, jangan ragu untuk bergabung dengan OLXTOTO hari ini dan rasakan sensasi kemenangan!
    • Slot deposit dana adalah situs slot deposit dana yang juga menerima dari e-wallet lain seperti deposit via dana, ovo, gopay & linkaja terlengkap saat ini, sehingga para pemain yang tidak memiliki rekening bank lokal bisa tetap bermain slot dan terbantu dengan adanya fitur tersebut.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit dana adalah situs slot deposit dana minimal 5000 yang dijamin garansi super gacor dan gampang menang, dimana para pemain yang tidak memiliki rekening bank lokal tetap dalam bermain slot dengan melakukan deposit dana serta e-wallet lainnya seperti ovo, gopay maupun linkaja lengkap. Agar para pecinta slot di seluruh Indonesia tetap dapat menikmati permainan tanpa halangan apapun khususnya metode deposit, dimana ketersediaan cara deposit saat ini yang lebih beragam tentunya sangat membantu para pecinta slot.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit pulsa adalah situs slot deposit pulsa tanpa potongan apapun yang dijamin garansi terpercaya, dimana kamu bisa bermain slot dengan melakukan deposit pulsa dan tanpa dikenakan potongan apapun sehingga dana yang masuk ke dalam akun akan 100% utuh. Proses penarikan dana juga dijamin gampang dan tidak sulit sehingga kamu tidak perlu khawatir akan kemenangan yang akan kamu peroleh dengan sangat mudah jika bermain disini.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT PULSA TANPA POTONGAN ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
  • Topics

×
×
  • Create New...

Important Information

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