Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

hello people,

 

I have made a block with many bugs I don't understand.

 

problem 1: If I restart minecraft, all the block changes to grass.

problem 2: if I hit the block, the block gives the texture for grass for a half second.

problem 3: If I am close enough, the block spreads as fast as I can run.

But if I am further away, the block doesn't spread at all.

problem 4: if an entity walks over the block, the wither effect doesnt work, it is a sort of corrupt.

 

here is the class:

package enderpower.Blocks;

import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import enderpower.lib.R;
import enderpower.main.Enderpower;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class CursedGrass extends Block {

@SideOnly(Side.CLIENT)
    private IIcon field_149991_b;
    @SideOnly(Side.CLIENT)
    private IIcon field_149993_M;
    @SideOnly(Side.CLIENT)
    private IIcon field_149994_N;
    
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int p_149691_1_, int p_149691_2_)
    {
        return p_149691_1_ == 1 ? this.field_149991_b : (p_149691_1_ == 0 ? Blocks.dirt.getBlockTextureFromSide(p_149691_1_) : this.blockIcon);
    }
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(IBlockAccess p_149673_1_, int p_149673_2_, int p_149673_3_, int p_149673_4_, int p_149673_5_)
    {
        if (p_149673_5_ == 1)
        {
            return this.field_149991_b;
        }
        else if (p_149673_5_ == 0)
        {
            return Blocks.dirt.getBlockTextureFromSide(p_149673_5_);
        }
        else
        {
            Material material = p_149673_1_.getBlock(p_149673_2_, p_149673_3_ + 1, p_149673_4_).getMaterial();
            return material != Material.snow && material != Material.craftedSnow ? this.blockIcon : this.field_149993_M;
        }
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister p_149651_1_)
    {
        this.blockIcon = p_149651_1_.registerIcon(this.getTextureName() + "_side");
        this.field_149991_b = p_149651_1_.registerIcon(this.getTextureName() + "_top");
        this.field_149994_N = p_149651_1_.registerIcon(this.getTextureName() + "_side_overlay");
    }


protected CursedGrass() {
	super(Material.grass);
}

public void randomDisplayTick(World world, int x, int y, int z, Random random){
	if(world.getBlock(x + 1, y, z) == Blocks.grass){
		world.setBlock(x + 1, y, z, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x - 1, y, z) == Blocks.grass){
		world.setBlock(x - 1, y, z, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x + 1, y, z + 1) == Blocks.grass){
		world.setBlock(x + 1, y, z + 1, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x - 1, y, z + 1) == Blocks.grass){
		world.setBlock(x - 1, y, z + 1, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x + 1, y, z - 1) == Blocks.grass){
		world.setBlock(x + 1, y, z - 1, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x - 1, y, z - 1) == Blocks.grass){
		world.setBlock(x - 1, y, z - 1, EnderpowerBlocks.cursedgrass);
	}


	if(world.getBlock(x, y + 1, z) == Blocks.grass){
		world.setBlock(x, y + 1, z, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x + 1, y + 1, z) == Blocks.grass){
		world.setBlock(x + 1, y + 1, z, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x - 1, y + 1, z) == Blocks.grass){
		world.setBlock(x - 1, y + 1, z, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x + 1, y + 1, z + 1) == Blocks.grass){
		world.setBlock(x + 1, y + 1, z + 1, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x - 1, y + 1, z + 1) == Blocks.grass){
		world.setBlock(x - 1, y + 1, z + 1, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x + 1, y + 1, z - 1) == Blocks.grass){
		world.setBlock(x + 1, y + 1, z - 1, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x - 1, y + 1, z - 1) == Blocks.grass){
		world.setBlock(x - 1, y + 1, z - 1, EnderpowerBlocks.cursedgrass);
	}


	if(world.getBlock(x, y - 1, z) == Blocks.grass){
		world.setBlock(x, y - 1, z, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x + 1, y - 1, z) == Blocks.grass){
		world.setBlock(x + 1, y - 1, z, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x - 1, y - 1, z) == Blocks.grass){
		world.setBlock(x - 1, y - 1, z, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x + 1, y - 1, z + 1) == Blocks.grass){
		world.setBlock(x + 1, y - 1, z + 1, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x - 1, y - 1, z + 1) == Blocks.grass){
		world.setBlock(x - 1, y - 1, z + 1, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x + 1, y - 1, z - 1) == Blocks.grass){
		world.setBlock(x + 1, y - 1, z - 1, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x - 1, y - 1, z - 1) == Blocks.grass){
		world.setBlock(x - 1, y - 1, z - 1, EnderpowerBlocks.cursedgrass);
	}
	if(world.getBlock(x, y + 1, z) == Blocks.tallgrass){
		world.setBlock(x, y + 1, z, Blocks.air);
	}
	if(world.getBlock(x, y + 1, z) == Blocks.double_plant){
		world.setBlock(x, y + 1, z, Blocks.air);
	}
	if(world.getBlock(x, y + 2, z) == Blocks.double_plant){
		world.setBlock(x, y + 2, z, Blocks.air);
	}

}

@Override
public void onEntityWalking(World world, int x, int y, int z, Entity entity){
	((EntityLivingBase) entity).addPotionEffect(new PotionEffect(20, 400, 0, true));
	System.out.println("anyone walked over the block");

}




}

  • Author

I looked in the grass code.

And in my class I changed randomDisplayTick in updateTick and added needs random tick.

Now every problem is just fixed.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.