Added animation type CRUMBLE

This commit is contained in:
Esophose 2019-04-17 02:11:58 -06:00
parent 6e34b1cb6b
commit 8ff4e315eb
8 changed files with 110 additions and 14 deletions

View File

@ -7,7 +7,6 @@ import org.bukkit.block.Block;
import org.bukkit.entity.FallingBlock; import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.util.Collection; import java.util.Collection;

View File

@ -9,7 +9,6 @@ import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet; import com.songoda.ultimatetimber.tree.TreeBlockSet;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.FallingBlock; import org.bukkit.entity.FallingBlock;

View File

@ -0,0 +1,96 @@
package com.songoda.ultimatetimber.animation;
import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.adapter.VersionAdapter;
import com.songoda.ultimatetimber.manager.ConfigurationManager;
import com.songoda.ultimatetimber.tree.DetectedTree;
import com.songoda.ultimatetimber.tree.FallingTreeBlock;
import com.songoda.ultimatetimber.tree.ITreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeDefinition;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class TreeAnimationCrumble extends TreeAnimation {
public TreeAnimationCrumble(DetectedTree detectedTree, Player player) {
super(TreeAnimationType.CRUMBLE, detectedTree, player);
}
@Override
public void playAnimation(Runnable whenFinished) {
UltimateTimber ultimateTimber = UltimateTimber.getInstance();
VersionAdapter versionAdapter = ultimateTimber.getVersionAdapter();
boolean useCustomSound = ConfigurationManager.Setting.USE_CUSTOM_SOUNDS.getBoolean();
boolean useCustomParticles = ConfigurationManager.Setting.USE_CUSTOM_PARTICLES.getBoolean();
// Order blocks by y-axis, lowest first, but shuffled randomly
int currentY = -1;
List<List<ITreeBlock<Block>>> treeBlocks = new ArrayList<>();
List<ITreeBlock<Block>> currentPartition = new ArrayList<>();
List<ITreeBlock<Block>> orderedDetectedTreeBlocks = new ArrayList<>(this.detectedTree.getDetectedTreeBlocks().getAllTreeBlocks());
orderedDetectedTreeBlocks.sort(Comparator.comparingInt(x -> x.getLocation().getBlockY()));
for (ITreeBlock<Block> treeBlock : orderedDetectedTreeBlocks) {
if (currentY != treeBlock.getLocation().getBlockY()) {
Collections.shuffle(currentPartition);
treeBlocks.add(new ArrayList<>(currentPartition));
currentPartition.clear();
currentY = treeBlock.getLocation().getBlockY();
}
currentPartition.add(treeBlock);
}
Collections.shuffle(currentPartition);
treeBlocks.add(new ArrayList<>(currentPartition));
Player p = this.player;
TreeDefinition td = this.detectedTree.getTreeDefinition();
boolean hst = this.hasSilkTouch;
new BukkitRunnable() {
@Override
public void run() {
if (!treeBlocks.isEmpty()) {
List<ITreeBlock<Block>> partition = treeBlocks.get(0);
for (int i = 0; i < 3 && !partition.isEmpty(); i++) {
ITreeBlock<Block> treeBlock = partition.remove(0);
FallingTreeBlock fallingTreeBlock = TreeAnimationCrumble.this.convertToFallingBlock((TreeBlock)treeBlock);
if (fallingTreeBlock == null)
continue;
versionAdapter.toggleGravityFallingBlock(fallingTreeBlock.getBlock(), true);
fallingTreeBlock.getBlock().setVelocity(Vector.getRandom().setY(0).subtract(new Vector(0.5, 0, 0.5)).multiply(0.15));
TreeAnimationCrumble.this.fallingTreeBlocks.add(fallingTreeBlock);
if (TreeAnimationCrumble.this.fallingTreeBlocks == null)
TreeAnimationCrumble.this.fallingTreeBlocks = new TreeBlockSet<>(fallingTreeBlock);
if (useCustomSound)
versionAdapter.playLandingSound(treeBlock);
if (useCustomParticles)
versionAdapter.playFallingParticles(td, treeBlock);
}
if (partition.isEmpty()) {
treeBlocks.remove(0);
}
}
if (treeBlocks.isEmpty() && TreeAnimationCrumble.this.fallingTreeBlocks.getAllTreeBlocks().isEmpty()) {
whenFinished.run();
this.cancel();
}
}
}.runTaskTimer(ultimateTimber, 0, 1);
}
}

View File

