-
Notifications
You must be signed in to change notification settings - Fork 4
Implement Time Lapse #16
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:Time_Lapse
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 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c85183a
Added Time Lapse
SpaceNerden 979bbbe
Change Time Lapse recipe to use copper blocks instead (https://discor…
SpaceNerden 1180382
Rebased to latest
SpaceNerden e7049be
Fix NullPointerException when clicking mid-air with the item in hand
SpaceNerden efb3688
Play ding when item is used
SpaceNerden c346700
Change sound to BLOCK_END_PORTAL_SPAWN from noteblock chime
SpaceNerden 47a532a
Add particles around chest
SpaceNerden b4c84e4
Change sound to BLOCK_BELL_RESONATE and remove particles
SpaceNerden 48557f9
fix: add -roni postfix to Time Lapse (Time Lapseroni)
SpaceNerden 5f5c023
fix: add TimeLapseroni to CollectionManager and renamed TimeLapse fil…
SpaceNerden e7563b8
fix: resolve plguin typo
SpaceNerden 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
111 changes: 111 additions & 0 deletions
111
src/main/java/xyz/holocons/mc/holoitemsrevamp/enchantment/TimeLapseroni.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,111 @@ | ||
| package xyz.holocons.mc.holoitemsrevamp.enchantment; | ||
|
|
||
| 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.Material; | ||
| import org.bukkit.Sound; | ||
| import org.bukkit.World; | ||
| import org.bukkit.block.Container; | ||
| import org.bukkit.enchantments.Enchantment; | ||
| import org.bukkit.entity.Player; | ||
| 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.Map; | ||
|
|
||
| public class TimeLapseroni extends CustomEnchantment implements EnchantmentAbility { | ||
|
|
||
| private final HoloItemsRevamp plugin; | ||
|
|
||
| public TimeLapseroni(HoloItemsRevamp plugin) { | ||
| super(plugin, "time_lapseroni"); | ||
| 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.CLOCK; | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull Component displayName(int level) { | ||
| return Component.text("Time Lapseroni", NamedTextColor.GOLD) | ||
| .decoration(TextDecoration.ITALIC, false); | ||
| } | ||
|
|
||
| @Override | ||
| public int getCostMultiplier() { | ||
| return Integer.MAX_VALUE; | ||
| } | ||
|
|
||
| @Override | ||
| public void onPlayerInteract(PlayerInteractEvent event, ItemStack itemStack) { | ||
|
|
||
| final var clickedBlock = event.getClickedBlock(); | ||
|
|
||
| // If the clicked block is null, return | ||
| if (clickedBlock == null){ | ||
| return; | ||
| } | ||
|
|
||
| // If not right-clicked or a container, return | ||
| final var blockState = clickedBlock.getState(); | ||
| if(!event.getAction().isRightClick() || !(blockState instanceof Container)){ | ||
| return; | ||
| } | ||
|
|
||
| Container container = (Container) blockState; | ||
|
|
||
| Map<ItemStack, Material> metals = Map.of( | ||
| new ItemStack(Material.COPPER_INGOT), Material.RAW_COPPER, | ||
| new ItemStack(Material.IRON_INGOT), Material.RAW_IRON, | ||
| new ItemStack(Material.GOLD_INGOT), Material.RAW_GOLD, | ||
| new ItemStack(Material.NETHERITE_SCRAP), Material.ANCIENT_DEBRIS, | ||
| new ItemStack(Material.IRON_BLOCK), Material.RAW_IRON_BLOCK, | ||
| new ItemStack(Material.GOLD_BLOCK), Material.RAW_GOLD_BLOCK, | ||
| new ItemStack(Material.COPPER_BLOCK), Material.RAW_COPPER_BLOCK | ||
| ); | ||
|
|
||
|
|
||
| // Iterate over the container and if an item exists and its type is one of the above, replace it. | ||
| boolean consumeItem = false; | ||
| for (ItemStack item : container.getInventory()) { | ||
| if (item == null) { | ||
| continue; | ||
| } | ||
| for (ItemStack metal : metals.keySet()) { | ||
| if (item.isSimilar(metal)) { | ||
| item.setType(metals.get(metal)); | ||
| consumeItem = true; | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // Deletes item if it was used. | ||
| if(consumeItem){ | ||
| final Player player = event.getPlayer(); | ||
| final World world = player.getWorld(); | ||
|
|
||
| world.playSound(player.getLocation(), Sound.BLOCK_BELL_RESONATE, 0.1f, 0.1f ); | ||
| event.getItem().setAmount(0); | ||
| } | ||
| } | ||
| } | ||
|
|
70 changes: 70 additions & 0 deletions
70
src/main/java/xyz/holocons/mc/holoitemsrevamp/item/TimeLapseroniItem.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,70 @@ | ||
| package xyz.holocons.mc.holoitemsrevamp.item; | ||
|
|
||
| import com.strangeone101.holoitemsapi.enchantment.EnchantManager; | ||
| import com.strangeone101.holoitemsapi.item.CustomItem; | ||
| import com.strangeone101.holoitemsapi.enchantment.Enchantable; | ||
| import net.kyori.adventure.text.Component; | ||
| import net.kyori.adventure.text.format.NamedTextColor; | ||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.enchantments.Enchantment; | ||
| 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 TimeLapseroniItem extends CustomItem implements Enchantable { | ||
|
|
||
| private final static String name = "time_lapseroni"; | ||
| private final static Material material = Material.CLOCK; | ||
| private final static Component displayName = Component.text("Time Lapseroni", NamedTextColor.GOLD); | ||
| private final static List<Component> lore = List.of( | ||
| Component.text("Unsmelt Ingots") | ||
| ); | ||
|
|
||
| private final EnchantManager enchantManager; | ||
|
|
||
| public TimeLapseroniItem(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.CLOCK); | ||
| recipe.setIngredient('B', Material.COPPER_BLOCK); | ||
| recipe.setIngredient('C', Material.BLAST_FURNACE); | ||
| 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.