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 modelNumberToFireAt;
public boolean cycleThroughModelsBeforeFiring;
public boolean setModelNumberWhenFullyLoaded;
public boolean rotateSideways;
public boolean rotateUpDown;
public boolean rotateStandHead;
@@ -60,6 +61,7 @@ public class SiegeEngine implements Cloneable {
public List<Integer> firingModelNumbers;
public int readyModelNumber;
public int nextModelNumber;
public int preFireModelNumber;
public SiegeEngineAmmoHolder ammoHolder;
// Optional variables
@@ -98,15 +100,16 @@ public class SiegeEngine implements Cloneable {
placementOffsetY = -1.125f;
readyModelNumber = customModelID;
modelNumberToFireAt = customModelID;
preFireModelNumber = customModelID;
firingModelNumbers = new ArrayList<Integer>();
ammoHolder = new SiegeEngineAmmoHolder();
//fuelItem = new ItemStack(Material.GUNPOWDER);
cycleThroughModelsBeforeFiring = false;
setModelNumberWhenFullyLoaded = false;
allowInvisibleStand = false;
shotAmount = 1;
ammoHolder.loadedFuel = maxFuel;
enabled = true;
cycleThroughModelsBeforeFiring = false;
rotateSideways = false;
rotateUpDown = 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) {
return;
}
if (living.getEquipment().getHelmet().getItemMeta().getCustomModelData() != readyModelNumber || ammoHolder.loadedProjectile == 0) {
if (player instanceof Player) {
((Player) player).sendMessage("§eCannot fire yet!");
}
return;
if (!setModelNumberWhenFullyLoaded) {
if (player instanceof Player) {
((Player) player).sendMessage("§eCannot fire yet!");
}
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.loadedProjectile = 0;
@@ -92,15 +92,7 @@ public class SiegeEngines extends JavaPlugin {
}
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
SiegeEngine trebuchet = new SiegeEngine("Trebuchet", Config.trebuchetProjectiles, new ItemStack(Material.STRING), 122);
// config options
@@ -126,21 +118,22 @@ public class SiegeEngines extends JavaPlugin {
definedSiegeEngines.put(trebuchet.readyModelNumber, trebuchet);
// 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
ballista.shotAmount = Config.ballistaShotAmount;
ballista.velocityPerFuel = Config.ballistaVelocityPerFuel;
ballista.maxFuel = Config.ballistaMaxFuel;
ballista.fuelItem = new ItemStack(Config.ballistaFuelItem);
ballista.projectiles = Config.ballistaProjectiles;
ballista.xOffset = 1;
ballista.yOffset = 1;
ballista.placementOffsetY = -0.75;
ballista.rotateStandHead = true;
ballista.rotateSideways = true;
ballista.setModelNumberWhenFullyLoaded = true;
ballista.readyModelNumber = 145;
ballista.modelNumberToFireAt = 143;
ballista.modelNumberToFireAt = 145;
ballista.preFireModelNumber = 143;
ballista.firingModelNumbers = new ArrayList<>(Arrays.asList(
143, 144, 145
));
@@ -1032,57 +1032,61 @@ public class ClickHandler implements Listener {
}
}
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
SiegeEngine siegeEngine = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
event.setCancelled(true);
ItemStack stack = equipment.fuelItem;
ItemStack stack = siegeEngine.fuelItem;
if (itemInHand.getType() == stack.getType()) {
if (equipment.canLoadFuel()) {
if (siegeEngine.canLoadFuel()) {
if (itemInHand.isSimilar(stack)) {
equipment.ammoHolder.loadedFuel += 1;
siegeEngine.ammoHolder.loadedFuel += 1;
stack.setAmount(1);
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.");
return;
}
if (itemInHand == null || itemInHand.getType() == Material.AIR
|| itemInHand.getType() == Config.controlItem) {
if (!pulledPropellantFromContainer(equipment.entity.getLocation(), equipment)) {
sendSiegeEngineHelpMSG(player, equipment);
if (!pulledPropellantFromContainer(siegeEngine.entity.getLocation(), siegeEngine)) {
sendSiegeEngineHelpMSG(player, siegeEngine);
return;
}
if (!pulledPropellantFromContainer(
equipment.entity.getLocation().getBlock().getRelative(0, -1, 0).getLocation(), equipment)) {
sendSiegeEngineHelpMSG(player, equipment);
siegeEngine.entity.getLocation().getBlock().getRelative(0, -1, 0).getLocation(), siegeEngine)) {
sendSiegeEngineHelpMSG(player, siegeEngine);
return;
}
if (!pulledPropellantFromContainer(
equipment.entity.getLocation().getBlock().getRelative(0, 1, 0).getLocation(), equipment)) {
sendSiegeEngineHelpMSG(player, equipment);
siegeEngine.entity.getLocation().getBlock().getRelative(0, 1, 0).getLocation(), siegeEngine)) {
sendSiegeEngineHelpMSG(player, siegeEngine);
return;
}
if (pulledAmmoFromContainer(equipment.entity.getLocation(), equipment)) {
if (pulledAmmoFromContainer(siegeEngine.entity.getLocation(), siegeEngine)) {
player.sendMessage("§eAdded ammunition to this Siege Engine.");
return;
}
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.");
return;
}
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.");
return;
}
}
if (equipment.fuelItem.isSimilar(itemInHand))
if (siegeEngine.fuelItem.isSimilar(itemInHand))
return;
for (ItemStack item : equipment.projectiles.keySet()) {
for (ItemStack item : siegeEngine.projectiles.keySet()) {
if (item.getType() == itemInHand.getType()) {
return;
}