optimize + folia ?
This commit is contained in:
parent
5f1597d5d1
commit
da65cabbf0
2 changed files with 26 additions and 62 deletions
|
|
@ -16,10 +16,15 @@ repositories {
|
||||||
name = "sonatype"
|
name = "sonatype"
|
||||||
url = "https://oss.sonatype.org/content/groups/public/"
|
url = "https://oss.sonatype.org/content/groups/public/"
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
name = "devmart-other"
|
||||||
|
url = "https://nexuslite.gcnt.net/repos/other/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly "dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT"
|
compileOnly "dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT"
|
||||||
|
implementation "com.tcoded:FoliaLib:0.2.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 17
|
def targetJavaVersion = 17
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package xyz.hynse.bbsdfia;
|
package xyz.hynse.bbsdfia;
|
||||||
|
|
||||||
|
import com.tcoded.folialib.FoliaLib;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
@ -23,7 +24,13 @@ public class Bbsdfia extends JavaPlugin implements Listener {
|
||||||
private int counter = 0;
|
private int counter = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
super.onEnable();
|
||||||
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
getServer().getLogger().info("Bbsdfia plugin started");
|
||||||
|
}*/
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
super.onEnable();
|
super.onEnable();
|
||||||
|
|
@ -65,14 +72,15 @@ public class Bbsdfia extends JavaPlugin implements Listener {
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onFallingBlockToBlock(EntityChangeBlockEvent e){
|
public void onFallingBlockToBlock(EntityChangeBlockEvent e) {
|
||||||
if(e.getEntityType() == EntityType.FALLING_BLOCK){
|
if (e.getEntityType() == EntityType.FALLING_BLOCK) {
|
||||||
Entity entity = e.getEntity();
|
Entity entity = e.getEntity();
|
||||||
Location loc = entity.getLocation();
|
Location loc = entity.getLocation();
|
||||||
Vector vel = entity.getVelocity();
|
Vector vel = entity.getVelocity();
|
||||||
Block movingTo = getBlockMovingTo(loc, vel);
|
Block movingTo = getBlockMovingTo(loc, vel);
|
||||||
|
FoliaLib foliaLib = new FoliaLib(this);
|
||||||
|
|
||||||
if(movingTo != null && movingTo.getType() == Material.END_PORTAL){
|
if (movingTo != null && movingTo.getType() == Material.END_PORTAL) {
|
||||||
Location spawnLoc = movingTo.getLocation();
|
Location spawnLoc = movingTo.getLocation();
|
||||||
spawnLoc.setX(spawnLoc.getX()+0.5);
|
spawnLoc.setX(spawnLoc.getX()+0.5);
|
||||||
spawnLoc.setY(spawnLoc.getY()+0.5);
|
spawnLoc.setY(spawnLoc.getY()+0.5);
|
||||||
|
|
@ -86,27 +94,30 @@ public class Bbsdfia extends JavaPlugin implements Listener {
|
||||||
dummyVel.add(new Vector(0, -0.2, 0));
|
dummyVel.add(new Vector(0, -0.2, 0));
|
||||||
firstBlock.setVelocity(dummyVel);
|
firstBlock.setVelocity(dummyVel);
|
||||||
|
|
||||||
// Schedule the spawning of the other two falling blocks with a delay
|
foliaLib.getImpl().runAtLocation(spawnLoc, () -> {
|
||||||
Bukkit.getScheduler().runTaskLater(this, () -> {
|
for (int i = 0; i < 2; i++) {
|
||||||
for(int i = 0; i < 2; i++){
|
|
||||||
Location spawnLoc1 = movingTo.getLocation();
|
Location spawnLoc1 = movingTo.getLocation();
|
||||||
spawnLoc1.setX(spawnLoc1.getX()+0.5);
|
spawnLoc1.setX(spawnLoc1.getX() + 0.5);
|
||||||
spawnLoc1.setY(spawnLoc1.getY()+0.5);
|
spawnLoc1.setY(spawnLoc1.getY() + 0.5);
|
||||||
spawnLoc1.setZ(spawnLoc1.getZ()+0.5);
|
spawnLoc1.setZ(spawnLoc1.getZ() + 0.5);
|
||||||
|
|
||||||
FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc1, ((FallingBlock) entity).getBlockData());
|
FallingBlock fallingBlock = (FallingBlock) entity;
|
||||||
|
FallingBlock dummy = spawnLoc1.getWorld().spawnFallingBlock(spawnLoc1, fallingBlock.getBlockData());
|
||||||
Vector dummyVel1 = vel.clone();
|
Vector dummyVel1 = vel.clone();
|
||||||
dummyVel1.setY(-dummyVel1.getY());
|
dummyVel1.setY(-dummyVel1.getY());
|
||||||
dummyVel1.multiply(new Vector(2, 2, 2));
|
dummyVel1.multiply(new Vector(2, 2, 2));
|
||||||
dummyVel1.add(new Vector(0, -0.2, 0));
|
dummyVel1.add(new Vector(0, -0.2, 0));
|
||||||
dummy.setVelocity(dummyVel1);
|
dummy.setVelocity(dummyVel1);
|
||||||
}
|
}
|
||||||
}, 10);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
@ -133,58 +144,6 @@ public class Bbsdfia extends JavaPlugin implements Listener {
|
||||||
FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data);
|
FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data);
|
||||||
newFallingBlock.setVelocity(velocity);
|
newFallingBlock.setVelocity(velocity);
|
||||||
}
|
}
|
||||||
@EventHandler
|
|
||||||
public void onEntityChangeBlock2(EntityChangeBlockEvent event) {
|
|
||||||
Entity entity = event.getEntity();
|
|
||||||
if (!(entity instanceof FallingBlock)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (entity.getWorld().getEnvironment() != World.Environment.THE_END) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Spawn a new falling block entity with velocity
|
|
||||||
entity.remove();
|
|
||||||
Location fuck = new Location(Bukkit.getWorld("world_the_end"), 100, 49 ,0);
|
|
||||||
fuck.getBlock().setType(Material.AIR);
|
|
||||||
World world = entity.getWorld();
|
|
||||||
Location location = entity.getLocation();
|
|
||||||
byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0];
|
|
||||||
Material material = ((FallingBlock) entity).getBlockData().getMaterial();
|
|
||||||
|
|
||||||
int index = counter % 4;
|
|
||||||
Vector velocity = velocities[index];
|
|
||||||
counter++;
|
|
||||||
|
|
||||||
FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data);
|
|
||||||
newFallingBlock.setVelocity(velocity);
|
|
||||||
}
|
|
||||||
@EventHandler
|
|
||||||
public void onEntityChangeBlock1(EntityChangeBlockEvent event) {
|
|
||||||
Entity entity = event.getEntity();
|
|
||||||
if (!(entity instanceof FallingBlock)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (entity.getWorld().getEnvironment() != World.Environment.THE_END) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Spawn a new falling block entity with velocity
|
|
||||||
entity.remove();
|
|
||||||
Location fuck = new Location(Bukkit.getWorld("world_the_end"), 100, 49 ,0);
|
|
||||||
fuck.getBlock().setType(Material.AIR);
|
|
||||||
World world = entity.getWorld();
|
|
||||||
Location location = entity.getLocation();
|
|
||||||
byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0];
|
|
||||||
Material material = ((FallingBlock) entity).getBlockData().getMaterial();
|
|
||||||
|
|
||||||
int index = counter % 4;
|
|
||||||
Vector velocity = velocities[index];
|
|
||||||
counter++;
|
|
||||||
|
|
||||||
FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data);
|
|
||||||
newFallingBlock.setVelocity(velocity);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Block getBlockMovingTo(Location loc, Vector vel){
|
Block getBlockMovingTo(Location loc, Vector vel){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue