Jump to content

[1.7.10] Spawning A Falling Entity


Recommended Posts



So I just asked a question about making a bomb bay. It was a bad question, so let me rephrase it.


Now, I'm trying to make a bomb bay. That is, essentially, just a block which spawns a bomb entity. I want the entity to spawn where the player is, and then fall down until it hits the ground. To make it spawn the entity, I want the player to press a key, and then have the entity spawn.


Now, I've already set up the key press. When the "B" key is pressed, my mod detects it. Now I need to make a block which has an inventory (just like a chest), which the player can put bombs into. When there are bombs in it, and the key is pressed, I want a bomb to spawn, and then fall down to the ground.


Now, I don't know how to spawn an entity at the player, and then have it fall down. I've made the entity, which explodes on impact, but I don't know how to make it fall.


Something to bear in mind, here, is that I'm working on an airship mod. it works, and you can fly airships around, so when the bomb falls it will be falling from an airship (just to be clear that I'm not making the player suddenly explode when the key is pressed).


So, my question is this: how can I make a method which checks to see if there is any bombs in the bomb bay, and then spawn an entity at the player, which will then fall?


Thanks :)

Link to comment
Share on other sites

I don't know if this is the right kind of mod to write if you still have to find out how you detect a keypress.

Nonetheless, plenty of info on all sort of sides:





Basic Java:



A lwjgl example:




Link to comment
Share on other sites

It's not really about the keypress itself (I didn't really word this question very well, to be honest), I've actually got controls for moving the ship set up already, I'm just not sure if I should just call the method which drops the bomb entity whenever the key is pressed, or whether I should detect the key and then use that inside of another method (or even something else). My real issue here is with getting the bomb to drop, I can detect the key fine. I guess that I should just make an entity which starts with a negative y velocity, or something along those lines. But, apart from that, I don't really know how to get the bomb to fall when it's spawned.

Link to comment
Share on other sites

It's really simple actually.

First of all, make your bomb a tileentity, I think that's a given.

In the update method just check a boolean if it should fall or not.

Then set a control panel(for instance, the helm) from where the player can operate the bomb.

I also take it the ship itself is a tileentity and the helm is a part of it.

Check in the update method of the ship if the player operating it(like in a minecart) is pressing a particular key, or you can write a custom method outside of the tileupdate. This is generally better since there is more code optimalization. In any case, check in the method if your particular key(or key bind) is down.

If it is down set the boolean of the bomb to true. How you do that will be most likely with reflection but I can't tell you how to get the bomb as I don't know if you have one or multiple bombs placed. It will most likely be a case of scanning the area for one.

Once the boolean has been set to true, simply start decreasing the y axis value. However you'll need to get it smooth. Have a look at the code of  an item that drops to the ground.

And the cannons aren't any more difficult. The only difference is calculating the rotation and trajectory of the cannon and bullet.

The rotation is the same as if you would animate a mob. Simply seperate it from the shipmodel, rotate it with opengl and translate the xyz coordinates to where you want it on the ship. The most difficult part is the arc. You'll have to fiddle around a bit with that but all you really have to do is look up how to calculate trajectories of objects. There are plenty of tutorials out there for all sorts of games.


Link to comment
Share on other sites

Alright, I have the entity bomb. Now, as opposed to having a button in the helm GUI, I have the keypress set up already. You said to make a boolean, which decreases the entity's y position when true, which I can understand fine (or at least I think so). I can just use a for loop for this.


To actually spawn the bomb (and to make things a little less complicated a this point), I thought of just using the player's inventory to hold the bombs. So, here's the code I added to my update method (where I handle all of my controls) to spawn it:


if(keys.bombkey.getIsKeyPressed()) {
			if(entityplayer.capabilities.isCreativeMode || entityplayer.inventory.consumeInventoryItem(Skyline.bomb)) {
				if(!world.isRemote) {
					world.spawnEntityInWorld(new EntityBomb(world, entityplayer));
					decreaseEntityBombYPos = true;


And, then, I'd have to make the loop which decreases the y position when this is true. Then, once the bomb exploded, would I have to set it to false for the next bomb? Or can it just be left to true so that they will fall anyway?

Link to comment
Share on other sites

Well, most of this based on how you design it really.


First, I want you to understand this is simply how I would do something. This doesn't mean this is the only correct way.

And actually, this should be your homework instead of mine.


It seems you do not understand what a tile entity (you should if want to add a complicated thing to minecraft). A tile entity creates an object for each separate block.

This is opposed to a normal block class which uses the same object for each block. This means a tile entity is more flexible but also takes more memory and cpu.

You can also save data particular to that block in the nbt of a tile entity. And each tile entity has a loop built in (a method called updateEntity) which is called every 1/20th of a second.


//Just a note, I changed something from my previous comment, this way is better.

//And I am also not accounting for the physical blocks, I assume you have a way of dealing with those.


We have(or I assume you have) at least 1 tileentity. The ship. Its update method handles everything that happens automatically such as movement by wind for instance. It also has a keydown event method. This method only fires if the player controlling the ship(once again, look at horses, minecarts etc) pressed a key.

The ship also has an inventory which can be loaded by, for instance placing bombs in slots in a gui, right clicking certain spots in the ship etc.

The ship also has a custom render class to render its object. In there you render the ship and you also check how many bombs there are in the inventory of the ship.

If the ship has at least 1 bomb it will render a big one above the hatch to drop bombs, else, for every bomb added it will render extras in shelves.

(And if you want to be really fancy you even let the big bomb disappear for a while after you've dropped the bomb to simulate the reloading).

So, the player controls the ship and presses a key. Our previously created function checks for the correct one and if correct will look into the inventory of the ship(a byte for instance) and if it more than 0 it will spawn above the hatch an explosive and decrement our byte(So the ship has one bomb less in the inventory and thus renders one less).

From this point onwards the bomb exists as a separate entity with its own loop. In that loop it decrements a value which renders the bomb on the y axis. Either look at the item or sand class or do some trickery with a loop that counts down the y value of a block(not the coordinate Y but the one that places the block points minY - maxY etc) and if it hits the bottom of the block you go to the next one and do the same. Then simply use that value in your render class to translate this together with the Y coordinate. It's a bit tricky though so make sure to have a good look at the sand class if it doesn't use a better method

(I didn't yet so I can't tell you how it works)


It falls until you tell it to stop(for instance if it collides with something). At that point you tell it to explode and you delete the tileentity(and block). Case Closed. The bomb is dropped and high above in the ship another one is ready to be dropped.

And if you want to drop several behind each other simply use an if statement and counter in the updateEntity method of the ship that will drop the bomb. Check if it has bombs, the counter is dividable (% in java) by a certain number (such as 100. E.g. every 100 1/20th seconds it will drop one), and if the playerdrop boolean is true(you'll need the gap between your key event method and the update method). If it is true, set counter to 0 and start counting. Etc.


But honestly, you should be able to come up with this easily if you want to make objects that can travel large distances without lagging in minecraft.

Now, why did I even bother writing this all out?


EDIT: you can obviously substitute the ships inventory with that of the controlling player. Simply use that to check how many bombs need to be rendered, dropped etc.

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.

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.

  • Create New...

Important Information

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