Skip to content
Draft
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
8852047
Create SplinterBook
cpaca May 26, 2024
3e9d9ed
Create Splinter.java
cpaca May 26, 2024
48d3bd1
Add Splinter to EnchantmentManager
cpaca May 26, 2024
cc62ac6
Add validity checker
cpaca May 26, 2024
f80031a
Implement the bulk of Splinter
cpaca May 26, 2024
b44319d
Make splinter charge its own function
cpaca May 26, 2024
8edc9e0
Implement addAdjacentBlocks
cpaca May 26, 2024
fbc149a
There's no way a wildcard import is needed there.
cpaca May 26, 2024
974c8b6
Add book to CollectionManager
cpaca May 26, 2024
ee2889c
Bugfixes
cpaca May 26, 2024
c1bab3e
Stop Splinter from changing materials
cpaca May 26, 2024
883a8a4
Update src/main/java/xyz/holocons/mc/holoitemsrevamp/enchantment/Spli…
cpaca May 28, 2024
02f3418
Split splinter validation for location and type.
cpaca Jun 2, 2024
19cc7a1
semicolon
cpaca Jun 2, 2024
14e7a10
Basic refactor of Splinter
cpaca Jun 2, 2024
22443ce
Reorganize splinter veinmine-one-block
cpaca Jun 2, 2024
2319b75
This is pre-checked already
cpaca Jun 2, 2024
e77dd1d
Remove unused variable
cpaca Jun 2, 2024
96cecca
dumb inversion error
cpaca Jun 2, 2024
35a04b9
Make splinter break multiple blocks per tick
cpaca Jun 2, 2024
78d6f05
Start of splinter v2
cpaca Jun 6, 2024
4f67107
Update src/main/java/xyz/holocons/mc/holoitemsrevamp/enchantment/Spli…
cpaca Jun 6, 2024
5dbafd9
Update src/main/java/xyz/holocons/mc/holoitemsrevamp/enchantment/Spli…
cpaca Jun 6, 2024
884a8a1
Fix non-compile bug
cpaca Jun 11, 2024
679ea87
Separate into is-shroom and is-log checks
cpaca Jun 11, 2024
fe66194
Wrong mushroom type check
cpaca Jun 11, 2024
a212ecc
Add isTrunkBlock function
cpaca Jun 11, 2024
8241e2f
Implement getPossibleBranches
cpaca Jun 11, 2024
835ce96
Trunks shouldn't return theirself
cpaca Jun 11, 2024
c514425
Implement getLegalNextMaterials
cpaca Jun 11, 2024
257bf7c
Implement scheduleSplinterAbility
cpaca Jun 11, 2024
d499b16
Fix tryCleanupSplinterData using new function
cpaca Jun 11, 2024
2cb8e2d
Finish up onBlockBreak
cpaca Jun 11, 2024
84f59d9
Forgot shroom branches also go downwards
cpaca Jun 11, 2024
87b8a39
Begin rework
dlee13 Jun 22, 2024
bd562cd
Pre-increment and pre-decrement
dlee13 Jun 22, 2024
57e0166
Avoid storing player objects
dlee13 Jun 22, 2024
a1880e5
Merge branch 'master' into Splinter
cpaca Jun 24, 2024
f6c8446
Fix logic for removing context
dlee13 Jun 24, 2024
acc138a
Merge branch 'Splinter' of https://github.com/cpaca/HoloItems into Sp…
dlee13 Jun 24, 2024
aece464
Add missing check
dlee13 Jun 24, 2024
d11f42e
Add null check for player
cpaca Jun 27, 2024
8c7320d
Move null check
dlee13 Jun 28, 2024
067f589
Merge branch 'master' into Splinter
dlee13 Jun 30, 2024
c505c98
Remove comment
dlee13 Jun 30, 2024
3ceadc8
Implement search for mushroom stem and brown mushroom block
dlee13 Jul 2, 2024
2fc8a42
Implement search for red mushroom block
dlee13 Jul 3, 2024
735a263
Merge branch 'master' into Splinter
dlee13 Jul 3, 2024
e58d635
Fix Splinter stopping too early
dlee13 Jul 3, 2024
97bcc55
Add special case splinter types
dlee13 Jul 3, 2024
382d9b5
Implement cherry
dlee13 Jul 5, 2024
c5b8e18
Implement acacia
dlee13 Jul 5, 2024
417cca1
Implement generic branch
dlee13 Jul 5, 2024
843ea78
Fix edge case for oak
dlee13 Jul 5, 2024
5c6b90a
Fix typo
dlee13 Jul 5, 2024
4b3e9fb
Merge branch 'master' into Splinter
dlee13 Jul 15, 2024
c42929e
Begin to implement mangrove
dlee13 Jul 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import xyz.holocons.mc.holoitemsrevamp.HoloItemsRevamp;
import xyz.holocons.mc.holoitemsrevamp.enchantment.Backdash;
import xyz.holocons.mc.holoitemsrevamp.enchantment.Magnet;
import xyz.holocons.mc.holoitemsrevamp.enchantment.Memento;
import xyz.holocons.mc.holoitemsrevamp.enchantment.TideRider;
import xyz.holocons.mc.holoitemsrevamp.enchantment.*;
import xyz.holocons.mc.holoitemsrevamp.integration.Integrations;

