-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
7 changed files
with
214 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../main/java/net/swofty/types/generic/event/actions/item/ActionItemAbilityBlockLeftUse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.swofty.types.generic.event.actions.item; | ||
|
||
import lombok.SneakyThrows; | ||
import net.minestom.server.event.player.PlayerBlockBreakEvent; | ||
import net.minestom.server.event.player.PlayerBlockInteractEvent; | ||
import net.minestom.server.item.ItemStack; | ||
import net.swofty.types.generic.event.EventNodes; | ||
import net.swofty.types.generic.event.SkyBlockEvent; | ||
import net.swofty.types.generic.event.SkyBlockEventClass; | ||
import net.swofty.types.generic.item.SkyBlockItem; | ||
import net.swofty.types.generic.item.components.AbilityComponent; | ||
import net.swofty.types.generic.item.handlers.ability.RegisteredAbility; | ||
import net.swofty.types.generic.user.PlayerAbilityHandler; | ||
import net.swofty.types.generic.user.SkyBlockPlayer; | ||
|
||
public class ActionItemAbilityBlockLeftUse implements SkyBlockEventClass { | ||
@SneakyThrows | ||
@SkyBlockEvent(node = EventNodes.PLAYER , requireDataLoaded = true) | ||
public void run(PlayerBlockBreakEvent event) { | ||
ItemStack itemStack = event.getPlayer().getItemInMainHand(); | ||
SkyBlockItem item = new SkyBlockItem(itemStack); | ||
SkyBlockPlayer player = (SkyBlockPlayer) event.getPlayer(); | ||
|
||
if (item.hasComponent(AbilityComponent.class)) { | ||
AbilityComponent abilityComponent = item.getComponent(AbilityComponent.class); | ||
RegisteredAbility ability; | ||
ability = abilityComponent.getAbility(RegisteredAbility.AbilityActivation.LEFT_CLICK_BLOCK); | ||
if (ability != null) { | ||
// Cancelling here will prevent the block from being broken | ||
event.setCancelled(true); | ||
if (!ability.getCost().canUse(player)) { | ||
ability.getCost().onFail(player); | ||
return; | ||
} | ||
|
||
PlayerAbilityHandler abilityHandler = player.getAbilityHandler(); | ||
if (!abilityHandler.canUseAbility(item, ability.getCooldownTicks())) { | ||
player.sendMessage("§cThis ability is on cooldown for " + | ||
Math.round((float) abilityHandler.getRemainingCooldown(item, ability.getCooldownTicks()) / 1000) + "s."); | ||
return; | ||
} | ||
|
||
abilityHandler.startAbilityCooldown(item); | ||
ability.execute(player, item, event.getBlockPosition(), event.getBlockFace()); | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...main/java/net/swofty/types/generic/event/actions/item/ActionItemAbilityBlockRightUse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package net.swofty.types.generic.event.actions.item; | ||
|
||
import lombok.SneakyThrows; | ||
import net.minestom.server.event.player.PlayerBlockInteractEvent; | ||
import net.minestom.server.item.ItemStack; | ||
import net.swofty.types.generic.event.EventNodes; | ||
import net.swofty.types.generic.event.SkyBlockEvent; | ||
import net.swofty.types.generic.event.SkyBlockEventClass; | ||
import net.swofty.types.generic.item.SkyBlockItem; | ||
import net.swofty.types.generic.item.components.AbilityComponent; | ||
import net.swofty.types.generic.item.handlers.ability.RegisteredAbility; | ||
import net.swofty.types.generic.user.PlayerAbilityHandler; | ||
import net.swofty.types.generic.user.SkyBlockPlayer; | ||
|
||
public class ActionItemAbilityBlockRightUse implements SkyBlockEventClass { | ||
@SneakyThrows | ||
@SkyBlockEvent(node = EventNodes.PLAYER , requireDataLoaded = true) | ||
public void run(PlayerBlockInteractEvent event) { | ||
ItemStack itemStack = event.getPlayer().getItemInMainHand(); | ||
SkyBlockItem item = new SkyBlockItem(itemStack); | ||
SkyBlockPlayer player = (SkyBlockPlayer) event.getPlayer(); | ||
|
||
if (item.hasComponent(AbilityComponent.class)) { | ||
AbilityComponent abilityComponent = item.getComponent(AbilityComponent.class); | ||
RegisteredAbility ability; | ||
ability = abilityComponent.getAbility(RegisteredAbility.AbilityActivation.RIGHT_CLICK_BLOCK); | ||
if (ability != null) { | ||
if (!ability.getCost().canUse(player)) { | ||
ability.getCost().onFail(player); | ||
return; | ||
} | ||
|
||
PlayerAbilityHandler abilityHandler = player.getAbilityHandler(); | ||
if (!abilityHandler.canUseAbility(item, ability.getCooldownTicks())) { | ||
player.sendMessage("§cThis ability is on cooldown for " + | ||
Math.round((float) abilityHandler.getRemainingCooldown(item, ability.getCooldownTicks()) / 1000) + "s."); | ||
return; | ||
} | ||
|
||
abilityHandler.startAbilityCooldown(item); | ||
ability.execute(player, item, event.getBlockPosition(), event.getBlockFace()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...in/java/net/swofty/types/generic/item/handlers/ability/abilities/BuildersWandAbility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package net.swofty.types.generic.item.handlers.ability.abilities; | ||
|
||
import net.minestom.server.coordinate.Point; | ||
import net.minestom.server.coordinate.Pos; | ||
import net.minestom.server.coordinate.Vec; | ||
import net.minestom.server.instance.Instance; | ||
import net.minestom.server.instance.block.Block; | ||
import net.minestom.server.instance.block.BlockFace; | ||
import net.minestom.server.item.Material; | ||
import net.minestom.server.utils.NamespaceID; | ||
import net.swofty.commons.item.ItemType; | ||
import net.swofty.types.generic.item.handlers.ability.RegisteredAbility; | ||
import net.swofty.types.generic.user.SkyBlockPlayer; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class BuildersWandAbility extends RegisteredAbility { | ||
|
||
@SuppressWarnings("preview") | ||
public BuildersWandAbility() { | ||
super("GRAND_ARCHITECT", "Grand Architect", | ||
"Right-click the face of a block to extend all connected block faces.", | ||
AbilityActivation.RIGHT_CLICK_BLOCK, 0, new RegisteredAbility.NoAbilityCost(), | ||
(player, item, origin, face) -> { | ||
fillConnectedFaces(player, new Pos(origin), face); | ||
}); | ||
} | ||
|
||
private static void fillConnectedFaces(SkyBlockPlayer player, Pos origin, BlockFace face) { | ||
Material fillMaterial = Material.fromNamespaceId(player.getInstance().getBlock(origin).namespace()); | ||
int blocksInInventory = player.countItem(ItemType.fromMaterial(fillMaterial)); | ||
int blockLimit = 164; | ||
if (blocksInInventory < blockLimit) | ||
blockLimit = blocksInInventory; | ||
|
||
List<Pos> blocks = new ArrayList<>(); | ||
List<Pos> blocksForUndo = new ArrayList<>(); // NOTE: To be used later | ||
blocks.add(origin); | ||
Instance w = player.getInstance(); | ||
Vec[] check = null; | ||
Vec translate = null; | ||
int blocksPlaced = 0; | ||
|
||
check = switch (face) { | ||
case NORTH, SOUTH -> | ||
new Vec[]{new Vec(-1, -1, 0), new Vec(-1, 0, 0), new Vec(-1, 1, 0), new Vec(0, -1, 0), new Vec(0, 1, 0), new Vec(1, -1, 0), new Vec(1, 0, 0), new Vec(1, 1, 0)}; | ||
case EAST, WEST -> | ||
new Vec[]{new Vec(0, -1, -1), new Vec(0, -1, 0), new Vec(0, -1, 1), new Vec(0, 0, -1), new Vec(0, 0, 1), new Vec(0, 1, -1), new Vec(0, 1, 0), new Vec(0, 1, 1)}; | ||
case TOP, BOTTOM -> | ||
new Vec[]{new Vec(-1, 0, -1), new Vec(-1, 0, 0), new Vec(-1, 0, 1), new Vec(0, 0, -1), new Vec(0, 0, 1), new Vec(1, 0, -1), new Vec(1, 0, 0), new Vec(1, 0, 1)}; | ||
}; | ||
translate = switch (face) { | ||
case NORTH -> new Vec(0, 0, -1); | ||
case SOUTH -> new Vec(0, 0, 1); | ||
case EAST -> new Vec(1, 0, 0); | ||
case WEST -> new Vec(-1, 0, 0); | ||
case TOP -> new Vec(0, 1, 0); | ||
case BOTTOM -> new Vec(0, -1, 0); | ||
}; | ||
while (!blocks.isEmpty() && blockLimit > 0) { | ||
Pos l = (blocks.get(0)); | ||
for (Vec vector : check) { | ||
if (w.getBlock(l.add(vector)).namespace().equals(fillMaterial.namespace()) && w | ||
.getBlock(l.add(vector).add(translate)).namespace().equals(Material.AIR.namespace())) { | ||
blocks.add(l.add(vector)); | ||
} | ||
} | ||
Pos fillBlock = l.add(translate); | ||
// TODO: make sure player is on island | ||
if (player.isOnIsland()) { | ||
blocks.removeIf(blocks.get(0)::equals); | ||
if (!player.getInstance().getBlock(fillBlock).namespace().equals(fillMaterial.namespace())) { | ||
player.getInstance().setBlock(fillBlock, Block.fromNamespaceId(fillMaterial.namespace())); | ||
|
||
blockLimit--; | ||
blocksPlaced++; | ||
blocksForUndo.add(fillBlock); | ||
} | ||
if (blocksPlaced == blockLimit) | ||
break; | ||
continue; | ||
} | ||
blocks.removeIf(blocks.get(0)::equals); | ||
blockLimit--; | ||
} | ||
if(blocksPlaced == 0) { | ||
player.sendMessage("§cYou cannot place any blocks! You do not have enough blocks to place with your Builder's wand!"); | ||
} | ||
if (blocksPlaced != 0) { | ||
player.takeItem(ItemType.fromMaterial(fillMaterial), blocksPlaced); | ||
player.sendMessage("&eYou built &a" + blocksPlaced + "&e blocks!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters