Skip to content

Commit

Permalink
Inertia fix && CD && no consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailTapio committed Aug 16, 2022
1 parent cac1f94 commit f527437
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/main/java/committee/nova/plr/ebb/ElytraBombing.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.google.inject.Inject;
import committee.nova.plr.ebb.util.Utilities;
import net.kyori.adventure.sound.Sound;
import org.apache.logging.log4j.Logger;
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.type.HandTypes;
import org.spongepowered.api.effect.sound.SoundTypes;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.entity.explosive.fused.PrimedTNT;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.filter.cause.First;
import org.spongepowered.api.event.filter.type.Include;
Expand All @@ -15,9 +18,8 @@
import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.item.ItemTypes;
import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.util.Tuple;
import org.spongepowered.api.util.Ticks;
import org.spongepowered.api.world.World;
import org.spongepowered.plugin.PluginContainer;
import org.spongepowered.plugin.builtin.jvm.Plugin;
Expand All @@ -42,25 +44,22 @@ public void onConstructPlugin(final ConstructPluginEvent event) {

@Listener
@Include(InteractItemEvent.Secondary.class)
public void onInteractItem(final InteractItemEvent.Secondary event, @First Player player) {
public void onInteractItem(final InteractItemEvent.Secondary event, @First ServerPlayer player) {
if (!player.elytraFlying().get()) return;
final ItemType tnt = ItemTypes.TNT.get();
if (player.cooldownTracker().hasCooldown(tnt)) return;
final ItemStackSnapshot stack = event.itemStack();
final ItemType type = stack.createStack().type();
if (type != player.itemInHand(HandTypes.MAIN_HAND).type()) return;
final Tuple<ItemType, ItemType> bombingItems = Tuple.of(ItemTypes.FIRE_CHARGE.get(), ItemTypes.FLINT_AND_STEEL.get());
if (!type.isAnyOf(bombingItems.first(), bombingItems.second())) return;
if (type != ItemTypes.FLINT_AND_STEEL.get()) return;
final Inventory inv = player.inventory();
final ItemType tnt = ItemTypes.TNT.get();
if (!inv.contains(tnt)) return;
if (Utilities.consumeStackByType(inv, tnt, 1) != 1) return;
if (type == bombingItems.first()) {
final ItemStack newStack = stack.createStack();
newStack.setQuantity(newStack.quantity() - 1);
player.setItemInHand(HandTypes.MAIN_HAND, newStack);
}
player.cooldownTracker().setCooldown(tnt, Ticks.of(60));
final World<?, ?> world = player.world();
final PrimedTNT tntEntity = world.createEntity(EntityTypes.TNT, player.position().add(0F, .5F, 0F));
tntEntity.velocity().set(player.velocity().get());
final PrimedTNT tntEntity = world.createEntity(EntityTypes.TNT, player.position().add(0F, -.5F, 0F));
tntEntity.offer(Keys.VELOCITY, player.velocity().get());
player.playSound(Sound.sound(SoundTypes.ENTITY_TNT_PRIMED, Sound.Source.PLAYER, 1F, 1F));
world.spawnEntity(tntEntity);
}

Expand Down

0 comments on commit f527437

Please sign in to comment.