Hi there, i want to make a molotov cocktail in minecraft. It is an XP bottle and if you throw it and it hits the ground there will be fire in a radius of... lets say 2. Then after a couple of seconds i want it to remove the fire. Can someone explain me on how to make this ? I do not have any code yet Thanks!
You would probably be using the ProjectileHitEvent, when it hits the ground you could check for all the blocks around them and set the air ones with the lowest y coordinate on fire and save those blocks, then create a scheduled task to set those blocks back to air
You could throw it and check when it hits the ground (using repeating task), create fire and keep it for a while using a repeating task and also check in the repeating task which creates the fire effect if there are players within a certain region and set them on fire. And, poof, you've your molotov
This might have errors.. Just made it on my notepad on the laptop.. Hope it kinda works.. Code:java public static final int RADIUS = 3;public static final int TICKS = 60; @EventHandlerpublic void onMolotovImpact(ExpBottleEvent event) { event.setExperience(0); Location center = event.getEntity().getLocation(); final List<Block> burn = new ArrayList<Block>(); int y = event.getEntity().getLocation().getBlockY(); for (x = -RADIUS; x <= RADIUS; x++) { for (z = -RADIUS; z <= RADIUS; z++) { Block block = event.getEntity().getWorld().getBlockAt(x, y, z); if (block.getType() != Material.AIR) continue; block.setType(Material.FIRE); burn.add(block); } } Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { @Override public void run() { for (Block block : burn) if (block.getType() == Material.FIRE) block.setType(Material.AIR); } }, TICKS);} SuppaTim stink123456 There is an ExpBottleEvent. It is fired when an ExpBottle hits the ground. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
stink123456 Yes of course, but you cannot control the Exp dropped with the event. ExpBottleEvent.setExperience() can.
Slikey Hi, sorry that i am replying that late but i got this now: Code:java package me.Weszzz.SurviveIt; import java.util.ArrayList;import java.util.List; import org.bukkit.Bukkit;import org.bukkit.Location;import org.bukkit.Material;import org.bukkit.block.Block;import org.bukkit.event.EventHandler;import org.bukkit.event.entity.ExpBottleEvent; public class Molotov { public static final int RADIUS = 3; public static final int TICKS = 60; @EventHandler public void onMolotovImpact(ExpBottleEvent event) { event.setExperience(0); Location center = event.getEntity().getLocation(); final List<Block> burn = new ArrayList<Block>(); int y = event.getEntity().getLocation().getBlockY(); for (x = -RADIUS; x <= RADIUS; x++) { for (z = -RADIUS; z <= RADIUS; z++) { Block block = event.getEntity().getWorld().getBlockAt(x, y, z); if (block.getType() != Material.AIR) continue; block.setType(Material.FIRE); burn.add(block); } } Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { @Override public void run() { for (Block block : burn) if (block.getType() == Material.FIRE) block.setType(Material.AIR); } }, TICKS); }} But on line 24, 25, 26 and 34 i get errors. The errors are: Line 24: Multiple markers at this line - x cannot be resolved to a variable - x cannot be resolved to a variable - x cannot be resolved to a variable Line 25: Multiple markers at this line - z cannot be resolved to a variable - z cannot be resolved to a variable - z cannot be resolved to a variable Line 26: Multiple markers at this line - z cannot be resolved to a variable - x cannot be resolved to a variable Line 34: plugin cannot be resolved to a variable Could you help me with this ? Thanks! Slikey I already fixed the errors on line 24, 25 and 26. The only error now is on line 34. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Slikey I did that and now i got this in my Molotov class: Code:java package me.Weszzz.SurviveIt; import java.util.ArrayList;import java.util.List; import org.bukkit.Bukkit;import org.bukkit.Location;import org.bukkit.Material;import org.bukkit.block.Block;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.entity.ExpBottleEvent; public class Molotovimplements Listener { private test plugin; public Molotov(test instance) { this.plugin = instance; } public static final int RADIUS = 3; public static final int TICKS = 60; @EventHandler public void onMolotovImpact(ExpBottleEvent event) { event.setExperience(0); Location center = event.getEntity().getLocation(); final List<Block> burn = new ArrayList<Block>(); int x = event.getEntity().getLocation().getBlockX(); int y = event.getEntity().getLocation().getBlockY(); int z = event.getEntity().getLocation().getBlockZ(); for (x = -RADIUS; x <= RADIUS; x++) { for (z = -RADIUS; z <= RADIUS; z++) { Block block = event.getEntity().getWorld().getBlockAt(x, y, z); if (block.getType() != Material.AIR) continue; block.setType(Material.FIRE); burn.add(block); } } Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { @Override public void run() { for (Block block : burn) if (block.getType() == Material.FIRE) block.setType(Material.AIR); } }, TICKS); }} In my main class i did this: Code:java this.getServer().getPluginManager().registerEvents(new Molotov(this), this); But now if i throw a Bottle 'O Enchanting and it lands nothing happens.. Sometimes i hear the fire sound but i see no fire. Whats wrong ?
Weszzz you don't set the position right Code:java int posX = event.getEntity().getLocation().getBlockX(); int posY = event.getEntity().getLocation().getBlockY(); int posZ = event.getEntity().getLocation().getBlockZ(); for (x = -RADIUS; x <= RADIUS; x++) { for (z = -RADIUS; z <= RADIUS; z++) { Block block = event.getEntity().getWorld().getBlockAt(posX + x, y, posZ + z); if (block.getType() != Material.AIR) continue; block.setType(Material.FIRE); burn.add(block); } }