Posted April 21, 201510 yr 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. https://www.akliz.net/manage/aff.php?aff=179 coupon: kreezxil KreezCraft.com - Twitch.TV/Kreezxil - YouTube.com/Kreezxil
April 21, 201510 yr Author Will my method that I took raise issues in the future? https://www.akliz.net/manage/aff.php?aff=179 coupon: kreezxil KreezCraft.com - Twitch.TV/Kreezxil - YouTube.com/Kreezxil
April 21, 201510 yr Author Are you referring to the other functions of just the one for drops? https://www.akliz.net/manage/aff.php?aff=179 coupon: kreezxil KreezCraft.com - Twitch.TV/Kreezxil - YouTube.com/Kreezxil
April 21, 201510 yr 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 https://www.akliz.net/manage/aff.php?aff=179 coupon: kreezxil KreezCraft.com - Twitch.TV/Kreezxil - YouTube.com/Kreezxil
April 21, 201510 yr 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; } https://www.akliz.net/manage/aff.php?aff=179 coupon: kreezxil KreezCraft.com - Twitch.TV/Kreezxil - YouTube.com/Kreezxil
April 21, 201510 yr Author Which section is for sharing? Can you move this there? https://www.akliz.net/manage/aff.php?aff=179 coupon: kreezxil KreezCraft.com - Twitch.TV/Kreezxil - YouTube.com/Kreezxil
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.