11package top .zoyn .particlelib ;
22
3+ import com .google .common .collect .Lists ;
34import org .bukkit .Bukkit ;
45import org .bukkit .Location ;
56import org .bukkit .Particle ;
7+ import org .bukkit .World ;
8+ import org .bukkit .block .Block ;
69import org .bukkit .command .Command ;
710import org .bukkit .command .CommandSender ;
811import org .bukkit .entity .Player ;
912import org .bukkit .plugin .java .JavaPlugin ;
10- import top .zoyn .particlelib .pobject .Arc ;
11- import top .zoyn .particlelib .pobject .Astroid ;
13+ import org .bukkit .util .Vector ;
1214import top .zoyn .particlelib .pobject .Circle ;
13- import top .zoyn .particlelib .pobject .Heart ;
14- import top .zoyn .particlelib .utils .matrix .Matrixs ;
15+ import top .zoyn .particlelib .pobject .Grid ;
16+ import top .zoyn .particlelib .utils .projector .ThreeDProjector ;
17+ import top .zoyn .particlelib .utils .projector .TwoDProjector ;
1518
19+ import java .util .List ;
1620import java .util .concurrent .atomic .AtomicInteger ;
21+ import java .util .function .BiFunction ;
1722
1823/**
1924 * 粒子库主类
@@ -41,6 +46,56 @@ public static void sendLog(String message) {
4146 Bukkit .getConsoleSender ().sendMessage ("§e[§6ParticleLib§e] " + message );
4247 }
4348
49+ /**
50+ * 围绕一个方块画出其边框
51+ *
52+ * @param block 给定的方块
53+ * @param particle 要显示的粒子
54+ */
55+ public static void showBorderAndGridAboutBlock (Block block , Particle particle ) {
56+ Location low = block .getLocation ();
57+ Location high = low .clone ().add (0 , 5 , 0 );
58+ List <Location > lowers = Lists .newArrayList (
59+ low ,
60+ low .clone ().add (5 , 0 , 0 ),
61+ low .clone ().add (5 , 0 , 5 ),
62+ low .clone ().add (0 , 0 , 5 ));
63+ List <Location > highers = Lists .newArrayList (
64+ high ,
65+ high .clone ().add (5 , 0 , 0 ),
66+ high .clone ().add (5 , 0 , 5 ),
67+ high .clone ().add (0 , 0 , 5 ));
68+
69+ for (int i = 0 ; i < lowers .size (); i ++) {
70+ Location origin = lowers .get (i );
71+ Location top = highers .get (i );
72+ Location next ;
73+ Location topNext ;
74+ // 最后一个的时候
75+ if (i == 3 ) {
76+ next = lowers .get (0 );
77+ topNext = highers .get (0 );
78+ } else {
79+ next = lowers .get (i + 1 );
80+ topNext = highers .get (i + 1 );
81+ }
82+
83+ // 以下为画线操作
84+ Vector vectorON = next .clone ().subtract (origin ).toVector ().normalize ();
85+ Vector vectorOT = top .clone ().subtract (origin ).toVector ().normalize ();
86+ Vector vectorTT = topNext .clone ().subtract (top ).toVector ().normalize ();
87+ for (double j = 0 ; j < 5 ; j += 0.1 ) {
88+ low .getWorld ().spawnParticle (particle , origin .clone ().add (vectorON .clone ().multiply (j )), 1 , 0 , 0 , 0 , 0 );
89+ low .getWorld ().spawnParticle (particle , origin .clone ().add (vectorOT .clone ().multiply (j )), 1 , 0 , 0 , 0 , 0 );
90+ low .getWorld ().spawnParticle (particle , top .clone ().add (vectorTT .clone ().multiply (j )), 1 , 0 , 0 , 0 , 0 );
91+ }
92+ // 绘制网格面
93+ Grid grid = new Grid (origin , topNext , 1.4D );
94+ grid .setParticle (Particle .FLAME );
95+ grid .show ();
96+ }
97+ }
98+
4499 @ Override
45100 public void onEnable () {
46101 instance = this ;
@@ -55,18 +110,109 @@ public void onDisable() {
55110 @ Override
56111 public boolean onCommand (CommandSender sender , Command cmd , String label , String [] args ) {
57112 Player player = (Player ) sender ;
113+
114+ // showBorderAndGridAboutBlock(player.getLocation().getBlock(), Particle.VILLAGER_HAPPY);
115+
116+ // Grid grid = new Grid(player.getLocation(), player.getLocation().add(5, -8, 0), 1.2D);
117+ //
118+ // grid.setPeriod(20);
119+ // grid.alwaysShowAsync();
120+
121+ Vector vector = player .getLocation ().getDirection ();
122+ Location location = player .getLocation ();
123+ World world = location .getWorld ();
124+ ThreeDProjector projector = new ThreeDProjector (location , vector );
125+ Bukkit .getScheduler ().runTaskTimer (this , () -> {
126+ double y = 0 ;
127+ for (int i = 0 ; i < 8 * 360 ; i += 20 ) {
128+ double rad = Math .toRadians (i );
129+ double x = Math .cos (rad );
130+ y += 0.1 ;
131+ double z = Math .sin (rad );
132+ // 通过投影器开始转换坐标
133+ Location loc = projector .apply (x , y , z );
134+ world .spawnParticle (Particle .VILLAGER_HAPPY , loc , 1 , 0 , 0 , 0 , 0 );
135+ }
136+ }, 0L , 10L );
137+
138+ // Vector vector = player.getLocation().getDirection();
139+ // Location location = player.getLocation();
140+ // World world = location.getWorld();
141+ // BiFunction<Double, Double, Location> method = TwoDProjector.create2DProjector(location, vector);
142+ // Bukkit.getScheduler().runTaskTimer(this, () -> {
143+ // for (int i = 0; i < 360; i++) {
144+ // double rad = Math.toRadians(i);
145+ // double x = Math.cos(rad);
146+ // double z = Math.sin(rad);
147+ // // 通过投影器开始转换坐标
148+ // Location loc = method.apply(x, z);
149+ // world.spawnParticle(Particle.VILLAGER_HAPPY, loc, 1, 0, 0, 0, 0);
150+ // }
151+ // }, 0L, 10L);
152+
153+ // Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
154+ // showBorderAboutBlock(player.getLocation().getBlock(), Particle.FIREWORKS_SPARK);
155+ // }, 0, 7L);
156+
157+ // Line.buildLine(flipHigh, high.clone().add(-1, 0, 0), 0.1, Particle.VILLAGER_HAPPY);
158+ // Line.buildLine(flipHigh, high.clone().add(0, 0, -1), 0.1, Particle.VILLAGER_HAPPY);
159+ //
160+ // Line.buildLine(flipLow, low.clone().add(1, 0, 0), 0.1, Particle.VILLAGER_HAPPY);
161+ // Line.buildLine(flipLow, low.clone().add(0, 0, 1), 0.1, Particle.VILLAGER_HAPPY);
162+ //
163+ // Line.buildLine(low, flipHigh, 0.1, Particle.VILLAGER_HAPPY);
164+ // Line.buildLine(high, flipLow, 0.1, Particle.VILLAGER_HAPPY);
165+ // double width = 1;
166+ // double length = 1;
167+ // double height = 1;
168+
169+ // Vector vector = new Vector(0, 0, 0);
170+
171+
172+ // ThreeDProjector projector = new ThreeDProjector(player.getLocation(), player.getLocation().getDirection());
173+ // double y = 0D;
174+ // for (int i = 0; i < 360 * 8; i += 5) {
175+ // double radians = Math.toRadians(i);
176+ // double x = Math.cos(radians);
177+ // y += 0.02;
178+ // double z = Math.sin(radians);
179+ //
180+ // player.getLocation().getWorld().spawnParticle(Particle.VILLAGER_HAPPY, projector.apply(x, y, z), 1);
181+ // }
182+
183+ // Location launchLocation = player.getEyeLocation().add(player.getLocation().getDirection().multiply(1.2));
184+ // Ray ray = new Ray(launchLocation, player.getLocation().getDirection(), 10, 0.02);
185+ //
186+ // ray.setStopType(Ray.RayStopType.HIT_ENTITY)
187+ // .setHitEntityConsumer(entity -> {
188+ // entity.setCustomName("§a芜湖!");
189+ // entity.setCustomNameVisible(true);
190+ // })
191+ // .setEntityFilter(entity -> entity.getName().equalsIgnoreCase(player.getName()));
192+ //
193+ // ray.show();
194+ //
195+ // Ray ray = new Ray(launchLocation, player.getLocation().getDirection(), 10, 0.02, 0.5D, Ray.RayStopType.HIT_ENTITY, entity -> {
196+ // entity.setCustomName("§a芜湖!");
197+ // entity.setCustomNameVisible(true);
198+ // }, entity -> entity.getName().equalsIgnoreCase(player.getName()));
199+
58200//
59201// Astroid astroid = new Astroid(player.getLocation());
60202// astroid.setParticle(Particle.FIREWORKS_SPARK);
61203// astroid.show();
204+
205+
62206//
63207// Heart heart = new Heart(player.getLocation());
64208// heart.alwaysShowAsync();
65209
66- // Polygon polygon = new Polygon(3 , player.getLocation());
67- // polygon.setParticle(Particle.VILLAGER_HAPPY );
210+ // Polygon polygon = new Polygon(4 , player.getLocation());
211+ // polygon.setParticle(Particle.FLAME );
68212// polygon.setStep(0.5);
69213// polygon.alwaysShowAsync();
214+
215+
70216//
71217// polygon = new Polygon(3, player.getLocation());
72218// polygon.setMatrix(Matrixs.rotate2D(90).multiply(2));
@@ -191,28 +337,6 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
191337// }.runTaskTimer(this, 0L, 10L);
192338//
193339//
194- // Vector vector = player.getLocation().getDirection();
195- // Location location = player.getLocation();
196- // World world = location.getWorld();
197- // BiFunction<Double, Double, Location> method = TwoDProjector.create2DProjector(location, vector);
198- // new BukkitRunnable() {
199- // @Override
200- // public void run() {
201- // for (int i = 0; i < 360; i++) {
202- // double rad = Math.toRadians(i);
203- // double x = Math.cos(rad);
204- // double z = Math.sin(rad);
205- //
206- //// Location loc = method.apply(x, z);
207- // Location loc = location.clone().add(1, 0, 1);
208- // world.spawnParticle(Particle.VILLAGER_HAPPY, loc, 1, 0, 0, 0, 0);
209- //// world.spawnParticle(Particle.FLAME, loc, 1, 0, 0, 0, 0);
210- // world.spawnParticle(Particle.FLAME, method.apply(1D, 1D), 1, 0, 0, 0, 0);
211- // }
212- // }
213- // }.runTaskTimer(this, 0L, 10L);
214-
215-
216340 return true ;
217341 }
218342}
0 commit comments