import java.util.List;
Expand Down Expand Up @@ -112,6 +109,8 @@ private static Set<CustomEnchantment> buildCustomEnchantments(HoloItemsRevamp pl
new Magnet(plugin),
new Memento(plugin),
new TideRider(plugin),
new Backdash(plugin));
new Backdash(plugin),
new Splinter(plugin)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import xyz.holocons.mc.holoitemsrevamp.HoloItemsRevamp;
import xyz.holocons.mc.holoitemsrevamp.item.BackdashBoots;
import xyz.holocons.mc.holoitemsrevamp.item.DummyBlockBlock;
import xyz.holocons.mc.holoitemsrevamp.item.MagnetBook;
import xyz.holocons.mc.holoitemsrevamp.item.MementoItem;
import xyz.holocons.mc.holoitemsrevamp.item.TideRiderItem;
import xyz.holocons.mc.holoitemsrevamp.item.*;

public class CollectionManager {

Expand Down Expand Up @@ -1055,7 +1051,7 @@ public List<Component> getLore() {
}

private static Idol buildFlare(HoloItemsRevamp plugin) {
return new Idol() {
return new Idol(new SplinterBook(plugin)) {

@Override
public @NotNull String getSkinUrl() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
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.*;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Orientable;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import xyz.holocons.mc.holoitemsrevamp.HoloItemsRevamp;
import xyz.holocons.mc.holoitemsrevamp.integration.Integrations;

import java.util.*;

public class Splinter extends CustomEnchantment implements EnchantmentAbility {

private final HoloItemsRevamp plugin;

private final MaterialSetTag COMPATIBLE_MATERIALS;

private static final Map<Player, ActiveSplinter> splinters = new HashMap<>();

public Splinter(HoloItemsRevamp plugin){
super(plugin, "splinter");
this.plugin = plugin;
var materialSetTagKey = new NamespacedKey(plugin, "splinter_materials");
this.COMPATIBLE_MATERIALS = new MaterialSetTag(materialSetTagKey, this::isCompatibleMaterial).lock();
}

@Override
public int getMaxLevel() {
return 1;
}

@Override
public boolean conflictsWith(@NotNull Enchantment enchantment) {
return false;
}

@Override
public boolean canEnchantItem(@NotNull ItemStack itemStack) {
return MaterialTags.AXES.isTagged(itemStack);
}

@Override
public @NotNull Component displayName(int i) {
return Component.text()
.color(NamedTextColor.GRAY)
.decoration(TextDecoration.ITALIC, false)
.append(Component.text("Splinter"))
.build();
}

@Override
public int getCostMultiplier() {
return 12;
}

@Override
public void onBlockBreak(BlockBreakEvent event, ItemStack itemStack) {
Block blockBroken = event.getBlock();
if(isInvalidSplinterType(blockBroken.getType()) || isInvalidSplinterLocation(blockBroken.getLocation())){
return;
}
// Presuming the block is a log - ie, it has an orientation.
var player = event.getPlayer();
tryCleanupSplinterData(player, blockBroken);

boolean isTree = isLogBlock(blockBroken.getType());
boolean isShroom = isShroomBlock(blockBroken.getType());
boolean isTrunk = isTrunkBlock(blockBroken);
if(isTree && isTrunk){
handleTreeTrunkBroken(player, blockBroken);
}
else if(isTree){
// && !isTrunk
// aka && isBranch
handleTreeBranchBroken(player, blockBroken);
}
else if(isShroom && isTrunk){
handleShroomStemBroken(player, blockBroken);
}
else if(isShroom){
// && !isTrunk
// aka && isBranch
handleShroomBlockBroken(player, blockBroken);
}
// else{} here shouldnt be reachable since anything else would be an invalid splinter type
}

/**
* Try to cleanup a player's Splinter data. If the data is scheduled for cleanup, but the newTrunk isn't a valid
* new trunk block, it will delete the data from the map entirely.
* @param player The player's
* @param newTrunk The proposed new trunk block
*/
private void tryCleanupSplinterData(Player player, Block newTrunk){
final var activeSplinter = splinters.get(player);
// if(!shouldCleanup)
if(activeSplinter != null && activeSplinter.scheduledSplinters != 0){
// there is still a splinter going, so don't cleanup until that one's done
return;
}

splinters.remove(player);

if(!isTrunkBlock(newTrunk)){
return;
}

ActiveSplinter newData = new ActiveSplinter();
newData.origin = newTrunk;
newData.remainingCharges = 32; // In the future we can make this based on enchLevel
newData.scheduledSplinters = 0;
splinters.put(player, newData);
}

private void handleTreeTrunkBroken(Player player, Block trunkBlock){
// TODO
}

private void handleTreeBranchBroken(Player player, Block branchBlock){
// TODO
}

private void handleShroomStemBroken(Player player, Block stemBlock){
// aka the shroom stem
// TODO
}

private void handleShroomBlockBroken(Player player, Block branchBlock){
// TODO
}

private void scheduleSplinterAbility(Player player, Block block) {
var data = splinters.get(player);
if(data.remainingCharges <= 0){
// No power left to schedule anything.
return;
}
int splinterDelay = data.scheduledSplinters;
// Update and save data
data.remainingCharges -= 1;
data.scheduledSplinters += 1;
splinters.put(player, data);

// Schedule a splinter
new BukkitRunnable(){
@Override
public void run() {
// Break the block
// TODO: Check if the player is holding a Splinter axe first.
// I got the itemStack to check for splinter, but idk how to check for splinter.
var activeItem = player.getActiveItem();
player.breakBlock(block);

// ... then update the data.
var updatedData = splinters.get(player);
updatedData.scheduledSplinters -= 1;
splinters.put(player, updatedData);
}
}.runTaskLater(plugin, splinterDelay);
}

/**
* Gets the potential next-branch blocks from this starting branch block. The trunk block is used since branches
* don't "curl in" on theirself, they continue to go farther from the trunk. If the branch is actually part
* of the trunk, all 8 adjacent blocks plus the 8 additional branches are returned.
*/
private List<Block> getPossibleBranches(Block trunk, Block branch){
// Since the main operations afaik will be append and iterator, this is slightly better than arraylist.
// Not by much.
List<Block> ret = new LinkedList<>();
Comment thread
dlee13 marked this conversation as resolved.
Outdated

int deltaX = branch.getX() - trunk.getX();
int deltaZ = branch.getZ() - trunk.getZ();

int[] relXs = getRelsToCheck(deltaX);
int[] relZs = getRelsToCheck(deltaZ);

boolean isShroom = isShroomBlock(branch.getType());

for(int relX : relXs){
for(int relZ : relZs){
if(relX == 0 && relZ == 0){
continue;
}
if(isShroom){
// Remember shroom branches also go downwards
ret.add(branch.getRelative(relX, -1, relZ));
}
ret.add(branch.getRelative(relX, 0, relZ));
ret.add(branch.getRelative(relX, 1, relZ));
}
}

return ret;
}

private int[] getRelsToCheck(int delta){
// "Get relatives to check"
if(delta > 0){
return new int[]{1};
}
else if(delta < 0){
return new int[]{-1};
}
else{
// start == 0
return new int[]{-1, 0, 1};
}
}

/**
* In summary: Log-splinters should only continue with other log-splinters, but shroom-splinters should be able
* to move from stem to mushroom block. (That said, mushroom block shouldn't be able to move back to stem.)
* Note: This will also return an empty list (aka "no legal next material") if the baseMaterial is not a legal
* splinter material.
*/
private List<Material> getLegalNextMaterials(Block block){
List<Material> ret = new LinkedList<>();
if(isLogBlock(block.getType())){
ret.add(block.getType());
}
else if(isShroomBlock(block.getType())){
ret.add(block.getType());
if(isTrunkBlock(block)){
// shroom trunks (aka stems) should also be able to go to shroom leaves (aka mushroom blocks)
ret.add(Material.RED_MUSHROOM_BLOCK);
ret.add(Material.BROWN_MUSHROOM_BLOCK);
}
}
// else: return empty list, aka unchanged
return ret;
}

private boolean isInvalidSplinterType(Material type) {
return !this.COMPATIBLE_MATERIALS.isTagged(type);
}

private boolean isInvalidSplinterLocation(Location loc){
return !Integrations.WORLDGUARD.canUseEnchantment(loc, Splinter.class);
}

private boolean isCompatibleMaterial(Material material) {
return isLogBlock(material) || isShroomBlock(material);
}

private boolean isLogBlock(Material material){
// Remember later: All log-blocks are orientable. (shrooms are compatible-material but not orientable.)
return Tag.LOGS.isTagged(material);
}

private boolean isShroomBlock(Material material){
return MaterialTags.MUSHROOM_BLOCKS.isTagged(material);
}

private boolean isTrunkBlock(Block block){
var material = block.getType();
if(isLogBlock(material)){
if(block.getBlockData() instanceof Orientable orientable){
return orientable.getAxis() == Axis.Y;
}
// non-orientable log shouldn't be possible, but just in case:
return false;
}
else if(isShroomBlock(material)){
return Material.MUSHROOM_STEM == material;
}
else{
return false;
}
}

private static class ActiveSplinter {
Block origin;
int remainingCharges;
int scheduledSplinters;
}
}
Loading