Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlockData - add cloner #6829

Merged
merged 5 commits into from
Jul 1, 2024

Conversation

ShaneBeee
Copy link
Contributor

@ShaneBeee ShaneBeee commented Jun 28, 2024

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

@sovdeeth sovdeeth added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. 2.9 Targeting a 2.9.X version release labels Jun 28, 2024
Copy link
Member

@Pikachu920 Pikachu920 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a test :D

@sovdeeth sovdeeth added the patch-ready A PR/issue that has been approved and is ready to be merged/closed for the next patch version. label Jun 30, 2024
@sovdeeth sovdeeth merged commit 13b230c into SkriptLang:dev/feature Jul 1, 2024
5 checks passed
@ShaneBeee ShaneBeee deleted the fix/block-data-clone branch July 1, 2024 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.9 Targeting a 2.9.X version release bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. patch-ready A PR/issue that has been approved and is ready to be merged/closed for the next patch version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants