SteamWar/BauSystem
Archiviert
13
0

Simplify TPSLimit_12

Simplify TPSLimit_15
Dieser Commit ist enthalten in:
jojo 2020-12-25 18:06:19 +01:00
Ursprung 7f42fffd0c
Commit 65456ea19c
3 geänderte Dateien mit 14 neuen und 51 gelöschten Zeilen

Datei anzeigen

@ -32,37 +32,20 @@ import java.util.Set;
class TPSLimit_12 {
private static Set<PacketPlayOutEntityVelocity> velocityPackets = new HashSet<>();
private static Set<Packet<?>> packets = new HashSet<>();
static void createVelocityPacketCache(World world) {
velocityPackets.clear();
static void createTickCache(World world) {
packets.clear();
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
velocityPackets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), 0, 0, 0));
});
}
packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), 0, 0, 0));
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
static void sendVelocityPackets() {
sendPacketsToPlayer(velocityPackets);
}
static void sendTntMetaData(World world) {
Set<Packet<?>> packets = new HashSet<>();
world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> {
net.minecraft.server.v1_12_R1.Entity serverEntity = ((CraftEntity) entity).getHandle();
packets.add(new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true));
});
sendPacketsToPlayer(packets);
}
static void sendTeleports(World world) {
Set<Packet<?>> packets = new HashSet<>();
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
});
static void sendTickPackets() {
sendPacketsToPlayer(packets);
}

Datei anzeigen

@ -32,38 +32,21 @@ import java.util.Set;
class TPSLimit_15 {
private static Set<PacketPlayOutEntityVelocity> velocityPackets = new HashSet<>();
private static Set<Packet<?>> packets = new HashSet<>();
private static final Vec3D noMotion = new Vec3D(0, 0, 0);
static void createVelocityPacketCache(World world) {
velocityPackets.clear();
static void createTickCache(World world) {
packets.clear();
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
velocityPackets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion));
});
}
packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion));
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
static void sendVelocityPackets() {
sendPacketsToPlayer(velocityPackets);
}
static void sendTntMetaData(World world) {
Set<Packet<?>> packets = new HashSet<>();
world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> {
net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle();
packets.add(new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true));
});
sendPacketsToPlayer(packets);
}
static void sendTeleports(World world) {
Set<Packet<?>> packets = new HashSet<>();
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
});
static void sendTickPackets() {
sendPacketsToPlayer(packets);
}

Datei anzeigen

@ -102,13 +102,10 @@ public class CommandTPSLimiter implements CommandExecutor {
} else {
if (tpsLimiter != null) return;
tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
versionDependantCall(() -> TPSLimit_12.sendTntMetaData(world), () -> TPSLimit_15.sendTntMetaData(world));
versionDependantCall(() -> TPSLimit_12.createVelocityPacketCache(world), () -> TPSLimit_15.createVelocityPacketCache(world));
versionDependantCall(() -> TPSLimit_12.createTickCache(world), () -> TPSLimit_15.createTickCache(world));
for (int i = 0; i < (20 / currentTPSLimit); i++) {
sleepUntilNextTick();
versionDependantCall(() -> TPSLimit_12.sendTeleports(world), () -> TPSLimit_15.sendTeleports(world));
versionDependantCall(TPSLimit_12::sendVelocityPackets, TPSLimit_15::sendVelocityPackets);
versionDependantCall(TPSLimit_12::sendTickPackets, TPSLimit_15::sendTickPackets);
}
}, 0, 1);
}