fixed unbreakable mortar, buggy brewing stands, added blast sound, and fixed interaction code

master
Soper Aylamo 2021-05-04 11:23:29 -04:00
parent 65f0a2fa1b
commit 501bd77d4e
Signed by: Soper
GPG Key ID: A27AC885ACC3BEAE
3 changed files with 14 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import org.bukkit.block.Container;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -23,13 +24,18 @@ public class MortarInteract implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack item = player.getInventory().getItemInMainHand(); ItemStack item = player.getInventory().getItemInMainHand();
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
if(block == null) return;
if(block.getBlockData().getMaterial() == Material.BREWING_STAND){ if(block.getBlockData().getMaterial() == Material.BREWING_STAND){
Nameable brewingStandMortar = (Nameable) event.getClickedBlock().getState(); Nameable brewingStandMortar = (Nameable) event.getClickedBlock().getState();
String blockName = brewingStandMortar.getCustomName(); String blockName = brewingStandMortar.getCustomName();
if(blockName == null) return;
if(blockName.equals(ChatColor.GRAY + "Basic Mortar") || blockName.equals(ChatColor.GRAY + "Mortar")){ if(blockName.equals(ChatColor.GRAY + "Basic Mortar") || blockName.equals(ChatColor.GRAY + "Mortar")){
if(event.getAction() == Action.RIGHT_CLICK_BLOCK) event.setCancelled(true);
if((item.getType() == Material.ARROW) && item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals(ChatColor.GRAY + "Shell")){ if((item.getType() == Material.ARROW) && item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals(ChatColor.GRAY + "Shell")){
MortarHandler mortarHandler = new MortarHandler(new Mortar(block)); MortarHandler mortarHandler = new MortarHandler(new Mortar(block));
mortarHandler.fireShell(new Shell(item)); player.sendMessage(mortarHandler.fireShell(new Shell(item)));
if(item.getAmount() > 1) item.setAmount(item.getAmount()-1);
else player.getInventory().setItemInMainHand(null);
} }
} }
} }

View File

@ -8,7 +8,7 @@ import org.bukkit.block.Container;
public class Mortar { public class Mortar {
Location location; public Location location;
public static String BASIC_MORTAR_NAME = ChatColor.GRAY + "Basic Mortar"; public static String BASIC_MORTAR_NAME = ChatColor.GRAY + "Basic Mortar";
public static String NORMAL_MORTAR_NAME = ChatColor.GRAY + "Mortar"; public static String NORMAL_MORTAR_NAME = ChatColor.GRAY + "Mortar";
@ -23,7 +23,10 @@ public class Mortar {
public double velocityMultiplier; //Multiplier applied to the shell's velocity public double velocityMultiplier; //Multiplier applied to the shell's velocity
public boolean incendiaryCapable; //Is the mortar fit to fire an incendiary-type shell? public boolean incendiaryCapable; //Is the mortar fit to fire an incendiary-type shell?
public Block block;
public Mortar(Block mortar){ public Mortar(Block mortar){
block = mortar;
location = mortar.getLocation(); location = mortar.getLocation();
Nameable brewingStandMortar = (Nameable) mortar.getState(); Nameable brewingStandMortar = (Nameable) mortar.getState();
String mortarName = brewingStandMortar.getCustomName(); String mortarName = brewingStandMortar.getCustomName();

View File

@ -11,8 +11,9 @@ public class MortarHandler {
this.mortar = mortar; this.mortar = mortar;
} }
public void fireShell(Shell shell){ public String /*void*/ fireShell(Shell shell){
mortar.block.getWorld().playSound(mortar.location, "entity.generic.explode", 1, 1.5F);
return "DEBUG: Shell has been fired.";
} }
} }