SkriptLang / Skript

Skript is a Spigot plugin which allows server admins to customize their server easily, but without the hassle of programming a plugin or asking/paying someone to program a plugin for them.
https://docs.skriptlang.org
GNU General Public License v3.0
1.02k stars 358 forks source link

BlockData - add cloner #6829

Closed ShaneBeee closed 1 day ago

ShaneBeee commented 4 days ago

Description

This PR aims to add a cloner to BlockData.

I noticed an issue someone brought forward the other day, when using BlockData, the data is created at parse time. If you manipulate the data in a command for instance, the original object is manipulated.

EX: (this uses reflect, as that is what they were using in their for instance)

import:
    org.bukkit.block.structure.StructureRotation

command /test:
    trigger:
        set {_d} to oak_stairs[]

        send "Before: &a%{_d}%"

        {_d}.rotate(StructureRotation.CLOCKWISE_90)

        send "After: &b%{_d}%"

When running the command several times:

> test
[10:19:48 INFO]: Before: minecraft:oak_stairs[facing=north;half=bottom;shape=straight;waterlogged=false]
[10:19:48 INFO]: After: minecraft:oak_stairs[facing=east;half=bottom;shape=straight;waterlogged=false]
> test
[10:19:50 INFO]: Before: minecraft:oak_stairs[facing=east;half=bottom;shape=straight;waterlogged=false]
[10:19:50 INFO]: After: minecraft:oak_stairs[facing=south;half=bottom;shape=straight;waterlogged=false]
> test
[10:19:50 INFO]: Before: minecraft:oak_stairs[facing=south;half=bottom;shape=straight;waterlogged=false]
[10:19:50 INFO]: After: minecraft:oak_stairs[facing=west;half=bottom;shape=straight;waterlogged=false]
> test
[10:19:51 INFO]: Before: minecraft:oak_stairs[facing=west;half=bottom;shape=straight;waterlogged=false]
[10:19:51 INFO]: After: minecraft:oak_stairs[facing=north;half=bottom;shape=straight;waterlogged=false]
> test
[10:19:51 INFO]: Before: minecraft:oak_stairs[facing=north;half=bottom;shape=straight;waterlogged=false]
[10:19:51 INFO]: After: minecraft:oak_stairs[facing=east;half=bottom;shape=straight;waterlogged=false]

(take note on "facing") As you can see, the original data is being modified.

Adding a cloner solves this problem. After this PR:

> test
[10:22:39 INFO]: Before: minecraft:oak_stairs[facing=north;half=bottom;shape=straight;waterlogged=false]
[10:22:39 INFO]: After: minecraft:oak_stairs[facing=east;half=bottom;shape=straight;waterlogged=false]
> test
[10:22:39 INFO]: Before: minecraft:oak_stairs[facing=north;half=bottom;shape=straight;waterlogged=false]
[10:22:39 INFO]: After: minecraft:oak_stairs[facing=east;half=bottom;shape=straight;waterlogged=false]
> test
[10:22:40 INFO]: Before: minecraft:oak_stairs[facing=north;half=bottom;shape=straight;waterlogged=false]
[10:22:40 INFO]: After: minecraft:oak_stairs[facing=east;half=bottom;shape=straight;waterlogged=false]
> test
[10:22:40 INFO]: Before: minecraft:oak_stairs[facing=north;half=bottom;shape=straight;waterlogged=false]
[10:22:40 INFO]: After: minecraft:oak_stairs[facing=east;half=bottom;shape=straight;waterlogged=false]
> 

(that note that "shape" doesn't persist)


Target Minecraft Versions: any Requirements: none Related Issues: none