2019-11-25 06:29:25 +00:00
|
|
|
package com.burnedkirby.TurnBasedMinecraft.common;
|
2018-09-12 05:43:59 +00:00
|
|
|
|
2022-05-17 05:47:42 +00:00
|
|
|
import net.minecraft.core.Registry;
|
|
|
|
import net.minecraft.resources.ResourceKey;
|
|
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.item.ArrowItem;
|
|
|
|
import net.minecraft.world.level.Level;
|
2018-09-17 06:49:10 +00:00
|
|
|
|
2018-09-12 05:43:59 +00:00
|
|
|
public class Utility
|
|
|
|
{
|
|
|
|
public static float yawDirection(double posX, double posZ, double targetX, double targetZ)
|
|
|
|
{
|
|
|
|
double radians = Math.atan2(targetZ - posZ, targetX - posX);
|
|
|
|
radians = (radians - Math.PI / 2.0);
|
|
|
|
if(radians < 0.0)
|
|
|
|
{
|
|
|
|
radians += Math.PI * 2.0;
|
|
|
|
}
|
|
|
|
return (float)(radians * 180.0 / Math.PI);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float pitchDirection(double posX, double posY, double posZ, double targetX, double targetY, double targetZ)
|
|
|
|
{
|
|
|
|
double diffX = targetX - posX;
|
|
|
|
double diffY = targetY - posY;
|
|
|
|
double diffZ = targetZ - posZ;
|
|
|
|
double distance = Math.sqrt(diffX * diffX + diffZ * diffZ);
|
|
|
|
if(Math.abs(diffY) < 0.1)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return (float)(-Math.atan(diffY / distance) * 180.0 / Math.PI);
|
|
|
|
}
|
|
|
|
}
|
2018-09-17 06:49:10 +00:00
|
|
|
|
2022-05-17 05:47:42 +00:00
|
|
|
public static boolean doesPlayerHaveArrows(Player player)
|
2018-09-17 06:49:10 +00:00
|
|
|
{
|
2022-05-17 05:47:42 +00:00
|
|
|
for(int i = 0; i < player.getInventory().getContainerSize(); ++i)
|
2018-09-17 06:49:10 +00:00
|
|
|
{
|
2022-05-17 05:47:42 +00:00
|
|
|
if(player.getInventory().getItem(i).getItem() instanceof ArrowItem)
|
2018-09-17 06:49:10 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-18 07:26:09 +00:00
|
|
|
|
|
|
|
public static double distanceBetweenEntities(Entity a, Entity b)
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
return Math.sqrt(Math.pow(a.getX() - b.getX(), 2.0) + Math.pow(a.getY()- b.getY(), 2.0) + Math.pow(a.getZ()- b.getZ(), 2.0));
|
2020-11-12 08:10:01 +00:00
|
|
|
}
|
|
|
|
|
2022-05-17 05:47:42 +00:00
|
|
|
public static String serializeDimension(ResourceKey<Level> dimObject) {
|
2021-05-21 05:44:31 +00:00
|
|
|
return dimObject.getRegistryName().toString();
|
2020-11-12 08:10:01 +00:00
|
|
|
}
|
|
|
|
|
2022-05-17 05:47:42 +00:00
|
|
|
public static ResourceKey<Level> deserializeDimension(String dimString) {
|
2020-11-12 08:10:01 +00:00
|
|
|
ResourceLocation dimRes = new ResourceLocation(dimString);
|
2022-05-17 05:47:42 +00:00
|
|
|
return ResourceKey.create(Registry.DIMENSION_REGISTRY, dimRes);
|
2018-10-18 07:26:09 +00:00
|
|
|
}
|
2018-09-12 05:43:59 +00:00
|
|
|
}
|