Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.secknv.nkmod.item;
- import javax.annotation.Nullable;
- import net.minecraft.block.Block;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.item.EntityItemFrame;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.IItemPropertyGetter;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import net.secknv.nkmod.tileentity.TileEntityCoil;
- public class NkCompass implements IItemPropertyGetter{
- @SideOnly(Side.CLIENT)
- double rotation;
- @SideOnly(Side.CLIENT)
- double rota;
- @SideOnly(Side.CLIENT)
- long lastUpdateTick;
- @SideOnly(Side.CLIENT)
- public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
- {
- if (entityIn == null && !stack.isOnItemFrame())
- {
- return 0.0F;
- }
- else
- {
- boolean flag = entityIn != null;
- Entity entity = (Entity)(flag ? entityIn : stack.getItemFrame());
- if (worldIn == null)
- {
- worldIn = entity.worldObj;
- }
- double d0;
- if (worldIn.provider.isSurfaceWorld())
- {
- double d1 = flag ? (double)entity.rotationYaw : this.getFrameRotation((EntityItemFrame)entity);
- d1 = d1 % 360.0D;
- double d2 = this.getSpawnToAngle(worldIn, entity);
- d0 = Math.PI - ((d1 - 90.0D) * 0.01745329238474369D - d2);
- }
- else
- {
- d0 = Math.random() * (Math.PI * 2D);
- }
- if (flag)
- {
- d0 = this.wobble(worldIn, d0);
- }
- float f = (float)(d0 / (Math.PI * 2D));
- return MathHelper.positiveModulo(f, 1.0F);
- }
- }
- @SideOnly(Side.CLIENT)
- private double wobble(World p_185093_1_, double p_185093_2_)
- {
- if (p_185093_1_.getTotalWorldTime() != this.lastUpdateTick)
- {
- this.lastUpdateTick = p_185093_1_.getTotalWorldTime();
- double d0 = p_185093_2_ - this.rotation;
- d0 = d0 % (Math.PI * 2D);
- d0 = MathHelper.clamp_double(d0, -1.0D, 1.0D);
- this.rota += d0 * 0.1D;
- this.rota *= 0.8D;
- this.rotation += this.rota;
- }
- return this.rotation;
- }
- @SideOnly(Side.CLIENT)
- private double getFrameRotation(EntityItemFrame p_185094_1_)
- {
- return (double)MathHelper.clampAngle(180 + p_185094_1_.facingDirection.getHorizontalIndex() * 90);
- }
- @SideOnly(Side.CLIENT)
- private double getSpawnToAngle(World worldIn, Entity ent)
- {
- //can I use this to look for nearby Coils?
- //idea is find neraby coil, get it's object and use it's messUpCompass value in the if below
- //worldIn.getEntitiesWithinAABB(EntityPlayer.class, <AABB>)
- //first sets blockpos to world spawnpoint
- BlockPos blockpos = worldIn.getSpawnPoint();;
- //if true changes the blockpos var used to calculate compass angle to the blockpos of the BlockCoil
- if(nearby_coil_object.messUpCompass){
- blockpos = coil_object.getCoilPosition();
- }
- return Math.atan2((double)blockpos.getZ() - ent.posZ, (double)blockpos.getX() - ent.posX);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement