Jump to content

[1.7.10] Kill a minecart without its drops


IceMetalPunk

Recommended Posts

I'm trying to kill a particular minecart, but without it dropping anything. (The reason is that I'm making a rail which destroys carts that travel over it, but with its own custom drops instead of the minecart's default drops.) I haven't been able to figure out how to do this. Whether I cal entity.setDead() or entity.killMinecart(), it always drops its own items. I've even tried setting entity.captureDrops=true before killing it, as the code seemed to suggest that would stop the drops, but it didn't.

 

How can I kill a minecart without any drops? (That includes killing container minecarts without them dropping their contents, too, by the way.)

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

I can't update to 1.8 as I'm trying to keep my mod compatible next to some popular mods that haven't updated yet. But it seems that wouldn't be what I'm looking for anyway; I need it to not drop *anything*, including the cart itself. This is true not only of container minecarts, but just regular minecarts as well, which don't even have that variable member.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

*EDIT* Wait, no, I'm not an idiot. Maybe. For some odd reason, the onEntityCollidedWithBlock() method is getting called twice per collision, both on the server. Why is it doing that? This is the code I'm using, in a custom class that extends BlockRailPowered:

 

	@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
	if (world.isRemote || !(entity instanceof EntityMinecart)) {
		return;
	}
	NBTTagCompound cartTags = (NBTTagCompound) entity.getEntityData().copy();
	ItemStack cartItem = ((EntityMinecart) entity).getCartItem();
	cartItem.stackTagCompound = cartTags;
	EntityItem droppedItem = new EntityItem(world, entity.posX, entity.posY, entity.posZ, cartItem);
	entity.setDead();
	world.spawnEntityInWorld(droppedItem);
	System.out.println("World is remote? "+world.isRemote);
}

 

As you can see, I'm outputting one message with the world's remote status, yet every collision, I'm getting two identical outputs, both saying the world is not remote, but both spawning item entities. What's with the doubling?

 

Previous post below...

>_< Wait, never mind. It turns out, I'm an idiot. I posted this after testing with a plain minecart with no inventory, and I thought it was dropping itself because it was dropping two minecarts, whereas the custom drops were supposed to be just one. After you said calling .setDead() on a regular minecart shouldn't drop anything, I did a bit more testing, and I realized I was making the stupid mistake of spawning my custom itemstacks on both the server and the client, which is why there were two...so the problem I thought I had didn't actually exist >_<

 

Sorry! I do still need to make sure container carts don't drop their items, though, so I'll try to make it work with reflection and if I have any trouble, I'll ask about it here. Thanks for the help!

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Not sure why that is, but you shouldn't really care about it.

Um...it's extremely important. The code is designed to make a copy of the minecart in item form--in other words, to "break it" without its components (i.e. cart and chest, cart and hopper, etc.) or its inventory contents flying everywhere. If that code is running twice per collision, it becomes an inventory duplicator, where players can roll a minecart chest full of items over it and get twice the inventory back, then rinse and repeat. It's a game-breaking bug... I don't know why it's happening, but it definitely needs to be fixed before I can release the mod.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

So even if you kill the Minecart on the first collision it is called again? You can easily work around that by only interacting with the Minecart if

entity.isDead

is false.

D'oh, so simple! xD

 

So now I've fixed that problem, and run into another. I'm trying to copy the cart's NBT data into the dropped ItemStack's stackTagCompound. If I understand correctly, that should mean if it breaks a container cart, it'll drop a container cart item which, when placed, will have the same contents the original cart had, yes? And yet, though I'm not getting any errors, the dropped cart is always empty when placed, even if the original cart had contents. I thought it'd be as simple as using .getEntityData().copy() on the minecart and setting the ItemStack's stackTagCompound to that, but it didn't work. So then I tried creating a new NBTTagCompound and writing the minecart's NBT data to it, then setting *that* to stackTagCompound...still nothing.

 

Here's the current code; why isn't it copying the contents properly, and how can I make it do that?

 

@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
	if (world.isRemote || !(entity instanceof EntityMinecart)) {
		return;
	}
	if (entity.isDead) {
		return;
	}
	NBTTagCompound cartTags = new NBTTagCompound();
	entity.writeToNBT(cartTags);
	ItemStack cartItem = ((EntityMinecart) entity).getCartItem();
	cartItem.stackSize = 1;
	cartItem.stackTagCompound = cartTags;
	System.out.println(cartItem.stackTagCompound); // tags print out perfectly fine, including contents
	EntityItem droppedItem = new EntityItem(world, entity.posX, entity.posY, entity.posZ, cartItem);

	if (entity instanceof EntityMinecartContainer) {
		try {
			Field dropConts = EntityMinecartContainer.class.getDeclaredField("dropContentsWhenDead");
			dropConts.setAccessible(true);
			dropConts.setBoolean(entity, false);
		}
		catch (NoSuchFieldException e) {
			System.out.println("No such field!");
		}
		catch (SecurityException e) {
			System.out.println("Security exception!");
		}
		catch (IllegalArgumentException e) {
			System.out.println("Illegal Argument!");
		}
		catch (IllegalAccessException e) {
			System.out.println("Illegal Access Exception!");
		}
	}

	entity.setDead();
	world.spawnEntityInWorld(droppedItem);
}

 

If the tags print fine, why don't they get set when I place the cart back down? Why is the inventory lost?

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Ah. I was under the impression that setting the item stack's stackTagCompound would cause those tags to be used on the item placed, regardless of what the item was, where applicable. Okay, I'll try doing it with event handlers, then, and hopefully I can make this work. Thanks again.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Ah. I was under the impression that setting the item stack's stackTagCompound would cause those tags to be used on the item placed, regardless of what the item was, where applicable.

 

Because

1) Minecraft totally has that behavior natively (hint: item stack NBT is used for hardly nothing: enchantments and nametags and that's about it).

2) That's totally how code works: reading arbitrary data tags and knowing what the fuck to do with them.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

    • Slot Gacor >> Mudah Maxwin Bersama Djarum4D   Slot gacor adalah salah satu jenis permainan judi online yang sangat populer di Indonesia. Bermain slot gacor berarti bermain permainan slot dengan kemungkinan keluaran yang lebih tinggi daripada slot tradisional. Dalam artikel ini, kami akan membahas secara lengkap tentang slot gacor, mulai dari pengertian dasar, cara bermain, strategi pemain, serta aspek keamanan dan etika dalam bermain.
    • DAFTAR & LOGIN TAYO4D   Slot gacor online adalah permainan yang menarik dan menghasilkan keuntungan untuk banyak pemain di seluruh dunia. Dalam artikel ini, kita akan membahas tentang cara memilih dan memainkan slot gacor online terbaik.
    • Tayo4D : Bandar Online Togel Dan Slot Terbesar Di Indonesia     Pemain taruhan Tayo4D yang berkualitas memerlukan platform yang aman, terpercaya, dan mudah digunakan. Dalam era teknologi ini, banyak situs online yang menawarkan layanan taruhan togel 4D, tetapi memilih yang tepat menjadi tuntas. Berikut adalah cara untuk membuat artikel yang membahas tentang situs online terpercaya untuk permainan taruhan togel 4D.  
    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam perjudian dunia berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
  • Topics

×
×
  • Create New...

Important Information

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