From a0c644dd1c68f49926271b89a8210a929bc041c0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 21 Jul 2022 15:20:23 +0200 Subject: [PATCH] Optimize code Signed-off-by: yoyosource --- .../features/simulator/FakeTNT19.java | 93 +++++++++++++++++++ .../simulator/SimulatorPreview19.java | 8 +- .../simulator/SimulatorPreviewStorage.java | 2 - 3 files changed, 100 insertions(+), 3 deletions(-) diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/FakeTNT19.java b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/FakeTNT19.java index 90347f64..38e0c138 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/FakeTNT19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/FakeTNT19.java @@ -19,20 +19,37 @@ package de.steamwar.bausystem.features.simulator; +import net.minecraft.core.BlockPosition; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; import net.minecraft.network.syncher.DataWatcher; import net.minecraft.network.syncher.DataWatcherObject; import net.minecraft.network.syncher.DataWatcherRegistry; +import net.minecraft.tags.TagsBlock; +import net.minecraft.util.MathHelper; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.*; import net.minecraft.world.entity.item.EntityTNTPrimed; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.ExplosionDamageCalculator; +import net.minecraft.world.level.RayTrace; import net.minecraft.world.level.World; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.AxisAlignedBB; +import net.minecraft.world.phys.MovingObjectPosition; +import net.minecraft.world.phys.MovingObjectPositionBlock; +import net.minecraft.world.phys.Vec3D; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.craftbukkit.v1_19_R1.SpigotTimings; import org.bukkit.entity.Explosive; +import org.bukkit.entity.Vehicle; import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.vehicle.VehicleBlockCollisionEvent; import javax.annotation.Nullable; import java.util.List; @@ -80,6 +97,82 @@ public class FakeTNT19 extends EntityTNTPrimed { return !this.du(); } + private Vec3D g(Vec3D vec3d) { + AxisAlignedBB axisalignedbb = this.cz(); + List list = this.s.b(this, axisalignedbb.b(vec3d)); + Vec3D vec3d1 = vec3d.g() == 0.0 ? vec3d : a(this, vec3d, axisalignedbb, this.s, list); + boolean flag = vec3d.c != vec3d1.c; + boolean flag1 = vec3d.d != vec3d1.d; + boolean flag2 = vec3d.e != vec3d1.e; + boolean flag3 = this.y || flag1 && vec3d.d < 0.0; + if (this.P > 0.0F && flag3 && (flag || flag2)) { + Vec3D vec3d2 = a(this, new Vec3D(vec3d.c, (double)this.P, vec3d.e), axisalignedbb, this.s, list); + Vec3D vec3d3 = a(this, new Vec3D(0.0, (double)this.P, 0.0), axisalignedbb.b(vec3d.c, 0.0, vec3d.e), this.s, list); + if (vec3d3.d < (double)this.P) { + Vec3D vec3d4 = a(this, new Vec3D(vec3d.c, 0.0, vec3d.e), axisalignedbb.c(vec3d3), this.s, list).e(vec3d3); + if (vec3d4.i() > vec3d2.i()) { + vec3d2 = vec3d4; + } + } + + if (vec3d2.i() > vec3d1.i()) { + return vec3d2.e(a(this, new Vec3D(0.0, -vec3d2.d + vec3d.d, 0.0), axisalignedbb.c(vec3d2), this.s, list)); + } + } + + return vec3d1; + } + + @Override + public void a(EnumMoveType enummovetype, Vec3D vec3d) { + if (this.E.g() > 1.0E-7) { + vec3d = vec3d.h(this.E); + this.E = Vec3D.b; + this.f(Vec3D.b); + } + + Vec3D vec3d1 = this.g(vec3d); + double d0 = vec3d1.g(); + if (d0 > 1.0E-7) { + this.e(this.dg() + vec3d1.c, this.di() + vec3d1.d, this.dm() + vec3d1.e); + } + + boolean flag = !MathHelper.b(vec3d.c, vec3d1.c); + boolean flag1 = !MathHelper.b(vec3d.e, vec3d1.e); + this.z = flag || flag1; + this.A = vec3d.d != vec3d1.d; + this.B = this.A && vec3d.d < 0.0; + if (this.z) { + this.C = this.b(vec3d1); + } else { + this.C = false; + } + + this.y = this.A && vec3d.d < 0.0; + BlockPosition blockposition = this.aA(); + IBlockData iblockdata = this.s.a_(blockposition); + // this.a(vec3d1.d, this.y, iblockdata, blockposition); + if (!this.du()) { + if (this.z) { + Vec3D vec3d2 = this.de(); + this.n(flag ? 0.0 : vec3d2.c, vec3d2.d, flag1 ? 0.0 : vec3d2.e); + } + + net.minecraft.world.level.block.Block block = iblockdata.b(); + if (vec3d.d != vec3d1.d) { + block.a(this.s, this); + } + + if (this.y) { + block.a(this.s, blockposition, iblockdata, this); + } + + this.ax(); + float f2 = this.aD(); + this.f(this.de().d((double)f2, 1.0, (double)f2)); + } + } + @Override public void k() { if (!this.aN()) { diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/SimulatorPreview19.java b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/SimulatorPreview19.java index b8cdf8a6..1559b01a 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/SimulatorPreview19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/SimulatorPreview19.java @@ -45,6 +45,7 @@ public class SimulatorPreview19 implements SimulatorPreview { AtomicInteger maxTick = new AtomicInteger(0); Map>>> toSpawn = new HashMap<>(); + AtomicInteger tntCount = new AtomicInteger(0); result.forEach((integer, integerSetMap) -> { List>>> internal = new ArrayList<>(); integerSetMap.forEach((integer1, pairs) -> { @@ -52,12 +53,17 @@ public class SimulatorPreview19 implements SimulatorPreview { }); internal.sort(Comparator.comparingInt(Pair::getKey)); - toSpawn.put(integer, internal.stream().map(Pair::getValue).map(ArrayList::new).peek(Collections::shuffle).collect(Collectors.toList())); + toSpawn.put(integer, internal.stream().map(Pair::getValue).peek(pairs -> { + tntCount.addAndGet(pairs.stream().mapToInt(Pair::getValue).sum()); + }).map(ArrayList::new).peek(Collections::shuffle).collect(Collectors.toList())); if (maxTick.get() < integer) { maxTick.set(integer); } }); + if (tntCount.get() > 500) { + return new Record(false); + } List fakeTNT19s = new ArrayList<>(); Record record = new Record(false); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java index f37cc938..f2845d6e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java @@ -57,8 +57,6 @@ public class SimulatorPreviewStorage { pair.getValue().add(player); ShowModeParameter showModeParameter = new ShowModeParameter(); - showModeParameter.setInterpolate_XZ(true); - showModeParameter.setInterpolate_Y(true); TraceEntityShowMode showMode = new TraceEntityShowMode(player, showModeParameter); pair.getKey().showAll(showMode); showModes.put(player, new Pair<>(tntSimulator, showMode));