Jump to content

Custom Rendered block not dropping when broken


dwinget2008

Recommended Posts

I have a custom rendered block that I am trying to get to drop when a player breaks it with their fist. It will break and drop the block Id when a tool is used, but not when punched.

 

I have tried the idDropped, quantitydropped, and breakBlock methods but none of them seem to be doing the trick.

 

here is the code. Normally I use the pastbin but my browser doen't want to open it up right now. Thanks for your help.

 

BlockClass

 

package throughtheages.blocks;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import throughtheages.main.Reference;
import throughtheages.main.ThroughTheAges;
import throughtheages.tileentity.TileEntitySmallRock;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class SmallRock extends BlockContainer
{

    public SmallRock(int par1, Material par2Material)
    {
        super(par1, par2Material);
        
        this.setBlockBounds(1f/16f*6.5f, 0f, 1f/16f*6.5f, 1f-1f/16f*6.5f, 1f-1f/16f*14f, 1f-1f/16f*6.5f);
        
        this.setUnlocalizedName("smallrock");
        this.setCreativeTab(ThroughTheAges.throughTheAges);
        
        
            
    }
    
    @Override
    public TileEntity createNewTileEntity(World world)
    {
        return new TileEntitySmallRock();
    }
    
    public int getRenderType()
    {
        return -1;
    }
    
   
    
    public boolean isOpaqueCube()
    {
        return false;
    }
    
    public boolean renderAsNormalBlock()
    {
        return false;
    }
    
    @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister register)
    {
        this.blockIcon = register.registerIcon(Reference.MOD_ID + ":smallrock");
    }

    

}

 

 

BlockHandler

 

package throughtheages.blocks;

import throughtheages.main.ThroughTheAges;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

public class BlockHandler
{
    public static Block smallRock;
    
    
    public static void configureBlocks(Configuration config)
    {
        smallRock = new SmallRock(config.get("Blocks", "Small Rock", 1002).getInt(), Material.rock);
        
        
        registerBlock(smallRock, "smallrock", "Small Rock");       
    }
    
    private static void registerBlock(Block block, String string, String name){
        GameRegistry.registerBlock(block, string);
        LanguageRegistry.addName(block, name);
    }
       
    
    
    

}

 

 

 

If you need the renderes, and I don't think that you should, just ask Iand I will provide them.

Link to comment
Share on other sites

Hi

 

Just to confirm - do you know that a Block is only a Block when it is placed?

A Block in a person's hand or inventory is an Item, not a Block

And just to be confusing, a dropped Item is actually an Entity.

 

There are a few tutorials around on it- see

http://wuppy29.blogspot.nl/2013/07/forge-modding-16.html

http://www.minecraftforge.net/wiki/Generic_Mod

http://greyminecraftcoder.blogspot.com.au/p/list-of-topics.html

 

-TGG

Sorry if you did already know this stuff, just making sure...

 

Link to comment
Share on other sites

Yes I already knew most of that. I am just finding an issue when I break the block with a fist vs. pickaxe. When I break it with a pickaxe it drops just fine, meaning that you get the block. When broken with a fist it breaks like grass and you don't get the block back.

 

This is a custom rendered block, and from what I have learned they need to be classed as a block container, not sure why on that but that is what I read / saw.

 

Like I said the block works fine until you break it with your fist. just want to be able to break it with a first and get the drop, much like a flower or a any other block that you can pick up with just your fist.

 

 

Link to comment
Share on other sites

Hi

 

You can have custom renderers for any Block, not just BlockContainer.

http://greyminecraftcoder.blogspot.com.au/2013/07/block-rendering.html

 

Breaking a block with your fist will drop an item (by calling Block.harvestBlock) if:

(1) you override Block.canHarvestBlock to true, or

(2) block.blockMaterial.isToolNotRequired() returns true, or

(3) you have registered for the HarvestCheck event and you return true.

 

