Jump to content

Recommended Posts

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.

 

 

Posted

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

Posted

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

×   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

    • You will find the crash-report or log in your minecraft directory (crash-report or logs folder)
    • Use a modpack which is using these 2 mods as working base:   https://www.curseforge.com/minecraft/modpacks/life-in-the-village-3
    • inicie un mundo donde instale Croptopia y Farmer's Delight, entonces instale el addon Croptopia Delight pero no funciona. es la version 1.18.2
    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
  • Topics

×
×
  • Create New...

Important Information

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