当前位置: 首页 > 知识库问答 >
问题:

Minecraft插件-随机传送时块生成滞后

诸葛砚
2023-03-14
public class RTPCommand implements CommandExecutor {

Main main;
int i, j, x, z;
World world;
Player player;

public RTPCommand(Main main) {
    this.main = main;
    world = Bukkit.getWorld("world");
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if(label.equalsIgnoreCase("rtp") && sender instanceof Player){
        player = (Player) sender;
        Random random = new Random();
        x = random.nextInt(10000);
        z = random.nextInt(10000);
        Bukkit.broadcastMessage("X : " + x + " // Z: " + z);
        i = x - 160;j = z - 160;
        new TaskTimer().runTaskTimer(main, 0, 2);
    }
    return false;
}

class TaskTimer extends BukkitRunnable{

    @Override
    public void run() {
        Chunk chunk = world.getChunkAt(i, j);
        chunk.load(true);
        j += 16;
        if(j == (z + 160)){
            if(i == (x + 160)){
                cancel();
                System.out.println("FINI.");
                player.teleport(new Location(world, x, world.getHighestBlockYAt(x, z), z));
            }else{
                i += 16;
                j = z - 160;
            }
        }
    }
}
}

共有1个答案

邓鸿信
2023-03-14

块不是位置。

块是位置的1/16,因此示例x=6600,z=7520将是x=412 z=470的块位置

类似地,x=40,z=150
的块坐标在x=640-656,z=2400-2416的世界中等于x/z的范围

 类似资料:
  • 在1.7.10中是否有一个事件用于当一个块生成时,所以我可以在它上面放置一些东西。还是我一定要在这一代人中做到这一点? 我已经上网了,但我找不到 事件之类的。

  • random 生成随机数包 文档:https://www.npmjs.com/package/random 安装:npm install --save random 封装代码: app / extend / context.js // 导入 jwt const jwt = require('jsonwebtoken') // 导入随机数包 const random = require('rando

  • 问题 你需要生成在一定范围内的随机数。 解决方案 使用 JavaScript 的 Math.random() 来获得浮点数,满足 0<=X<1.0 。使用乘法和 Math.floor 得到在一定范围内的数字。 probability = Math.random() 0.0 <= probability < 1.0 # => true # 注意百分位数不会达到 100。从 0 到 100 的范围实

  • 本文向大家介绍Python随机生成数据后插入到PostgreSQL,包括了Python随机生成数据后插入到PostgreSQL的使用技巧和注意事项,需要的朋友参考一下 用Python随机生成学生姓名,三科成绩和班级数据,再插入到PostgreSQL中。 模块用psycopg2 random 以上就是利用Python随机生成数据后插入到PostgreSQL数据库中的全部内容,希望给大家学习Pytho

  • 我已经在kuberenetes中使用散列分片设置了分片的MongoDB集群。我首先创建了配置服务器副本集,然后创建了2个分片副本集。最终创建了mongos来连接分片集群。 我按照下面的链接设置分片MongoDB点击https://docs . MongoDB . com/manual/tutorial/deploy-sharded-cluster-hashed-sharding/ 在创建mongo