Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
chunk load my best friend
Browse files Browse the repository at this point in the history
  • Loading branch information
MidnightTale committed Apr 12, 2023
1 parent f3168ee commit cc112ae
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions src/main/java/xyz/hynse/foliaflow/FoliaFlow.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package xyz.hynse.foliaflow;

import io.papermc.paper.event.entity.EntityMoveEvent;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
Expand All @@ -9,7 +8,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

Expand Down Expand Up @@ -54,14 +53,17 @@ public void onDisable() {
}

@EventHandler
public void onEntityMove(EntityMoveEvent event) {
handleMove(event.getEntity().getLocation());
public void onChunkLoad(ChunkLoadEvent event) {
Block obsidianBlock = obsidianLocation.getBlock();
if (event.getWorld() == endWorld && obsidianBlock.getType() == Material.OBSIDIAN) { // check if the chunk is in the end and the block is obsidian
obsidianBlock.setType(Material.AIR); // set the block to air
}
}

private void handleMove(Location location) {
if (location.getWorld() == endWorld && location.distance(obsidianLocation) <= 1.0) { // check if the location is in the end and within 1 block of the obsidian platform
Block obsidianBlock = obsidianLocation.getBlock();
obsidianBlock.setType(Material.AIR); // set the block to air
@EventHandler
public void onBlockChange(org.bukkit.event.block.BlockFromToEvent event) {
if (event.getBlock().getLocation().equals(obsidianLocation)) { // check if the block change event is for the obsidian block location
event.setCancelled(true); // cancel the event to prevent the obsidian block from changing
}
}

Expand Down Expand Up @@ -96,26 +98,33 @@ public void onFallingBlockToBlock(EntityChangeBlockEvent e){


@EventHandler
public void onFallingBlockSpawn(EntitySpawnEvent e) {
if (e.getEntityType() == EntityType.FALLING_BLOCK && e.getEntity().getWorld().getEnvironment() == World.Environment.THE_END) {
Entity entity = e.getEntity();
Location loc = entity.getLocation();

debug("Falling block spawned at location " + loc);

// Set the initial velocity of the falling block
int index = counter % 4;
counter ++;
Vector velocity = velocities[index];
entity.setVelocity(velocity);

// Remove the block from the movingBlocks set after a delay, to prevent it from being immediately moved again
getServer().getScheduler().runTaskLater(this, () -> movingBlocks.remove(loc.getBlock().getLocation()), 20L);
public void onChunkLoadend(ChunkLoadEvent e) {
Chunk chunk = e.getChunk();
World world = chunk.getWorld();
if (world.getEnvironment() == World.Environment.THE_END) {
// Iterate through all the entities in the chunk
for (Entity entity : chunk.getEntities()) {
if (entity.getType() == EntityType.FALLING_BLOCK) {
Location loc = entity.getLocation();

debug("Falling block spawned at location " + loc);

// Set the initial velocity of the falling block
int index = counter % 4;
counter ++;
Vector velocity = velocities[index];
entity.setVelocity(velocity);

// Remove the block from the movingBlocks set after a delay, to prevent it from being immediately moved again
getServer().getScheduler().runTaskLater(this, () -> movingBlocks.remove(loc.getBlock().getLocation()), 20L);
}
}
}
}




Block getBlockMovingTo(Location loc, Vector vel) {
double absMax = 0, max = 0;
char dir = ' ';
Expand Down

0 comments on commit cc112ae

Please sign in to comment.