Block definition problem

Discussion in 'Plugin Development' started by Shelldonite, Feb 26, 2024.

Thread Status:
Not open for further replies.
  1. Offline

    Shelldonite

    I'm rewriting a long old plugin and porting it to version 1.19.4. Everything would be fine, but I came across non-working methods (including getBlockTypeIdAt - It has been replaced by getBlockAt, which is used to determine the ID of a block located at the specified coordinates, as far as I understand). I fixed all the errors except one problematic part of the code:
    Code:
    public void onVehicleMove(VehicleMoveEvent event) {
            if (event.getVehicle() instanceof Minecart) {
                Minecart cart = (Minecart)event.getVehicle();
                int[] xarr$ = this.xmodifier;
    
                for (int xmod : xarr$) {
                    int[] yarr$ = this.ymodifier;
    
                    for (int ymod : yarr$) {
                        int[] zarr$ = this.zmodifier;
    
                        for (int zmod : zarr$) {
                            this.cartx = cart.getLocation().getBlockX();
                            this.carty = cart.getLocation().getBlockY();
                            this.cartz = cart.getLocation().getBlockZ();
                            this.blockx = this.cartx + xmod;
                            this.blocky = this.carty + ymod;
                            this.blockz = this.cartz + zmod;
                            this.block = cart.getWorld().getBlockAt(this.blockx, this.blocky, this.blockz);
                            if (this.block == Material.OAK_WALL_SIGN.getId() || this.block == Material.OAK_SIGN.getId()) {
                                Sign sign = (Sign) this.block.getState();
                                String[] text = sign.getLines();
                                if (text[0].equalsIgnoreCase("[mсa]")) {
                                    if (text[1].equalsIgnoreCase("fly")) {
                                        cart.setFlyingVelocityMod(this.flyingmod);
                                    } else if (text[1].equalsIgnoreCase("nofly")) {
                                        cart.setFlyingVelocityMod(this.noflyingmod);
                                    } else {
                                        this.error = false;
    
                                        try {
                                            this.line1 = Double.parseDouble(text[1]);
                                        } catch (Exception var18) {
                                            sign.setLine(2, "  ОШИБКА");
                                            sign.setLine(3, "НЕВЕРНОЕ ЗНАЧЕНИЕ");
                                            sign.update();
                                            this.error = true;
                                        }
    
                                        if (!this.error) {
                                            if (0.0 < this.line1 & this.line1 <= 50.0) {
                                                cart.setMaxSpeed(0.4 * Double.parseDouble(text[1]));
                                            } else {
                                                sign.setLine(2, "  ОШИБКА");
                                                sign.setLine(3, "НЕВЕРНОЕ ЗНАЧЕНИЕ");
                                                sign.update();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
    
        }
    Specifically, the lines confuse me:
    Code:
    this.block = cart.getWorld().getBlockAt(this.blockx, this.blocky, this.blockz);
                            if (this.block == Material.OAK_WALL_SIGN.getId() || this.block == Material.OAK_SIGN.getId())
    Essentially, the first line defines the type of a particular block located at the coordinates assigned to the variables this.blockx, this.blocky, this.blockz. The second line checks whether this particular block is OAK_WALL_SIGN or OAK_SIGN by their ID. These lines refuse to work, but, as Intellij IDEA tells me, the problem is that the comparison operation occurs between different types of variables (this.block is an integer, OAK_WALL_SIGN and OAK_SIGN are strings, due to the fact that integer values have disappeared in new versions block identifiers).
    The point is probably clear to me, but I don’t know which alternative to use to solve my problem. I'm a complete newbie, I decided to practice, please explain where I went wrong.
     
  2. Online

    timtower Administrator Administrator Moderator

    @Shelldonite this.block is a Block, use getType() to get the material, and remove the getId
     
  3. Offline

    Shelldonite

    I replaced getBlockAt() with getType() method. Removed getid() after blocks. Error: Incompatible types: org.bukkit.Material cannot be converted to org.bukkit.block.Block. this.block as you said is org.bukkit.block.Block, while OAK_SIGN and OAK_WALL_SIGN - org.bukkit.Material.
     
  4. Online

    timtower Administrator Administrator Moderator

    @Shelldonite You add it to getBlockAt(), not replace it.
     
Thread Status:
Not open for further replies.

Share This Page