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.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.util.Collection;

View File

@ -9,7 +9,6 @@ import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
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<>();
if (!orderedLogBlocks.isEmpty()) {
ITreeBlock<Block> treeBlock = orderedLogBlocks.get(0);
orderedLogBlocks.remove(treeBlock);
ITreeBlock<Block> treeBlock = orderedLogBlocks.remove(0);
toDestroy.add(treeBlock);
} else if (!leafBlocks.isEmpty()) {
ITreeBlock<Block> treeBlock = leafBlocks.get(0);
leafBlocks.remove(treeBlock);
ITreeBlock<Block> treeBlock = leafBlocks.remove(0);
toDestroy.add(treeBlock);
if (!leafBlocks.isEmpty()) {
treeBlock = leafBlocks.get(0);
leafBlocks.remove(treeBlock);
treeBlock = leafBlocks.remove(0);
toDestroy.add(treeBlock);
}
}

View File

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

View File

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

View File

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

View File

@ -118,10 +118,11 @@ use-custom-particles: true
bonus-loot-multiplier: 2
# The type of animation to use for tree toppling
# Types: FANCY, DISINTEGRATE, NONE
# Types: FANCY, DISINTEGRATE, CRUMBLE, NONE
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
scatter-tree-blocks-on-ground: false