Fix data values returned by the query functions in the expression language

This commit is contained in:
TomyLobo 2023-03-09 05:18:23 +01:00
parent f6646aaab1
commit b5b9c6ab86

View File

@ -23,6 +23,7 @@
import com.sk89q.worldedit.internal.expression.ExpressionEnvironment;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.registry.LegacyMapper;
public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
@ -46,40 +47,39 @@ public Vector3 toWorldRel(double x, double y, double z) {
return current.add(x, y, z);
}
@SuppressWarnings("deprecation")
private int getLegacy(BlockVector3 position, int index) {
final int[] legacy = LegacyMapper.getInstance().getLegacyFromBlock(extent.getBlock(position).toImmutableState());
return legacy == null ? 0 : legacy[index];
}
@Override
public int getBlockType(double x, double y, double z) {
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId();
return getLegacy(toWorld(x, y, z), 0);
}
@SuppressWarnings("deprecation")
@Override
public int getBlockData(double x, double y, double z) {
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyData();
return getLegacy(toWorld(x, y, z), 1);
}
@SuppressWarnings("deprecation")
@Override
public int getBlockTypeAbs(double x, double y, double z) {
return extent.getBlock(BlockVector3.at(x, y, z)).getBlockType().getLegacyId();
return getLegacy(BlockVector3.at(x, y, z), 0);
}
@SuppressWarnings("deprecation")
@Override
public int getBlockDataAbs(double x, double y, double z) {
return extent.getBlock(BlockVector3.at(x, y, z)).getBlockType().getLegacyData();
return getLegacy(BlockVector3.at(x, y, z), 1);
}
@SuppressWarnings("deprecation")
@Override
public int getBlockTypeRel(double x, double y, double z) {
return extent.getBlock(toWorldRel(x, y, z).toBlockPoint()).getBlockType().getLegacyId();
return getLegacy(toWorldRel(x, y, z).toBlockPoint(), 0);
}
@SuppressWarnings("deprecation")
@Override
public int getBlockDataRel(double x, double y, double z) {
return extent.getBlock(toWorldRel(x, y, z).toBlockPoint()).getBlockType().getLegacyData();
return getLegacy(toWorldRel(x, y, z).toBlockPoint(), 1);
}
public void setCurrentBlock(Vector3 current) {