-
Notifications
You must be signed in to change notification settings - Fork 4
Implement Timefall #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SpaceNerden
wants to merge
11
commits into
TraceLTRC:master
Choose a base branch
from
SpaceNerden:Timefall
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
eb70272
Implement Timefall
SpaceNerden ee2b718
refractor: refractor branch to latest
SpaceNerden a152b9b
fix: change implementation of Timefalleroni
SpaceNerden 5893f6e
fix: activation on chest right-click
SpaceNerden 81a4e0e
perf: change implementation of timefalleroni
SpaceNerden 773282e
fix: remove debug log
SpaceNerden 295f161
docs: fix strange comment
SpaceNerden 9cfc3d8
Randomize random tick count and effect radius
dlee13 70835da
Fix typo
dlee13 59de33f
Account for random tick speed game rule
dlee13 bea29e4
Randomize chance of item consumption
dlee13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
109 changes: 109 additions & 0 deletions
109
src/main/java/xyz/holocons/mc/holoitemsrevamp/enchantment/Timefall.java
This file contains hidden or 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,109 @@ | ||
| package xyz.holocons.mc.holoitemsrevamp.enchantment; | ||
|
|
||
| import com.destroystokyo.paper.MaterialSetTag; | ||
| import com.destroystokyo.paper.MaterialTags; | ||
| import com.strangeone101.holoitemsapi.enchantment.CustomEnchantment; | ||
| import com.strangeone101.holoitemsapi.enchantment.EnchantmentAbility; | ||
| import net.kyori.adventure.text.Component; | ||
| import net.kyori.adventure.text.format.NamedTextColor; | ||
| import net.kyori.adventure.text.format.TextDecoration; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.Particle; | ||
| import org.bukkit.block.Block; | ||
| import org.bukkit.enchantments.Enchantment; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.block.Action; | ||
| import org.bukkit.event.player.PlayerInteractEvent; | ||
| import org.bukkit.inventory.ItemStack; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import xyz.holocons.mc.holoitemsrevamp.HoloItemsRevamp; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Random; | ||
|
|
||
| public class Timefall extends CustomEnchantment implements EnchantmentAbility { | ||
|
|
||
| private final HoloItemsRevamp plugin; | ||
|
|
||
| public Timefall(HoloItemsRevamp plugin) { | ||
| super(plugin, "timefall"); | ||
| this.plugin = plugin; | ||
| } | ||
|
|
||
| @Override | ||
| public int getMaxLevel() { | ||
| return 1; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean conflictsWith(@NotNull Enchantment other) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canEnchantItem(@NotNull ItemStack item) { | ||
| return item.getType() == Material.POWDER_SNOW_BUCKET; | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull Component displayName(int level) { | ||
| return Component.text("Timefall", NamedTextColor.GOLD) | ||
| .decoration(TextDecoration.ITALIC, false); | ||
| } | ||
|
|
||
| @Override | ||
| public int getCostMultiplier() { | ||
| return Integer.MAX_VALUE; | ||
| } | ||
|
|
||
| @Override | ||
| public void onPlayerInteract(PlayerInteractEvent event, ItemStack itemStack) { | ||
|
|
||
| // If not right-clicked or a container, return | ||
| if(!event.getAction().isRightClick() || event.getAction() != Action.RIGHT_CLICK_BLOCK){ | ||
| return; | ||
| } | ||
|
|
||
| // If the block right-clicked is an interactable block, return | ||
| if(event.getClickedBlock().getBlockData().getMaterial().isInteractable()){ | ||
| return; | ||
| } | ||
|
|
||
| ItemStack item = event.getItem(); | ||
| item.setType(Material.BUCKET); | ||
| item.setItemMeta(new ItemStack(Material.BUCKET).getItemMeta()); | ||
|
|
||
| Player player = event.getPlayer(); | ||
| player.setFreezeTicks(60); | ||
| Location center = player.getLocation(); | ||
| player.getWorld().spawnParticle(Particle.WHITE_ASH, center, 200, 5, 5, 5); | ||
|
|
||
| int ticks = 25; | ||
| boolean consumeItem = false; | ||
|
|
||
| for (int x=-5; x<=5; x++) { | ||
| for (int y=-5; y<=5; y++) { | ||
| for(int z=-5; z<=5; z++) { | ||
| Block block = center.clone().add(x, y, z).getBlock(); | ||
| if(block.getBlockData().isRandomlyTicked()) | ||
| { | ||
| for (int i = 0; i < ticks; i++) { | ||
| block.randomTick(); | ||
| } | ||
| consumeItem = true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| // Deletes item if it was used. | ||
| if(consumeItem){ | ||
| event.getItem().subtract(1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
74 changes: 74 additions & 0 deletions
74
src/main/java/xyz/holocons/mc/holoitemsrevamp/item/TimefallItem.java
This file contains hidden or 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,74 @@ | ||
| package xyz.holocons.mc.holoitemsrevamp.item; | ||
|
|
||
| import com.strangeone101.holoitemsapi.enchantment.EnchantManager; | ||
| import com.strangeone101.holoitemsapi.enchantment.Enchantable; | ||
| import com.strangeone101.holoitemsapi.item.CustomItem; | ||
| import com.strangeone101.holoitemsapi.recipe.RecipeManager; | ||
| import net.kyori.adventure.text.Component; | ||
| import net.kyori.adventure.text.format.NamedTextColor; | ||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.enchantments.Enchantment; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.inventory.ItemStack; | ||
| import org.bukkit.inventory.Recipe; | ||
| import org.bukkit.inventory.ShapedRecipe; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import xyz.holocons.mc.holoitemsrevamp.HoloItemsRevamp; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class TimefallItem extends CustomItem implements Enchantable { | ||
|
|
||
| private final static String name = "timefall"; | ||
| private final static Material material = Material.POWDER_SNOW_BUCKET; | ||
| private final static Component displayName = Component.text("Timefall", NamedTextColor.BLUE); | ||
|
|
||
| private final static List<Component> lore = List.of( | ||
| Component.text("Accelerate oxidation") | ||
| ); | ||
|
|
||
| private final EnchantManager enchantManager; | ||
|
|
||
| public TimefallItem(HoloItemsRevamp plugin) { | ||
| super(plugin, name, material, displayName, lore); | ||
| this.enchantManager = plugin.getEnchantManager(); | ||
| this.setStackable(false); | ||
| this.register(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Recipe getRecipe() { | ||
| final var recipe = new ShapedRecipe(getKey(), buildStack(null)); | ||
| recipe.shape( | ||
| "ABA", | ||
| "BCB", | ||
| "ABA" | ||
| ); | ||
| recipe.setIngredient('A', Material.SNOW); | ||
| recipe.setIngredient('B', Material.BONE_BLOCK); | ||
| recipe.setIngredient('C', Material.BUCKET); | ||
| return recipe; | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull Enchantment getEnchantment() { | ||
| return Enchantment.getByKey(getKey()); | ||
| } | ||
|
|
||
| @Override | ||
| public ItemStack applyEnchantment(ItemStack itemStack) { | ||
| var enchantedStack = itemStack.clone(); | ||
| var enchantedMeta = enchantedStack.hasItemMeta() ? enchantedStack.getItemMeta() : Bukkit.getItemFactory().getItemMeta(enchantedStack.getType()); | ||
|
|
||
| if (enchantedMeta.addEnchant(getEnchantment(), 1, false)) { | ||
| enchantedStack.setItemMeta(enchantedMeta); | ||
| enchantManager.removeCustomEnchantmentLore(enchantedStack); | ||
| enchantManager.applyCustomEnchantmentLore(enchantedStack); | ||
| return enchantedStack; | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.