Jump to content

Custom Multi-Tool


memcallen

Recommended Posts

I created an Item, it's essentially a customizable tool. I can't make it detect when you break a block though. Also this code doesn't work:

	public float getDigSpeed(ItemStack itemstack, Block block, int metadata){
	NBTTagCompound nbt = itemstack.getTagCompound();
	try{
		if(nbt!=null){
			System.out.println("has NBT");
	speed = nbt.getInteger("Engine");
	tool = nbt.getInteger("Tool");
		}else System.out.println("Doesn't have NBT");
	}catch(Exception e){e.printStackTrace();}

	if(block.getMaterial()==Material.rock){
		if(tool==1){
			return speed*10;
		}
	}
	if(block.getMaterial()==Material.wood){
		if(tool==2){
			return speed*6;
		}
	}
	if(block.getMaterial()==Material.ground){
		return speed*3;
	}


	return super.getDigSpeed(itemstack, block, metadata)+1F;

}

 

EDIT:

scratch that, I made it work, but it drops two items when I do break the block. how could I fix this?- also it's only when I break a block that you can break with your fist.

The proud(ish) developer of Ancients

Link to comment
Share on other sites

Yes but the thing is, is that I would need a TON of code for what i'm making. It's basically a tool that can break certain blocks depending on the NBT, kind of like a super Tinkerer's Construct tool. I have the part that breaks the blocks at different speeds but if I break a block that you can break with your fist and get an item, it drops two items.

 

Here's the onBlockDestroyed function:

public boolean onBlockDestroyed(ItemStack itemstack,World world, Block block,int x,int y,int z,EntityLivingBase elb){

	List<ItemStack> drops = block.getDrops(world, x, y, z, world.getBlockMetadata(x,y,z), 0);

	for(ItemStack is:drops){
		if(!world.isRemote)
		world.spawnEntityInWorld(new EntityItem(world,x,y,z,is));
	}

	return true;
}

so it's an "artificial" tool if you want to call it that. It doesn't actually extend ItemTool.

The proud(ish) developer of Ancients

Link to comment
Share on other sites

Blocks handle their own drops, believe it or not!

 

I notice you are spawning items in the world when onBlockDestroyed is called. If you do this, you will get more than what the block drops normally, as the block you destroyed has its own drop list which it also calls when it is broken. The reason it behaves this way only for things you can break with your fists is because those blocks have a low harvest level, and will drop whether or not the tool used to break them is of an effective harvest level. For blocks with higher harvest level, they won't drop if the tool does not have a sufficient harvest level. Your tool will the block's drops regardless, and so ends up spawning the drops twice for blocks with a low harvest level.

 

If you want to continue using this method, you'll have to make it so that the block doesn't drop its own drops when broken with your tool. I would not recommend this method.

 

Another way might be to set your tool's harvest level, and override the methods that test whether the tool is effective against a given material.

Link to comment
Share on other sites

As said above - this is NOT good way of doing this, but hey - "If it works, it ain't stupid"

 

1. Use HarvestDropsEvent from net.minecraftforge.event.world.BlockEvent

2. Subscribe to it and check if harvester is not null and is player (second is not that much needed).

3. If so, then check currently held item, if item == your item, then start dropping from droplist (which is also in event).

4. Also if you wanna do it this way remember to remove your code from item, because now it'll be in event.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Yes, it is certainly possible!

 

Everything extending from net.minecraft.block has a getHarvestLevel method, so you have all the pieces you need at your disposal already. Once again, I do not recommend continuing down this path, as you will be overriding existing universal methods (blocks have drop lists and drop items on their own) with your own methods (spawn items in world via unusual tool method). My prediction is that doing this will turn out to be more trouble than it's worth.

 

I will assume you have considered all this and a very good reason for doing it this way, so cheers and good luck!

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

    • OLXTOTO: Menikmati Sensasi Bermain Togel dan Slot dengan Aman dan Mengasyikkan Dunia perjudian daring terus berkembang dengan cepat, dan salah satu situs yang telah menonjol dalam pasar adalah OLXTOTO. Sebagai platform resmi untuk permainan togel dan slot, OLXTOTO telah memenangkan kepercayaan banyak pemain dengan menyediakan pengalaman bermain yang aman, adil, dan mengasyikkan. DAFTAR OLXTOTO DISINI <a href="https://imgbb.com/"><img src="https://i.ibb.co/GnjSVpx/daftar1-480x480.webp" alt="daftar1-480x480" border="0" /></a> Keamanan Sebagai Prioritas Utama Salah satu aspek utama yang membuat OLXTOTO begitu menonjol adalah komitmennya terhadap keamanan pemain. Dengan menggunakan teknologi enkripsi terkini, situs ini memastikan bahwa semua informasi pribadi dan keuangan para pemain tetap aman dan terlindungi dari akses yang tidak sah. Beragam Permainan yang Menarik Di OLXTOTO, pemain dapat menemukan beragam permainan yang menarik untuk dinikmati. Mulai dari permainan klasik seperti togel hingga slot modern dengan fitur-fitur inovatif, ada sesuatu untuk setiap selera dan preferensi. Grafik yang memukau dan efek suara yang mengagumkan menambah keseruan setiap putaran. Peluang Menang yang Tinggi Salah satu hal yang paling menarik bagi para pemain adalah peluang menang yang tinggi yang ditawarkan oleh OLXTOTO. Dengan pembayaran yang adil dan peluang yang setara bagi semua pemain, setiap taruhan memberikan kesempatan nyata untuk memenangkan hadiah besar. Layanan Pelanggan yang Responsif Tim layanan pelanggan OLXTOTO siap membantu para pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Dengan layanan yang ramah dan responsif, pemain dapat yakin bahwa mereka akan mendapatkan bantuan yang mereka butuhkan dengan cepat dan efisien. Kesimpulan OLXTOTO telah membuktikan dirinya sebagai salah satu situs terbaik untuk penggemar togel dan slot online. Dengan fokus pada keamanan, beragam permainan yang menarik, peluang menang yang tinggi, dan layanan pelanggan yang luar biasa, tidak mengherankan bahwa situs ini telah menjadi pilihan utama bagi banyak pemain. Jadi, jika Anda mencari pengalaman bermain yang aman, adil, dan mengasyikkan, jangan ragu untuk bergabung dengan OLXTOTO hari ini dan rasakan sensasi kemenangan!
    • Slot deposit dana adalah situs slot deposit dana yang juga menerima dari e-wallet lain seperti deposit via dana, ovo, gopay & linkaja terlengkap saat ini, sehingga para pemain yang tidak memiliki rekening bank lokal bisa tetap bermain slot dan terbantu dengan adanya fitur tersebut.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit dana adalah situs slot deposit dana minimal 5000 yang dijamin garansi super gacor dan gampang menang, dimana para pemain yang tidak memiliki rekening bank lokal tetap dalam bermain slot dengan melakukan deposit dana serta e-wallet lainnya seperti ovo, gopay maupun linkaja lengkap. Agar para pecinta slot di seluruh Indonesia tetap dapat menikmati permainan tanpa halangan apapun khususnya metode deposit, dimana ketersediaan cara deposit saat ini yang lebih beragam tentunya sangat membantu para pecinta slot.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit pulsa adalah situs slot deposit pulsa tanpa potongan apapun yang dijamin garansi terpercaya, dimana kamu bisa bermain slot dengan melakukan deposit pulsa dan tanpa dikenakan potongan apapun sehingga dana yang masuk ke dalam akun akan 100% utuh. Proses penarikan dana juga dijamin gampang dan tidak sulit sehingga kamu tidak perlu khawatir akan kemenangan yang akan kamu peroleh dengan sangat mudah jika bermain disini.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT PULSA TANPA POTONGAN ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit pulsa merupakan situs slot deposit pulsa tanpa potongan apapun yang dijamin 100% garansi bebas biaya dimana deposit pulsa yang masuk ke dalam akun tidak akan dikenakan potongan apapun sehingga para pemain tidak akan terbebani dan bisa memanfaatkan modal bermain mereka dengan lebih maksimal. Sebab slot deposit pulsa tanpa potongan ini bertujuan untuk membantu para pecinta slot yang gemar bermain tetapi terhalang oleh keterbatasan akses dan modal, yang maka dari itu kami hadirkan fasilitas terbaru ini.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT PULSA TANPA POTONGAN ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
  • Topics

×
×
  • Create New...

Important Information

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