123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- package me.km.api;
- import java.util.Objects;
- import me.km.dimensions.ModDimensions;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.Entity;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.Vec3d;
- import net.minecraft.world.World;
- public class Location
- {
- private final World w;
- private Vec3d pos;
- private float yaw;
- private float pitch;
-
- public Location(World w, Vec3d pos, float yaw, float pitch)
- {
- this.w = w;
- this.pos = pos;
- this.yaw = yaw;
- this.pitch = pitch;
- }
-
- public Location(World w, Vec3d pos)
- {
- this(w, pos, 0, 0);
- }
-
- public Location(World w, BlockPos pos, float yaw, float pitch)
- {
- this(w, new Vec3d(pos.getX(), pos.getY(), pos.getZ()), yaw, pitch);
- }
-
- public Location(World w, BlockPos pos)
- {
- this(w, pos, 0, 0);
- }
-
- public Location(Entity ent)
- {
- this(ent.world, ent.getPositionVector(), ent.rotationYaw, ent.rotationPitch);
- }
-
- public static Location rounded(Entity ent)
- {
- return new Location(ent.world, ent.getPosition());
- }
- @Override
- public int hashCode()
- {
- int hash = 5;
- hash = 73 * hash + Objects.hashCode(this.w);
- hash = 73 * hash + Objects.hashCode(this.pos);
- hash = 73 * hash + Float.floatToIntBits(this.yaw);
- hash = 73 * hash + Float.floatToIntBits(this.pitch);
- return hash;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if(obj.getClass() == Location.class)
- {
- Location l = (Location) obj;
- Vec3d v = l.getPos();
- return l.getWorld().equals(w) && v.equals(pos) && yaw == l.yaw && pitch == l.pitch;
- }
- return false;
- }
-
- public Location add(double x, double y, double z)
- {
- return new Location(w, pos.addVector(x, y, z));
- }
- public World getWorld()
- {
- return w;
- }
- public Vec3d getPos()
- {
- return pos;
- }
-
- public BlockPos getBlockPos()
- {
- return new BlockPos(pos.xCoord, pos.yCoord, pos.zCoord);
- }
- public float getYaw()
- {
- return yaw;
- }
- public float getPitch()
- {
- return pitch;
- }
- public void setPitch(float pitch)
- {
- this.pitch = pitch;
- }
- public void setYaw(float yaw)
- {
- this.yaw = yaw;
- }
-
- public static IBlockState getRelativeBlock(World w, BlockPos pos, int x, int y, int z)
- {
- return w.getBlockState(pos.add(x, y, z));
- }
- @Override
- public String toString()
- {
- return ModDimensions.getWorldName(w) + ":" + pos.xCoord + ":" + pos.yCoord +
- ":" + pos.zCoord + ":" + yaw + ":" + pitch;
- }
- }
|