Skip to content

Commit

Permalink
Fix wind charges & add option for explosion drops
Browse files Browse the repository at this point in the history
  • Loading branch information
max1mde committed Oct 17, 2024
1 parent 06f6564 commit 93bbb1b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'com.maximde'
version = '3.1.1'
version = '3.2.0'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private void createRealisticExplosion(EntityExplodeEvent event) {
if(event.isCancelled()) return;
if(fancyPhysics.getPluginConfig().isPerformanceMode() && event.getLocation().getChunk().getEntities().length > 2000) return;
event.setYield(40);
if(event.getEntity().getName().toLowerCase().contains("wind charge")) return;
final var entitysAmount = event.getLocation().getChunk().getEntities().length;
final var oldBlockList = new HashMap<Location, Material>();
for (Block block : event.blockList()) {
Expand All @@ -50,13 +51,14 @@ private void createRealisticExplosion(EntityExplodeEvent event) {
oldBlockList.put(block.getLocation(), block.getType());
}
if(fancyPhysics.getPluginConfig().isPerformanceMode() && entitysAmount> 500) {
block.getLocation().getWorld().dropItem(block.getLocation(), new ItemStack(block.getType()));
if(fancyPhysics.getPluginConfig().isDropsOnExplode()) block.getLocation().getWorld().dropItem(block.getLocation(), new ItemStack(block.getType()));
block.setType(Material.AIR);
continue;
}

var fallingBlock = block.getWorld().spawnFallingBlock(block.getLocation().add(0,1,0), block.getType().createBlockData());
if(fancyPhysics.getPluginConfig().isNaturalDropsOnExplode()) fallingBlock.setDropItem(false);
if(fancyPhysics.getPluginConfig().isNaturalDropsOnExplode() || !fancyPhysics.getPluginConfig().isDropsOnExplode()) fallingBlock.setDropItem(false);
if(!fancyPhysics.getPluginConfig().isDropsOnExplode()) fallingBlock.addScoreboardTag("NoDrop");
fallingBlock.setVelocity(new Vector(x, y, z));
block.setType(Material.AIR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public HitGroundListener(FancyPhysics fancyPhysics) {
public void onBlockFall(EntityChangeBlockEvent event) {
if(this.fancyPhysics.getPluginConfig().getDisabledWorldsList().contains(event.getEntity().getLocation().getWorld().getName())) return;
createParticles(event);
if (event.getEntityType() != EntityType.FALLING_BLOCK) return;
var fallingBlock = (FallingBlock) event.getEntity();
if(fallingBlock.getScoreboardTags().contains("NoDrop")) {
fallingBlock.remove();
}
}

private void createParticles(EntityChangeBlockEvent event) {
Expand All @@ -30,6 +35,9 @@ private void createParticles(EntityChangeBlockEvent event) {
if(event.getBlock().getType() != Material.AIR) return;
if (event.getEntityType() != EntityType.FALLING_BLOCK) return;
var fallingBlock = (FallingBlock) event.getEntity();
if(fallingBlock.getScoreboardTags().contains("NoDrop")) {
fallingBlock.remove();
}
if(fallingBlock.getScoreboardTags().contains("DontBreak")) return;
var material = fallingBlock.getBlockData().getMaterial();
if(material == Material.DRAGON_EGG) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.maximde.fancyphysics.listeners.player;

import com.maximde.fancyphysics.FancyPhysics;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -49,6 +50,7 @@ private void checkBlockPhysics(Block startBlock) {

Material mainMaterial = startBlock.getType();
int maxDistance = fancyPhysics.getPluginConfig().getMaxBridgingLength(mainMaterial);

if(maxDistance < 0) return;
Block nearestSupportedBlock = findNearestSupportedBlock(startBlock, maxBlocks);
if (nearestSupportedBlock == null) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/maximde/fancyphysics/utils/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Config {
private boolean sprintGlassBreak;
private boolean visualCrafting;
private boolean naturalDropsOnExplode;
private boolean dropsOnExplode;
private boolean fallingBlockPhysics;
private boolean flyUpParticles;
private boolean blockCrackOnFall;
Expand Down Expand Up @@ -82,6 +83,7 @@ private void initDefaults() {
"VisualCrafting",
"FallingBlockPhysics",
"Explosion.NaturalDrops",
"Explosion.Drops",
"BlockCrackOnFall",
"Tree.ChopDelay",
"Tree.GravityIfInAir",
Expand Down Expand Up @@ -176,6 +178,7 @@ private void initValues() {
sprintGlassBreak = cfg.getBoolean("SprintBreak.Glass");
visualCrafting = cfg.getBoolean("VisualCrafting");
naturalDropsOnExplode = cfg.getBoolean("Explosion.NaturalDrops");
dropsOnExplode = cfg.getBoolean("Explosion.Drops");
flyUpParticles = cfg.getBoolean("Particle.Animation.FlyUp");
fallingBlockPhysics = cfg.getBoolean("FallingBlockPhysics");
blockCrackOnFall = cfg.getBoolean("BlockCrackOnFall");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.joml.Quaternionf;
import org.joml.Vector3f;
import java.util.Random;
import java.util.Vector;
import java.util.concurrent.ThreadLocalRandom;

public class ParticleDisplay {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SpawnPhysicsProtection:
Explosion:
Physics: true
NaturalDrops: true
Drops: true
EntityDeathParticles: true
BlockBreakingParticlesByPlayer: true
Particle:
Expand Down

0 comments on commit 93bbb1b

Please sign in to comment.