Skip to content

Commit

Permalink
Update TurretManager.java
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 committed Sep 10, 2024
1 parent b20afb2 commit 42e8730
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/main/java/com/snowleopard1863/APTurrets/TurretManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void mount(Player player, @NotNull Location signPos) {
player.teleport(signPos);

// Effects to add zoom and lock a player from jumping
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 1000000, 6));
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000000, 200));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOWNESS, 1000000, 6));
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP_BOOST, 1000000, 200));
}

public void demount(Player player, @Nullable Location signPos) {
Expand All @@ -90,8 +90,8 @@ public void demount(Player player, @Nullable Location signPos) {
}

// Remove potion effects and set their walking speed back to normal
player.removePotionEffect(PotionEffectType.JUMP);
player.removePotionEffect(PotionEffectType.SLOW);
player.removePotionEffect(PotionEffectType.JUMP_BOOST);
player.removePotionEffect(PotionEffectType.SLOWNESS);
}

public void fire(Player player) {
Expand All @@ -115,7 +115,7 @@ public void fire(Player player) {
if (runRaycast(player))
return;

Arrow arrow = launchArrow(player);
Arrow arrow = launchArrow(player, Config.TurretAmmo); // TODO: Support tags
arrow.setCritical(true);

World world = player.getWorld();
Expand All @@ -124,12 +124,12 @@ public void fire(Player player) {
}

@NotNull
private Arrow launchArrow(Player player) {
private Arrow launchArrow(Player player, ItemStack item) {
Arrow arrow;
try {
ServerPlayer nmsPlayer = (ServerPlayer) player.getClass().getMethod("getHandle").invoke(player);
ServerLevel nmsWorld = nmsPlayer.getLevel();
net.minecraft.world.entity.projectile.Arrow nmsArrow = new net.minecraft.world.entity.projectile.Arrow(nmsWorld, nmsPlayer);
ServerLevel nmsWorld = nmsPlayer.serverLevel();
net.minecraft.world.entity.projectile.Arrow nmsArrow = new net.minecraft.world.entity.projectile.Arrow(nmsWorld, nmsPlayer, (net.minecraft.world.item.ItemStack) item.getClass().getMethod("getHandle").invoke(item));
nmsArrow.setNoGravity(true);
nmsWorld.addFreshEntity(nmsArrow);
arrow = (Arrow) nmsArrow.getBukkitEntity();
Expand All @@ -140,7 +140,6 @@ private Arrow launchArrow(Player player) {
arrow.setShooter(player);
Location offset = player.getLocation().add(player.getLocation().getDirection().multiply(4));
arrow.setVelocity(offset.getDirection().multiply(Config.ArrowVelocity));
arrow.setBounce(false);
arrow.setMetadata("isTurretBullet", new FixedMetadataValue(TurretsMain.getInstance(), true));
arrow.setKnockbackStrength(Config.KnockbackStrength);
double rand = Math.random();
Expand All @@ -157,7 +156,7 @@ private boolean takeAmmo(Player player) {
Block adjacentBlock = getBlockSignAttachedTo(signBlock);
if (adjacentBlock instanceof InventoryHolder) {
Inventory i = ((InventoryHolder) adjacentBlock.getState()).getInventory();
if (i.containsAtLeast(new ItemStack(Config.TurretAmmo), 1)) {
if (i.containsAtLeast(Config.TurretAmmo, 1)) {
i.remove(Config.TurretAmmo);
return true;
}
Expand Down

0 comments on commit 42e8730

Please sign in to comment.