@ -48,17 +48,14 @@ public class TreeAnimationDisintegrate extends TreeAnimation {
List<ITreeBlock<Block>> toDestroy = new ArrayList<>(); List<ITreeBlock<Block>> toDestroy = new ArrayList<>();
if (!orderedLogBlocks.isEmpty()) { if (!orderedLogBlocks.isEmpty()) {
ITreeBlock<Block> treeBlock = orderedLogBlocks.get(0); ITreeBlock<Block> treeBlock = orderedLogBlocks.remove(0);
orderedLogBlocks.remove(treeBlock);
toDestroy.add(treeBlock); toDestroy.add(treeBlock);
} else if (!leafBlocks.isEmpty()) { } else if (!leafBlocks.isEmpty()) {
ITreeBlock<Block> treeBlock = leafBlocks.get(0); ITreeBlock<Block> treeBlock = leafBlocks.remove(0);
leafBlocks.remove(treeBlock);
toDestroy.add(treeBlock); toDestroy.add(treeBlock);
if (!leafBlocks.isEmpty()) { if (!leafBlocks.isEmpty()) {
treeBlock = leafBlocks.get(0); treeBlock = leafBlocks.remove(0);
leafBlocks.remove(treeBlock);
toDestroy.add(treeBlock); toDestroy.add(treeBlock);
} }
} }

View File

@ -6,6 +6,6 @@ package com.songoda.ultimatetimber.animation;
public enum TreeAnimationType { public enum TreeAnimationType {
FANCY, FANCY,
DISINTIGRATE, DISINTIGRATE,
CHAOS, CRUMBLE,
NONE NONE
} }

View File

@ -3,6 +3,7 @@ package com.songoda.ultimatetimber.manager;
import com.songoda.ultimatetimber.UltimateTimber; import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.adapter.VersionAdapter; import com.songoda.ultimatetimber.adapter.VersionAdapter;
import com.songoda.ultimatetimber.animation.TreeAnimation; import com.songoda.ultimatetimber.animation.TreeAnimation;
import com.songoda.ultimatetimber.animation.TreeAnimationCrumble;
import com.songoda.ultimatetimber.animation.TreeAnimationDisintegrate; import com.songoda.ultimatetimber.animation.TreeAnimationDisintegrate;
import com.songoda.ultimatetimber.animation.TreeAnimationFancy; import com.songoda.ultimatetimber.animation.TreeAnimationFancy;
import com.songoda.ultimatetimber.animation.TreeAnimationNone; import com.songoda.ultimatetimber.animation.TreeAnimationNone;
@ -79,6 +80,9 @@ public class TreeAnimationManager extends Manager implements Listener, Runnable
case "DISINTEGRATE": case "DISINTEGRATE":
this.registerTreeAnimation(new TreeAnimationDisintegrate(detectedTree, player)); this.registerTreeAnimation(new TreeAnimationDisintegrate(detectedTree, player));
break; break;
case "CRUMBLE":
this.registerTreeAnimation(new TreeAnimationCrumble(detectedTree, player));
break;
case "NONE": case "NONE":
this.registerTreeAnimation(new TreeAnimationNone(detectedTree, player)); this.registerTreeAnimation(new TreeAnimationNone(detectedTree, player));
break; break;

View File

@ -117,11 +117,11 @@ use-custom-particles: true
bonus-loot-multiplier: 2 bonus-loot-multiplier: 2
# The type of animation to use for tree toppling # The type of animation to use for tree toppling
# Types: FANCY, DISINTEGRATE, NONE # Types: FANCY, DISINTEGRATE, CRUMBLE, NONE
tree-animation-type: FANCY tree-animation-type: FANCY
# If the tree-animation-type is FANCY, make the blocks stick to the ground # If the tree-animation-type is FANCY or CRUMBLE, make the blocks stick to the ground
# Does nothing if tree-animation-type is not FANCY # Does nothing if tree-animation-type is not FANCY or CRUMBLE
# Default: false # Default: false
scatter-tree-blocks-on-ground: false scatter-tree-blocks-on-ground: false

View File

@ -118,10 +118,11 @@ use-custom-particles: true
bonus-loot-multiplier: 2 bonus-loot-multiplier: 2
# The type of animation to use for tree toppling # The type of animation to use for tree toppling
# Types: FANCY, DISINTEGRATE, NONE # Types: FANCY, DISINTEGRATE, CRUMBLE, NONE
tree-animation-type: FANCY tree-animation-type: FANCY
# If the tree-animation-type uses falling block entities, make the falling blocks stick to the ground # If the tree-animation-type is FANCY or CRUMBLE, make the blocks stick to the ground
# Does nothing if tree-animation-type is not FANCY or CRUMBLE
# Default: false # Default: false
scatter-tree-blocks-on-ground: false scatter-tree-blocks-on-ground: false