ballista WIP

This commit is contained in:
ShermansWorld committed 2024-01-15 16:08:06 -05:00
1 parent ff723d61c5
commit 56743deb3e
3 files changed
+44 -35

No files matched your search

@@ -51,6 +51,7 @@ public class SiegeEngine implements Cloneable {
public int millisecondsToLoad; public int millisecondsToLoad;
public int modelNumberToFireAt; public int modelNumberToFireAt;
public boolean cycleThroughModelsBeforeFiring; public boolean cycleThroughModelsBeforeFiring;
public boolean setModelNumberWhenFullyLoaded;
public boolean rotateSideways; public boolean rotateSideways;
public boolean rotateUpDown; public boolean rotateUpDown;
public boolean rotateStandHead; public boolean rotateStandHead;
@@ -60,6 +61,7 @@ public class SiegeEngine implements Cloneable {
public List<Integer> firingModelNumbers; public List<Integer> firingModelNumbers;
public int readyModelNumber; public int readyModelNumber;
public int nextModelNumber; public int nextModelNumber;
public int preFireModelNumber;
public SiegeEngineAmmoHolder ammoHolder; public SiegeEngineAmmoHolder ammoHolder;
// Optional variables // Optional variables
@@ -98,15 +100,16 @@ public class SiegeEngine implements Cloneable {
placementOffsetY = -1.125f; placementOffsetY = -1.125f;
readyModelNumber = customModelID; readyModelNumber = customModelID;
modelNumberToFireAt = customModelID; modelNumberToFireAt = customModelID;
preFireModelNumber = customModelID;
firingModelNumbers = new ArrayList<Integer>(); firingModelNumbers = new ArrayList<Integer>();
ammoHolder = new SiegeEngineAmmoHolder(); ammoHolder = new SiegeEngineAmmoHolder();
//fuelItem = new ItemStack(Material.GUNPOWDER); //fuelItem = new ItemStack(Material.GUNPOWDER);
cycleThroughModelsBeforeFiring = false; cycleThroughModelsBeforeFiring = false;
setModelNumberWhenFullyLoaded = false;
allowInvisibleStand = false; allowInvisibleStand = false;
shotAmount = 1; shotAmount = 1;
ammoHolder.loadedFuel = maxFuel; ammoHolder.loadedFuel = maxFuel;
enabled = true; enabled = true;
cycleThroughModelsBeforeFiring = false;
rotateSideways = false; rotateSideways = false;
rotateUpDown = true; rotateUpDown = true;
rotateStandHead = true; rotateStandHead = true;
@@ -250,12 +253,21 @@ public class SiegeEngine implements Cloneable {
if (living == null || living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) { if (living == null || living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) {
return; return;
} }
if (living.getEquipment().getHelmet().getItemMeta().getCustomModelData() != readyModelNumber || ammoHolder.loadedProjectile == 0) { if (living.getEquipment().getHelmet().getItemMeta().getCustomModelData() != readyModelNumber || ammoHolder.loadedProjectile == 0) {
if (player instanceof Player) { if (!setModelNumberWhenFullyLoaded) {
((Player) player).sendMessage("§eCannot fire yet!"); if (player instanceof Player) {
} ((Player) player).sendMessage("§eCannot fire yet!");
return; }
return;
} else {
if (setModelNumberWhenFullyLoaded && living.getEquipment().getHelmet().getItemMeta().getCustomModelData() != preFireModelNumber) {
if (player instanceof Player) {
((Player) player).sendMessage("§eCannot fire yet!");
}
return;
}
}
} }
ammoHolder.loadedFuel = 0; ammoHolder.loadedFuel = 0;
ammoHolder.loadedProjectile = 0; ammoHolder.loadedProjectile = 0;
@@ -92,15 +92,7 @@ public class SiegeEngines extends JavaPlugin {
} }
public static void AddDefaults() { public static void AddDefaults() {
// Predefined projectiles with default values
//SiegeEngineProjectile fireballShot = EntityProjectile.getDefaultFireballShot();
//SiegeEngineProjectile stoneShot = ExplosiveProjectile.getDefaultStoneShot();
//SiegeEngineProjectile repeatingShot = ExplosiveProjectile.getDefaultRepeatingShot();
//SiegeEngineProjectile breachShot = ExplosiveProjectile.getDefaultBreachShot();
//SiegeEngineProjectile scatterShot = EntityProjectile.getDefaultScatterShot();
//SiegeEngineProjectile rocketShot = FireworkProjectile.getDefaultRocketShot(SiegeEnginesUtil.DEFAULT_ROCKET);
// Trebuchet // Trebuchet
SiegeEngine trebuchet = new SiegeEngine("Trebuchet", Config.trebuchetProjectiles, new ItemStack(Material.STRING), 122); SiegeEngine trebuchet = new SiegeEngine("Trebuchet", Config.trebuchetProjectiles, new ItemStack(Material.STRING), 122);
// config options // config options
@@ -126,21 +118,22 @@ public class SiegeEngines extends JavaPlugin {
definedSiegeEngines.put(trebuchet.readyModelNumber, trebuchet); definedSiegeEngines.put(trebuchet.readyModelNumber, trebuchet);
// Ballista // Ballista
SiegeEngine ballista = new SiegeEngine("Ballista", Config.ballistaProjectiles, new ItemStack(Material.GUNPOWDER), 145); SiegeEngine ballista = new SiegeEngine("Ballista", Config.ballistaProjectiles, new ItemStack(Material.STRING), 145);
// config options // config options
ballista.shotAmount = Config.ballistaShotAmount; ballista.shotAmount = Config.ballistaShotAmount;
ballista.velocityPerFuel = Config.ballistaVelocityPerFuel; ballista.velocityPerFuel = Config.ballistaVelocityPerFuel;
ballista.maxFuel = Config.ballistaMaxFuel; ballista.maxFuel = Config.ballistaMaxFuel;
ballista.fuelItem = new ItemStack(Config.ballistaFuelItem); ballista.fuelItem = new ItemStack(Config.ballistaFuelItem);
ballista.projectiles = Config.ballistaProjectiles; ballista.projectiles = Config.ballistaProjectiles;
ballista.xOffset = 1; ballista.xOffset = 1;
ballista.yOffset = 1; ballista.yOffset = 1;
ballista.placementOffsetY = -0.75; ballista.placementOffsetY = -0.75;
ballista.rotateStandHead = true; ballista.rotateStandHead = true;
ballista.rotateSideways = true; ballista.rotateSideways = true;
ballista.setModelNumberWhenFullyLoaded = true;
ballista.readyModelNumber = 145; ballista.readyModelNumber = 145;
ballista.modelNumberToFireAt = 143; ballista.modelNumberToFireAt = 145;
ballista.preFireModelNumber = 143;
ballista.firingModelNumbers = new ArrayList<>(Arrays.asList( ballista.firingModelNumbers = new ArrayList<>(Arrays.asList(
143, 144, 145 143, 144, 145
)); ));
@@ -1032,57 +1032,61 @@ public class ClickHandler implements Listener {
} }
} }
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) { if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId()); SiegeEngine siegeEngine = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
event.setCancelled(true); event.setCancelled(true);
ItemStack stack = equipment.fuelItem; ItemStack stack = siegeEngine.fuelItem;
if (itemInHand.getType() == stack.getType()) { if (itemInHand.getType() == stack.getType()) {
if (equipment.canLoadFuel()) { if (siegeEngine.canLoadFuel()) {
if (itemInHand.isSimilar(stack)) { if (itemInHand.isSimilar(stack)) {
equipment.ammoHolder.loadedFuel += 1; siegeEngine.ammoHolder.loadedFuel += 1;
stack.setAmount(1); stack.setAmount(1);
player.getInventory().removeItem(stack); player.getInventory().removeItem(stack);
sendSiegeEngineHelpMSG(player, equipment); sendSiegeEngineHelpMSG(player, siegeEngine);
// If fully loaded && requires change in animation when loaded (i.e. ballista)
if (!siegeEngine.canLoadFuel() && siegeEngine.setModelNumberWhenFullyLoaded) {
SiegeEnginesUtil.UpdateEntityIdModel(siegeEngine.entity, siegeEngine.preFireModelNumber, siegeEngine.worldName);
}
} }
} }
} }
if (pulledHeldAmmoFromPlayer(player, equipment)) { if (pulledHeldAmmoFromPlayer(player, siegeEngine)) {
player.sendMessage("§eAdded ammunition to this Siege Engine."); player.sendMessage("§eAdded ammunition to this Siege Engine.");
return; return;
} }
if (itemInHand == null || itemInHand.getType() == Material.AIR if (itemInHand == null || itemInHand.getType() == Material.AIR
|| itemInHand.getType() == Config.controlItem) { || itemInHand.getType() == Config.controlItem) {
if (!pulledPropellantFromContainer(equipment.entity.getLocation(), equipment)) { if (!pulledPropellantFromContainer(siegeEngine.entity.getLocation(), siegeEngine)) {
sendSiegeEngineHelpMSG(player, equipment); sendSiegeEngineHelpMSG(player, siegeEngine);
return; return;
} }
if (!pulledPropellantFromContainer( if (!pulledPropellantFromContainer(
equipment.entity.getLocation().getBlock().getRelative(0, -1, 0).getLocation(), equipment)) { siegeEngine.entity.getLocation().getBlock().getRelative(0, -1, 0).getLocation(), siegeEngine)) {
sendSiegeEngineHelpMSG(player, equipment); sendSiegeEngineHelpMSG(player, siegeEngine);
return; return;
} }
if (!pulledPropellantFromContainer( if (!pulledPropellantFromContainer(
equipment.entity.getLocation().getBlock().getRelative(0, 1, 0).getLocation(), equipment)) { siegeEngine.entity.getLocation().getBlock().getRelative(0, 1, 0).getLocation(), siegeEngine)) {
sendSiegeEngineHelpMSG(player, equipment); sendSiegeEngineHelpMSG(player, siegeEngine);
return; return;
} }
if (pulledAmmoFromContainer(equipment.entity.getLocation(), equipment)) { if (pulledAmmoFromContainer(siegeEngine.entity.getLocation(), siegeEngine)) {
player.sendMessage("§eAdded ammunition to this Siege Engine."); player.sendMessage("§eAdded ammunition to this Siege Engine.");
return; return;
} }
if (pulledAmmoFromContainer( if (pulledAmmoFromContainer(
equipment.entity.getLocation().getBlock().getRelative(0, -1, 0).getLocation(), equipment)) { siegeEngine.entity.getLocation().getBlock().getRelative(0, -1, 0).getLocation(), siegeEngine)) {
player.sendMessage("§eAdded ammunition to this Siege Engine."); player.sendMessage("§eAdded ammunition to this Siege Engine.");
return; return;
} }
if (pulledAmmoFromContainer( if (pulledAmmoFromContainer(
equipment.entity.getLocation().getBlock().getRelative(0, 1, 0).getLocation(), equipment)) { siegeEngine.entity.getLocation().getBlock().getRelative(0, 1, 0).getLocation(), siegeEngine)) {
player.sendMessage("§eAdded ammunition to this Siege Engine."); player.sendMessage("§eAdded ammunition to this Siege Engine.");
return; return;
} }
} }
if (equipment.fuelItem.isSimilar(itemInHand)) if (siegeEngine.fuelItem.isSimilar(itemInHand))
return; return;
for (ItemStack item : equipment.projectiles.keySet()) { for (ItemStack item : siegeEngine.projectiles.keySet()) {
if (item.getType() == itemInHand.getType()) { if (item.getType() == itemInHand.getType()) {
return; return;
} }