rocket sand

This commit is contained in:
MidnightTale 2023-04-12 08:23:36 +07:00
commit 297d70e907
2 changed files with 32 additions and 17 deletions

View file

@ -2,11 +2,16 @@ plugins {
id 'java' id 'java'
} }
group = 'xyz.hynse' group = 'xyz.hynse'
version = '1.1-SNAPSHOT' version = '1.1-SNAPSHOT'
repositories { repositories {
mavenCentral() mavenCentral()
maven {
name = "devmart-other"
url = "https://nexuslite.gcnt.net/repos/other/"
}
maven { maven {
name = "papermc-repo" name = "papermc-repo"
url = "https://repo.papermc.io/repository/maven-public/" url = "https://repo.papermc.io/repository/maven-public/"
@ -15,14 +20,12 @@ 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"} implementation "com.tcoded:FoliaLib:0.2.0"
compileOnly "dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT"
}
def targetJavaVersion = 17 def targetJavaVersion = 17
java { java {

View file

@ -1,10 +1,8 @@
package xyz.hynse.bbsdfia; package xyz.hynse.bbsdfia;
import com.tcoded.folialib.FoliaLib;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -21,7 +19,6 @@ public class Bbsdfia extends JavaPlugin implements Listener {
super.onEnable(); super.onEnable();
getServer().getPluginManager().registerEvents(this, this); getServer().getPluginManager().registerEvents(this, this);
getServer().getLogger().info("Bbsdfia plugin started"); getServer().getLogger().info("Bbsdfia plugin started");
} }
@Override @Override
@ -29,7 +26,7 @@ public class Bbsdfia extends JavaPlugin implements Listener {
super.onDisable(); super.onDisable();
getServer().getLogger().info("Bbsdfia plugin stopped"); getServer().getLogger().info("Bbsdfia plugin stopped");
} }
FoliaLib foliaLib = new FoliaLib(this);
@EventHandler @EventHandler
public void onFallingBlockToBlock(EntityChangeBlockEvent e){ public void onFallingBlockToBlock(EntityChangeBlockEvent e){
if(e.getEntityType() == EntityType.FALLING_BLOCK){ if(e.getEntityType() == EntityType.FALLING_BLOCK){
@ -37,23 +34,38 @@ public class Bbsdfia extends JavaPlugin implements Listener {
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);
if(movingTo != null && movingTo.getType() == Material.END_PORTAL){ if(movingTo != null && movingTo.getType() == Material.END_PORTAL){
Location spawnLoc = new Location(Bukkit.getWorld("world_the_end"), 100, 50 ,0); Location spawnLoc = movingTo.getLocation();
foliaLib.getImpl().runAtEntity(entity, () -> { spawnLoc.setX(spawnLoc.getX()+0.5);
spawnLoc.setY(spawnLoc.getY()+0.5);
spawnLoc.setZ(spawnLoc.getZ()+0.5);
FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData());
Vector dummyVel = vel.clone(); Vector dummyVel = vel.clone();
dummyVel.setY(-dummyVel.getY()); dummyVel.setY(-dummyVel.getY());
dummyVel.multiply(new Vector(2, 2, 2)); // double the velocity dummyVel.multiply(new Vector(2, 2, 2));
// add a constant downward velocity to simulate gravity dummyVel.add(new Vector(0, -0.2, 0));
dummyVel.add(new Vector(0, 0.3, 0));
dummy.setVelocity(dummyVel); dummy.setVelocity(dummyVel);
});
} }
} }
} }
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
if (event.getEntity() instanceof FallingBlock fallingBlock) {
if (fallingBlock.getWorld().getEnvironment() == World.Environment.THE_END) {
Location blockLocation = fallingBlock.getLocation();
blockLocation.setY(blockLocation.getY() + 1);
if (blockLocation.getBlock().getType() == Material.AIR) {
Vector velocity = fallingBlock.getVelocity();
velocity.setY(5);
fallingBlock.setVelocity(velocity);
}
}
}
}
Block getBlockMovingTo(Location loc, Vector vel){ Block getBlockMovingTo(Location loc, Vector vel){