Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ItemWayfinderCompass extends Item {
- public int dimension;
- private int posX, posZ;
- public ItemWayfinderCompass(Properties properties) {
- super(properties);
- this.addPropertyOverride(new ResourceLocation("angle"), new IItemPropertyGetter() {
- @OnlyIn(Dist.CLIENT)
- double rotation, rota;
- @OnlyIn(Dist.CLIENT)
- long lastUpdateTick;
- @OnlyIn(Dist.CLIENT)
- public float call(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.world;
- }
- double d0 = 0;
- NBTTagCompound tags = stack.getTag();
- if (tags != null && tags.hasKey("dimension")) {
- dimension = stack.getTag().getInt("dimension");
- if (worldIn.getDimension().getType().getId() == dimension) {
- double d1 = flag ? (double)entity.rotationYaw : this.getFrameRotation((EntityItemFrame)entity);
- d1 = MathHelper.positiveModulo(d1 / 360.0D, 1.0D);
- double d2 = this.getSpawnToAngle(worldIn, entity) / (Math.PI * 2D);
- d0 = 0.5D - (d1 - 0.25D - d2);
- } else {
- d0 = Math.random();
- }
- if (flag) {
- d0 = this.wobble(worldIn, d0);
- }
- return MathHelper.positiveModulo((float)d0, 1.0F);
- } else {
- return (float) MathHelper.positiveModulo((float)d0 * Math.random() * 5, 1.0F);
- }
- }
- }
- @OnlyIn(Dist.CLIENT)
- private double wobble(World worldIn, double p_185093_2_) {
- if (worldIn.getGameTime() != this.lastUpdateTick) {
- this.lastUpdateTick = worldIn.getGameTime();
- double d0 = p_185093_2_ - this.rotation;
- d0 = MathHelper.positiveModulo(d0 + 0.5D, 1.0D) - 0.5D;
- this.rota += d0 * 0.1D;
- this.rota *= 0.8D;
- this.rotation = MathHelper.positiveModulo(this.rotation + this.rota, 1.0D);
- }
- return this.rotation;
- }
- @OnlyIn(Dist.CLIENT)
- private double getFrameRotation(EntityItemFrame p_185094_1_) {
- return (double)MathHelper.wrapDegrees(180 + p_185094_1_.facingDirection.getHorizontalIndex() * 90);
- }
- @OnlyIn(Dist.CLIENT)
- private double getSpawnToAngle(World p_185092_1_, Entity p_185092_2_) {
- if(p_185092_1_ != null && p_185092_2_ instanceof EntityPlayer) {
- EntityPlayer player = (EntityPlayer)p_185092_2_;
- ItemStack itemstack = player.inventory.getCurrentItem();
- if (!itemstack.isEmpty() && itemstack.getItem() == TLSItems.WAYFINDER_COMPASS && itemstack.hasTag() && itemstack.getTag().hasKey("dimension")) {
- posX = itemstack.getTag().getInt("posX");
- posZ = itemstack.getTag().getInt("posZ");
- }
- }
- return Math.atan2((double)posZ - p_185092_2_.posZ, (double)posX - p_185092_2_.posX);
- }
- });
- }
- @OnlyIn(Dist.CLIENT)
- public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> list, ITooltipFlag flagIn) {
- if(!stack.hasTag()) {
- stack.setTag(new NBTTagCompound());
- }
- if(stack.hasTag() && stack.getTag().hasKey("dimension")) {
- list.add(new TextComponentTranslation("tooltip.thelostsea.dimension ", new Object() + stack.getTag().getString("dim_name")));
- list.add(new TextComponentTranslation("tooltip.thelostsea.x ", new Object() + String.valueOf(stack.getTag().getInt("posX"))));
- list.add(new TextComponentTranslation("tooltip.thelostsea.y ", new Object() + String.valueOf(stack.getTag().getInt("posY"))));
- }
- }
- @Override
- public EnumActionResult onItemUse(ItemUseContext context) {
- EntityPlayer player = context.getPlayer();
- BlockPos pos = context.getPos();
- ItemStack stack = player.getHeldItemMainhand();
- NBTTagCompound tags = stack.getTag();
- if(tags == null) {
- tags = new NBTTagCompound();
- }
- Block block = context.getWorld().getBlockState(context.getPos()).getBlock();
- if (context.getPlayer().isSneaking()) {
- if (!context.getWorld().isRemote && block != null) {
- tags.setString("dim_name", player.getEntityWorld().getDimension().getType().getRegistryName().toString());
- tags.setInt("dimension", player.dimension.getId());
- tags.setInt("posX", pos.getX());
- tags.setInt("posZ", pos.getZ());
- stack.setTag(tags);
- return EnumActionResult.SUCCESS;
- }
- }
- return EnumActionResult.FAIL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement