Package info.u_team.u_team_core.util
Class LevelUtil
java.lang.Object
info.u_team.u_team_core.util.LevelUtil
Some utility methods for level interaction.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends net.minecraft.world.level.saveddata.SavedData>
TgetSaveData(net.minecraft.server.level.ServerLevel level, String name, Function<net.minecraft.nbt.CompoundTag, T> load, Supplier<T> defaultData) Get a saved instance (own implementation) ofSavedData.static <T extends net.minecraft.world.level.saveddata.SavedData>
TgetSaveData(net.minecraft.server.level.ServerLevel level, Function<net.minecraft.nbt.CompoundTag, T> load, String name, Function<String, T> defaultData) Get a saved instance (own implementation) ofSavedData.static net.minecraft.server.level.ServerLevelgetServerLevel(net.minecraft.server.MinecraftServer server, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key) Get theServerLevelfrom theResourceKeystatic net.minecraft.server.level.ServerLevelgetServerLevel(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key) Get theServerLevelfrom theResourceKeystatic net.minecraft.world.phys.HitResultrayTraceServerSide(net.minecraft.world.entity.Entity entity, double range) Raytrace from an entities look vector for collisions in range.static net.minecraft.world.phys.HitResultrayTraceServerSide(net.minecraft.world.entity.Entity entity, double range, net.minecraft.world.level.ClipContext.Block blockMode, net.minecraft.world.level.ClipContext.Fluid fluidMode) Raytrace from an entities look vector for collisions in range.static net.minecraft.world.entity.EntityteleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key, double x, double y, double z, float yaw, float pitch) Teleports any entity to a given location in a givenDimensionType.static net.minecraft.world.entity.EntityteleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key, net.minecraft.core.BlockPos pos) Teleports any entity to a given location in a givenServerLevel.static net.minecraft.world.entity.EntityteleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key, net.minecraft.world.phys.Vec3 pos) Teleports any entity to a given location in a givenServerLevel.static net.minecraft.world.entity.EntityteleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, double x, double y, double z, float yaw, float pitch) Teleports any entity to a given location in a givenServerLevel.static net.minecraft.world.entity.EntityteleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, double x, double y, double z, float yaw, float pitch, boolean detach) Teleports any entity to a given location in a givenServerLevel.static net.minecraft.world.entity.EntityteleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos) Teleports any entity to a given location in a givenServerLevel.static net.minecraft.world.entity.EntityteleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, net.minecraft.world.phys.Vec3 pos) Teleports any entity to a given location in a givenServerLevel.
-
Constructor Details
-
LevelUtil
public LevelUtil()
-
-
Method Details
-
rayTraceServerSide
public static net.minecraft.world.phys.HitResult rayTraceServerSide(net.minecraft.world.entity.Entity entity, double range) Raytrace from an entities look vector for collisions in range. Use default block modeClipContext.Block.OUTLINEand fluid modeClipContext.Fluid.NONE.- Parameters:
entity- Entity from where we get the look vectorrange- Range in blocks- Returns:
- Raytrace result with information about the trace
-
rayTraceServerSide
public static net.minecraft.world.phys.HitResult rayTraceServerSide(net.minecraft.world.entity.Entity entity, double range, net.minecraft.world.level.ClipContext.Block blockMode, net.minecraft.world.level.ClipContext.Fluid fluidMode) Raytrace from an entities look vector for collisions in range.- Parameters:
entity- Entity from where we get the look vectorrange- Range in blocksblockMode- Mode for block collisionsfluidMode- Mode for fluid collisions- Returns:
- Raytrace result with information about the trace
-
getSaveData
public static <T extends net.minecraft.world.level.saveddata.SavedData> T getSaveData(net.minecraft.server.level.ServerLevel level, Function<net.minecraft.nbt.CompoundTag, T> load, String name, Function<String, T> defaultData) Get a saved instance (own implementation) ofSavedData. If it does not exist, a new one is created.- Type Parameters:
T- Custom level save data class- Parameters:
level- Server levelname- Name of this datadefaultData- Function for creating an instance and for the default instance- Returns:
- An instance of
with the loaded data or default data.
-
getSaveData
public static <T extends net.minecraft.world.level.saveddata.SavedData> T getSaveData(net.minecraft.server.level.ServerLevel level, String name, Function<net.minecraft.nbt.CompoundTag, T> load, Supplier<T> defaultData) Get a saved instance (own implementation) ofSavedData. If it does not exist, a new one is created.- Type Parameters:
T- Custom level save data class- Parameters:
level- Server levelname- Name of this datadefaultData- Supplier for creating an instance and for the default instance- Returns:
- An instance of
with the loaded data or default data.
-
getServerLevel
public static net.minecraft.server.level.ServerLevel getServerLevel(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key) Get theServerLevelfrom theResourceKey- Parameters:
entity- An entity used to get the server instance withEntity.getServer()key- The dimension key- Returns:
- The server level for the given key
-
getServerLevel
public static net.minecraft.server.level.ServerLevel getServerLevel(net.minecraft.server.MinecraftServer server, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key) Get theServerLevelfrom theResourceKey- Parameters:
server- The server instancekey- The dimension key- Returns:
- The server level for the given key
-
teleportEntity
public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key, net.minecraft.core.BlockPos pos) Teleports any entity to a given location in a givenServerLevel. Don't change the yaw and pitch of the entity.- Parameters:
entity- The entity to teleportkey- The dimension key where the entity should be teleported. Can be the same as the current dimension key or a different onepos- The position the entity should be teleported to- Returns:
- The teleported entity
-
teleportEntity
public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key, net.minecraft.world.phys.Vec3 pos) Teleports any entity to a given location in a givenServerLevel. Don't change the yaw and pitch of the entity.- Parameters:
entity- The entity to teleportkey- The dimension key where the entity should be teleported. Can be the same as the current dimension key or a different onepos- The position the entity should be teleported to- Returns:
- The teleported entity
-
teleportEntity
public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos) Teleports any entity to a given location in a givenServerLevel. Don't change the yaw and pitch of the entity.- Parameters:
entity- The entity to teleportlevel- The server level where the entity should be teleported. Can be the same as the current level or a different onepos- The position the entity should be teleported to- Returns:
- The teleported entity
-
teleportEntity
public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, net.minecraft.world.phys.Vec3 pos) Teleports any entity to a given location in a givenServerLevel. Don't change the yaw and pitch of the entity.- Parameters:
entity- The entity to teleportlevel- The server level where the entity should be teleported. Can be the same as the current level or a different onepos- The position the entity should be teleported to- Returns:
- The teleported entity
-
teleportEntity
public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key, double x, double y, double z, float yaw, float pitch) Teleports any entity to a given location in a givenDimensionType.- Parameters:
entity- The entity to teleportkey- The dimension key where the entity should be teleported. Can be the same as the current dimension key or a different onex- X-Coordinatey- Y-Coordinatez- Z-Coordinateyaw- Yawpitch- Pitch- Returns:
- The teleported entity
-
teleportEntity
public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, double x, double y, double z, float yaw, float pitch) Teleports any entity to a given location in a givenServerLevel.- Parameters:
entity- The entity to teleportlevel- The server level where the entity should be teleported. Can be the same as the current level or a different onex- X-Coordinatey- Y-Coordinatez- Z-Coordinateyaw- Yawpitch- Pitch- Returns:
- The teleported entity
-
teleportEntity
public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, double x, double y, double z, float yaw, float pitch, boolean detach) Teleports any entity to a given location in a givenServerLevel.- Parameters:
entity- The entity to teleportlevel- The server level where the entity should be teleported. Can be the same as the current level or a different onex- X-Coordinatey- Y-Coordinatez- Z-Coordinateyaw- Yawpitch- Pitchdetach- Detach the entity- Returns:
- The teleported entity
-