Update TNT and cache of Block and BlockData for faster get
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
a68f45d824
Commit
89ee198968
@ -20,18 +20,46 @@
|
||||
package de.steamwar.bausystem.features.simulator;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Simulator19 implements Simulator {
|
||||
|
||||
public static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
private static final Map<Vector, Material> BLOCK_TYPES_MAP = new HashMap<>();
|
||||
private static final Map<Vector, BlockData> BLOCK_DATA_MAP = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public synchronized void run() {
|
||||
TNT tnt = new TNT(0, 120, 0);
|
||||
do {
|
||||
System.out.println(tnt);
|
||||
} while (!tnt.tick());
|
||||
System.out.println(tnt);
|
||||
|
||||
BLOCK_TYPES_MAP.clear();
|
||||
BLOCK_DATA_MAP.clear();
|
||||
}
|
||||
|
||||
public static Material getBlockType(int x, int y, int z) {
|
||||
Vector vector = new Vector(x, y, z);
|
||||
return BLOCK_TYPES_MAP.computeIfAbsent(vector, v -> WORLD.getBlockAt(v.getBlockX(), v.getBlockY(), v.getBlockZ()).getType());
|
||||
}
|
||||
|
||||
public static BlockData getBlockData(int x, int y, int z) {
|
||||
Vector vector = new Vector(x, y, z);
|
||||
return BLOCK_DATA_MAP.computeIfAbsent(vector, v -> WORLD.getBlockAt(v.getBlockX(), v.getBlockY(), v.getBlockZ()).getBlockData());
|
||||
}
|
||||
|
||||
public static void setBlock(int x, int y, int z, Material material) {
|
||||
Vector vector = new Vector(x, y, z);
|
||||
BLOCK_TYPES_MAP.put(vector, material);
|
||||
BLOCK_DATA_MAP.put(vector, material.createBlockData());
|
||||
}
|
||||
}
|
||||
|
@ -30,12 +30,8 @@ import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraft.world.phys.shapes.VoxelShapes;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Bed;
|
||||
import org.bukkit.block.data.type.Fence;
|
||||
import org.bukkit.block.data.type.Gate;
|
||||
import org.bukkit.block.data.type.Wall;
|
||||
import org.bukkit.block.data.type.*;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -130,8 +126,9 @@ public class TNT {
|
||||
|
||||
this.onGround = this.verticalCollision && movement.getY() < 0.0D;
|
||||
Vector blockPos = getLandingPos();
|
||||
Block block = Simulator19.WORLD.getBlockAt(blockPos.getBlockX(), blockPos.getBlockY(), blockPos.getBlockZ());
|
||||
fall(vec3d.getX(), onGround, block, blockPos);
|
||||
Material material = Simulator19.getBlockType(blockPos.getBlockX(), blockPos.getBlockY(), blockPos.getBlockZ());
|
||||
BlockData blockData = Simulator19.getBlockData(blockPos.getBlockX(), blockPos.getBlockY(), blockPos.getBlockZ());
|
||||
fall(vec3d.getX(), onGround);
|
||||
|
||||
if (horizontalCollision) {
|
||||
this.vx = bl ? 0.0 : this.vx;
|
||||
@ -139,12 +136,12 @@ public class TNT {
|
||||
}
|
||||
|
||||
if (movement.getY() != vec3d.getY()) {
|
||||
if (block.getType() == Material.SLIME_BLOCK) {
|
||||
if (material == Material.SLIME_BLOCK) {
|
||||
if (this.vy < 0.0) {
|
||||
this.vy = -this.vy * 0.8;
|
||||
}
|
||||
}
|
||||
if (block.getBlockData() instanceof Bed) {
|
||||
if (blockData instanceof Bed) {
|
||||
if (this.vy < 0.0) {
|
||||
this.vy = -this.vy * 0.6600000262260437 * 0.8;
|
||||
}
|
||||
@ -152,7 +149,7 @@ public class TNT {
|
||||
}
|
||||
|
||||
if (onGround) {
|
||||
if (block.getType() == Material.SLIME_BLOCK) {
|
||||
if (material == Material.SLIME_BLOCK) {
|
||||
double cy = Math.abs(this.vy);
|
||||
if (cy < 0.1) {
|
||||
double cy2 = 0.4 + cy * 0.2;
|
||||
@ -232,9 +229,8 @@ public class TNT {
|
||||
int y = floor(this.y - 0.2F);
|
||||
int z = floor(this.z);
|
||||
|
||||
if (Simulator19.WORLD.getBlockAt(x, y, z).isEmpty()) {
|
||||
Block block = Simulator19.WORLD.getBlockAt(x, y - 1, z);
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (Simulator19.getBlockType(x, y, z).isAir()) {
|
||||
BlockData blockData = Simulator19.getBlockData(x, y - 1, z);
|
||||
if (blockData instanceof Fence || blockData instanceof Wall || blockData instanceof Gate) {
|
||||
return new Vector(x, y - 1, z);
|
||||
}
|
||||
@ -242,11 +238,13 @@ public class TNT {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
private void fall(double heightDifference, boolean onGround, Block state, Vector landedPosition) {
|
||||
private void fall(double heightDifference, boolean onGround) {
|
||||
if (onGround) {
|
||||
/*
|
||||
if (this.fallDistance > 0.0F) {
|
||||
state.getBlock().onLandedUpon(this.world, state, landedPosition, this, this.fallDistance);
|
||||
// TODO: Is this needed?: state.getBlock().onLandedUpon(this.world, state, landedPosition, this, this.fallDistance);
|
||||
}
|
||||
*/
|
||||
|
||||
this.onLanding();
|
||||
} else if (heightDifference < 0.0) {
|
||||
@ -265,18 +263,32 @@ public class TNT {
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
for (int y = y1; y <= y2; y++) {
|
||||
for (int z = z1; z <= z2; z++) {
|
||||
Block block = Simulator19.WORLD.getBlockAt(x, y, z);
|
||||
Material material = Simulator19.getBlockType(x, y, z);
|
||||
|
||||
if (block.getType() == Material.POWDER_SNOW) {
|
||||
if (material == Material.POWDER_SNOW) {
|
||||
slowMovement(new Vector(0.8999999761581421, 1.5, 0.8999999761581421));
|
||||
} else if (block.getType() == Material.HONEY_BLOCK) {
|
||||
} else if (material == Material.HONEY_BLOCK) {
|
||||
if (isSliding(new Vector(x, y, z))) {
|
||||
updateSlidingVelocity();
|
||||
}
|
||||
} else if (block.getType() == Material.COBWEB) {
|
||||
} else if (material == Material.COBWEB) {
|
||||
slowMovement(new Vector(0.25, 0.05000000074505806, 0.25));
|
||||
} else if (block.getType() == Material.BUBBLE_COLUMN) {
|
||||
// TODO: Bubble column
|
||||
} else if (material == Material.BUBBLE_COLUMN) {
|
||||
boolean drag = ((BubbleColumn) Simulator19.getBlockData(x, y, z)).isDrag();
|
||||
if (Simulator19.getBlockType(x, y + 1, z).isAir()) {
|
||||
if (drag) {
|
||||
this.vy = Math.max(-0.9, vy - 0.03);
|
||||
} else {
|
||||
this.vy = Math.min(1.8, vy + 0.1);
|
||||
}
|
||||
} else {
|
||||
if (drag) {
|
||||
this.vy = Math.max(-0.3, vy - 0.03);
|
||||
} else {
|
||||
this.vy = Math.min(0.7, vy + 0.06);
|
||||
}
|
||||
onLanding();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -308,6 +320,26 @@ public class TNT {
|
||||
return d + 1.0E-7 > f || e + 1.0E-7 > f;
|
||||
}
|
||||
|
||||
private float getVelocityMultiplier() {
|
||||
Material material = Simulator19.getBlockType(floor(x), floor(y), floor(z));
|
||||
float f = 1F;
|
||||
if (material == Material.SOUL_SAND) {
|
||||
f = 0.5F;
|
||||
} else if (material == Material.HONEY_BLOCK) {
|
||||
f = 0.4F;
|
||||
}
|
||||
if (material != Material.WATER && material != Material.BUBBLE_COLUMN) {
|
||||
if (f != 1) return f;
|
||||
material = Simulator19.getBlockType(floor(x), floor(y - 0.5000001), floor(z));
|
||||
if (material == Material.SOUL_SAND) {
|
||||
f = 0.5F;
|
||||
} else if (material == Material.HONEY_BLOCK) {
|
||||
f = 0.4F;
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
private void onLanding() {
|
||||
this.fallDistance = 0.0F;
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren