SteamWar/BauSystem2.0
Archiviert
12
0

Add basic Explosion
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-04-16 13:00:17 +02:00
Ursprung a2cdcc0b47
Commit faf62a6ee7
2 geänderte Dateien mit 104 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,102 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
public class Explosion {
private static final Random RANDOM = new Random();
private static final float POWER = 4.0F;
private final TNT tnt;
private final double x;
private final double y;
private final double z;
private final List<TNT> entities;
public Explosion(TNT tnt, double x, double y, double z, List<TNT> entities) {
this.tnt = tnt;
this.x = x;
this.y = y;
this.z = z;
this.entities = entities;
}
public void calculate() {
Set<Vector> affectedBlocks = new HashSet<>();
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
if (i == 0 || i == 15 || j == 0 || j == 15 || k == 0 || k == 15) {
double d = i / 15.0F * 2.0F - 1.0F;
double e = j / 15.0F * 2.0F - 1.0F;
double f = k / 15.0F * 2.0F - 1.0F;
double g = Math.sqrt(d * d + e * e + f * f);
d /= g;
e /= g;
f /= g;
float h = POWER * (0.7F + RANDOM.nextFloat() * 0.6F);
double m = x;
double n = y;
double o = z;
for (; h > 0.0F; h -= 0.22500001F) {
int x = TNT.floor(m);
int y = TNT.floor(n);
int z = TNT.floor(o);
BlockData blockData = Simulator19.getBlockData(x, y, z);
if (blockData != null) {
h -= (blockData.getMaterial().getBlastResistance() + 0.3F) * 0.3F;
}
if (blockData instanceof Waterlogged) {
Waterlogged waterlogged = (Waterlogged) blockData;
if (waterlogged.isWaterlogged()) {
h = 0.0F;
}
}
if (h > 0.0F) {
affectedBlocks.add(new Vector(x, y, z));
}
m += d * 0.30000001192092896;
n += e * 0.30000001192092896;
o += f * 0.30000001192092896;
}
}
}
}
}
// TODO: Add velocity change of other tnt entities
// System.out.println(affectedBlocks.size());
}
}

Datei anzeigen

@ -81,7 +81,8 @@ public class TNT {
this.fuse--; this.fuse--;
if (this.fuse <= 0) { if (this.fuse <= 0) {
// TODO: Add explosion Explosion explosion = new Explosion(this, x, y + 0.98 * 0.0625, z);
explosion.calculate();
return true; return true;
} }
return false; return false;