Robertof Posted November 22, 2012 Posted November 22, 2012 Hello, I'm pretty new to Forge programming (but not to programming in general), and I need to ask a thing. I already tried to ask that in IRC but I got no response. Anyways, I have a class 'ItemMyPickaxe' which should replace some blocks when they break. However I didn't find anything to do this. I tried 2 different solutions: Using onBlockStartBreak() and then running playerEntity.worldObj.setBlock (blockX, blockY, blockZ, newblock) That would've work perfectly, but then I realized that I need to drop even items, not just blocks. So, nope. Then I tried again with onBlockStartBreak(), this time dropping the block manually using the code in Block.dropBlockAsItem_do(). But using that leads to 1) the drop entity not being placed correctly, for a reason unknown to me 2) the need to add the code in ItemInWorldManager.tryHarvestBlock(x,y,z). But that's too much, and also dangerous for future updates. Can anyone help me on this? (to make an example - a thing like Azanor's TC2 Pickaxe of the core is what I would need: it cooked the items on the fly and dropped them, but I still didn't understand how to do that) Thank you very much, Robertof Quote
Jdb100 Posted November 22, 2012 Posted November 22, 2012 //This tells it what to drop public int idDropped(int par1, Random par2Random, int par3) { //This is what it drops. DimensionBase is my base mod file,ruby is what i want it to drop and shiftedIndex is for items and BlockID is for blocks. return DimensionBase.ruby.shiftedIndex; } //Amount it drops public int quantityDropped(Random random) { return 4; } EDIT:this goes in the Block.java Quote Creator of Jobo's ModLoader If I helped you could you please click the thank you button and applaud my karma.
Robertof Posted November 22, 2012 Author Posted November 22, 2012 Yep but as I said - I don't have the access to the original block (and I don't wanna edit the original classes). I just have the access to the tool. By the way I guess I should use a temporary block which drops what is in the metadata. Thanks anyways. //This tells it what to drop public int idDropped(int par1, Random par2Random, int par3) { //This is what it drops. DimensionBase is my base mod file,ruby is what i want it to drop and shiftedIndex is for items and BlockID is for blocks. return DimensionBase.ruby.shiftedIndex; } //Amount it drops public int quantityDropped(Random random) { return 4; } EDIT:this goes in the Block.java Quote
Robertof Posted November 23, 2012 Author Posted November 23, 2012 Sorry for the double post - but I fixed that: /** * A function which generates an EntityItem * from an ItemStack, given World and x, y, z coordinates. * @param wObj The world object where the entity will be spawned. * @param result The ItemStack to drop. It will be automatically copied. * @param x X coordinate * @param y Y coordinate * @param z Z coordinate * @author Robertof */ protected void genBlockDrop (World wObj, ItemStack result, int x, int y, int z) { if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { float var6 = 0.7F; double var7 = (double)(wObj.rand.nextFloat() * var6) + (double)(1.0F - var6) * 0.5D; double var9 = (double)(wObj.rand.nextFloat() * var6) + (double)(1.0F - var6) * 0.5D; double var11 = (double)(wObj.rand.nextFloat() * var6) + (double)(1.0F - var6) * 0.5D; EntityItem ei = new EntityItem(wObj, (double)x + var7, (double)y + var9, (double)z + var11, new ItemStack (result.itemID, result.stackSize, result.getItemDamage())); if (result.hasTagCompound()) ei.item.setTagCompound((NBTTagCompound) result.getTagCompound().copy()); ei.delayBeforeCanPickup = 10; wObj.spawnEntityInWorld(ei); } } add that to onBlockStartBreak along with something to add damage to the tool used (if you want), then return true and you are good to go. Quote
Recommended Posts
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.