forked from SteamWar/SteamWar
Add SimulatorPreview and SimulatorPreviewTNT
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 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.preview;
|
||||
|
||||
public class SimulatorPreview {
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 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.preview;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class SimulatorPreviewTNT {
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
private boolean gravity = false;
|
||||
private int fuse = 80;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private double vx;
|
||||
private double vy;
|
||||
private double vz;
|
||||
|
||||
private boolean onGround;
|
||||
|
||||
public SimulatorPreviewTNT(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
double d = random.nextDouble() * Math.PI * 2;
|
||||
this.vx = -Math.sin(d) * 0.02;
|
||||
this.vy = 0.2;
|
||||
this.vz = -Math.cos(d) * 0.02;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
// Gravity
|
||||
if (!gravity) {
|
||||
vy -= 0.04;
|
||||
}
|
||||
|
||||
// Movement
|
||||
move();
|
||||
|
||||
// TODO: EffectsFromOtherBlocks
|
||||
|
||||
// Velocity * 0.98
|
||||
vx *= 0.98;
|
||||
vy *= 0.98;
|
||||
vz *= 0.98;
|
||||
|
||||
// OnGround Velocity * 0.7 -0.5 0.7
|
||||
if (false) {
|
||||
vx *= 0.7;
|
||||
vy *= -0.5;
|
||||
vz *= 0.7;
|
||||
}
|
||||
|
||||
// Decrease Fuse
|
||||
fuse--;
|
||||
if (fuse <= 0) {
|
||||
// Explode on zero Fuse
|
||||
explode();
|
||||
} else {
|
||||
// TODO: or do water Movement!
|
||||
}
|
||||
}
|
||||
|
||||
public void move() {
|
||||
Vector vec = collide();
|
||||
double d = vec.lengthSquared();
|
||||
if (d > 1.0E-7 || new Vector(vx, vy, vz).lengthSquared() - d < 1.0E-7) {
|
||||
x += vx;
|
||||
y += vy;
|
||||
z += vz;
|
||||
}
|
||||
|
||||
boolean flag = !equal(vx, vec.getX());
|
||||
boolean flag1 = !equal(vz, vec.getZ());
|
||||
boolean horizontalCollision = flag || flag1;
|
||||
if (Math.abs(vy) > 0.0F) {
|
||||
boolean verticalCollision = vy != vec.getY();
|
||||
onGround = verticalCollision && vy < (double) 0.0F;
|
||||
}
|
||||
|
||||
if (horizontalCollision) {
|
||||
if (flag) vx = 0;
|
||||
if (flag1) vz = 0;
|
||||
}
|
||||
// TODO: Get Block -> updateEntityMovementAfterFallOn!
|
||||
// TODO: Get BlockSpeedFactor multiply
|
||||
}
|
||||
|
||||
public static boolean equal(double x, double y) {
|
||||
return Math.abs(y - x) < (double) 1.0E-5F;
|
||||
}
|
||||
|
||||
public Vector collide() {
|
||||
if (x == 0 && y == 0 && z == 0) return new Vector(0, 0, 0);
|
||||
// TODO: Implement rest!
|
||||
return null;
|
||||
}
|
||||
|
||||
public void explode() {
|
||||
// TODO: Implement
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user