(see

ItemInWorldManager.tryHarvestBlock
                if (block != null)
                {
                    flag1 = block.canHarvestBlock(thisPlayerMP, i1);
                }

 

-TGG

You don't need to override any of the other methods you mentioned unless you want a different item or quantity to drop, the default methods will drop one of the blockID as an Item.

Link to comment
Share on other sites

What is your material set as because if it is rock or iron you need a pick to mine it, but if it is something like sand or wood, you can break it with your fists.

 

Try changing this part:

public SmallRock(int par1, Material par2Material)

    {

        super(par1, par2Material);

       

        this.setBlockBounds(1f/16f*6.5f, 0f, 1f/16f*6.5f, 1f-1f/16f*6.5f, 1f-1f/16f*14f, 1f-1f/16f*6.5f);

       

        this.setUnlocalizedName("smallrock");

        this.setCreativeTab(ThroughTheAges.throughTheAges);

       

       

           

    }

 

Into this:

public SmallRock(int par1)

    {

        super(par1, Material.sand);

 

        this.setBlockBounds(1f/16f*6.5f, 0f, 1f/16f*6.5f, 1f-1f/16f*6.5f, 1f-1f/16f*14f, 1f-1f/16f*6.5f);

        this.setUnlocalizedName("smallrock");

        this.setCreativeTab(ThroughTheAges.throughTheAges);

    }

 

PS: Something I like to do is to give the Unlocalized name when you initialize the block in your main class, so you can use the class for more than one item and have it have the block back and display the Texture according to the Unlocalized name.

Don't be afraid to ask question when modding, there are no stupid question! Unless you don't know java then all your questions are stupid!

Link to comment
Share on other sites

What is your material set as because if it is rock or iron you need a pick to mine it, but if it is something like sand or wood, you can break it with your fists.

 

Try changing this part:

public SmallRock(int par1, Material par2Material)

    {

        super(par1, par2Material);

       

        this.setBlockBounds(1f/16f*6.5f, 0f, 1f/16f*6.5f, 1f-1f/16f*6.5f, 1f-1f/16f*14f, 1f-1f/16f*6.5f);

       

        this.setUnlocalizedName("smallrock");

        this.setCreativeTab(ThroughTheAges.throughTheAges);

       

       

           

    }

 

Into this:

public SmallRock(int par1)

    {

        super(par1, Material.sand);

 

        this.setBlockBounds(1f/16f*6.5f, 0f, 1f/16f*6.5f, 1f-1f/16f*6.5f, 1f-1f/16f*14f, 1f-1f/16f*6.5f);

        this.setUnlocalizedName("smallrock");

        this.setCreativeTab(ThroughTheAges.throughTheAges);

    }

 

PS: Something I like to do is to give the Unlocalized name when you initialize the block in your main class, so you can use the class for more than one item and have it have the block back and display the Texture according to the Unlocalized name.

 

This was what I finally figured out as well that it was the material that I was using. I changed it to ground and that did the trick.

 

New question, if you feel like adding more input, any thoughts on adding a custom material to the materials list. I think I have an idea and will try it out but I am curious if there is a better way.

Link to comment
Share on other sites

Hi

 

You can have custom renderers for any Block, not just BlockContainer.

http://greyminecraftcoder.blogspot.com.au/2013/07/block-rendering.html

 

Breaking a block with your fist will drop an item (by calling Block.harvestBlock) if:

(1) you override Block.canHarvestBlock to true, or

(2) block.blockMaterial.isToolNotRequired() returns true, or

(3) you have registered for the HarvestCheck event and you return true.

 

(see

ItemInWorldManager.tryHarvestBlock
                if (block != null)
                {
                    flag1 = block.canHarvestBlock(thisPlayerMP, i1);
                }

 

-TGG

You don't need to override any of the other methods you mentioned unless you want a different item or quantity to drop, the default methods will drop one of the blockID as an Item.

 

Thanks. I will look into this. I want to look into "altering" the rock material, being as that is what the block is, so that I can harvest without a pick. thanks for your help.

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

    • So i have a custom ore and, arround the ore, a bunch of randomly placed custom stone blocks should be placed. After applying it, i've found that it causes moderate to extreme world generation lag (new chunks refusing to load after moving for a while, height slices of the same chunk appearing and disappearing as I get into them instead of the usual long continous chunk, new chunks generating extremely close to me instead of to the set render distance...) I've been debugging for a while and I know for a fact this is causing the lag (and sometimes freeze of the world loading screen on a new world and/or the saving world screen when quitting), since comenting it just makes the worldgen work as usual and I want to see if its really that computationally expensive, if there are other ways of doing it or if the process can be simplfied or optimized. I've tried a lot of combinations for the same code but I am just stuck. Is it some kind of generation cascading im missing?   Here is the code for the class. The code inside the if (placed) is the one causing this mess. I can see that the code might not be the most optimized thing, but it does what's supposed to... but at the cost of causing all this. Any tips? package es.nullbyte.relativedimensions.worldgen.oregen.oreplacements; import es.nullbyte.relativedimensions.blocks.BlockInit; import es.nullbyte.relativedimensions.blocks.ModBlockTags; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext; import net.minecraft.world.level.levelgen.feature.OreFeature; import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; import java.util.Optional; public class AberrantOreFeature extends OreFeature { public AberrantOreFeature() { super(OreConfiguration.CODEC); } @Override public boolean place(FeaturePlaceContext<OreConfiguration> ctx) { // Get the world and the position from the context WorldGenLevel world = ctx.level(); BlockPos origin = ctx.origin(); // Offset the origin by 8 in the x and z directions to avoid cascading chunk generation BlockPos offsetOrigin = origin.offset(8, 0, 8); // Create a new context with the offset origin FeaturePlaceContext<OreConfiguration> offsetCtx = new FeaturePlaceContext<>( Optional.empty(), world, ctx.chunkGenerator(), ctx.random(), offsetOrigin, ctx.config() ); // Generate the entire vein of ore at the offset origin boolean placed = super.place(offsetCtx); // If the vein was generated successfully if (placed) { // Define the block to replace surrounding blocks with BlockState surroundingBlockState = BlockInit.ABERRANT_MINERALOID.get().defaultBlockState(); // Generate a random size for the area of corruption int areaSizeX = ctx.random().nextInt(3) + 1; // between 1 and 4 int areaSizeY = ctx.random().nextInt(3) + 1; // between 1 and 4 int areaSizeZ = ctx.random().nextInt(3) + 1; // between 1 and 4 // Calculate the number of blocks to be corrupted based on the area size double numBlocksToCorrupt = (areaSizeX + areaSizeY + areaSizeZ / 2.0) ; // Counter for the number of blocks corrupted int numBlocksCorrupted = 0; // Loop for each block to be corrupted while (numBlocksCorrupted < numBlocksToCorrupt) { // Generate a random position within the area, using the offset origin BlockPos randomPos = offsetOrigin.offset( ctx.random().nextInt(2 * areaSizeX + 1) - areaSizeX, // between -areaSize and areaSize ctx.random().nextInt(2 * areaSizeY + 1) - areaSizeY, ctx.random().nextInt(2 * areaSizeZ + 1) - areaSizeZ ); // If the block at the random position is in the IS_ORE_ABERRANTABLE tag, replace it if (world.getBlockState(randomPos).is(ModBlockTags.STONE_ABERRANTABLE)) { world.setBlock(randomPos, surroundingBlockState, 2); numBlocksCorrupted++; } } } return placed; } }  
    • Here is a tutorial from this same forum that I tried and kinda made work. Take into account that you will have to manage the offset (like rotation, and the offset relative to things like the main hand, offhand etc) by yourself and that can get very troublesome at times.  
    • I have done this now but have got the error:   'food(net.minecraft.world.food.FoodProperties)' in 'net.minecraft.world.item.Item.Properties' cannot be applied to                '(net.minecraftforge.registries.RegistryObject<net.minecraft.world.item.Item>)' public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register( "lemon_juice", () -> new Item( new HoneyBottleItem.Properties().stacksTo(1).food( (new FoodProperties.Builder()) .nutrition(3) .saturationMod(0.25F) .effect(() -> new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 1500), 0.01f ) .build() ) )); The code above is from the ModFoods class, the one below from the ModItems class. public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register("lemon_juice", () -> new Item(new Item.Properties().food(ModFoods.LEMON_JUICE)));   I shall keep going between them to try and figure out the cause. I am sorry if this is too much for you to help with, though I thank you greatly for your patience and all the effort you have put in to help me.
    • I have been following these exact tutorials for quite a while, I must agree that they are amazing and easy to follow. I have registered the item in the ModFoods class, I tried to do it in ModItems (Where all the items should be registered) but got errors, I think I may need to revert this and figure it out from there. Once again, thank you for your help! 👍 Just looking back, I have noticed in your code you added ITEMS.register, which I am guessing means that they are being registered in ModFoods, I shall go through the process of trial and error to figure this out.
    • ♈+2349027025197ஜ Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join a brotherhood for protection and wealth here’s is your opportunity, but you should know there’s no ritual without repercussions but with the right guidance and support from this great temple your destiny is certain to be changed for the better and equally protected depending if you’re destined for greatness Call now for enquiry +2349027025197☎+2349027025197₩™ I want to join ILLUMINATI occult without human sacrificeGREATORLDRADO BROTHERHOOD OCCULT , Is The Club of the Riches and Famous; is the world oldest and largest fraternity made up of 3 Millions Members. We are one Family under one father who is the Supreme Being. In Greatorldrado BROTHERHOOD we believe that we were born in paradise and no member should struggle in this world. Hence all our new members are given Money Rewards once they join in order to upgrade their lifestyle.; interested viewers should contact us; on. +2349027025197 ۝ஐℰ+2349027025197 ₩Greatorldrado BROTHERHOOD OCCULT IS A SACRED FRATERNITY WITH A GRAND LODGE TEMPLE SITUATED IN G.R.A PHASE 1 PORT HARCOURT NIGERIA, OUR NUMBER ONE OBLIGATION IS TO MAKE EVERY INITIATE MEMBER HERE RICH AND FAMOUS IN OTHER RISE THE POWERS OF GUARDIANS OF AGE+. +2349027025197   SEARCHING ON HOW TO JOIN THE Greatorldrado BROTHERHOOD MONEY RITUAL OCCULT IS NOT THE PROBLEM BUT MAKE SURE YOU'VE THOUGHT ABOUT IT VERY WELL BEFORE REACHING US HERE BECAUSE NOT EVERYONE HAS THE HEART TO DO WHAT IT TAKES TO BECOME ONE OF US HERE, BUT IF YOU THINK YOU'RE SERIOUS MINDED AND READY TO RUN THE SPIRITUAL RACE OF LIFE IN OTHER TO ACQUIRE ALL YOU NEED HERE ON EARTH CONTACT SPIRITUAL GRANDMASTER NOW FOR INQUIRY +2349027025197   +2349027025197 Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join
  • Topics

×
×
  • Create New...

Important Information

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