package info.u_team.u_team_core.util.world;

import java.util.function.Function;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.*;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.storage.WorldSavedData;

public class WorldUtil {
	
	public static RayTraceResult rayTraceServerSide(PlayerEntity player, double range) {
		return rayTraceServerSide(player, range, RayTraceFluidMode.NEVER, false, true);
	}
	
	public static RayTraceResult rayTraceServerSide(PlayerEntity player, double range, RayTraceFluidMode liquidMode, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock) {
		Vec3d playerVector = new Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ);
		Vec3d lookVector = player.getLookVec();
		Vec3d locationVector = playerVector.add(lookVector.x * range, lookVector.y * range, lookVector.z * range);
		return player.world.rayTraceBlocks(playerVector, locationVector, liquidMode, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
	}
	
	public static <T extends WorldSavedData> T getSaveData(World world, String name, Function<String, T> function) {
		final DimensionType type = world.getDimension().getType();
		T instance = world.getSavedData(type, function, name);
		if (instance == null) {
			instance = function.apply(name);
			world.setSavedData(type, name, instance);
		}
		return instance;
	}
}

@@ -64,24 +64,24 @@
 unction.
-Function
+Supplier
 ;%0A%0Aimpor
@@ -183,19 +183,35 @@
 aft.
-world.World
+util.math.RayTraceContext.*
 ;%0Aim
@@ -239,31 +239,19 @@
 rld.
-dimension.DimensionType
+ServerWorld
 ;%0Aim
@@ -460,44 +460,41 @@
 ge, 
-RayTraceFluidMode.NEVER, false, true
+BlockMode.OUTLINE, FluidMode.NONE
 );%0A%09
@@ -585,118 +585,60 @@
 ge, 
-RayTraceFluidMode liquid
+Block
 Mode
-,
  b
-oolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock) %7B%0A%09%09
+lockMode, FluidMode fluidMode) %7B%0A%09%09final 
 Vec3
@@ -726,24 +726,30 @@
 er.posZ);%0A%09%09
+final 
 Vec3d lookVe
@@ -778,16 +778,22 @@
 ec();%0A%09%09
+final 
 Vec3d lo
@@ -928,16 +928,36 @@
 eBlocks(
+new RayTraceContext(
 playerVe
@@ -982,78 +982,37 @@
 or, 
-liquidMode, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock
+blockMode, fluidMode, player)
 );%0A%09
@@ -1071,16 +1071,22 @@
 aveData(
+Server
 World wo
@@ -1107,286 +1107,89 @@
 me, 
-Function%3CString, T%3E function) %7B%0A%09%09final DimensionType type = world.getDimension().getType();%0A%09%09T instance = world.getSavedData(type, function, name);%0A%09%09if (instance == null) %7B%0A%09%09%09instance = function.apply(name);%0A%09%09%09world.setSavedData(type, name, instance);%0A%09%09%7D%0A%09%09return instance
+Supplier%3CT%3E function) %7B%0A%09%09return world.getSavedData().getOrCreate(function, name)
 ;%0A%09%7D

Fix raytrace method