Added onExplosion Scarpet Event (#620)
* Added onExplosion Scarpet Event * Reverted changes to Full.md * Grammar corrections by James103 Co-authored-by: James103 <37945304+James103@users.noreply.github.com> * Separated Explosion Mixins Applied Ghoulboy78 suggestion. WARNING: 'blocks' list is now empty if 'explosionNoBlockDamage' carpet rule is set to 'true' * List Value from Triple Suggested by Gnembon * Explosion Mixin priority Suggestion by Gnembon * Added affectedEntities parameter * Updated docs * Optimizing calls * Update src/main/java/carpet/helpers/OptimizedExplosion.java * Update docs/scarpet/api/Events.md Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com> * Update docs/scarpet/api/Events.md Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com> * Update src/main/java/carpet/mixins/Explosion_scarpetEventMixin.java Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com> Co-authored-by: James103 <37945304+James103@users.noreply.github.com> Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com>
This commit is contained in:
7 files changed
+117
-3
No files matched your search
@@ -48,6 +48,8 @@ import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.EXPLOSION;
|
||||
|
||||
public class OptimizedExplosion
|
||||
{
|
||||
private static List<Entity> entitylist;
|
||||
@@ -68,9 +70,14 @@ public class OptimizedExplosion
|
||||
private static ArrayList<Float> chances = new ArrayList<>();
|
||||
private static BlockPos blastChanceLocation;
|
||||
|
||||
// Creating entity list for scarpet event
|
||||
private static List<Entity> entityList = new ArrayList<>();
|
||||
|
||||
public static void doExplosionA(Explosion e, ExplosionLogHelper eLogger) {
|
||||
ExplosionAccessor eAccess = (ExplosionAccessor) e;
|
||||
|
||||
entityList.clear();
|
||||
boolean eventNeeded = EXPLOSION.isNeeded();
|
||||
blastCalc(e);
|
||||
|
||||
if (!CarpetSettings.explosionNoBlockDamage) {
|
||||
@@ -156,6 +163,11 @@ public class OptimizedExplosion
|
||||
densityCache.put(pair, density);
|
||||
}
|
||||
|
||||
// If it is needed, it saves the entity
|
||||
if (eventNeeded) {
|
||||
entityList.add(entity);
|
||||
}
|
||||
|
||||
double d10 = (1.0D - d12) * density;
|
||||
entity.damage(e.getDamageSource(),
|
||||
(float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D)));
|
||||
@@ -195,6 +207,11 @@ public class OptimizedExplosion
|
||||
double posY = eAccess.getY();
|
||||
double posZ = eAccess.getZ();
|
||||
|
||||
// If it is needed, calls scarpet event
|
||||
if (EXPLOSION.isNeeded()) {
|
||||
EXPLOSION.onExplosion((ServerWorld) world, eAccess.getX(), eAccess.getY(), eAccess.getZ(), eAccess.getPower(), e.getDamageSource(), eAccess.isCreateFire(), e.getAffectedBlocks(), entityList);
|
||||
}
|
||||
|
||||
boolean damagesTerrain = eAccess.getDestructionType() != Explosion.DestructionType.NONE;
|
||||
|
||||
// explosionSound incremented till disabling the explosion particles and sound
|
||||
@@ -598,4 +615,4 @@ public class OptimizedExplosion
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user