Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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

Posted

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.

Posted

You know that onEntityCollidedWithBlock() is called every tick right?

You just can't kill the Minecraft fast enought to trigger the event only once.

I suggest using a boolean.

Posted

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.

Posted

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.

Posted

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.

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

    • Honestly, the forums are a back burner thing. Not many people use it. Best option is discord. I know that I haven't looked at the forums for more then admin tasks in quite a while. You're also best off not following tutorials which give you code. Knowing programming and reading the MC/Forge code yourself would be the best way to go.
    • on my last computer, i had a similar problem with forge/ neoforge mods but instead them launcher screen was black
    • I am trying to make a mod, all it is, a config folder that tells another mod to not require a dependency, pretty simple right.. well, I dont want whoever downloads my mod to have to download 4 other mods and then decide if they want 2 more that they kinda really need.. i want to make my mod basically implement all of these mods, i really dont care how it does it, ive tried putting them in every file location you can think of, ive downloaded intellij, mcreator, and tried vmware but thats eh (had it from school). I downloaded them in hopes theyd create the correct file i needed but honestly im only more lost now. I have gotten my config file to work, if i put all these mods into my own mods folder and the config file into the config and it works (unvbelievably) but i want to share this to everyone else, lets just say this mod will legitimately get 7M downloads.  I tried putting them in a run folder then having it create all the contents in that for a game (mods,config..etc) then i drop the mods in and all the sudden i cant even open the game, like it literally works with my own world i play on, but i cant get it to work on any coding platform, they all have like built in java versions you cant switch, its a nightmare. I am on 1.20.1 I need Java 17 (i dont think the specific versions of 17 matter) I have even tried recreating the mods i want to implement and deleting import things like net.adamsandler.themodsname and replacing it with what mine is. that only creates other problems, where im at right now is i got the thing to start opening then it crashes, closest ive gotten it, then it just says this  exception in thread "main" cpw.mods.niofs.union.unionfilesystem$uncheckedioexception: java.util.zip.zipexception: zip end header not found caused by: java.util.zip.zipexception: zip end header not found basically saying theres something wrong with my java.exe file, so i tried downloading so many different versions of java and putting them all in so many different spots, nothing, someone online says its just a mod that isnt built right so i put the mod into an editor and bunch of errors came up, id post it but i deleted it on accident, i just need help integrating mods
    • Vanilla 1.16.5 Crash Report [#L2KYKaK] - mclo.gs  
    • Hello, probably the last update, if anyone has the same problem or this can be of any help, the answer was pretty simple, textures started rendering just using a Tesselator instead of a VertexConsumer given by a MultibufferSource and a RenderType, pretty simple
  • Topics

×
×
  • Create New...

Important Information

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