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

Scenario:

Need to drop at least 1 block from my custom glass blocks

 

What I did:

created my own GlassBlock class and extended the BlockGlass class provided by Minecraft. I then copied the quantityDropped() function to my version of the class and changed the return value from 0 to 1.

 

The function I modified:

@Override
public int quantityDropped(Random random) {
                return 0;
        }

 

Changed the 0 to a 1:

@Override
public int quantityDropped(Random random) {
                return 1; //return 1 block to the ground
        }

 

The full class:

package com.kreezxil.modname.blocks;

import java.util.Random;

import net.minecraft.block.BlockGlass;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class GlassBlock extends BlockGlass {

private static final boolean ignoreSimilarity = false;

public GlassBlock(String unlocalizedName, Material material, float hardness, float resistance, boolean ignoreSimilarity) {
	super(material, ignoreSimilarity);
	this.setUnlocalizedName(unlocalizedName);
	this.setCreativeTab(CreativeTabs.tabBlock);
	this.setHardness(hardness);
	this.setResistance(resistance);
	this.setStepSound(soundTypeGlass);
}

public GlassBlock(String unlocalizedName, Material material, float hardness, float resistance) {
	this(unlocalizedName, material, hardness, resistance, ignoreSimilarity);
}

public GlassBlock(String unlocalizedName, float hardness, float resistance) {
	this(unlocalizedName, Material.glass, hardness, resistance, ignoreSimilarity);
}

public GlassBlock(String unlocalizedName) {
	this(unlocalizedName, 0.5f, 1.0f);
}

@Override
public boolean isOpaqueCube() {
	return false;
}

@Override
public int quantityDropped(Random random) {
                return 0;
        }

    @SideOnly(Side.CLIENT)
    public EnumWorldBlockLayer getBlockLayer()
    {
        return EnumWorldBlockLayer.CUTOUT;
    }

    @Override
    public boolean isFullCube()
    {
        return false;
    }

}

 

The other functions I copied in to my class to solve the issues with the insides of my blocks rendering black and sometimes opaque.

 

 

  • Author

No, but the way you have it right now doesn't accomplish what you wanted...

 

Since I'm a newbie to Forge modding, can you explain why it doesn't accomplish what I want?

 

I tested i quantityDropped by changing the return from 1 to 2 and when I broke the object it gave me 2 on the ground as I expected. If I knew what the main difference between quantityDropped and getDrops I will be understand your concern better.

 

Thanks.

 

Kreezxil

  • Author

Well, if you did actually change it to 2 then fine (in your main post you have it return 0).

If it works, great.

 

Why did you make this post?

 

In my original post I showed what the routine is called and what I changed it too and then I showed my own GlassBlock class that extended BlockGlass.

 

I made the post to show what I did so that maybe someone else might learn from it. And, with the distinct possibility that someone such as yourself might impart to me a better way to do what it was that I just did.

 

By the by, from looking at the function you suggested, it appears that returns a possible list of drops that the block can drop, kind of like breaking grass can return all kinds of seeds.

 

The function you suggested I override is as follows:

/**
     * This returns a complete list of items dropped from this block.
     *
     * @param world The current world
     * @param pos Block position in world
     * @param state Current state
     * @param fortune Breakers fortune level
     * @return A ArrayList containing all items this block drops
     */
    public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
    {
        List<ItemStack> ret = new java.util.ArrayList<ItemStack>();

        Random rand = world instanceof World ? ((World)world).rand : RANDOM;

        int count = quantityDropped(state, fortune, rand);
        for(int i = 0; i < count; i++)
        {
            Item item = this.getItemDropped(state, rand, fortune);
            if (item != null)
            {
                ret.add(new ItemStack(item, 1, this.damageDropped(state)));
            }
        }
        return ret;
    }

 

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.